]> git.saurik.com Git - wxWidgets.git/blame - tests/vectors/vectors.cpp
fixed setting BUILD variable in any case (not only when DEBUG=auto)
[wxWidgets.git] / tests / vectors / vectors.cpp
CommitLineData
e966f815
VS
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/vectors/vectors.cpp
3// Purpose: wxVector<T> unit test
4// Author: Vaclav Slavik
5// Created: 2007-07-07
6// RCS-ID: $Id$
7// Copyright: (c) 2007 Vaclav Slavik
8///////////////////////////////////////////////////////////////////////////////
9
10// ----------------------------------------------------------------------------
11// headers
12// ----------------------------------------------------------------------------
13
14#include "testprec.h"
15
16#ifdef __BORLANDC__
17 #pragma hdrstop
18#endif
19
20#ifndef WX_PRECOMP
21 #include "wx/wx.h"
22#endif // WX_PRECOMP
23
24#include "wx/vector.h"
25
26// --------------------------------------------------------------------------
27// test class
28// --------------------------------------------------------------------------
29
30class VectorsTestCase : public CppUnit::TestCase
31{
32public:
33 VectorsTestCase() {}
34
35private:
36 CPPUNIT_TEST_SUITE( VectorsTestCase );
4e570340
VS
37 CPPUNIT_TEST( PushPopTest );
38 CPPUNIT_TEST( Insert );
39 CPPUNIT_TEST( Erase );
6757b667 40 CPPUNIT_TEST( Iterators );
e966f815
VS
41 CPPUNIT_TEST_SUITE_END();
42
4e570340
VS
43 void PushPopTest();
44 void Insert();
45 void Erase();
6757b667 46 void Iterators();
e966f815
VS
47
48 DECLARE_NO_COPY_CLASS(VectorsTestCase)
49};
50
51// register in the unnamed registry so that these tests are run by default
52CPPUNIT_TEST_SUITE_REGISTRATION( VectorsTestCase );
53
54// also include in it's own registry so that these tests can be run alone
55CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VectorsTestCase, "VectorsTestCase" );
56
4e570340 57void VectorsTestCase::PushPopTest()
e966f815
VS
58{
59 wxVector<int> v;
60
61 CPPUNIT_ASSERT( v.size() == 0 );
62 v.push_back(1);
63 CPPUNIT_ASSERT( v.size() == 1 );
64 v.push_back(2);
65 CPPUNIT_ASSERT( v.size() == 2 );
66 v.push_back(42);
67 CPPUNIT_ASSERT( v.size() == 3 );
68
69 CPPUNIT_ASSERT( v[0] == 1 );
70 CPPUNIT_ASSERT( v[1] == 2 );
71 CPPUNIT_ASSERT( v[2] == 42 );
4e570340
VS
72
73 v.pop_back();
74 CPPUNIT_ASSERT( v.size() == 2 );
75 CPPUNIT_ASSERT( v[0] == 1 );
76 CPPUNIT_ASSERT( v[1] == 2 );
77
78 v.pop_back();
79 CPPUNIT_ASSERT( v.size() == 1 );
80 CPPUNIT_ASSERT( v[0] == 1 );
81
82 v.pop_back();
83 CPPUNIT_ASSERT( v.size() == 0 );
84 CPPUNIT_ASSERT( v.empty() );
85
86 wxVector<char> vEmpty;
87}
88
89void VectorsTestCase::Insert()
90{
91 wxVector<char> v;
92
93 v.insert(v.end(), 'a');
94 CPPUNIT_ASSERT( v.size() == 1 );
95 CPPUNIT_ASSERT( v[0] == 'a' );
96
97 v.insert(v.end(), 'b');
98 CPPUNIT_ASSERT( v.size() == 2 );
99 CPPUNIT_ASSERT( v[0] == 'a' );
100 CPPUNIT_ASSERT( v[1] == 'b' );
101
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' );
107
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' );
114}
115
116void VectorsTestCase::Erase()
117{
118 wxVector<int> v;
119
120 v.push_back(1);
121 v.push_back(2);
122 v.push_back(3);
123 v.push_back(4);
124 CPPUNIT_ASSERT( v.size() == 4 );
125
126 v.erase(v.begin(), v.end()-1);
127 CPPUNIT_ASSERT( v.size() == 1 );
128 CPPUNIT_ASSERT( v[0] == 4 );
129
130 v.clear();
131 v.push_back(1);
132 v.push_back(2);
133 v.push_back(3);
134 v.push_back(4);
135 CPPUNIT_ASSERT( v.size() == 4 );
136
137 v.erase(v.begin());
138 CPPUNIT_ASSERT( v.size() == 3 );
139 CPPUNIT_ASSERT( v[0] == 2 );
140 CPPUNIT_ASSERT( v[1] == 3 );
141 CPPUNIT_ASSERT( v[2] == 4 );
e966f815 142}
6757b667
VS
143
144void VectorsTestCase::Iterators()
145{
146 wxVector<int> v;
147 v.push_back(1);
148 v.push_back(2);
149 v.push_back(3);
150 v.push_back(4);
151
152 int value = 1;
153 for ( wxVector<int>::iterator i = v.begin(); i != v.end(); ++i, ++value )
154 {
155 CPPUNIT_ASSERT_EQUAL( value, *i );
156 }
157}