X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/be2c4488bff82d0d3d377429f3cefc969a7c6645..d48ae46b24b5c9e1e76bea82fbf6fe557fa3f087:/tests/arrays/arrays.cpp diff --git a/tests/arrays/arrays.cpp b/tests/arrays/arrays.cpp index 0e52f865e7..a776a2c1db 100644 --- a/tests/arrays/arrays.cpp +++ b/tests/arrays/arrays.cpp @@ -11,7 +11,7 @@ // headers // ---------------------------------------------------------------------------- -#include "wx/wxprec.h" +#include "testprec.h" #ifdef __BORLANDC__ #pragma hdrstop @@ -23,8 +23,6 @@ #include "wx/dynarray.h" -#include "wx/cppunit.h" - // ---------------------------------------------------------------------------- // helpers for testing values and sizes // ---------------------------------------------------------------------------- @@ -127,12 +125,18 @@ int wxCMPFUNC_CONV name ## RevCompare(T* first, T* second) \ typedef unsigned short ushort; +DEFINE_COMPARE(Char, char); DEFINE_COMPARE(UShort, ushort); DEFINE_COMPARE(Int, int); +WX_DEFINE_ARRAY_CHAR(char, wxArrayChar); +WX_DEFINE_SORTED_ARRAY_CHAR(char, wxSortedArrayCharNoCmp); +WX_DEFINE_SORTED_ARRAY_CMP_CHAR(char, CharCompareValues, wxSortedArrayChar); + WX_DEFINE_ARRAY_SHORT(ushort, wxArrayUShort); WX_DEFINE_SORTED_ARRAY_SHORT(ushort, wxSortedArrayUShortNoCmp); WX_DEFINE_SORTED_ARRAY_CMP_SHORT(ushort, UShortCompareValues, wxSortedArrayUShort); + WX_DEFINE_SORTED_ARRAY_CMP_INT(int, IntCompareValues, wxSortedArrayInt); // ---------------------------------------------------------------------------- @@ -150,14 +154,18 @@ private: CPPUNIT_TEST( wxObjArrayTest ); CPPUNIT_TEST( wxArrayUShortTest ); CPPUNIT_TEST( wxArrayIntTest ); + CPPUNIT_TEST( wxArrayCharTest ); CPPUNIT_TEST( TestSTL ); + CPPUNIT_TEST( Alloc ); CPPUNIT_TEST_SUITE_END(); void wxStringArrayTest(); void wxObjArrayTest(); void wxArrayUShortTest(); void wxArrayIntTest(); + void wxArrayCharTest(); void TestSTL(); + void Alloc(); DECLARE_NO_COPY_CLASS(ArraysTestCase) }; @@ -190,7 +198,7 @@ void ArraysTestCase::wxStringArrayTest() wxArrayString a2(a1); - CPPUNIT_ASSERT( COMPARE_8_VALUES( a2 , _T("thermit") , + CPPUNIT_ASSERT( COMPARE_8_VALUES( a2 , _T("thermit") , _T("condor") , _T("lion") , _T("lion") , @@ -202,7 +210,7 @@ void ArraysTestCase::wxStringArrayTest() wxSortedArrayString a3(a1); - CPPUNIT_ASSERT( COMPARE_8_VALUES( a3 , _T("alligator") , + CPPUNIT_ASSERT( COMPARE_8_VALUES( a3 , _T("alligator") , _T("condor") , _T("dog") , _T("human") , @@ -216,7 +224,7 @@ void ArraysTestCase::wxStringArrayTest() for (wxArrayString::iterator it = a1.begin(), en = a1.end(); it != en; ++it) a4.Add(*it); - CPPUNIT_ASSERT( COMPARE_8_VALUES( a4 , _T("alligator") , + CPPUNIT_ASSERT( COMPARE_8_VALUES( a4 , _T("alligator") , _T("condor") , _T("dog") , _T("human") , @@ -270,6 +278,22 @@ void ArraysTestCase::wxStringArrayTest() _T("thermit") , _T("alligator") ) ); CPPUNIT_ASSERT( COMPARE_COUNT( a1 , 5 ) ); + CPPUNIT_ASSERT( a1.Index( _T("dog") ) == 0 ); + CPPUNIT_ASSERT( a1.Index( _T("human") ) == 1 ); + CPPUNIT_ASSERT( a1.Index( _T("humann") ) == wxNOT_FOUND ); + CPPUNIT_ASSERT( a1.Index( _T("condor") ) == 2 ); + CPPUNIT_ASSERT( a1.Index( _T("thermit") ) == 3 ); + CPPUNIT_ASSERT( a1.Index( _T("alligator") ) == 4 ); + + wxArrayString a5; + + CPPUNIT_ASSERT( a5.Add( _T("x"), 1 ) == 0 ); + CPPUNIT_ASSERT( a5.Add( _T("a"), 3 ) == 1 ); + + CPPUNIT_ASSERT( COMPARE_4_VALUES( a5, _T("x") , + _T("a") , + _T("a") , + _T("a") ) ); } void ArraysTestCase::wxObjArrayTest() @@ -332,33 +356,65 @@ 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); +TestArrayOf(Char); + TestArrayOf(Int); +void ArraysTestCase::Alloc() +{ + wxArrayInt a; + a.Add(17); + a.Add(9); + CPPUNIT_ASSERT_EQUAL( size_t(2), a.GetCount() ); + + a.Alloc(1000); + + CPPUNIT_ASSERT_EQUAL( size_t(2), a.GetCount() ); + CPPUNIT_ASSERT_EQUAL( 17, a[0] ); + CPPUNIT_ASSERT_EQUAL( 9, a[1] ); +} + void ArraysTestCase::TestSTL() { wxArrayInt list1; wxArrayInt::iterator it, en; wxArrayInt::reverse_iterator rit, ren; int i; - for ( i = 0; i < 5; ++i ) + static const int COUNT = 5; + + for ( i = 0; i < COUNT; ++i ) list1.push_back(i); + CPPUNIT_ASSERT( list1.capacity() >= (size_t)COUNT ); + CPPUNIT_ASSERT_EQUAL( (size_t)COUNT, list1.size() ); + for ( it = list1.begin(), en = list1.end(), i = 0; it != en; ++it, ++i ) { CPPUNIT_ASSERT( *it == i ); } - for ( rit = list1.rbegin(), ren = list1.rend(), i = 4; + CPPUNIT_ASSERT_EQUAL( COUNT, i ); + + for ( rit = list1.rbegin(), ren = list1.rend(), i = COUNT; rit != ren; ++rit, --i ) { - CPPUNIT_ASSERT( *rit == i ); + CPPUNIT_ASSERT( *rit == i-1 ); } + CPPUNIT_ASSERT_EQUAL( 0, i ); + CPPUNIT_ASSERT( *list1.rbegin() == *(list1.end()-1) && *list1.begin() == *(list1.rend()-1) ); @@ -367,7 +423,7 @@ void ArraysTestCase::TestSTL() CPPUNIT_ASSERT( *list1.begin() == *(it-1) && *list1.rbegin() == *(rit-1) ); - CPPUNIT_ASSERT( ( list1.front() == 0 ) && ( list1.back() == 4 ) ); + CPPUNIT_ASSERT( ( list1.front() == 0 ) && ( list1.back() == COUNT - 1 ) ); list1.erase(list1.begin()); list1.erase(list1.end()-1);