ReactOS 0.4.15-dev-7889-g76290a6
VectorTest Class Reference
Inheritance diagram for VectorTest:
Collaboration diagram for VectorTest:

Protected Member Functions

void vec_test_1 ()
 
void vec_test_2 ()
 
void vec_test_3 ()
 
void vec_test_4 ()
 
void vec_test_5 ()
 
void vec_test_6 ()
 
void vec_test_7 ()
 
void capacity ()
 
void at ()
 
void pointer ()
 
void auto_ref ()
 
void allocator_with_state ()
 
void iterators ()
 
void optimizations_check ()
 
void assign_check ()
 
void ebo ()
 

Private Member Functions

 CPPUNIT_TEST_SUITE (VectorTest)
 
 CPPUNIT_TEST (vec_test_1)
 
 CPPUNIT_TEST (vec_test_2)
 
 CPPUNIT_TEST (vec_test_3)
 
 CPPUNIT_TEST (vec_test_4)
 
 CPPUNIT_TEST (vec_test_5)
 
 CPPUNIT_TEST (vec_test_6)
 
 CPPUNIT_TEST (vec_test_7)
 
 CPPUNIT_TEST (capacity)
 
 CPPUNIT_TEST (at)
 
 CPPUNIT_TEST (pointer)
 
 CPPUNIT_TEST (auto_ref)
 
 CPPUNIT_TEST (allocator_with_state)
 
 CPPUNIT_TEST (iterators)
 
 CPPUNIT_TEST (optimizations_check)
 
 CPPUNIT_TEST (assign_check)
 
 CPPUNIT_TEST (ebo)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Attributes

 CPPUNIT_STOP_IGNORE
 

Detailed Description

Definition at line 20 of file vector_test.cpp.

Member Function Documentation

◆ allocator_with_state()

void VectorTest::allocator_with_state ( )
protected

Definition at line 373 of file vector_test.cpp.

374 {
375 char buf1[1024];
376 StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1));
377
378 char buf2[1024];
379 StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2));
380
381 {
382 typedef vector<int, StackAllocator<int> > VectorInt;
383 VectorInt vint1(10, 0, stack1);
384 VectorInt vint1Cpy(vint1);
385
386 VectorInt vint2(10, 1, stack2);
387 VectorInt vint2Cpy(vint2);
388
389 vint1.swap(vint2);
390
391 CPPUNIT_ASSERT( vint1.get_allocator().swaped() );
392 CPPUNIT_ASSERT( vint2.get_allocator().swaped() );
393
394 CPPUNIT_ASSERT( vint1 == vint2Cpy );
395 CPPUNIT_ASSERT( vint2 == vint1Cpy );
396 CPPUNIT_ASSERT( vint1.get_allocator() == stack2 );
397 CPPUNIT_ASSERT( vint2.get_allocator() == stack1 );
398 }
399 CPPUNIT_ASSERT( stack1.ok() );
400 CPPUNIT_ASSERT( stack2.ok() );
401 }
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200

◆ assign_check()

void VectorTest::assign_check ( )
protected

Definition at line 445 of file vector_test.cpp.

446{
447#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES)
448 vector<int> v(3,1);
449 int array[] = { 1, 2, 3, 4, 5 };
450
451 v.assign( array, array + 5 );
452 CPPUNIT_CHECK( v[4] == 5 );
453 CPPUNIT_CHECK( v[0] == 1 );
454 CPPUNIT_CHECK( v[1] == 2 );
455#endif
456}
#define CPPUNIT_CHECK(X)
Definition: cppunit_mini.h:195
const GLdouble * v
Definition: gl.h:2040

◆ at()

void VectorTest::at ( )
protected

Definition at line 313 of file vector_test.cpp.

313 {
315 vector<int> const& cv = v;
316
317 v.push_back(10);
318 CPPUNIT_ASSERT( v.at(0) == 10 );
319 v.at(0) = 20;
320 CPPUNIT_ASSERT( cv.at(0) == 20 );
321
322#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
323 try {
324 v.at(1) = 20;
326 }
327 catch (out_of_range const&) {
328 }
329 catch (...) {
331 }
332#endif
333}
#define CPPUNIT_FAIL
Definition: cppunit_mini.h:206
reference at(size_type __n)
Definition: _vector.h:210

◆ auto_ref()

void VectorTest::auto_ref ( )
protected

Definition at line 344 of file vector_test.cpp.

345{
347 for (int i = 0; i < 5; ++i) {
348 ref.push_back(i);
349 }
350
351 vector<vector<int> > v_v_int(1, ref);
352 v_v_int.push_back(v_v_int[0]);
353 v_v_int.push_back(ref);
354 v_v_int.push_back(v_v_int[0]);
355 v_v_int.push_back(v_v_int[0]);
356 v_v_int.push_back(ref);
357
358 vector<vector<int> >::iterator vvit(v_v_int.begin()), vvitEnd(v_v_int.end());
359 for (; vvit != vvitEnd; ++vvit) {
360 CPPUNIT_ASSERT( *vvit == ref );
361 }
362
363 /*
364 * Forbidden by the Standard:
365 v_v_int.insert(v_v_int.end(), v_v_int.begin(), v_v_int.end());
366 for (vvit = v_v_int.begin(), vvitEnd = v_v_int.end();
367 vvit != vvitEnd; ++vvit) {
368 CPPUNIT_ASSERT( *vvit == ref );
369 }
370 */
371}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: send.c:48

◆ capacity()

void VectorTest::capacity ( )
protected

Definition at line 293 of file vector_test.cpp.

294{
295 {
297
298 CPPUNIT_ASSERT( v.capacity() == 0 );
299 v.push_back(42);
300 CPPUNIT_ASSERT( v.capacity() >= 1 );
301 v.reserve(5000);
302 CPPUNIT_ASSERT( v.capacity() >= 5000 );
303 }
304
305 {
306 //Test that used to generate an assertion when using __debug_alloc.
308 va.reserve(1);
309 va.reserve(2);
310 }
311}
void reserve(size_type __n)
Definition: _vector.c:62

◆ CPPUNIT_TEST() [1/16]

VectorTest::CPPUNIT_TEST ( allocator_with_state  )
private

◆ CPPUNIT_TEST() [2/16]

VectorTest::CPPUNIT_TEST ( assign_check  )
private

◆ CPPUNIT_TEST() [3/16]

VectorTest::CPPUNIT_TEST ( at  )
private

◆ CPPUNIT_TEST() [4/16]

VectorTest::CPPUNIT_TEST ( auto_ref  )
private

◆ CPPUNIT_TEST() [5/16]

VectorTest::CPPUNIT_TEST ( capacity  )
private

◆ CPPUNIT_TEST() [6/16]

VectorTest::CPPUNIT_TEST ( ebo  )
private

◆ CPPUNIT_TEST() [7/16]

VectorTest::CPPUNIT_TEST ( iterators  )
private

◆ CPPUNIT_TEST() [8/16]

VectorTest::CPPUNIT_TEST ( optimizations_check  )
private

◆ CPPUNIT_TEST() [9/16]

VectorTest::CPPUNIT_TEST ( pointer  )
private

◆ CPPUNIT_TEST() [10/16]

VectorTest::CPPUNIT_TEST ( vec_test_1  )
private

◆ CPPUNIT_TEST() [11/16]

VectorTest::CPPUNIT_TEST ( vec_test_2  )
private

◆ CPPUNIT_TEST() [12/16]

VectorTest::CPPUNIT_TEST ( vec_test_3  )
private

◆ CPPUNIT_TEST() [13/16]

VectorTest::CPPUNIT_TEST ( vec_test_4  )
private

◆ CPPUNIT_TEST() [14/16]

VectorTest::CPPUNIT_TEST ( vec_test_5  )
private

◆ CPPUNIT_TEST() [15/16]

VectorTest::CPPUNIT_TEST ( vec_test_6  )
private

◆ CPPUNIT_TEST() [16/16]

VectorTest::CPPUNIT_TEST ( vec_test_7  )
private

◆ CPPUNIT_TEST_SUITE()

VectorTest::CPPUNIT_TEST_SUITE ( VectorTest  )
private

◆ CPPUNIT_TEST_SUITE_END()

VectorTest::CPPUNIT_TEST_SUITE_END ( )
private

◆ ebo()

void VectorTest::ebo ( )
protected

Definition at line 527 of file vector_test.cpp.

528{
529 // We use heap memory as test failure can corrupt vector internal
530 // representation making executable crash on vector destructor invocation.
531 // We prefer a simple memory leak, internal corruption should be reveal
532 // by size or capacity checks.
534 V *pv1 = new V(1, 1);
535 V *pv2 = new V(10, 2);
536
537 size_t v1Capacity = pv1->capacity();
538 size_t v2Capacity = pv2->capacity();
539
540 pv1->swap(*pv2);
541
542 CPPUNIT_ASSERT( pv1->size() == 10 );
543 CPPUNIT_ASSERT( pv1->capacity() == v2Capacity );
544 CPPUNIT_ASSERT( (*pv1)[5] == 2 );
545
546 CPPUNIT_ASSERT( pv2->size() == 1 );
547 CPPUNIT_ASSERT( pv2->capacity() == v1Capacity );
548 CPPUNIT_ASSERT( (*pv2)[0] == 1 );
549
550 delete pv2;
551 delete pv1;
552}
const void * pv2
Definition: winddi.h:2453

◆ iterators()

void VectorTest::iterators ( )
protected

Definition at line 458 of file vector_test.cpp.

459{
460 vector<int> vint(10, 0);
461 vector<int> const& crvint = vint;
462
463 CPPUNIT_ASSERT( vint.begin() == vint.begin() );
464 CPPUNIT_ASSERT( crvint.begin() == vint.begin() );
465 CPPUNIT_ASSERT( vint.begin() == crvint.begin() );
466 CPPUNIT_ASSERT( crvint.begin() == crvint.begin() );
467
468 CPPUNIT_ASSERT( vint.begin() != vint.end() );
469 CPPUNIT_ASSERT( crvint.begin() != vint.end() );
470 CPPUNIT_ASSERT( vint.begin() != crvint.end() );
471 CPPUNIT_ASSERT( crvint.begin() != crvint.end() );
472
473 CPPUNIT_ASSERT( vint.rbegin() == vint.rbegin() );
474 // Not Standard:
475 //CPPUNIT_ASSERT( vint.rbegin() == crvint.rbegin() );
476 //CPPUNIT_ASSERT( crvint.rbegin() == vint.rbegin() );
477 CPPUNIT_ASSERT( crvint.rbegin() == crvint.rbegin() );
478
479 CPPUNIT_ASSERT( vint.rbegin() != vint.rend() );
480 // Not Standard:
481 //CPPUNIT_ASSERT( vint.rbegin() != crvint.rend() );
482 //CPPUNIT_ASSERT( crvint.rbegin() != vint.rend() );
483 CPPUNIT_ASSERT( crvint.rbegin() != crvint.rend() );
484}
iterator end()
Definition: _vector.h:184
reverse_iterator rbegin()
Definition: _vector.h:187
iterator begin()
Definition: _vector.h:182
reverse_iterator rend()
Definition: _vector.h:189

◆ optimizations_check()

void VectorTest::optimizations_check ( )
protected

Definition at line 433 of file vector_test.cpp.

434{
435#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES)
436 vector<Point> v1(1);
437 CPPUNIT_ASSERT( v1.size() == 1 );
438
439 vector<PointEx> v2(v1.begin(), v1.end());
440 CPPUNIT_ASSERT( v2.size() == 1 );
441 CPPUNIT_ASSERT( v2[0].builtFromBase == true );
442#endif
443}
GLfloat GLfloat v1
Definition: glext.h:6062
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063

◆ pointer()

void VectorTest::pointer ( )
protected

Definition at line 335 of file vector_test.cpp.

336{
340
341 v3.insert( v3.end(), v1.begin(), v1.end() );
342}
GLfloat GLfloat GLfloat GLfloat v3
Definition: glext.h:6064

◆ vec_test_1()

void VectorTest::vec_test_1 ( )
protected

Definition at line 69 of file vector_test.cpp.

70{
71 vector<int> v1; // Empty vector of integers.
72
73 CPPUNIT_ASSERT( v1.empty() == true );
74 CPPUNIT_ASSERT( v1.size() == 0 );
75
76 // CPPUNIT_ASSERT( v1.max_size() == INT_MAX / sizeof(int) );
77 // cout << "max_size = " << v1.max_size() << endl;
78 v1.push_back(42); // Add an integer to the vector.
79
80 CPPUNIT_ASSERT( v1.size() == 1 );
81
82 CPPUNIT_ASSERT( v1[0] == 42 );
83
84 {
85 vector<vector<int> > vect(10);
86 vector<vector<int> >::iterator it(vect.begin()), end(vect.end());
87 for (; it != end; ++it) {
88 CPPUNIT_ASSERT( (*it).empty() );
89 CPPUNIT_ASSERT( (*it).size() == 0 );
90 CPPUNIT_ASSERT( (*it).capacity() == 0 );
91 CPPUNIT_ASSERT( (*it).begin() == (*it).end() );
92 }
93 }
94}
GLuint GLuint end
Definition: gl.h:1545

◆ vec_test_2()

void VectorTest::vec_test_2 ( )
protected

Definition at line 96 of file vector_test.cpp.

97{
98 vector<double> v1; // Empty vector of doubles.
99 v1.push_back(32.1);
100 v1.push_back(40.5);
101 vector<double> v2; // Another empty vector of doubles.
102 v2.push_back(3.56);
103
104 CPPUNIT_ASSERT( v1.size() == 2 );
105 CPPUNIT_ASSERT( v1[0] == 32.1 );
106 CPPUNIT_ASSERT( v1[1] == 40.5 );
107
108 CPPUNIT_ASSERT( v2.size() == 1 );
109 CPPUNIT_ASSERT( v2[0] == 3.56 );
110 size_t v1Cap = v1.capacity();
111 size_t v2Cap = v2.capacity();
112
113 v1.swap(v2); // Swap the vector's contents.
114
115 CPPUNIT_ASSERT( v1.size() == 1 );
116 CPPUNIT_ASSERT( v1.capacity() == v2Cap );
117 CPPUNIT_ASSERT( v1[0] == 3.56 );
118
119 CPPUNIT_ASSERT( v2.size() == 2 );
120 CPPUNIT_ASSERT( v2.capacity() == v1Cap );
121 CPPUNIT_ASSERT( v2[0] == 32.1 );
122 CPPUNIT_ASSERT( v2[1] == 40.5 );
123
124 v2 = v1; // Assign one vector to another.
125
126 CPPUNIT_ASSERT( v2.size() == 1 );
127 CPPUNIT_ASSERT( v2[0] == 3.56 );
128}

◆ vec_test_3()

void VectorTest::vec_test_3 ( )
protected

Definition at line 130 of file vector_test.cpp.

131{
132 typedef vector<char> vec_type;
133
134 vec_type v1; // Empty vector of characters.
135 v1.push_back('h');
136 v1.push_back('i');
137
138 CPPUNIT_ASSERT( v1.size() == 2 );
139 CPPUNIT_ASSERT( v1[0] == 'h' );
140 CPPUNIT_ASSERT( v1[1] == 'i' );
141
142 vec_type v2(v1.begin(), v1.end());
143 v2[1] = 'o'; // Replace second character.
144
145 CPPUNIT_ASSERT( v2.size() == 2 );
146 CPPUNIT_ASSERT( v2[0] == 'h' );
147 CPPUNIT_ASSERT( v2[1] == 'o' );
148
149 CPPUNIT_ASSERT( (v1 == v2) == false );
150
151 CPPUNIT_ASSERT( (v1 < v2) == true );
152}

◆ vec_test_4()

void VectorTest::vec_test_4 ( )
protected

Definition at line 154 of file vector_test.cpp.

155{
156 vector<int> v(4);
157
158 v[0] = 1;
159 v[1] = 4;
160 v[2] = 9;
161 v[3] = 16;
162
163 CPPUNIT_ASSERT( v.front() == 1 );
164 CPPUNIT_ASSERT( v.back() == 16 );
165
166 v.push_back(25);
167
168 CPPUNIT_ASSERT( v.back() == 25 );
169 CPPUNIT_ASSERT( v.size() == 5 );
170
171 v.pop_back();
172
173 CPPUNIT_ASSERT( v.back() == 16 );
174 CPPUNIT_ASSERT( v.size() == 4 );
175}

◆ vec_test_5()

void VectorTest::vec_test_5 ( )
protected

Definition at line 177 of file vector_test.cpp.

178{
179 int array [] = { 1, 4, 9, 16 };
180
181 vector<int> v(array, array + 4);
182
183 CPPUNIT_ASSERT( v.size() == 4 );
184
185 CPPUNIT_ASSERT( v[0] == 1 );
186 CPPUNIT_ASSERT( v[1] == 4 );
187 CPPUNIT_ASSERT( v[2] == 9 );
188 CPPUNIT_ASSERT( v[3] == 16 );
189}

◆ vec_test_6()

void VectorTest::vec_test_6 ( )
protected

Definition at line 191 of file vector_test.cpp.

192{
193 int array [] = { 1, 4, 9, 16, 25, 36 };
194
195 vector<int> v(array, array + 6);
197
198 CPPUNIT_ASSERT( v.size() == 6 );
199 CPPUNIT_ASSERT( v[0] == 1 );
200 CPPUNIT_ASSERT( v[1] == 4 );
201 CPPUNIT_ASSERT( v[2] == 9 );
202 CPPUNIT_ASSERT( v[3] == 16 );
203 CPPUNIT_ASSERT( v[4] == 25 );
204 CPPUNIT_ASSERT( v[5] == 36 );
205
206 vit = v.erase( v.begin() ); // Erase first element.
207 CPPUNIT_ASSERT( *vit == 4 );
208
209 CPPUNIT_ASSERT( v.size() == 5 );
210 CPPUNIT_ASSERT( v[0] == 4 );
211 CPPUNIT_ASSERT( v[1] == 9 );
212 CPPUNIT_ASSERT( v[2] == 16 );
213 CPPUNIT_ASSERT( v[3] == 25 );
214 CPPUNIT_ASSERT( v[4] == 36 );
215
216 vit = v.erase(v.end() - 1); // Erase last element.
217 CPPUNIT_ASSERT( vit == v.end() );
218
219 CPPUNIT_ASSERT( v.size() == 4 );
220 CPPUNIT_ASSERT( v[0] == 4 );
221 CPPUNIT_ASSERT( v[1] == 9 );
222 CPPUNIT_ASSERT( v[2] == 16 );
223 CPPUNIT_ASSERT( v[3] == 25 );
224
225
226 v.erase(v.begin() + 1, v.end() - 1); // Erase all but first and last.
227
228 CPPUNIT_ASSERT( v.size() == 2 );
229 CPPUNIT_ASSERT( v[0] == 4 );
230 CPPUNIT_ASSERT( v[1] == 25 );
231
232}
iterator erase(iterator __pos)
Definition: _vector.h:623
value_type * iterator
Definition: _vector.h:124

◆ vec_test_7()

void VectorTest::vec_test_7 ( )
protected

Definition at line 234 of file vector_test.cpp.

235{
236 int array1 [] = { 1, 4, 25 };
237 int array2 [] = { 9, 16 };
238
239 vector<int> v(array1, array1 + 3);
241 vit = v.insert(v.begin(), 0); // Insert before first element.
242 CPPUNIT_ASSERT( *vit == 0 );
243
244 vit = v.insert(v.end(), 36); // Insert after last element.
245 CPPUNIT_ASSERT( *vit == 36 );
246
247 CPPUNIT_ASSERT( v.size() == 5 );
248 CPPUNIT_ASSERT( v[0] == 0 );
249 CPPUNIT_ASSERT( v[1] == 1 );
250 CPPUNIT_ASSERT( v[2] == 4 );
251 CPPUNIT_ASSERT( v[3] == 25 );
252 CPPUNIT_ASSERT( v[4] == 36 );
253
254 // Insert contents of array2 before fourth element.
255 v.insert(v.begin() + 3, array2, array2 + 2);
256
257 CPPUNIT_ASSERT( v.size() == 7 );
258
259 CPPUNIT_ASSERT( v[0] == 0 );
260 CPPUNIT_ASSERT( v[1] == 1 );
261 CPPUNIT_ASSERT( v[2] == 4 );
262 CPPUNIT_ASSERT( v[3] == 9 );
263 CPPUNIT_ASSERT( v[4] == 16 );
264 CPPUNIT_ASSERT( v[5] == 25 );
265 CPPUNIT_ASSERT( v[6] == 36 );
266
267 v.clear();
268 CPPUNIT_ASSERT( v.empty() );
269
270 v.insert(v.begin(), 5, 10);
271 CPPUNIT_ASSERT( v.size() == 5 );
272 CPPUNIT_ASSERT( v[0] == 10 );
273 CPPUNIT_ASSERT( v[1] == 10 );
274 CPPUNIT_ASSERT( v[2] == 10 );
275 CPPUNIT_ASSERT( v[3] == 10 );
276 CPPUNIT_ASSERT( v[4] == 10 );
277
278 /*
279 {
280 vector<float> vf(2.0f, 3.0f);
281 CPPUNIT_ASSERT( vf.size() == 2 );
282 CPPUNIT_ASSERT( vf.front() == 3.0f );
283 CPPUNIT_ASSERT( vf.back() == 3.0f );
284 }
285 */
286}
iterator insert(iterator __pos, const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.c:223

Member Data Documentation

◆ CPPUNIT_STOP_IGNORE

VectorTest::CPPUNIT_STOP_IGNORE
private

Definition at line 41 of file vector_test.cpp.


The documentation for this class was generated from the following file: