1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_vector.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,126 @@
1.4 +/***********************************************************************************
1.5 + test_vector.cpp
1.6 +
1.7 + * Copyright (c) 1997
1.8 + * Mark of the Unicorn, Inc.
1.9 + *
1.10 + * Permission to use, copy, modify, distribute and sell this software
1.11 + * and its documentation for any purpose is hereby granted without fee,
1.12 + * provided that the above copyright notice appear in all copies and
1.13 + * that both that copyright notice and this permission notice appear
1.14 + * in supporting documentation. Mark of the Unicorn makes no
1.15 + * representations about the suitability of this software for any
1.16 + * purpose. It is provided "as is" without express or implied warranty.
1.17 +
1.18 +***********************************************************************************/
1.19 +#include "Tests.h"
1.20 +#include "TestClass.h"
1.21 +#include "LeakCheck.h"
1.22 +# if defined (EH_NEW_HEADERS)
1.23 +#include <vector>
1.24 +#else
1.25 +#include <vector.h>
1.26 +#endif
1.27 +#include "test_construct.h"
1.28 +#include "test_assign_op.h"
1.29 +#include "test_push_back.h"
1.30 +#include "test_insert.h"
1.31 +#include "test_push_front.h"
1.32 +
1.33 +# if defined (__GNUC__) && defined (__APPLE__)
1.34 +typedef EH_STD::vector<TestClass, eh_allocator(TestClass) > TestVector;
1.35 +# else
1.36 +typedef EH_STD::__vector__<TestClass, eh_allocator(TestClass) > TestVector;
1.37 +# endif
1.38 +
1.39 +inline sequence_container_tag
1.40 +container_category(const TestVector&)
1.41 +{
1.42 + return sequence_container_tag();
1.43 +}
1.44 +
1.45 +void prepare_insert_n( TestVector& c, size_t insCnt );
1.46 +
1.47 +void prepare_insert_n( TestVector& c, size_t insCnt )
1.48 +{
1.49 + if ( random_number(2) )
1.50 + c.reserve( c.size() + insCnt );
1.51 +}
1.52 +
1.53 +struct test_reserve
1.54 +{
1.55 + test_reserve( size_t n ) : fAmount(n) {
1.56 + gTestController.SetCurrentTestName("vector::reserve()");
1.57 + }
1.58 +
1.59 + void operator()( TestVector& v ) const
1.60 + {
1.61 + v.reserve( fAmount );
1.62 + }
1.63 +private:
1.64 + size_t fAmount;
1.65 +};
1.66 +
1.67 +inline void prepare_insert_range( TestVector& vec, size_t, TestClass* first, TestClass* last )
1.68 +{
1.69 + if ( random_number(2) )
1.70 + {
1.71 + ptrdiff_t d = 0;
1.72 + EH_DISTANCE( first, last, d );
1.73 + vec.reserve( vec.size() + d );
1.74 + }
1.75 +}
1.76 +
1.77 +void test_vector()
1.78 +{
1.79 +
1.80 + ConstCheck( 0, test_construct_n<TestVector>( random_number(random_base) ) );
1.81 +
1.82 + TestVector emptyVector;
1.83 + TestVector testVector, testVector2;
1.84 + size_t vectorSize = random_number(random_base);
1.85 +
1.86 + testVector.reserve(vectorSize*4);
1.87 + while ( testVector.size() < vectorSize )
1.88 + {
1.89 + TestClass x;
1.90 + testVector.push_back( x );
1.91 + testVector2.push_back( TestClass() );
1.92 + }
1.93 +
1.94 + size_t insCnt = random_number(random_base);
1.95 + TestClass *insFirst = new TestVector::value_type[1+ insCnt];
1.96 +
1.97 + ConstCheck( 0, test_construct_pointer_range<TestVector>(insFirst, insFirst+insCnt) );
1.98 +
1.99 + WeakCheck( testVector, insert_range_tester(testVector, insFirst, insFirst+insCnt) );
1.100 + WeakCheck( testVector, insert_range_at_begin_tester(testVector, insFirst, insFirst+insCnt) );
1.101 + WeakCheck( testVector, insert_range_at_end_tester(testVector, insFirst, insFirst+insCnt) );
1.102 + delete[] insFirst;
1.103 +
1.104 + WeakCheck( testVector, test_insert_one<TestVector>(testVector) );
1.105 + WeakCheck( testVector, test_insert_one<TestVector>(testVector, 0) );
1.106 + WeakCheck( testVector, test_insert_one<TestVector>(testVector, (int)testVector.size()) );
1.107 +
1.108 + WeakCheck( testVector, test_insert_n<TestVector>(testVector, random_number(random_base) ) );
1.109 + WeakCheck( testVector, test_insert_n<TestVector>(testVector, random_number(random_base), 0 ) );
1.110 + WeakCheck( testVector, test_insert_n<TestVector>(testVector, random_number(random_base), (int)testVector.size() ) );
1.111 +
1.112 + WeakCheck( testVector, insert_range_tester(testVector, testVector2.begin(), testVector2.end() ) );
1.113 +
1.114 +
1.115 + StrongCheck( testVector, test_reserve( testVector.capacity() + random_number(random_base) ) );
1.116 + StrongCheck( testVector, test_push_back<TestVector>(testVector) );
1.117 + StrongCheck( emptyVector, test_push_back<TestVector>(emptyVector) );
1.118 +
1.119 + ConstCheck( 0, test_default_construct<TestVector>() );
1.120 + ConstCheck( 0, test_construct_n_instance<TestVector>( random_number(random_base) ) );
1.121 + ConstCheck( 0, test_construct_iter_range<TestVector>( testVector2 ) );
1.122 + ConstCheck( testVector, test_copy_construct<TestVector>() );
1.123 +
1.124 + testVector2.resize( testVector.size() * 3 / 2 );
1.125 + WeakCheck( testVector, test_assign_op<TestVector>( testVector2 ) );
1.126 + testVector2.clear();
1.127 + testVector2.resize( testVector.size() * 2 / 3 );
1.128 + WeakCheck( testVector, test_assign_op<TestVector>( testVector2 ) );
1.129 +}