Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentest_bit_vector.cpp
Go to the documentation of this file.
00001 /*********************************************************************************** 00002 test_bit_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 00018 #if defined( EH_BIT_VECTOR_IMPLEMENTED ) 00019 00020 # if defined (EH_NEW_HEADERS) 00021 # ifdef __SUNPRO_CC 00022 # include <stdio.h> 00023 # endif 00024 #include <vector> 00025 # else 00026 #include <bvector.h> 00027 # endif 00028 00029 #include "LeakCheck.h" 00030 #include "test_construct.h" 00031 #include "test_assign_op.h" 00032 #include "test_push_back.h" 00033 #include "test_insert.h" 00034 #include "test_push_front.h" 00035 00036 typedef EH_BIT_VECTOR BitVector; 00037 00038 inline sequence_container_tag 00039 container_category(const BitVector&) 00040 { 00041 return sequence_container_tag(); 00042 } 00043 00044 USING_CSTD_NAME(size_t) 00045 00046 // 00047 // test_BitVector_reserve 00048 // 00049 struct test_BitVector_reserve 00050 { 00051 test_BitVector_reserve( size_t n ) : fAmount(n) 00052 { 00053 gTestController.SetCurrentTestName("BitVector::reserve()"); 00054 } 00055 00056 void operator()( BitVector& v ) const 00057 { 00058 v.reserve( fAmount ); 00059 } 00060 private: 00061 size_t fAmount; 00062 }; 00063 00064 /*=================================================================================== 00065 test_bit_vector 00066 00067 EFFECTS: Performs tests on bit vectors 00068 ====================================================================================*/ 00069 void test_bit_vector() 00070 { 00071 #define __WORD_BIT (int(CHAR_BIT*sizeof(unsigned int))) 00072 00073 // Make some bit vectors to work with. 00074 BitVector emptyVector; 00075 BitVector testVector, testVector2; 00076 00077 EH_ASSERT( testVector.size() == 0 ); 00078 00079 size_t BitVectorSize = random_number( random_base ); 00080 // Half the time, choose a size that will guarantee immediate reallocation 00081 if ( random_number(2) ) 00082 BitVectorSize = BitVectorSize / __WORD_BIT * __WORD_BIT; 00083 00084 EH_ASSERT( testVector.size() == 0 ); 00085 testVector.reserve(BitVectorSize); 00086 EH_ASSERT( testVector.size() == 0 ); 00087 while (testVector.size() < BitVectorSize) { 00088 testVector.push_back(random_number(2) != 0); 00089 testVector2.push_back(random_number(2) != 0); 00090 } 00091 00092 // Test insertions 00093 StrongCheck(testVector, test_insert_one<BitVector>(testVector) ); 00094 StrongCheck(testVector, test_insert_one<BitVector>(testVector,0) ); 00095 StrongCheck(testVector, test_insert_one<BitVector>(testVector, (int)testVector.size()) ); 00096 00097 StrongCheck(testVector, test_insert_n<BitVector>(testVector, random_number(random_base) ) ); 00098 StrongCheck(testVector, test_insert_n<BitVector>(testVector, random_number(random_base),0 ) ); 00099 StrongCheck(testVector, test_insert_n<BitVector>(testVector, random_number(random_base), (int)testVector.size()) ); 00100 #if 0 00101 // Allocate some random bools to insert 00102 size_t insCnt = 1 + random_number(random_base); 00103 bool *insFirst = new BitVector::value_type[insCnt]; 00104 for (size_t n = 0; n < insCnt; n++) 00105 insFirst[n] = random_number(2); 00106 StrongCheck(testVector, insert_range_tester(testVector, insFirst, insFirst+insCnt)); 00107 StrongCheck(testVector, insert_range_at_begin_tester(testVector, insFirst, insFirst+insCnt)); 00108 StrongCheck(testVector, insert_range_at_end_tester(testVector, insFirst, insFirst+insCnt)); 00109 ConstCheck(0, test_construct_pointer_range<BitVector>( insFirst, insFirst + insCnt)); 00110 delete[] insFirst; 00111 #endif 00112 StrongCheck(testVector, insert_range_tester(testVector, testVector2.begin(), testVector2.end())); 00113 StrongCheck(testVector, insert_range_at_begin_tester(testVector, testVector2.begin(), 00114 testVector2.end())); 00115 StrongCheck(testVector, insert_range_at_end_tester(testVector, testVector2.begin(), 00116 testVector2.end())); 00117 StrongCheck(testVector, test_BitVector_reserve( testVector.capacity() + random_number(50))); 00118 StrongCheck(testVector, test_push_back<BitVector>(testVector)); 00119 StrongCheck(emptyVector, test_push_back<BitVector>(emptyVector)); 00120 00121 ConstCheck(0, test_default_construct<BitVector>()); 00122 ConstCheck(0, test_construct_n<BitVector>(random_number(random_base))); 00123 ConstCheck(0, test_construct_n_instance<BitVector>(random_number(random_base))); 00124 ConstCheck(0, test_construct_iter_range<BitVector>(testVector2)); 00125 ConstCheck(testVector, test_copy_construct<BitVector>() ); 00126 WeakCheck(testVector, test_assign_op<BitVector>(testVector2) ); 00127 } 00128 00129 # endif /* BIT_VECTOR_IMPLEMENTED */ Generated on Sat May 26 2012 04:34:05 for ReactOS by
1.7.6.1
|