1 /*********************************************************************************** 2 test_string.cpp 3 4 * Copyright (c) 1997 5 * Mark of the Unicorn, Inc. 6 * 7 * Permission to use, copy, modify, distribute and sell this software 8 * and its documentation for any purpose is hereby granted without fee, 9 * provided that the above copyright notice appear in all copies and 10 * that both that copyright notice and this permission notice appear 11 * in supporting documentation. Mark of the Unicorn makes no 12 * representations about the suitability of this software for any 13 * purpose. It is provided "as is" without express or implied warranty. 14 15 ***********************************************************************************/ 16 #include "Prefix.h" 17 #if defined( EH_STRING_IMPLEMENTED ) 18 #include "Tests.h" 19 #include "TestClass.h" 20 #include "LeakCheck.h" 21 #include "test_construct.h" 22 #include "test_assign_op.h" 23 #include "test_push_back.h" 24 #include "test_insert.h" 25 #include "test_push_front.h" 26 #include <string> 27 28 USING_CSTD_NAME(size_t) 29 30 typedef EH_STD::basic_string<char, EH_STD::char_traits<char>, eh_allocator(char) > TestString; 31 32 inline sequence_container_tag 33 container_category(const TestString&) 34 { 35 return sequence_container_tag(); 36 } 37 38 void test_string() { 39 TestString testString, testString2; 40 size_t ropeSize = random_number(random_base); 41 42 while ( testString.size() < ropeSize ) { 43 TestString::value_type x = TestString::value_type(random_number(random_base)) ; // initialize before use 44 testString.append(1, x ); 45 testString2.append(1, TestString::value_type() ); 46 } 47 WeakCheck( testString, test_insert_one<TestString>(testString) ); 48 WeakCheck( testString, test_insert_one<TestString>(testString, 0) ); 49 WeakCheck( testString, test_insert_one<TestString>(testString, (int)testString.size()) ); 50 51 WeakCheck( testString, test_insert_n<TestString>(testString, random_number(random_base) ) ); 52 WeakCheck( testString, test_insert_n<TestString>(testString, random_number(random_base), 0 ) ); 53 WeakCheck( testString, test_insert_n<TestString>(testString, random_number(random_base), (int)testString.size() ) ); 54 55 size_t insCnt = random_number(random_base); 56 TestString::value_type *insFirst = new TestString::value_type[1+insCnt]; 57 58 WeakCheck( testString, insert_range_tester(testString, insFirst, insFirst+insCnt) ); 59 WeakCheck( testString, insert_range_at_begin_tester(testString, insFirst, insFirst+insCnt) ); 60 WeakCheck( testString, insert_range_at_end_tester(testString, insFirst, insFirst+insCnt) ); 61 62 ConstCheck( 0, test_construct_pointer_range<TestString>(insFirst, insFirst+insCnt) ); 63 delete[] insFirst; 64 65 WeakCheck( testString, insert_range_tester(testString, testString2.begin(), testString2.end() ) ); 66 /* 67 WeakCheck( testString, test_push_front<TestString>(testString) ); 68 WeakCheck( testString, test_push_back<TestString>(testString) ); 69 */ 70 ConstCheck( 0, test_default_construct<TestString>() ); 71 // requires _Reserve_t ConstCheck( 0, test_construct_n<TestString>( random_number(random_base) ) ); 72 ConstCheck( 0, test_construct_n_instance<TestString>( random_number(random_base) ) ); 73 ConstCheck( 0, test_construct_iter_range<TestString>( testString2 ) ); 74 ConstCheck( testString, test_copy_construct<TestString>() ); 75 76 WeakCheck( testString, test_assign_op<TestString>( testString2 ) ); 77 } 78 79 #endif // EH_ROPE_IMPLEMENTED 80