sl@0: /*********************************************************************************** sl@0: test_algobase.cpp sl@0: sl@0: * Copyright (c) 1997 sl@0: * Mark of the Unicorn, Inc. sl@0: * sl@0: * Permission to use, copy, modify, distribute and sell this software sl@0: * and its documentation for any purpose is hereby granted without fee, sl@0: * provided that the above copyright notice appear in all copies and sl@0: * that both that copyright notice and this permission notice appear sl@0: * in supporting documentation. Mark of the Unicorn makes no sl@0: * representations about the suitability of this software for any sl@0: * purpose. It is provided "as is" without express or implied warranty. sl@0: sl@0: ***********************************************************************************/ sl@0: sl@0: # include "Prefix.h" sl@0: # if defined (EH_NEW_HEADERS) sl@0: # ifdef __SUNPRO_CC sl@0: # include sl@0: # endif sl@0: #include sl@0: # else sl@0: #include sl@0: # endif sl@0: #include "Tests.h" sl@0: #include "LeakCheck.h" sl@0: #include "TestClass.h" sl@0: sl@0: // EH_USE_STD sl@0: sl@0: enum { kBufferSize = 100 }; sl@0: sl@0: struct test_uninitialized_copy sl@0: { sl@0: test_uninitialized_copy() sl@0: : stuff( new TestClass[kBufferSize] ), end_of_stuff(stuff + kBufferSize) { sl@0: gTestController.SetCurrentTestName("uninitialized_copy()"); sl@0: } sl@0: sl@0: ~test_uninitialized_copy() { delete[] stuff; } sl@0: sl@0: void operator()( TestClass* buffer ) const sl@0: { sl@0: EH_STD::uninitialized_copy((TestClass*)stuff, (TestClass*)end_of_stuff, buffer ); sl@0: EH_ASSERT( EH_STD::equal( (TestClass*)stuff, (TestClass*)end_of_stuff, buffer ) ); sl@0: stl_destroy( buffer, buffer+kBufferSize ); sl@0: } sl@0: sl@0: private: sl@0: TestClass * stuff; sl@0: TestClass * end_of_stuff; sl@0: }; sl@0: sl@0: struct test_uninitialized_fill sl@0: { sl@0: test_uninitialized_fill() { sl@0: gTestController.SetCurrentTestName("uninitialized_fill()"); sl@0: } sl@0: sl@0: void operator()( TestClass* buffer ) const sl@0: { sl@0: TestClass* buf_end = buffer + kBufferSize; sl@0: EH_STD::uninitialized_fill( buffer, buf_end, testValue ); sl@0: for ( EH_CSTD::size_t i = 0; i < kBufferSize; i++ ) sl@0: EH_ASSERT( buffer[i] == testValue ); sl@0: stl_destroy( buffer, buf_end ); sl@0: } sl@0: private: sl@0: TestClass testValue; sl@0: }; sl@0: sl@0: struct test_uninitialized_fill_n sl@0: { sl@0: test_uninitialized_fill_n() { sl@0: gTestController.SetCurrentTestName("uninitialized_fill_n()"); sl@0: } sl@0: void operator()( TestClass* buffer ) const sl@0: { sl@0: TestClass* end = buffer + kBufferSize; sl@0: EH_STD::uninitialized_fill_n( buffer, (EH_CSTD::size_t)kBufferSize, testValue ); sl@0: for ( EH_CSTD::size_t i = 0; i < kBufferSize; i++ ) sl@0: EH_ASSERT( buffer[i] == testValue ); sl@0: stl_destroy( buffer, end ); sl@0: } sl@0: private: sl@0: TestClass testValue; sl@0: }; sl@0: sl@0: void test_algobase() sl@0: { sl@0: // force alignment sl@0: double arr[ sizeof(TestClass) * kBufferSize ]; sl@0: TestClass* c = (TestClass*)arr; sl@0: WeakCheck( c, test_uninitialized_copy() ); sl@0: WeakCheck( c, test_uninitialized_fill() ); sl@0: WeakCheck( c, test_uninitialized_fill_n() ); sl@0: }