1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/arrays/arrays.cpp
3 // Purpose: wxArray unit test
4 // Author: Vadim Zeitlin, Wlodzimierz ABX Skiba
6 // Copyright: (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
23 #include "wx/dynarray.h"
25 // ----------------------------------------------------------------------------
26 // helpers for testing values and sizes
27 // ----------------------------------------------------------------------------
29 #define COMPARE_VALUE( array , index , value ) ( array.Item( index ) == value )
31 #define COMPARE_2_VALUES( array , p0 , p1 ) \
32 COMPARE_VALUE( array , 0 , p0 ) && \
33 COMPARE_VALUE( array , 1 , p1 )
35 #define COMPARE_3_VALUES( array , p0 , p1 , p2 ) \
36 COMPARE_2_VALUES( array , p0 , p1 ) && \
37 COMPARE_VALUE( array , 2 , p2 )
39 #define COMPARE_4_VALUES( array , p0 , p1 , p2 , p3 ) \
40 COMPARE_3_VALUES( array , p0 , p1 , p2 ) && \
41 COMPARE_VALUE( array , 3 , p3 )
43 #define COMPARE_5_VALUES( array , p0 , p1 , p2 , p3 , p4 ) \
44 COMPARE_4_VALUES( array , p0 , p1 , p2 , p3 ) && \
45 COMPARE_VALUE( array , 4 , p4 )
47 #define COMPARE_6_VALUES( array , p0 , p1 , p2 , p3 , p4 , p5 ) \
48 COMPARE_5_VALUES( array , p0 , p1 , p2 , p3 , p4 ) && \
49 COMPARE_VALUE( array , 5 , p5 )
51 #define COMPARE_7_VALUES( array , p0 , p1 , p2 , p3 , p4 , p5 , p6 ) \
52 COMPARE_6_VALUES( array , p0 , p1 , p2 , p3 , p4 , p5 ) && \
53 COMPARE_VALUE( array , 6 , p6 )
55 #define COMPARE_8_VALUES( array , p0 , p1 , p2 , p3 , p4 , p5 , p6 , p7 ) \
56 COMPARE_7_VALUES( array , p0 , p1 , p2 , p3 , p4 , p5 , p6 ) && \
57 COMPARE_VALUE( array , 7 , p7 )
59 #define COMPARE_9_VALUES( array , p0 , p1 , p2 , p3 , p4 , p5 , p6 , p7 , p8 ) \
60 COMPARE_8_VALUES( array , p0 , p1 , p2 , p3 , p4 , p5 , p6 , p7 ) && \
61 COMPARE_VALUE( array , 8 , p8 )
63 #define COMPARE_10_VALUES( array , p0 , p1 , p2 , p3 , p4 , p5 , p6 , p7 , p8 , p9 ) \
64 COMPARE_9_VALUES( array , p0 , p1 , p2 , p3 , p4 , p5 , p6 , p7 , p8 ) && \
65 COMPARE_VALUE( array , 9 , p9 )
67 #define COMPARE_COUNT( array , n ) \
68 ( array.GetCount() == n ) && \
69 ( array.Last() == array.Item( n - 1 ) )
71 // ----------------------------------------------------------------------------
72 // helpers for testing wxObjArray
73 // ----------------------------------------------------------------------------
78 Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; }
79 Bar(const Bar
& bar
) : m_name(bar
.m_name
) { ms_bars
++; }
82 static size_t GetNumber() { return ms_bars
; }
84 const wxChar
*GetName() const { return m_name
.c_str(); }
89 static size_t ms_bars
;
92 size_t Bar::ms_bars
= 0;
94 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
95 #include "wx/arrimpl.cpp"
96 WX_DEFINE_OBJARRAY(ArrayBars
)
98 // ----------------------------------------------------------------------------
99 // helpers for sorting arrays and comparing items
100 // ----------------------------------------------------------------------------
102 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
103 const wxString
& second
)
105 return first
.length() - second
.length();
108 #define DEFINE_COMPARE(name, T) \
110 int wxCMPFUNC_CONV name ## CompareValues(T first, T second) \
112 return first - second; \
115 int wxCMPFUNC_CONV name ## Compare(T* first, T* second) \
117 return *first - *second; \
120 int wxCMPFUNC_CONV name ## RevCompare(T* first, T* second) \
122 return *second - *first; \
125 typedef unsigned short ushort;
127 DEFINE_COMPARE(Char
, char)
128 DEFINE_COMPARE(UShort
, ushort
)
129 DEFINE_COMPARE(Int
, int)
131 WX_DEFINE_ARRAY_CHAR(char, wxArrayChar
);
132 WX_DEFINE_SORTED_ARRAY_CHAR(char, wxSortedArrayCharNoCmp
);
133 WX_DEFINE_SORTED_ARRAY_CMP_CHAR(char, CharCompareValues
, wxSortedArrayChar
);
135 WX_DEFINE_ARRAY_SHORT(ushort
, wxArrayUShort
);
136 WX_DEFINE_SORTED_ARRAY_SHORT(ushort
, wxSortedArrayUShortNoCmp
);
137 WX_DEFINE_SORTED_ARRAY_CMP_SHORT(ushort
, UShortCompareValues
, wxSortedArrayUShort
);
139 WX_DEFINE_SORTED_ARRAY_CMP_INT(int, IntCompareValues
, wxSortedArrayInt
);
143 Item(int n_
= 0) : n(n_
) { }
148 WX_DEFINE_ARRAY_PTR(Item
*, ItemPtrArray
);
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 class ArraysTestCase
: public CppUnit::TestCase
160 CPPUNIT_TEST_SUITE( ArraysTestCase
);
161 CPPUNIT_TEST( wxStringArrayTest
);
162 CPPUNIT_TEST( SortedArray
);
163 CPPUNIT_TEST( wxStringArraySplitTest
);
164 CPPUNIT_TEST( wxStringArrayJoinTest
);
165 CPPUNIT_TEST( wxStringArraySplitJoinTest
);
167 CPPUNIT_TEST( wxObjArrayTest
);
168 CPPUNIT_TEST( wxArrayUShortTest
);
169 CPPUNIT_TEST( wxArrayIntTest
);
170 CPPUNIT_TEST( wxArrayCharTest
);
171 CPPUNIT_TEST( TestSTL
);
172 CPPUNIT_TEST( Alloc
);
173 CPPUNIT_TEST( Clear
);
174 CPPUNIT_TEST( Swap
);
175 CPPUNIT_TEST( IndexFromEnd
);
176 CPPUNIT_TEST_SUITE_END();
178 void wxStringArrayTest();
180 void wxStringArraySplitTest();
181 void wxStringArrayJoinTest();
182 void wxStringArraySplitJoinTest();
183 void wxObjArrayTest();
184 void wxArrayUShortTest();
185 void wxArrayIntTest();
186 void wxArrayCharTest();
193 DECLARE_NO_COPY_CLASS(ArraysTestCase
)
196 // register in the unnamed registry so that these tests are run by default
197 CPPUNIT_TEST_SUITE_REGISTRATION( ArraysTestCase
);
199 // also include in its own registry so that these tests can be run alone
200 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ArraysTestCase
, "ArraysTestCase" );
202 void ArraysTestCase::wxStringArrayTest()
205 a1
.Add(wxT("thermit"));
206 a1
.Add(wxT("condor"));
207 a1
.Add(wxT("lion"), 3);
209 a1
.Add(wxT("human"));
210 a1
.Add(wxT("alligator"));
212 CPPUNIT_ASSERT( COMPARE_8_VALUES( a1
, wxT("thermit") ,
219 wxT("alligator") ) );
220 CPPUNIT_ASSERT( COMPARE_COUNT( a1
, 8 ) );
222 wxArrayString
a2(a1
);
224 CPPUNIT_ASSERT( COMPARE_8_VALUES( a2
, wxT("thermit") ,
231 wxT("alligator") ) );
232 CPPUNIT_ASSERT( COMPARE_COUNT( a2
, 8 ) );
234 wxSortedArrayString
a3(a1
);
236 CPPUNIT_ASSERT( COMPARE_8_VALUES( a3
, wxT("alligator") ,
244 CPPUNIT_ASSERT( COMPARE_COUNT( a3
, 8 ) );
246 wxSortedArrayString a4
;
247 for (wxArrayString::iterator it
= a1
.begin(), en
= a1
.end(); it
!= en
; ++it
)
250 CPPUNIT_ASSERT( COMPARE_8_VALUES( a4
, wxT("alligator") ,
258 CPPUNIT_ASSERT( COMPARE_COUNT( a4
, 8 ) );
262 CPPUNIT_ASSERT( COMPARE_5_VALUES( a1
, wxT("thermit") ,
266 wxT("alligator") ) );
267 CPPUNIT_ASSERT( COMPARE_COUNT( a1
, 5 ) );
271 CPPUNIT_ASSERT( COMPARE_5_VALUES( a2
, wxT("thermit") ,
275 wxT("alligator") ) );
276 CPPUNIT_ASSERT( COMPARE_COUNT( a2
, 5 ) );
280 CPPUNIT_ASSERT( COMPARE_5_VALUES( a1
, wxT("alligator") ,
285 CPPUNIT_ASSERT( COMPARE_COUNT( a1
, 5 ) );
289 CPPUNIT_ASSERT( COMPARE_5_VALUES( a1
, wxT("thermit") ,
293 wxT("alligator") ) );
294 CPPUNIT_ASSERT( COMPARE_COUNT( a1
, 5 ) );
296 a1
.Sort(&StringLenCompare
);
298 CPPUNIT_ASSERT( COMPARE_5_VALUES( a1
, wxT("dog") ,
302 wxT("alligator") ) );
303 CPPUNIT_ASSERT( COMPARE_COUNT( a1
, 5 ) );
304 CPPUNIT_ASSERT( a1
.Index( wxT("dog") ) == 0 );
305 CPPUNIT_ASSERT( a1
.Index( wxT("human") ) == 1 );
306 CPPUNIT_ASSERT( a1
.Index( wxT("humann") ) == wxNOT_FOUND
);
307 CPPUNIT_ASSERT( a1
.Index( wxT("condor") ) == 2 );
308 CPPUNIT_ASSERT( a1
.Index( wxT("thermit") ) == 3 );
309 CPPUNIT_ASSERT( a1
.Index( wxT("alligator") ) == 4 );
311 CPPUNIT_ASSERT( a1
.Index( wxT("dog"), /*bCase=*/true, /*fromEnd=*/true ) == 0 );
312 CPPUNIT_ASSERT( a1
.Index( wxT("human"), /*bCase=*/true, /*fromEnd=*/true ) == 1 );
313 CPPUNIT_ASSERT( a1
.Index( wxT("humann"), /*bCase=*/true, /*fromEnd=*/true ) == wxNOT_FOUND
);
314 CPPUNIT_ASSERT( a1
.Index( wxT("condor"), /*bCase=*/true, /*fromEnd=*/true ) == 2 );
315 CPPUNIT_ASSERT( a1
.Index( wxT("thermit"), /*bCase=*/true, /*fromEnd=*/true ) == 3 );
316 CPPUNIT_ASSERT( a1
.Index( wxT("alligator"), /*bCase=*/true, /*fromEnd=*/true ) == 4 );
320 CPPUNIT_ASSERT( a5
.Add( wxT("x"), 1 ) == 0 );
321 CPPUNIT_ASSERT( a5
.Add( wxT("a"), 3 ) == 1 );
323 CPPUNIT_ASSERT( COMPARE_4_VALUES( a5
, wxT("x") ,
328 a5
.assign(a1
.end(), a1
.end());
329 CPPUNIT_ASSERT( a5
.empty() );
331 a5
.assign(a1
.begin(), a1
.end());
332 CPPUNIT_ASSERT( a5
== a1
);
334 #ifdef wxHAS_VECTOR_TEMPLATE_ASSIGN
335 const wxString months
[] = { "Jan", "Feb", "Mar" };
336 a5
.assign(months
, months
+ WXSIZEOF(months
));
337 CPPUNIT_ASSERT_EQUAL( WXSIZEOF(months
), a5
.size() );
338 CPPUNIT_ASSERT( COMPARE_3_VALUES(a5
, "Jan", "Feb", "Mar") );
339 #endif // wxHAS_VECTOR_TEMPLATE_ASSIGN
342 CPPUNIT_ASSERT_EQUAL( 0, a5
.size() );
345 CPPUNIT_ASSERT_EQUAL( 7, a5
.size() );
346 CPPUNIT_ASSERT_EQUAL( "Foo", a5
[3] );
349 CPPUNIT_ASSERT_EQUAL( 3, a5
.size() );
350 CPPUNIT_ASSERT_EQUAL( "Foo", a5
[2] );
353 void ArraysTestCase::SortedArray()
355 wxSortedArrayString a
;
358 CPPUNIT_ASSERT_EQUAL( 0, a
.Index("c") );
362 CPPUNIT_ASSERT_EQUAL( 0, a
.Index("a") );
365 void ArraysTestCase::wxStringArraySplitTest()
370 wxString str
= wxT(",,,,first,second,third,,");
371 const wxChar
*expected
[] =
372 { wxT(""), wxT(""), wxT(""), wxT(""), wxT("first"),
373 wxT("second"), wxT("third"), wxT(""), wxT("") };
375 wxArrayString
exparr(WXSIZEOF(expected
), expected
);
376 wxArrayString
realarr(wxSplit(str
, wxT(',')));
377 CPPUNIT_ASSERT( exparr
== realarr
);
381 wxString str
= wxT(",\\,first,second,third,");
382 const wxChar
*expected
[] =
383 { wxT(""), wxT(",first"), wxT("second"), wxT("third"), wxT("") };
384 const wxChar
*expected2
[] =
385 { wxT(""), wxT("\\"), wxT("first"), wxT("second"), wxT("third"), wxT("") };
388 wxArrayString
exparr(WXSIZEOF(expected
), expected
);
389 wxArrayString
realarr(wxSplit(str
, wxT(','), wxT('\\')));
390 CPPUNIT_ASSERT( exparr
== realarr
);
392 // escaping turned off:
393 wxArrayString
exparr2(WXSIZEOF(expected2
), expected2
);
394 wxArrayString
realarr2(wxSplit(str
, wxT(','), wxT('\0')));
395 CPPUNIT_ASSERT( exparr2
== realarr2
);
399 // test is escape characters placed before non-separator character are
400 // just ignored as they should:
401 wxString str
= wxT(",\\,,fir\\st,se\\cond\\,,\\third");
402 const wxChar
*expected
[] =
403 { wxT(""), wxT(","), wxT("fir\\st"), wxT("se\\cond,"), wxT("\\third") };
404 const wxChar
*expected2
[] =
405 { wxT(""), wxT("\\"), wxT(""), wxT("fir\\st"), wxT("se\\cond\\"),
406 wxT(""), wxT("\\third") };
409 wxArrayString
exparr(WXSIZEOF(expected
), expected
);
410 wxArrayString
realarr(wxSplit(str
, wxT(','), wxT('\\')));
411 CPPUNIT_ASSERT( exparr
== realarr
);
413 // escaping turned off:
414 wxArrayString
exparr2(WXSIZEOF(expected2
), expected2
);
415 wxArrayString
realarr2(wxSplit(str
, wxT(','), wxT('\0')));
416 CPPUNIT_ASSERT( exparr2
== realarr2
);
420 void ArraysTestCase::wxStringArrayJoinTest()
425 const wxChar
*arr
[] = { wxT("first"), wxT(""), wxT("second"), wxT("third") };
426 wxString expected
= wxT("first,,second,third");
428 wxArrayString
arrstr(WXSIZEOF(arr
), arr
);
429 wxString result
= wxJoin(arrstr
, wxT(','));
430 CPPUNIT_ASSERT( expected
== result
);
434 const wxChar
*arr
[] = { wxT("first, word"), wxT(",,second"), wxT("third,,") };
435 wxString expected
= wxT("first\\, word,\\,\\,second,third\\,\\,");
436 wxString expected2
= wxT("first, word,,,second,third,,");
439 wxArrayString
arrstr(WXSIZEOF(arr
), arr
);
440 wxString result
= wxJoin(arrstr
, wxT(','), wxT('\\'));
441 CPPUNIT_ASSERT( expected
== result
);
443 // escaping turned off:
444 wxString result2
= wxJoin(arrstr
, wxT(','), wxT('\0'));
445 CPPUNIT_ASSERT( expected2
== result2
);
449 // test is escape characters placed in the original array are just ignored as they should:
450 const wxChar
*arr
[] = { wxT("first\\, wo\\rd"), wxT("seco\\nd"), wxT("\\third\\") };
451 wxString expected
= wxT("first\\\\, wo\\rd,seco\\nd,\\third\\");
452 wxString expected2
= wxT("first\\, wo\\rd,seco\\nd,\\third\\");
455 wxArrayString
arrstr(WXSIZEOF(arr
), arr
);
456 wxString result
= wxJoin(arrstr
, wxT(','), wxT('\\'));
457 CPPUNIT_ASSERT( expected
== result
);
459 // escaping turned off:
460 wxString result2
= wxJoin(arrstr
, wxT(','), wxT('\0'));
461 CPPUNIT_ASSERT( expected2
== result2
);
465 void ArraysTestCase::wxStringArraySplitJoinTest()
467 wxChar separators
[] = { wxT('a'), wxT(','), wxT('_'), wxT(' '), wxT('\\'),
468 wxT('&'), wxT('{'), wxT('A'), wxT('<'), wxT('>'),
469 wxT('\''), wxT('\n'), wxT('!'), wxT('-') };
471 // test with a string: split it and then rejoin it:
473 wxString str
= wxT("This is a long, long test; if wxSplit and wxJoin do work ")
474 wxT("correctly, then splitting and joining this 'text' _multiple_ ")
475 wxT("times shouldn't cause any loss of content.\n")
476 wxT("This is some latex code: ")
477 wxT("\\func{wxString}{wxJoin}{")
478 wxT("\\param{const wxArray String\\&}{ arr}, ")
479 wxT("\\param{const wxChar}{ sep}, ")
480 wxT("\\param{const wxChar}{ escape = '\\'}}.\n")
481 wxT("This is some HTML code: ")
482 wxT("<html><head><meta http-equiv=\"content-type\">")
483 wxT("<title>Initial page of Mozilla Firefox</title>")
484 wxT("</meta></head></html>");
487 for (i
= 0; i
< WXSIZEOF(separators
); i
++)
489 wxArrayString arr
= wxSplit(str
, separators
[i
]);
490 CPPUNIT_ASSERT( str
== wxJoin(arr
, separators
[i
]) );
494 // test with an array: join it and then resplit it:
496 const wxChar
*arr
[] =
498 wxT("first, second!"), wxT("this is the third!!"),
499 wxT("\nThat's the fourth token\n\n"), wxT(" - fifth\ndummy\ntoken - "),
500 wxT("_sixth__token__with_underscores"), wxT("The! Last! One!")
502 wxArrayString
theArr(WXSIZEOF(arr
), arr
);
504 for (i
= 0; i
< WXSIZEOF(separators
); i
++)
506 wxString string
= wxJoin(theArr
, separators
[i
]);
507 CPPUNIT_ASSERT( theArr
== wxSplit(string
, separators
[i
]) );
510 wxArrayString emptyArray
;
511 wxString string
= wxJoin(emptyArray
, wxT(';'));
512 CPPUNIT_ASSERT( string
.empty() );
514 CPPUNIT_ASSERT( wxSplit(string
, wxT(';')).empty() );
516 CPPUNIT_ASSERT_EQUAL( 2, wxSplit(wxT(";"), wxT(';')).size() );
519 void ArraysTestCase::wxObjArrayTest()
523 Bar
bar(wxT("first bar in general, second bar in array (two copies!)"));
525 CPPUNIT_ASSERT_EQUAL( 0, bars
.GetCount() );
526 CPPUNIT_ASSERT_EQUAL( 1, Bar::GetNumber() );
528 bars
.Add(new Bar(wxT("first bar in array")));
531 CPPUNIT_ASSERT_EQUAL( 3, bars
.GetCount() );
532 CPPUNIT_ASSERT_EQUAL( 4, Bar::GetNumber() );
534 bars
.RemoveAt(1, bars
.GetCount() - 1);
536 CPPUNIT_ASSERT_EQUAL( 1, bars
.GetCount() );
537 CPPUNIT_ASSERT_EQUAL( 2, Bar::GetNumber() );
541 CPPUNIT_ASSERT_EQUAL( 0, bars
.GetCount() );
542 CPPUNIT_ASSERT_EQUAL( 1, Bar::GetNumber() );
544 CPPUNIT_ASSERT_EQUAL( 0, Bar::GetNumber() );
547 #define TestArrayOf(name) \
549 void ArraysTestCase::wxArray ## name ## Test() \
557 CPPUNIT_ASSERT( COMPARE_10_VALUES(a,1,17,17,5,5,5,3,3,3,3) ); \
558 CPPUNIT_ASSERT( COMPARE_COUNT( a , 10 ) ); \
560 a.Sort(name ## Compare); \
562 CPPUNIT_ASSERT( COMPARE_10_VALUES(a,1,3,3,3,3,5,5,5,17,17) ); \
563 CPPUNIT_ASSERT( COMPARE_COUNT( a , 10 ) ); \
565 a.Sort(name ## RevCompare); \
567 CPPUNIT_ASSERT( COMPARE_10_VALUES(a,17,17,5,5,5,3,3,3,3,1) ); \
568 CPPUNIT_ASSERT( COMPARE_COUNT( a , 10 ) ); \
570 wxSortedArray##name b; \
577 CPPUNIT_ASSERT( COMPARE_4_VALUES(b,1,3,5,17) ); \
578 CPPUNIT_ASSERT( COMPARE_COUNT( b , 4 ) ); \
579 CPPUNIT_ASSERT( b.Index( 0 ) == wxNOT_FOUND ); \
580 CPPUNIT_ASSERT( b.Index( 1 ) == 0 ); \
581 CPPUNIT_ASSERT( b.Index( 3 ) == 1 ); \
582 CPPUNIT_ASSERT( b.Index( 4 ) == wxNOT_FOUND ); \
583 CPPUNIT_ASSERT( b.Index( 5 ) == 2 ); \
584 CPPUNIT_ASSERT( b.Index( 6 ) == wxNOT_FOUND ); \
585 CPPUNIT_ASSERT( b.Index( 17 ) == 3 ); \
594 void ArraysTestCase::Alloc()
599 CPPUNIT_ASSERT_EQUAL( 2, a
.GetCount() );
603 CPPUNIT_ASSERT_EQUAL( 2, a
.GetCount() );
604 CPPUNIT_ASSERT_EQUAL( 17, a
[0] );
605 CPPUNIT_ASSERT_EQUAL( 9, a
[1] );
608 void ArraysTestCase::Clear()
612 WX_CLEAR_ARRAY(items
);
613 CPPUNIT_ASSERT_EQUAL( 0, items
.size() );
615 items
.push_back(new Item(17));
616 items
.push_back(new Item(71));
617 CPPUNIT_ASSERT_EQUAL( 2, items
.size() );
619 WX_CLEAR_ARRAY(items
);
620 CPPUNIT_ASSERT_EQUAL( 0, items
.size() );
626 template <typename A
, typename T
>
627 void DoTestSwap(T v1
, T v2
, T v3
,
628 A
* WXUNUSED(dummyUglyVC6Workaround
))
632 CPPUNIT_ASSERT( a1
.empty() && a2
.empty() );
636 CPPUNIT_ASSERT( a1
.empty() );
637 CPPUNIT_ASSERT_EQUAL( 1, a2
.size() );
642 CPPUNIT_ASSERT_EQUAL( 1, a1
.size() );
643 CPPUNIT_ASSERT_EQUAL( 2, a2
.size() );
644 CPPUNIT_ASSERT_EQUAL( v1
, a1
[0] );
645 CPPUNIT_ASSERT_EQUAL( v3
, a2
[1] );
648 CPPUNIT_ASSERT_EQUAL( 2, a1
.size() );
649 CPPUNIT_ASSERT_EQUAL( 1, a2
.size() );
652 } // anonymous namespace
654 void ArraysTestCase::Swap()
656 DoTestSwap("Foo", "Bar", "Baz", (wxArrayString
*)NULL
);
658 DoTestSwap(1, 10, 100, (wxArrayInt
*)NULL
);
659 DoTestSwap(6, 28, 496, (wxArrayLong
*)NULL
);
662 void ArraysTestCase::TestSTL()
665 wxArrayInt::iterator it
, en
;
666 wxArrayInt::reverse_iterator rit
, ren
;
668 static const int COUNT
= 5;
670 for ( i
= 0; i
< COUNT
; ++i
)
673 CPPUNIT_ASSERT( list1
.capacity() >= (size_t)COUNT
);
674 CPPUNIT_ASSERT_EQUAL( COUNT
, list1
.size() );
676 for ( it
= list1
.begin(), en
= list1
.end(), i
= 0;
677 it
!= en
; ++it
, ++i
)
679 CPPUNIT_ASSERT( *it
== i
);
682 CPPUNIT_ASSERT_EQUAL( COUNT
, i
);
684 for ( rit
= list1
.rbegin(), ren
= list1
.rend(), i
= COUNT
;
685 rit
!= ren
; ++rit
, --i
)
687 CPPUNIT_ASSERT( *rit
== i
-1 );
690 CPPUNIT_ASSERT_EQUAL( 0, i
);
692 CPPUNIT_ASSERT( *list1
.rbegin() == *(list1
.end()-1) &&
693 *list1
.begin() == *(list1
.rend()-1) );
695 it
= list1
.begin()+1;
696 rit
= list1
.rbegin()+1;
697 CPPUNIT_ASSERT( *list1
.begin() == *(it
-1) &&
698 *list1
.rbegin() == *(rit
-1) );
700 CPPUNIT_ASSERT( ( list1
.front() == 0 ) && ( list1
.back() == COUNT
- 1 ) );
702 list1
.erase(list1
.begin());
703 list1
.erase(list1
.end()-1);
705 for ( it
= list1
.begin(), en
= list1
.end(), i
= 1;
706 it
!= en
; ++it
, ++i
)
708 CPPUNIT_ASSERT( *it
== i
);
713 items
.push_back(new Item(17));
714 CPPUNIT_ASSERT_EQUAL( 17, (*(items
.rbegin()))->n
);
715 CPPUNIT_ASSERT_EQUAL( 17, (**items
.begin()).n
);
718 void ArraysTestCase::IndexFromEnd()
725 CPPUNIT_ASSERT_EQUAL( 0, a
.Index(10) );
726 CPPUNIT_ASSERT_EQUAL( 1, a
.Index(1) );
727 CPPUNIT_ASSERT_EQUAL( 2, a
.Index(42) );
728 CPPUNIT_ASSERT_EQUAL( 0, a
.Index(10, /*bFromEnd=*/true) );
729 CPPUNIT_ASSERT_EQUAL( 1, a
.Index(1, /*bFromEnd=*/true) );
730 CPPUNIT_ASSERT_EQUAL( 2, a
.Index(42, /*bFromEnd=*/true) );