1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/vector_test.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,698 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +//Has to be first for StackAllocator swap overload to be taken
1.20 +//into account (at least using GCC 4.0.1)
1.21 +#include "stack_allocator.h"
1.22 +#include <e32std.h>
1.23 +
1.24 +#include <vector>
1.25 +#include <algorithm>
1.26 +#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
1.27 +# include <stdexcept>
1.28 +#endif
1.29 +
1.30 +#include "cppunit/cppunit_proxy.h"
1.31 +
1.32 +#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
1.33 +using namespace std;
1.34 +#endif
1.35 +
1.36 +//
1.37 +// TestCase class
1.38 +//
1.39 +class VectorTest : public CPPUNIT_NS::TestCase
1.40 +{
1.41 + CPPUNIT_TEST_SUITE(VectorTest);
1.42 + CPPUNIT_TEST(vec_test_1);
1.43 + CPPUNIT_TEST(vec_test_2);
1.44 + CPPUNIT_TEST(vec_test_3);
1.45 + CPPUNIT_TEST(vec_test_4);
1.46 + CPPUNIT_TEST(vec_test_5);
1.47 + CPPUNIT_TEST(vec_test_6);
1.48 + CPPUNIT_TEST(vec_test_7);
1.49 + CPPUNIT_TEST(capacity);
1.50 + CPPUNIT_TEST(at);
1.51 + CPPUNIT_TEST(pointer);
1.52 + CPPUNIT_TEST(auto_ref);
1.53 + CPPUNIT_TEST(allocator_with_state);
1.54 + CPPUNIT_TEST(iterators);
1.55 +#if defined (STLPORT) && defined (_STLP_NO_MEMBER_TEMPLATES)
1.56 + CPPUNIT_IGNORE;
1.57 +#endif
1.58 + CPPUNIT_TEST(optimizations_check);
1.59 + CPPUNIT_STOP_IGNORE;
1.60 + CPPUNIT_TEST(ebo);
1.61 + CPPUNIT_TEST(vec_cov1);
1.62 + CPPUNIT_TEST(vec_cov2);
1.63 + CPPUNIT_TEST(vec_cov3);
1.64 + CPPUNIT_TEST(vec_cov4);
1.65 + CPPUNIT_TEST_SUITE_END();
1.66 +
1.67 +protected:
1.68 + void vec_test_1();
1.69 + void vec_test_2();
1.70 + void vec_test_3();
1.71 + void vec_test_4();
1.72 + void vec_test_5();
1.73 + void vec_test_6();
1.74 + void vec_test_7();
1.75 + void capacity();
1.76 + void at();
1.77 + void pointer();
1.78 + void auto_ref();
1.79 + void allocator_with_state();
1.80 + void iterators();
1.81 + void optimizations_check();
1.82 + void ebo();
1.83 + void vec_cov1();
1.84 + void vec_cov2();
1.85 + void vec_cov3();
1.86 + void vec_cov4();
1.87 +};
1.88 +
1.89 +CPPUNIT_TEST_SUITE_REGISTRATION(VectorTest);
1.90 +
1.91 +//
1.92 +// tests implementation
1.93 +//
1.94 +void VectorTest::vec_test_1()
1.95 +{
1.96 + vector<int> v1; // Empty vector of integers.
1.97 +
1.98 + CPPUNIT_ASSERT( v1.empty() == true );
1.99 + CPPUNIT_ASSERT( v1.size() == 0 );
1.100 +
1.101 + // CPPUNIT_ASSERT( v1.max_size() == INT_MAX / sizeof(int) );
1.102 + // cout << "max_size = " << v1.max_size() << endl;
1.103 + v1.push_back(42); // Add an integer to the vector.
1.104 +
1.105 + CPPUNIT_ASSERT( v1.size() == 1 );
1.106 +
1.107 + CPPUNIT_ASSERT( v1[0] == 42 );
1.108 +
1.109 + {
1.110 + vector<vector<int> > vect(10);
1.111 + vector<vector<int> >::iterator it(vect.begin()), end(vect.end());
1.112 + for (; it != end; ++it) {
1.113 + CPPUNIT_ASSERT( (*it).empty() );
1.114 + CPPUNIT_ASSERT( (*it).size() == 0 );
1.115 + CPPUNIT_ASSERT( (*it).capacity() == 0 );
1.116 + CPPUNIT_ASSERT( (*it).begin() == (*it).end() );
1.117 + }
1.118 + }
1.119 +}
1.120 +
1.121 +void VectorTest::vec_test_2()
1.122 +{
1.123 + vector<double> v1; // Empty vector of doubles.
1.124 + v1.push_back(32.1);
1.125 + v1.push_back(40.5);
1.126 + vector<double> v2; // Another empty vector of doubles.
1.127 + v2.push_back(3.56);
1.128 +
1.129 + CPPUNIT_ASSERT( v1.size() == 2 );
1.130 + CPPUNIT_ASSERT( v1[0] == 32.1 );
1.131 + CPPUNIT_ASSERT( v1[1] == 40.5 );
1.132 +
1.133 + CPPUNIT_ASSERT( v2.size() == 1 );
1.134 + CPPUNIT_ASSERT( v2[0] == 3.56 );
1.135 + v1.swap(v2); // Swap the vector's contents.
1.136 +
1.137 + CPPUNIT_ASSERT( v1.size() == 1 );
1.138 + CPPUNIT_ASSERT( v1[0] == 3.56 );
1.139 +
1.140 + CPPUNIT_ASSERT( v2.size() == 2 );
1.141 + CPPUNIT_ASSERT( v2[0] == 32.1 );
1.142 + CPPUNIT_ASSERT( v2[1] == 40.5 );
1.143 +
1.144 + v2 = v1; // Assign one vector to another.
1.145 +
1.146 + CPPUNIT_ASSERT( v2.size() == 1 );
1.147 + CPPUNIT_ASSERT( v2[0] == 3.56 );
1.148 +}
1.149 +
1.150 +void VectorTest::vec_test_3()
1.151 +{
1.152 + typedef vector<char> vec_type;
1.153 +
1.154 + vec_type v1; // Empty vector of characters.
1.155 + v1.push_back('h');
1.156 + v1.push_back('i');
1.157 +
1.158 + CPPUNIT_ASSERT( v1.size() == 2 );
1.159 + CPPUNIT_ASSERT( v1[0] == 'h' );
1.160 + CPPUNIT_ASSERT( v1[1] == 'i' );
1.161 +
1.162 + vec_type v2(v1.begin(), v1.end());
1.163 + v2[1] = 'o'; // Replace second character.
1.164 +
1.165 + CPPUNIT_ASSERT( v2.size() == 2 );
1.166 + CPPUNIT_ASSERT( v2[0] == 'h' );
1.167 + CPPUNIT_ASSERT( v2[1] == 'o' );
1.168 +
1.169 + CPPUNIT_ASSERT( (v1 == v2) == false );
1.170 +
1.171 + CPPUNIT_ASSERT( (v1 < v2) == true );
1.172 +}
1.173 +
1.174 +void VectorTest::vec_test_4()
1.175 +{
1.176 + vector<int> v(4);
1.177 +
1.178 + v[0] = 1;
1.179 + v[1] = 4;
1.180 + v[2] = 9;
1.181 + v[3] = 16;
1.182 +
1.183 + CPPUNIT_ASSERT( v.front() == 1 );
1.184 + CPPUNIT_ASSERT( v.back() == 16 );
1.185 +
1.186 + v.push_back(25);
1.187 +
1.188 + CPPUNIT_ASSERT( v.back() == 25 );
1.189 + CPPUNIT_ASSERT( v.size() == 5 );
1.190 +
1.191 + v.pop_back();
1.192 +
1.193 + CPPUNIT_ASSERT( v.back() == 16 );
1.194 + CPPUNIT_ASSERT( v.size() == 4 );
1.195 +}
1.196 +
1.197 +void VectorTest::vec_test_5()
1.198 +{
1.199 + int array [] = { 1, 4, 9, 16 };
1.200 +
1.201 + vector<int> v(array, array + 4);
1.202 +
1.203 + CPPUNIT_ASSERT( v.size() == 4 );
1.204 +
1.205 + CPPUNIT_ASSERT( v[0] == 1 );
1.206 + CPPUNIT_ASSERT( v[1] == 4 );
1.207 + CPPUNIT_ASSERT( v[2] == 9 );
1.208 + CPPUNIT_ASSERT( v[3] == 16 );
1.209 +}
1.210 +
1.211 +void VectorTest::vec_test_6()
1.212 +{
1.213 + int array [] = { 1, 4, 9, 16, 25, 36 };
1.214 +
1.215 + vector<int> v(array, array + 6);
1.216 + vector<int>::iterator vit;
1.217 +
1.218 + CPPUNIT_ASSERT( v.size() == 6 );
1.219 + CPPUNIT_ASSERT( v[0] == 1 );
1.220 + CPPUNIT_ASSERT( v[1] == 4 );
1.221 + CPPUNIT_ASSERT( v[2] == 9 );
1.222 + CPPUNIT_ASSERT( v[3] == 16 );
1.223 + CPPUNIT_ASSERT( v[4] == 25 );
1.224 + CPPUNIT_ASSERT( v[5] == 36 );
1.225 +
1.226 + vit = v.erase( v.begin() ); // Erase first element.
1.227 + CPPUNIT_ASSERT( *vit == 4 );
1.228 +
1.229 + CPPUNIT_ASSERT( v.size() == 5 );
1.230 + CPPUNIT_ASSERT( v[0] == 4 );
1.231 + CPPUNIT_ASSERT( v[1] == 9 );
1.232 + CPPUNIT_ASSERT( v[2] == 16 );
1.233 + CPPUNIT_ASSERT( v[3] == 25 );
1.234 + CPPUNIT_ASSERT( v[4] == 36 );
1.235 +
1.236 + vit = v.erase(v.end() - 1); // Erase last element.
1.237 + CPPUNIT_ASSERT( vit == v.end() );
1.238 +
1.239 + CPPUNIT_ASSERT( v.size() == 4 );
1.240 + CPPUNIT_ASSERT( v[0] == 4 );
1.241 + CPPUNIT_ASSERT( v[1] == 9 );
1.242 + CPPUNIT_ASSERT( v[2] == 16 );
1.243 + CPPUNIT_ASSERT( v[3] == 25 );
1.244 +
1.245 +
1.246 + v.erase(v.begin() + 1, v.end() - 1); // Erase all but first and last.
1.247 +
1.248 + CPPUNIT_ASSERT( v.size() == 2 );
1.249 + CPPUNIT_ASSERT( v[0] == 4 );
1.250 + CPPUNIT_ASSERT( v[1] == 25 );
1.251 +
1.252 +}
1.253 +
1.254 +void VectorTest::vec_test_7()
1.255 +{
1.256 + int array1 [] = { 1, 4, 25 };
1.257 + int array2 [] = { 9, 16 };
1.258 +
1.259 + vector<int> v(array1, array1 + 3);
1.260 + vector<int>::iterator vit;
1.261 + vit = v.insert(v.begin(), 0); // Insert before first element.
1.262 + CPPUNIT_ASSERT( *vit == 0 );
1.263 +
1.264 + vit = v.insert(v.end(), 36); // Insert after last element.
1.265 + CPPUNIT_ASSERT( *vit == 36 );
1.266 +
1.267 + CPPUNIT_ASSERT( v.size() == 5 );
1.268 + CPPUNIT_ASSERT( v[0] == 0 );
1.269 + CPPUNIT_ASSERT( v[1] == 1 );
1.270 + CPPUNIT_ASSERT( v[2] == 4 );
1.271 + CPPUNIT_ASSERT( v[3] == 25 );
1.272 + CPPUNIT_ASSERT( v[4] == 36 );
1.273 +
1.274 + // Insert contents of array2 before fourth element.
1.275 + v.insert(v.begin() + 3, array2, array2 + 2);
1.276 +
1.277 + CPPUNIT_ASSERT( v.size() == 7 );
1.278 +
1.279 + CPPUNIT_ASSERT( v[0] == 0 );
1.280 + CPPUNIT_ASSERT( v[1] == 1 );
1.281 + CPPUNIT_ASSERT( v[2] == 4 );
1.282 + CPPUNIT_ASSERT( v[3] == 9 );
1.283 + CPPUNIT_ASSERT( v[4] == 16 );
1.284 + CPPUNIT_ASSERT( v[5] == 25 );
1.285 + CPPUNIT_ASSERT( v[6] == 36 );
1.286 +
1.287 + v.clear();
1.288 + CPPUNIT_ASSERT( v.empty() );
1.289 +
1.290 + v.insert(v.begin(), 5, 10);
1.291 + CPPUNIT_ASSERT( v.size() == 5 );
1.292 + CPPUNIT_ASSERT( v[0] == 10 );
1.293 + CPPUNIT_ASSERT( v[1] == 10 );
1.294 + CPPUNIT_ASSERT( v[2] == 10 );
1.295 + CPPUNIT_ASSERT( v[3] == 10 );
1.296 + CPPUNIT_ASSERT( v[4] == 10 );
1.297 +
1.298 + /*
1.299 + {
1.300 + vector<float> vf(2.0f, 3.0f);
1.301 + CPPUNIT_ASSERT( vf.size() == 2 );
1.302 + CPPUNIT_ASSERT( vf.front() == 3.0f );
1.303 + CPPUNIT_ASSERT( vf.back() == 3.0f );
1.304 + }
1.305 + */
1.306 +}
1.307 +
1.308 +struct TestStruct
1.309 +{
1.310 + unsigned int a[3];
1.311 +};
1.312 +
1.313 +void VectorTest::capacity()
1.314 +{
1.315 + {
1.316 + vector<int> v;
1.317 +
1.318 + CPPUNIT_ASSERT( v.capacity() == 0 );
1.319 + v.push_back(42);
1.320 + CPPUNIT_ASSERT( v.capacity() >= 1 );
1.321 + v.reserve(5000);
1.322 + CPPUNIT_ASSERT( v.capacity() >= 5000 );
1.323 + }
1.324 +
1.325 + {
1.326 + //Test that used to generate an assertion when using __debug_alloc.
1.327 + vector<TestStruct> va;
1.328 + va.reserve(1);
1.329 + va.reserve(2);
1.330 + }
1.331 +}
1.332 +
1.333 +void VectorTest::at() {
1.334 + vector<int> v;
1.335 + vector<int> const& cv = v;
1.336 +
1.337 + v.push_back(10);
1.338 + CPPUNIT_ASSERT( v.at(0) == 10 );
1.339 + v.at(0) = 20;
1.340 + CPPUNIT_ASSERT( cv.at(0) == 20 );
1.341 +
1.342 +#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
1.343 + for (;;) {
1.344 + try {
1.345 + v.at(1) = 20;
1.346 + CPPUNIT_ASSERT(false);
1.347 + }
1.348 + catch (out_of_range const&) {
1.349 + return;
1.350 + }
1.351 + catch (...) {
1.352 + CPPUNIT_ASSERT(false);
1.353 + }
1.354 + }
1.355 +#endif
1.356 +}
1.357 +
1.358 +void VectorTest::pointer()
1.359 +{
1.360 + vector<int *> v1;
1.361 + vector<int *> v2 = v1;
1.362 + vector<int *> v3;
1.363 +
1.364 + v3.insert( v3.end(), v1.begin(), v1.end() );
1.365 +}
1.366 +
1.367 +void VectorTest::auto_ref()
1.368 +{
1.369 + vector<int> ref;
1.370 + for (int i = 0; i < 5; ++i) {
1.371 + ref.push_back(i);
1.372 + }
1.373 +
1.374 + vector<vector<int> > v_v_int(1, ref);
1.375 + v_v_int.push_back(v_v_int[0]);
1.376 + v_v_int.push_back(ref);
1.377 + v_v_int.push_back(v_v_int[0]);
1.378 + v_v_int.push_back(v_v_int[0]);
1.379 + v_v_int.push_back(ref);
1.380 +
1.381 + vector<vector<int> >::iterator vvit(v_v_int.begin()), vvitEnd(v_v_int.end());
1.382 + for (; vvit != vvitEnd; ++vvit) {
1.383 + CPPUNIT_ASSERT( *vvit == ref );
1.384 + }
1.385 +
1.386 + /*
1.387 + * Forbidden by the Standard:
1.388 + v_v_int.insert(v_v_int.end(), v_v_int.begin(), v_v_int.end());
1.389 + for (vvit = v_v_int.begin(), vvitEnd = v_v_int.end();
1.390 + vvit != vvitEnd; ++vvit) {
1.391 + CPPUNIT_ASSERT( *vvit == ref );
1.392 + }
1.393 + */
1.394 +}
1.395 +
1.396 +void VectorTest::allocator_with_state()
1.397 +{
1.398 + char buf1[1024];
1.399 + StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1));
1.400 +
1.401 + char buf2[1024];
1.402 + StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2));
1.403 +
1.404 + {
1.405 + typedef vector<int, StackAllocator<int> > VectorInt;
1.406 + VectorInt vint1(10, 0, stack1);
1.407 + VectorInt vint1Cpy(vint1);
1.408 +
1.409 + VectorInt vint2(10, 1, stack2);
1.410 + VectorInt vint2Cpy(vint2);
1.411 +
1.412 + vint1.swap(vint2);
1.413 +
1.414 + CPPUNIT_ASSERT( vint1.get_allocator().swaped() );
1.415 + CPPUNIT_ASSERT( vint2.get_allocator().swaped() );
1.416 +
1.417 + CPPUNIT_ASSERT( vint1 == vint2Cpy );
1.418 + CPPUNIT_ASSERT( vint2 == vint1Cpy );
1.419 + CPPUNIT_ASSERT( vint1.get_allocator() == stack2 );
1.420 + CPPUNIT_ASSERT( vint2.get_allocator() == stack1 );
1.421 + }
1.422 + CPPUNIT_ASSERT( stack1.ok() );
1.423 + CPPUNIT_ASSERT( stack2.ok() );
1.424 +}
1.425 +
1.426 +struct Point {
1.427 + int x, y;
1.428 +};
1.429 +
1.430 +struct PointEx : public Point {
1.431 + PointEx() : builtFromBase(false) {}
1.432 + PointEx(const Point&) : builtFromBase(true) {}
1.433 +
1.434 + bool builtFromBase;
1.435 +};
1.436 +
1.437 +#if defined (STLPORT)
1.438 +namespace std {
1.439 + template <>
1.440 + struct __type_traits<PointEx> {
1.441 + typedef __false_type has_trivial_default_constructor;
1.442 + typedef __true_type has_trivial_copy_constructor;
1.443 + typedef __true_type has_trivial_assignment_operator;
1.444 + typedef __true_type has_trivial_destructor;
1.445 + typedef __true_type is_POD_type;
1.446 + };
1.447 +}
1.448 +#endif
1.449 +
1.450 +//This test check that vector implementation do not over optimize
1.451 +//operation as PointEx copy constructor is trivial
1.452 +void VectorTest::optimizations_check()
1.453 +{
1.454 +#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES)
1.455 + vector<Point> v1(1);
1.456 + CPPUNIT_ASSERT( v1.size() == 1 );
1.457 +
1.458 + vector<PointEx> v2(v1.begin(), v1.end());
1.459 + CPPUNIT_ASSERT( v2.size() == 1 );
1.460 + CPPUNIT_ASSERT( v2[0].builtFromBase == true );
1.461 +#endif
1.462 +}
1.463 +
1.464 +void VectorTest::iterators()
1.465 +{
1.466 + vector<int> vint(10, 0);
1.467 + vector<int> const& crvint = vint;
1.468 +
1.469 + CPPUNIT_ASSERT( vint.begin() == vint.begin() );
1.470 + CPPUNIT_ASSERT( crvint.begin() == vint.begin() );
1.471 + CPPUNIT_ASSERT( vint.begin() == crvint.begin() );
1.472 + CPPUNIT_ASSERT( crvint.begin() == crvint.begin() );
1.473 +
1.474 + CPPUNIT_ASSERT( vint.begin() != vint.end() );
1.475 + CPPUNIT_ASSERT( crvint.begin() != vint.end() );
1.476 + CPPUNIT_ASSERT( vint.begin() != crvint.end() );
1.477 + CPPUNIT_ASSERT( crvint.begin() != crvint.end() );
1.478 +
1.479 + CPPUNIT_ASSERT( vint.rbegin() == vint.rbegin() );
1.480 + // Not Standard:
1.481 + //CPPUNIT_ASSERT( vint.rbegin() == crvint.rbegin() );
1.482 + //CPPUNIT_ASSERT( crvint.rbegin() == vint.rbegin() );
1.483 + CPPUNIT_ASSERT( crvint.rbegin() == crvint.rbegin() );
1.484 +
1.485 + CPPUNIT_ASSERT( vint.rbegin() != vint.rend() );
1.486 + // Not Standard:
1.487 + //CPPUNIT_ASSERT( vint.rbegin() != crvint.rend() );
1.488 + //CPPUNIT_ASSERT( crvint.rbegin() != vint.rend() );
1.489 + CPPUNIT_ASSERT( crvint.rbegin() != crvint.rend() );
1.490 +}
1.491 +
1.492 +#if defined (STLPORT)
1.493 +# define NOTHROW _STLP_NOTHROW
1.494 +#else
1.495 +# define NOTHROW throw()
1.496 +#endif
1.497 +
1.498 +/* This allocator implementation purpose is simply to break some
1.499 + * internal STLport mecanism specific to the STLport own allocator
1.500 + * implementation. */
1.501 +template <class _Tp>
1.502 +struct NotSTLportAllocator : public allocator<_Tp> {
1.503 +#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATE_CLASSES)
1.504 + template <class _Tp1> struct rebind {
1.505 + typedef NotSTLportAllocator<_Tp1> other;
1.506 + };
1.507 +#endif
1.508 + NotSTLportAllocator() _STLP_NOTHROW {}
1.509 +#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATES)
1.510 + template <class _Tp1> NotSTLportAllocator(const NotSTLportAllocator<_Tp1>&) NOTHROW {}
1.511 +#endif
1.512 + NotSTLportAllocator(const NotSTLportAllocator<_Tp>&) NOTHROW {}
1.513 + ~NotSTLportAllocator() NOTHROW {}
1.514 +};
1.515 +
1.516 +/* This test check a potential issue with empty base class
1.517 + * optimization. Some compilers (VC6) do not implement it
1.518 + * correctly resulting ina wrong behavior. */
1.519 +void VectorTest::ebo()
1.520 +{
1.521 + // We use heap memory as test failure can corrupt vector internal
1.522 + // representation making executable crash on vector destructor invocation.
1.523 + // We prefer a simple memory leak, internal corruption should be reveal
1.524 + // by size or capacity checks.
1.525 + typedef vector<int, NotSTLportAllocator<int> > V;
1.526 + V *pv1 = new V(1, 1);
1.527 + V *pv2 = new V(10, 2);
1.528 +
1.529 + size_t v1Capacity = pv1->capacity();
1.530 + size_t v2Capacity = pv2->capacity();
1.531 +
1.532 + pv1->swap(*pv2);
1.533 +
1.534 + CPPUNIT_ASSERT( pv1->size() == 10 );
1.535 + CPPUNIT_ASSERT( pv1->capacity() == v2Capacity );
1.536 + CPPUNIT_ASSERT( (*pv1)[5] == 2 );
1.537 +
1.538 + CPPUNIT_ASSERT( pv2->size() == 1 );
1.539 + CPPUNIT_ASSERT( pv2->capacity() == v1Capacity );
1.540 + CPPUNIT_ASSERT( (*pv2)[0] == 1 );
1.541 +
1.542 + delete pv2;
1.543 + delete pv1;
1.544 +}
1.545 +void VectorTest::vec_cov1()
1.546 + {
1.547 + __UHEAP_MARK;
1.548 + {
1.549 + vector<int> v;
1.550 + vector<int> const& cv = v;
1.551 + v.push_back(10);
1.552 + v.push_back(20);
1.553 + v.push_back(30);
1.554 + v.push_back(40);
1.555 + v.push_back(50);
1.556 + CPPUNIT_ASSERT( cv.front() == 10 );
1.557 + CPPUNIT_ASSERT( cv.back() == 50 );
1.558 + }
1.559 + {
1.560 + int i;
1.561 + vector<int> vec;
1.562 + for (i = 1 ; i < 6 ; ++i )
1.563 + {
1.564 + vec.push_back ( 3 * i );
1.565 + }
1.566 + vector <int>::reverse_iterator rVPOS1 = vec.rend ( ) - 1;
1.567 + rVPOS1-=2;
1.568 + CPPUNIT_ASSERT( *rVPOS1 == 9 );
1.569 + vector <int>::reverse_iterator rVPOS2 =rVPOS1 + 2;
1.570 + CPPUNIT_ASSERT( *rVPOS2 == 3 );
1.571 + }
1.572 + {
1.573 + int i;
1.574 + vector<int> vec;
1.575 + for (i = 1 ; i < 6 ; ++i )
1.576 + {
1.577 + vec.push_back ( 2 * i );
1.578 + }
1.579 + vector <int>::reverse_iterator rVPOS1 = vec.rbegin ( );
1.580 + rVPOS1+=2;
1.581 + CPPUNIT_ASSERT( *rVPOS1 == 6 );
1.582 + }
1.583 + __UHEAP_MARKEND;
1.584 + }
1.585 +void VectorTest::vec_cov2()
1.586 + {
1.587 + __UHEAP_MARK;
1.588 + {
1.589 + int i;
1.590 + vector<int> vec;
1.591 + for (i = 1 ; i < 6 ; ++i )
1.592 + {
1.593 + vec.push_back ( 2 * i - 1 );
1.594 + }
1.595 + vector <int>::reverse_iterator rVPOS1 = vec.rend ( ) - 1;
1.596 + rVPOS1--;
1.597 + CPPUNIT_ASSERT( *rVPOS1 == 3 );
1.598 + }
1.599 + {
1.600 + int i;
1.601 + vector<int> vec;
1.602 + for (i = 1 ; i < 6 ; ++i )
1.603 + {
1.604 + vec.push_back ( 2 * i );
1.605 + }
1.606 + vector <int>::iterator pos;
1.607 + pos = find ( vec.begin ( ), vec.end ( ), 8 );
1.608 + reverse_iterator<vector<int>::iterator> rpos ( pos );
1.609 + reverse_iterator<vector<int>::iterator>::difference_type diff = 2;
1.610 + reverse_iterator<vector<int>::iterator>::reference refrpos = rpos [diff];
1.611 + CPPUNIT_ASSERT( refrpos == 2 );
1.612 + }
1.613 + {
1.614 + int i;
1.615 + vector<int> vec;
1.616 + for ( i = 1 ; i < 6 ; ++i )
1.617 + {
1.618 + vec.push_back ( i );
1.619 + }
1.620 + vector <int>::iterator pos;
1.621 + pos = find ( vec.begin ( ), vec.end ( ), 4 );
1.622 + vector <int>::reverse_iterator rpos ( pos );
1.623 + CPPUNIT_ASSERT( *rpos == 3 );
1.624 + }
1.625 + __UHEAP_MARKEND;
1.626 + }
1.627 +void VectorTest::vec_cov3()
1.628 + {
1.629 + __UHEAP_MARK;
1.630 + {
1.631 + int i;
1.632 + vector<int> vec;
1.633 + for (i = 1 ; i < 3 ; ++i )
1.634 + {
1.635 + vec.push_back ( 10 * i );
1.636 + }
1.637 + back_insert_iterator<vector<int> > backiter ( vec );
1.638 + *backiter = 30;
1.639 + backiter++;
1.640 + *backiter = 40;
1.641 + backiter++;
1.642 + vector <int>::iterator vIter;
1.643 + vIter = vec.begin ( ) ;
1.644 + CPPUNIT_ASSERT( *vIter == 10 );
1.645 + vIter++;
1.646 + CPPUNIT_ASSERT( *vIter == 20 );
1.647 + vIter++;
1.648 + CPPUNIT_ASSERT( *vIter == 30 );
1.649 + vIter++;
1.650 + CPPUNIT_ASSERT( *vIter == 40 );
1.651 + }
1.652 + {
1.653 + vector<int> vec;
1.654 + vec.push_back (10);
1.655 + insert_iterator<vector<int> > ii ( vec, vec.begin ( ) );
1.656 + *ii = 30;
1.657 + vector <int>::iterator vIter;
1.658 + vIter = vec.begin ( ) ;
1.659 + CPPUNIT_ASSERT( *vIter == 30 );
1.660 + }
1.661 + {
1.662 + int i;
1.663 + vector<int> vec;
1.664 + for (i = 1 ; i < 6 ; ++i )
1.665 + {
1.666 + vec.push_back ( 3 * i );
1.667 + }
1.668 + vector <int>::reverse_iterator rVPOS1 = vec.rend ( ) - 1;
1.669 + vector <int>::reverse_iterator rVPOS2 = vec.rbegin ( );
1.670 + CPPUNIT_ASSERT(*rVPOS2 > *rVPOS1);
1.671 + }
1.672 + __UHEAP_MARKEND;
1.673 + }
1.674 +
1.675 +void VectorTest::vec_cov4()
1.676 + {
1.677 + __UHEAP_MARK;
1.678 + vector<int> v;
1.679 + size_t x;
1.680 + v.push_back(10);
1.681 + v.push_back(20);
1.682 + v.push_back(30);
1.683 + v.push_back(40);
1.684 + v.push_back(50);
1.685 + x=v.max_size();
1.686 + #if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
1.687 + for (;;) {
1.688 + try {
1.689 + v.reserve(x+1);
1.690 + CPPUNIT_ASSERT(false);
1.691 + }
1.692 + catch (length_error const&) {
1.693 + return;
1.694 + }
1.695 + catch (...) {
1.696 + CPPUNIT_ASSERT(false);
1.697 + }
1.698 + }
1.699 +#endif
1.700 + __UHEAP_MARKEND;
1.701 +}