]>
git.saurik.com Git - wxWidgets.git/blob - tests/vectors/vectors.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/vectors/vectors.cpp
3 // Purpose: wxVector<T> unit test
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2007 Vaclav Slavik
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 #include "wx/vector.h"
26 // --------------------------------------------------------------------------
28 // --------------------------------------------------------------------------
30 class VectorsTestCase
: public CppUnit::TestCase
36 CPPUNIT_TEST_SUITE( VectorsTestCase
);
37 CPPUNIT_TEST( PushPopTest
);
38 CPPUNIT_TEST( Insert
);
39 CPPUNIT_TEST( Erase
);
40 CPPUNIT_TEST( Iterators
);
41 CPPUNIT_TEST_SUITE_END();
48 DECLARE_NO_COPY_CLASS(VectorsTestCase
)
51 // register in the unnamed registry so that these tests are run by default
52 CPPUNIT_TEST_SUITE_REGISTRATION( VectorsTestCase
);
54 // also include in it's own registry so that these tests can be run alone
55 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VectorsTestCase
, "VectorsTestCase" );
57 void VectorsTestCase::PushPopTest()
61 CPPUNIT_ASSERT( v
.size() == 0 );
63 CPPUNIT_ASSERT( v
.size() == 1 );
65 CPPUNIT_ASSERT( v
.size() == 2 );
67 CPPUNIT_ASSERT( v
.size() == 3 );
69 CPPUNIT_ASSERT( v
[0] == 1 );
70 CPPUNIT_ASSERT( v
[1] == 2 );
71 CPPUNIT_ASSERT( v
[2] == 42 );
74 CPPUNIT_ASSERT( v
.size() == 2 );
75 CPPUNIT_ASSERT( v
[0] == 1 );
76 CPPUNIT_ASSERT( v
[1] == 2 );
79 CPPUNIT_ASSERT( v
.size() == 1 );
80 CPPUNIT_ASSERT( v
[0] == 1 );
83 CPPUNIT_ASSERT( v
.size() == 0 );
84 CPPUNIT_ASSERT( v
.empty() );
86 wxVector
<char> vEmpty
;
89 void VectorsTestCase::Insert()
93 v
.insert(v
.end(), 'a');
94 CPPUNIT_ASSERT( v
.size() == 1 );
95 CPPUNIT_ASSERT( v
[0] == 'a' );
97 v
.insert(v
.end(), 'b');
98 CPPUNIT_ASSERT( v
.size() == 2 );
99 CPPUNIT_ASSERT( v
[0] == 'a' );
100 CPPUNIT_ASSERT( v
[1] == 'b' );
102 v
.insert(v
.begin(), '0');
103 CPPUNIT_ASSERT( v
.size() == 3 );
104 CPPUNIT_ASSERT( v
[0] == '0' );
105 CPPUNIT_ASSERT( v
[1] == 'a' );
106 CPPUNIT_ASSERT( v
[2] == 'b' );
108 v
.insert(v
.begin() + 2, 'X');
109 CPPUNIT_ASSERT( v
.size() == 4 );
110 CPPUNIT_ASSERT( v
[0] == '0' );
111 CPPUNIT_ASSERT( v
[1] == 'a' );
112 CPPUNIT_ASSERT( v
[2] == 'X' );
113 CPPUNIT_ASSERT( v
[3] == 'b' );
116 void VectorsTestCase::Erase()
124 CPPUNIT_ASSERT( v
.size() == 4 );
126 v
.erase(v
.begin(), v
.end()-1);
127 CPPUNIT_ASSERT( v
.size() == 1 );
128 CPPUNIT_ASSERT( v
[0] == 4 );
135 CPPUNIT_ASSERT( v
.size() == 4 );
138 CPPUNIT_ASSERT( v
.size() == 3 );
139 CPPUNIT_ASSERT( v
[0] == 2 );
140 CPPUNIT_ASSERT( v
[1] == 3 );
141 CPPUNIT_ASSERT( v
[2] == 4 );
144 void VectorsTestCase::Iterators()
153 for ( wxVector
<int>::iterator i
= v
.begin(); i
!= v
.end(); ++i
, ++value
)
155 CPPUNIT_ASSERT_EQUAL( value
, *i
);