Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentest_vector.cpp
Go to the documentation of this file.
00001 /*********************************************************************************** 00002 test_vector.cpp 00003 00004 * Copyright (c) 1997 00005 * Mark of the Unicorn, Inc. 00006 * 00007 * Permission to use, copy, modify, distribute and sell this software 00008 * and its documentation for any purpose is hereby granted without fee, 00009 * provided that the above copyright notice appear in all copies and 00010 * that both that copyright notice and this permission notice appear 00011 * in supporting documentation. Mark of the Unicorn makes no 00012 * representations about the suitability of this software for any 00013 * purpose. It is provided "as is" without express or implied warranty. 00014 00015 ***********************************************************************************/ 00016 #include "Tests.h" 00017 #include "TestClass.h" 00018 #include "LeakCheck.h" 00019 # if defined (EH_NEW_HEADERS) 00020 #include <vector> 00021 #else 00022 #include <vector.h> 00023 #endif 00024 #include "test_construct.h" 00025 #include "test_assign_op.h" 00026 #include "test_push_back.h" 00027 #include "test_insert.h" 00028 #include "test_push_front.h" 00029 00030 # if defined (__GNUC__) && defined (__APPLE__) 00031 typedef EH_STD::vector<TestClass, eh_allocator(TestClass) > TestVector; 00032 # else 00033 typedef EH_STD::__vector__<TestClass, eh_allocator(TestClass) > TestVector; 00034 # endif 00035 00036 inline sequence_container_tag 00037 container_category(const TestVector&) 00038 { 00039 return sequence_container_tag(); 00040 } 00041 00042 void prepare_insert_n( TestVector& c, size_t insCnt ); 00043 00044 void prepare_insert_n( TestVector& c, size_t insCnt ) 00045 { 00046 if ( random_number(2) ) 00047 c.reserve( c.size() + insCnt ); 00048 } 00049 00050 struct test_reserve 00051 { 00052 test_reserve( size_t n ) : fAmount(n) { 00053 gTestController.SetCurrentTestName("vector::reserve()"); 00054 } 00055 00056 void operator()( TestVector& v ) const 00057 { 00058 v.reserve( fAmount ); 00059 } 00060 private: 00061 size_t fAmount; 00062 }; 00063 00064 inline void prepare_insert_range( TestVector& vec, size_t, TestClass* first, TestClass* last ) 00065 { 00066 if ( random_number(2) ) 00067 { 00068 ptrdiff_t d = 0; 00069 EH_DISTANCE( first, last, d ); 00070 vec.reserve( vec.size() + d ); 00071 } 00072 } 00073 00074 void test_vector() 00075 { 00076 00077 ConstCheck( 0, test_construct_n<TestVector>( random_number(random_base) ) ); 00078 00079 TestVector emptyVector; 00080 TestVector testVector, testVector2; 00081 size_t vectorSize = random_number(random_base); 00082 00083 testVector.reserve(vectorSize*4); 00084 while ( testVector.size() < vectorSize ) 00085 { 00086 TestClass x; 00087 testVector.push_back( x ); 00088 testVector2.push_back( TestClass() ); 00089 } 00090 00091 size_t insCnt = random_number(random_base); 00092 TestClass *insFirst = new TestVector::value_type[1+ insCnt]; 00093 00094 ConstCheck( 0, test_construct_pointer_range<TestVector>(insFirst, insFirst+insCnt) ); 00095 00096 WeakCheck( testVector, insert_range_tester(testVector, insFirst, insFirst+insCnt) ); 00097 WeakCheck( testVector, insert_range_at_begin_tester(testVector, insFirst, insFirst+insCnt) ); 00098 WeakCheck( testVector, insert_range_at_end_tester(testVector, insFirst, insFirst+insCnt) ); 00099 delete[] insFirst; 00100 00101 WeakCheck( testVector, test_insert_one<TestVector>(testVector) ); 00102 WeakCheck( testVector, test_insert_one<TestVector>(testVector, 0) ); 00103 WeakCheck( testVector, test_insert_one<TestVector>(testVector, (int)testVector.size()) ); 00104 00105 WeakCheck( testVector, test_insert_n<TestVector>(testVector, random_number(random_base) ) ); 00106 WeakCheck( testVector, test_insert_n<TestVector>(testVector, random_number(random_base), 0 ) ); 00107 WeakCheck( testVector, test_insert_n<TestVector>(testVector, random_number(random_base), (int)testVector.size() ) ); 00108 00109 WeakCheck( testVector, insert_range_tester(testVector, testVector2.begin(), testVector2.end() ) ); 00110 00111 00112 StrongCheck( testVector, test_reserve( testVector.capacity() + random_number(random_base) ) ); 00113 StrongCheck( testVector, test_push_back<TestVector>(testVector) ); 00114 StrongCheck( emptyVector, test_push_back<TestVector>(emptyVector) ); 00115 00116 ConstCheck( 0, test_default_construct<TestVector>() ); 00117 ConstCheck( 0, test_construct_n_instance<TestVector>( random_number(random_base) ) ); 00118 ConstCheck( 0, test_construct_iter_range<TestVector>( testVector2 ) ); 00119 ConstCheck( testVector, test_copy_construct<TestVector>() ); 00120 00121 testVector2.resize( testVector.size() * 3 / 2 ); 00122 WeakCheck( testVector, test_assign_op<TestVector>( testVector2 ) ); 00123 testVector2.clear(); 00124 testVector2.resize( testVector.size() * 2 / 3 ); 00125 WeakCheck( testVector, test_assign_op<TestVector>( testVector2 ) ); 00126 } Generated on Sun May 27 2012 04:35:15 for ReactOS by
1.7.6.1
|