From 10dcbe6369f40ed96a7fad6a0aee6c74a6366759 Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Sat, 22 Jan 2005 13:28:49 +0000 Subject: [PATCH] Fix wxSortedArray::Index() when wxUSE_STL == 1, with tests. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31559 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/dynarray.cpp | 4 ++-- tests/arrays/arrays.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/common/dynarray.cpp b/src/common/dynarray.cpp index 738e9813a3..4f4915a25b 100644 --- a/src/common/dynarray.cpp +++ b/src/common/dynarray.cpp @@ -99,8 +99,8 @@ int name::Index(T lItem, CMPFUNC fnCompare) const \ { \ Predicate p((SCMPFUNC)fnCompare); \ const_iterator it = std::lower_bound(begin(), end(), lItem, p); \ - return (it != end() && \ - p(lItem, *it)) ? (int)(it - begin()) : wxNOT_FOUND; \ + return (it != end() && !p(lItem, *it)) ? \ + (int)(it - begin()) : wxNOT_FOUND; \ } \ \ void name::Shrink() \ diff --git a/tests/arrays/arrays.cpp b/tests/arrays/arrays.cpp index 719b266f30..c27f6a4a2d 100644 --- a/tests/arrays/arrays.cpp +++ b/tests/arrays/arrays.cpp @@ -268,6 +268,12 @@ void ArraysTestCase::wxStringArrayTest() _T("thermit") , _T("alligator") ) ); CPPUNIT_ASSERT( COMPARE_COUNT( a1 , 5 ) ); + CPPUNIT_ASSERT( a1.Index( "dog" ) == 0 ); + CPPUNIT_ASSERT( a1.Index( "human" ) == 1 ); + CPPUNIT_ASSERT( a1.Index( "humann" ) == wxNOT_FOUND ); + CPPUNIT_ASSERT( a1.Index( "condor" ) == 2 ); + CPPUNIT_ASSERT( a1.Index( "thermit" ) == 3 ); + CPPUNIT_ASSERT( a1.Index( "alligator" ) == 4 ); } void ArraysTestCase::wxObjArrayTest() @@ -330,6 +336,13 @@ void ArraysTestCase::wxArray ## name ## Test() \ \ CPPUNIT_ASSERT( COMPARE_4_VALUES(b,1,3,5,17) ); \ CPPUNIT_ASSERT( COMPARE_COUNT( b , 4 ) ); \ + CPPUNIT_ASSERT( b.Index( 0 ) == wxNOT_FOUND ); \ + CPPUNIT_ASSERT( b.Index( 1 ) == 0 ); \ + CPPUNIT_ASSERT( b.Index( 3 ) == 1 ); \ + CPPUNIT_ASSERT( b.Index( 4 ) == wxNOT_FOUND ); \ + CPPUNIT_ASSERT( b.Index( 5 ) == 2 ); \ + CPPUNIT_ASSERT( b.Index( 6 ) == wxNOT_FOUND ); \ + CPPUNIT_ASSERT( b.Index( 17 ) == 3 ); \ } TestArrayOf(UShort); -- 2.45.2