int main( ) { int rc = 0; int original_count = heap_count( ); try { if( !construct_test( ) || !heap_ok( "t01" ) ) rc = 1; if( !assign_test( ) || !heap_ok( "t02" ) ) rc = 1; if( !access_test( ) || !heap_ok( "t03" ) ) rc = 1; if( !relational_test( ) || !heap_ok( "t04" ) ) rc = 1; if( !capacity_test( ) || !heap_ok( "t05" ) ) rc = 1; if( !iterator_test( ) || !heap_ok( "t06" ) ) rc = 1; if( !append_test( ) || !heap_ok( "t07" ) ) rc = 1; if( !insert_test( ) || !heap_ok( "t08" ) ) rc = 1; if( !erase_test( ) || !heap_ok( "t09" ) ) rc = 1; if( !replace_test( ) || !heap_ok( "t10" ) ) rc = 1; if( !iterator_replace_test( ) || !heap_ok( "t11" ) ) rc = 1; if( !copy_test( ) || !heap_ok( "t12" ) ) rc = 1; if( !swap_test( ) || !heap_ok( "t13" ) ) rc = 1; if( !cstr_test( ) || !heap_ok( "t14" ) ) rc = 1; if( !find_test( ) || !heap_ok( "t15" ) ) rc = 1; if( !rfind_test( ) || !heap_ok( "t16" ) ) rc = 1; if( !find_first_of_test( ) || !heap_ok( "t17" ) ) rc = 1; if( !find_last_of_test( ) || !heap_ok( "t18" ) ) rc = 1; if( !find_first_not_of_test( ) || !heap_ok( "t19" ) ) rc = 1; if( !find_last_not_of_test( ) || !heap_ok( "t20" ) ) rc = 1; if( !substr_test( ) || !heap_ok( "t21" ) ) rc = 1; } catch( std::out_of_range e ) { std::cout << "Unexpected out_of_range exception: " << e.what( ) << "\n"; rc = 1; } catch( std::length_error e ) { std::cout << "Unexpected length_error exception: " << e.what( ) << "\n"; rc = 1; } catch( ... ) { std::cout << "Unexpected exception of unexpected type.\n"; rc = 1; } if( heap_count( ) != original_count ) { std::cout << "Possible memory leak!\n"; rc = 1; } return( rc ); }
int main(void) { string str; str_init(&str, "Hello, world!"); char *str2 = "Hello, world!"; int len = strlen(str2); printf("Pracuji se retezcem: \"%s\"\n",str.str); substr_test(str, str2, 1, 6, "Hello,", len); substr_test(str, str2, 8, 12, "world", len); substr_test(str, str2, 1, 13, "Hello, world!", len); substr_test(str, str2, 1, 20, "Hello, world!", len); substr_test(str, str2, -6, -1, "world!", len); substr_test(str, str2, 5, 4, "", len); substr_test(str, str2, -4, -5, "", len); substr_test(str, str2, -1, 3, "", len); substr_test(str, str2, 10, -6, "", len); str_free(&str); str_init(&str,"abc"); str2 = "abc"; len = strlen(str2); printf("\nPracuji se retezcem: \"%s\"\n",str.str); substr_test(str, str2, -4, -4, "", len); substr_test(str, str2, -3, -3, "a", len); substr_test(str, str2, -4, -3, "a", len); substr_test(str, str2, 3, 6, "c", len); substr_test(str, str2, 4, 4, "", len); str_free(&str); return 0; }