/*=================================================================================== assert_sorted_version EFFECTS: Asserts that buf is a stable-sorted version of orig. ====================================================================================*/ void assert_sorted_version( const SortBuffer& orig, const SortBuffer& buf ) { // Stop any potential failures that might occur during verification. gTestController.CancelFailureCountdown(); // Prepare an array of counts of the occurrence of each value in // the legal range. unsigned counts[SortClass::kRange]; EH_STD::fill_n( counts, (int)SortClass::kRange, 0 ); for ( const SortClass *q = orig.begin(); q != orig.end(); q++ ) counts[ q->value() ]++; // Check that each element is greater than the previous one, or if they are // equal, that their order has been preserved. for ( const SortClass* p = buf.begin(); p != buf.end(); p++ ) { if ( p != buf.begin() ) EH_ASSERT( p->value() > p[-1].value() || p->value() == p[-1].value() && p->GetAddress() > p[-1].GetAddress() ); // Decrement the appropriate count for each value. counts[ p->value() ]--; } // Check that the values were only rearranged, and none were lost. for ( unsigned j = 0; j < SortClass::kRange; j++ ) EH_ASSERT( counts[j] == 0 ); }
/*=================================================================================== test_bit_vector EFFECTS: Performs tests on bit vectors ====================================================================================*/ void test_bit_vector() { #define __WORD_BIT (int(CHAR_BIT*sizeof(unsigned int))) // Make some bit vectors to work with. BitVector emptyVector; BitVector testVector, testVector2; EH_ASSERT( testVector.size() == 0 ); size_t BitVectorSize = random_number( random_base ); // Half the time, choose a size that will guarantee immediate reallocation if ( random_number(2) ) BitVectorSize = BitVectorSize / __WORD_BIT * __WORD_BIT; EH_ASSERT( testVector.size() == 0 ); testVector.reserve(BitVectorSize); EH_ASSERT( testVector.size() == 0 ); while ( testVector.size() < BitVectorSize ) { testVector.push_back( bool(random_number(2)) ); testVector2.push_back( bool(random_number(2)) ); } // Test insertions StrongCheck( testVector, test_insert_one<BitVector>(testVector) ); StrongCheck( testVector, test_insert_one<BitVector>(testVector,0) ); StrongCheck( testVector, test_insert_one<BitVector>(testVector, (int)testVector.size()) ); StrongCheck( testVector, test_insert_n<BitVector>(testVector, random_number(random_base) ) ); StrongCheck( testVector, test_insert_n<BitVector>(testVector, random_number(random_base),0 ) ); StrongCheck( testVector, test_insert_n<BitVector>(testVector, random_number(random_base), (int)testVector.size()) ); # if 0 // Allocate some random bools to insert size_t insCnt = 1 + random_number(random_base); bool *insFirst = new BitVector::value_type[insCnt]; for ( size_t n = 0; n < insCnt; n++ ) insFirst[n] = random_number(2); StrongCheck( testVector, insert_range_tester(testVector, insFirst, insFirst+insCnt) ); StrongCheck( testVector, insert_range_at_begin_tester(testVector, insFirst, insFirst+insCnt) ); StrongCheck( testVector, insert_range_at_end_tester(testVector, insFirst, insFirst+insCnt) ); ConstCheck( 0, test_construct_pointer_range<BitVector>( insFirst, insFirst + insCnt ) ); delete[] insFirst; # endif StrongCheck( testVector, insert_range_tester(testVector, testVector2.begin(), testVector2.end() ) ); StrongCheck( testVector, insert_range_at_begin_tester(testVector, testVector2.begin(), testVector2.end() ) ); StrongCheck( testVector, insert_range_at_end_tester(testVector, testVector2.begin(), testVector2.end() ) ); StrongCheck( testVector, test_BitVector_reserve( testVector.capacity() + random_number(50) ) ); StrongCheck( testVector, test_push_back<BitVector>(testVector) ); StrongCheck( emptyVector, test_push_back<BitVector>(emptyVector) ); ConstCheck( 0, test_default_construct<BitVector>() ); ConstCheck( 0, test_construct_n<BitVector>( random_number(random_base) ) ); ConstCheck( 0, test_construct_n_instance<BitVector>( random_number(random_base) ) ); ConstCheck( 0, test_construct_iter_range<BitVector>( testVector2 ) ); ConstCheck( testVector, test_copy_construct<BitVector>() ); WeakCheck( testVector, test_assign_op<BitVector>( testVector2 ) ); }
void operator()( TestSList& slist ) const { slist.sort(); for ( TestSList::iterator p = slist.begin(), q; p != slist.end(); q = p, p++ ) if ( p != slist.begin() ) EH_ASSERT( *p >= *q ); }
void operator()( TestClass* buffer ) const { TestClass* end = buffer + kBufferSize; EH_STD::uninitialized_fill_n( buffer, (EH_CSTD::size_t)kBufferSize, testValue ); for ( EH_CSTD::size_t i = 0; i < kBufferSize; i++ ) EH_ASSERT( buffer[i] == testValue ); stl_destroy( buffer, end ); }
// push // // pJmpBufNode must point to a space allocated // via the new operator // void EHExceptionJmpBufStack::push(EHExceptionJmpBufNode * pJmpBufNode) { EH_ASSERT(pJmpBufNode->getLink() == NULL); pJmpBufNode->setLink(pTopNode_); pTopNode_ = pJmpBufNode; }
void operator()( TestList& list ) const { list.sort(); gTestController.CancelFailureCountdown(); for ( TestList::iterator p = list.begin(); p != list.end(); p++ ) if ( p != list.begin() ) { TestList::iterator tmp=p; --tmp; EH_ASSERT( *p >= *tmp ); } }
void operator()( SortBuffer& buf ) const { less_by_reference<SortClass> throw_cmp( partitionPoint ); SortClass* d = EH_STD::stable_partition( buf.begin(), buf.end(), throw_cmp ); // If we get here no exception occurred during the operation. // Stop any potential failures that might occur during verification. gTestController.CancelFailureCountdown(); // Prepare an array of counts of the occurrence of each value in // the legal range. unsigned counts[SortClass::kRange]; EH_STD::fill_n( counts, (int)SortClass::kRange, 0 ); for ( const SortClass *q = orig.begin(); q != orig.end(); q++ ) counts[ q->value() ]++; less_by_reference<TestClass> cmp( partitionPoint ); for ( const SortClass* p = buf.begin(); p != buf.end(); p++ ) { // Check that adjacent items with the same value haven't been // reordered. This could be a more thorough test. if ( p != buf.begin() && p->value() == p[-1].value() ) EH_ASSERT( p->GetAddress() > p[-1].GetAddress() ); // Check that the partitioning worked. EH_ASSERT( (p < d) == cmp( *p ) ); // Decrement the appropriate count for each value. counts[ p->value() ]--; } // Check that the values were only rearranged, and none were lost. for ( unsigned j = 0; j < SortClass::kRange; j++ ) EH_ASSERT( counts[j] == 0 ); }
static void* OperatorNew( size_t s ) { if ( !using_alloc_set ) { simulate_possible_failure(); alloc_count++; } char *p = AllocateBlock(s); if ( gTestController.TrackingEnabled() && gTestController.LeakDetectionEnabled() && !using_alloc_set ) { using_alloc_set = true; EH_ASSERT( alloc_set().find( p ) == alloc_set().end() ); alloc_set().insert( p ); using_alloc_set = false; } return p; }
bool TestController::ReportLeaked() { EndLeakDetection(); if (using_alloc_set) EH_ASSERT( alloc_count == static_cast<int>(alloc_set().size()) ); if ( alloc_count!=0 || object_count!=0 ) { EH_STD::cerr<<"\nEH TEST FAILURE !\n"; PrintTestName(true); if (alloc_count) EH_STD::cerr<<"ERROR : "<<alloc_count<<" outstanding allocations.\n"; if (object_count) EH_STD::cerr<<"ERROR : "<<object_count<<" non-destroyed objects.\n"; alloc_count = object_count = 0; return true; } return false; }
void _STLP_CALL operator delete(void* s) # endif { if ( s != 0 ) { if ( !using_alloc_set ) { alloc_count--; if ( gTestController.TrackingEnabled() && gTestController.LeakDetectionEnabled() ) { using_alloc_set = true; allocation_set::iterator p = alloc_set().find( (char*)s ); EH_ASSERT( p != alloc_set().end() ); alloc_set().erase( p ); using_alloc_set = false; } } # if ! defined (NO_FAST_ALLOCATOR) if ( !gFastAllocator.Free( s ) ) # endif EH_CSTD::free(s); } }
void operator()( TestClass* buffer ) const { EH_STD::uninitialized_copy((TestClass*)stuff, (TestClass*)end_of_stuff, buffer ); EH_ASSERT( EH_STD::equal( (TestClass*)stuff, (TestClass*)end_of_stuff, buffer ) ); stl_destroy( buffer, buffer+kBufferSize ); }