diff --git a/libtransmission/bencode-test.c b/libtransmission/bencode-test.c index 5e906bd75..b5639722c 100644 --- a/libtransmission/bencode-test.c +++ b/libtransmission/bencode-test.c @@ -29,53 +29,53 @@ testInt( void ) /* good int string */ tr_snprintf( (char*)buf, sizeof( buf ), "i64e" ); err = tr_bencParseInt( buf, buf + 4, &end, &val ); - check( err == 0 ); - check( val == 64 ); - check( end == buf + 4 ); + check_int_eq( 0, err ); + check_int_eq( 64, val ); + check( (buf + 4) == end ); /* missing 'e' */ end = NULL; val = 888; err = tr_bencParseInt( buf, buf + 3, &end, &val ); - check( err == EILSEQ ); - check( val == 888 ); + check_int_eq( EILSEQ, err ); + check_int_eq( 888, val ); check( end == NULL ); /* empty buffer */ err = tr_bencParseInt( buf, buf + 0, &end, &val ); - check( err == EILSEQ ); - check( val == 888 ); + check_int_eq( EILSEQ, err ); + check_int_eq( 888, val ); check( end == NULL ); /* bad number */ tr_snprintf( (char*)buf, sizeof( buf ), "i6z4e" ); err = tr_bencParseInt( buf, buf + 5, &end, &val ); - check( err == EILSEQ ); - check( val == 888 ); + check_int_eq( EILSEQ, err ); + check_int_eq( 888, val ); check( end == NULL ); /* negative number */ tr_snprintf( (char*)buf, sizeof( buf ), "i-3e" ); err = tr_bencParseInt( buf, buf + 4, &end, &val ); - check( err == 0 ); - check( val == -3 ); - check( end == buf + 4 ); + check_int_eq( 0, err ); + check_int_eq( -3, val ); + check( (buf + 4) == end ); /* zero */ tr_snprintf( (char*)buf, sizeof( buf ), "i0e" ); err = tr_bencParseInt( buf, buf + 4, &end, &val ); - check( err == 0 ); - check( val == 0 ); - check( end == buf + 3 ); + check_int_eq( 0, err ); + check_int_eq( 0, val ); + check( (buf + 3) == end ); /* no leading zeroes allowed */ val = 0; end = NULL; tr_snprintf( (char*)buf, sizeof( buf ), "i04e" ); err = tr_bencParseInt( buf, buf + 4, &end, &val ); - check( err == EILSEQ ); - check( val == 0 ); - check( end == NULL ); + check_int_eq( EILSEQ, err ); + check_int_eq( 0, val ); + check( NULL == end ); return 0; } @@ -92,9 +92,9 @@ testStr( void ) /* good string */ tr_snprintf( (char*)buf, sizeof( buf ), "4:boat" ); err = tr_bencParseStr( buf, buf + 6, &end, &str, &len ); - check( err == 0 ); + check_int_eq (0, err); + check_int_eq (4, len); check( !strncmp( (char*)str, "boat", len ) ); - check( len == 4 ); check( end == buf + 6 ); str = NULL; end = NULL; @@ -102,7 +102,8 @@ testStr( void ) /* string goes past end of buffer */ err = tr_bencParseStr( buf, buf + 5, &end, &str, &len ); - check( err == EILSEQ ); + check_int_eq (EILSEQ, err); + check_int_eq (0, len); check( str == NULL ); check( end == NULL ); check( !len ); @@ -110,9 +111,9 @@ testStr( void ) /* empty string */ tr_snprintf( (char*)buf, sizeof( buf ), "0:" ); err = tr_bencParseStr( buf, buf + 2, &end, &str, &len ); - check( err == 0 ); + check_int_eq (0, err); + check_int_eq (0, len); check( !*str ); - check( !len ); check( end == buf + 2 ); str = NULL; end = NULL; @@ -121,9 +122,9 @@ testStr( void ) /* short string */ tr_snprintf( (char*)buf, sizeof( buf ), "3:boat" ); err = tr_bencParseStr( buf, buf + 6, &end, &str, &len ); - check( err == 0 ); + check_int_eq (0, err); + check_int_eq (3, len); check( !strncmp( (char*)str, "boa", len ) ); - check( len == 3 ); check( end == buf + 5 ); str = NULL; end = NULL; @@ -156,8 +157,8 @@ testString( const char * str, #endif check( end == (const uint8_t*)str + len ); saved = tr_bencToStr( &val, TR_FMT_BENC, &savedLen ); - check( !strcmp( saved, str ) ); - check( len == (size_t)savedLen ); + check_streq (str, saved); + check_int_eq (savedLen, len); tr_free( saved ); tr_bencFree( &val ); } @@ -181,7 +182,7 @@ testParse( void ) err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end ); check( !err ); check( tr_bencGetInt( &val, &i ) ); - check( i == 64 ); + check_int_eq (64, i); check( end == buf + 4 ); tr_bencFree( &val ); @@ -191,13 +192,13 @@ testParse( void ) check( end == buf + strlen( (char*)buf ) ); check( val.val.l.count == 3 ); check( tr_bencGetInt( &val.val.l.vals[0], &i ) ); - check( i == 64 ); + check_int_eq (64, i); check( tr_bencGetInt( &val.val.l.vals[1], &i ) ); - check( i == 32 ); + check_int_eq (32, i); check( tr_bencGetInt( &val.val.l.vals[2], &i ) ); - check( i == 16 ); + check_int_eq (16, i); saved = tr_bencToStr( &val, TR_FMT_BENC, &len ); - check( !strcmp( saved, (char*)buf ) ); + check_streq ((char*)buf, saved); tr_free( saved ); tr_bencFree( &val ); @@ -213,7 +214,7 @@ testParse( void ) check( !err ); check( end == buf + 2 ); saved = tr_bencToStr( &val, TR_FMT_BENC, &len ); - check( !strcmp( saved, "le" ) ); + check_streq( "le", saved ); tr_free( saved ); tr_bencFree( &val ); @@ -256,7 +257,7 @@ testParse( void ) check( ( child = tr_bencListChild( &val, 0 ) ) ); check( ( child2 = tr_bencListChild( child, 0 ) ) ); saved = tr_bencToStr( &val, TR_FMT_BENC, &len ); - check( !strcmp( saved, "lld1:ai64e1:bi32eeee" ) ); + check_streq( "lld1:ai64e1:bi32eeee", saved ); tr_free( saved ); tr_bencFree( &val ); @@ -267,7 +268,7 @@ testParse( void ) check( !err ); check( end == buf + 2 ); saved = tr_bencToStr( &val, TR_FMT_BENC, &len ); - check( !strcmp( saved, "le" ) ); + check_streq( "le", saved ); tr_free( saved ); tr_bencFree( &val ); @@ -314,7 +315,7 @@ testJSONSnippet( const char * benc_str, fprintf( stderr, "json: %s\n", serialized ); fprintf( stderr, "want: %s\n", expected ); #endif - check( !strcmp( serialized, expected ) ); + check_streq (expected, serialized); tr_bencFree( &top ); evbuffer_free( buf ); return 0; @@ -384,21 +385,21 @@ testMerge( void ) tr_bencMergeDicts( &dest, /*const*/ &src ); check( tr_bencDictFindInt( &dest, "i1", &i )); - check( i == 1); + check_int_eq (1, i); check( tr_bencDictFindInt( &dest, "i2", &i )); - check( i == 4); + check_int_eq (4, i); check( tr_bencDictFindInt( &dest, "i3", &i )); - check( i == 3); + check_int_eq (3, i); check( tr_bencDictFindInt( &dest, "i4", &i )); - check( i == -35); + check_int_eq (-35, i); check( tr_bencDictFindStr( &dest, "s5", &s )); - check( strcmp( "abc", s ) == 0 ); + check_streq ("abc", s); check( tr_bencDictFindStr( &dest, "s6", &s )); - check( strcmp( "xyz", s ) == 0 ); + check_streq ("xyz", s); check( tr_bencDictFindStr( &dest, "s7", &s )); - check( strcmp( "127.0.0.1", s ) == 0 ); + check_streq ("127.0.0.1", s); check( tr_bencDictFindStr( &dest, "s8", &s )); - check( strcmp( "ghi", s ) == 0 ); + check_streq ("ghi", s); tr_bencFree( &dest ); tr_bencFree( &src ); @@ -428,7 +429,7 @@ testStackSmash( void ) check( !err ); check( end == in + ( depth * 2 ) ); saved = tr_bencToStr( &val, TR_FMT_BENC, &len ); - check( !strcmp( saved, (char*)in ) ); + check_streq ((char*)in, saved); tr_free( in ); tr_free( saved ); tr_bencFree( &val ); @@ -495,13 +496,13 @@ testParse2( void ) check( (char*)end == benc + len ); check( tr_bencIsDict( &top2 ) ); check( tr_bencDictFindInt( &top, "this-is-an-int", &intVal ) ); - check( intVal == 1234 ); + check_int_eq (1234, intVal); check( tr_bencDictFindBool( &top, "this-is-a-bool", &boolVal ) ); check( boolVal == true ); check( tr_bencDictFindStr( &top, "this-is-a-string", &strVal ) ); - check( !strcmp( strVal, "this-is-a-string" ) ); + check_streq ("this-is-a-string", strVal); check( tr_bencDictFindReal( &top, "this-is-a-real", &realVal ) ); - check( (int)(realVal*100) == 50 ); + check_int_eq (50, (int)(realVal*100)); tr_bencFree( &top2 ); tr_free( benc ); diff --git a/libtransmission/history-test.c b/libtransmission/history-test.c index b524937cb..370a736c0 100644 --- a/libtransmission/history-test.c +++ b/libtransmission/history-test.c @@ -15,14 +15,14 @@ test1( void ) memset( &h, 0, sizeof( tr_recentHistory ) ); tr_historyAdd( &h, 10000, 1 ); - check( (int)tr_historyGet( &h, 12000, 1000 ) == 0 ); - check( (int)tr_historyGet( &h, 12000, 3000 ) == 1 ); - check( (int)tr_historyGet( &h, 12000, 5000 ) == 1 ); + check_int_eq( 0, (int)tr_historyGet( &h, 12000, 1000 ) ); + check_int_eq( 1, (int)tr_historyGet( &h, 12000, 3000 ) ); + check_int_eq( 1, (int)tr_historyGet( &h, 12000, 5000 ) ); tr_historyAdd( &h, 20000, 1 ); - check( (int)tr_historyGet( &h, 22000, 1000 ) == 0 ); - check( (int)tr_historyGet( &h, 22000, 3000 ) == 1 ); - check( (int)tr_historyGet( &h, 22000, 15000 ) == 2 ); - check( (int)tr_historyGet( &h, 22000, 20000 ) == 2 ); + check_int_eq( 0, (int)tr_historyGet( &h, 22000, 1000 ) ); + check_int_eq( 1, (int)tr_historyGet( &h, 22000, 3000 ) ); + check_int_eq( 2, (int)tr_historyGet( &h, 22000, 15000 ) ); + check_int_eq( 2, (int)tr_historyGet( &h, 22000, 20000 ) ); return 0; } diff --git a/libtransmission/json-test.c b/libtransmission/json-test.c index 7d8c98715..b3a0c4f31 100644 --- a/libtransmission/json-test.c +++ b/libtransmission/json-test.c @@ -23,7 +23,7 @@ test_utf8( void ) check( !err ); check( tr_bencIsDict( &top ) ); check( tr_bencDictFindStr( &top, "key", &str ) ); - check( !strcmp( str, "Letöltések" ) ); + check_streq( "Letöltések", str ); if( !err ) tr_bencFree( &top ); @@ -32,7 +32,7 @@ test_utf8( void ) check( !err ); check( tr_bencIsDict( &top ) ); check( tr_bencDictFindStr( &top, "key", &str ) ); - check( !strcmp( str, "\\" ) ); + check_streq( "\\", str ); if( !err ) tr_bencFree( &top ); @@ -49,7 +49,7 @@ test_utf8( void ) check( !err ); check( tr_bencIsDict( &top ) ); check( tr_bencDictFindStr( &top, "key", &str ) ); - check( !strcmp( str, "Letöltések" ) ); + check_streq( "Letöltések", str ); json = tr_bencToStr( &top, TR_FMT_JSON, NULL ); if( !err ) tr_bencFree( &top ); @@ -60,7 +60,7 @@ test_utf8( void ) check( !err ); check( tr_bencIsDict( &top ) ); check( tr_bencDictFindStr( &top, "key", &str ) ); - check( !strcmp( str, "Letöltések" ) ); + check_streq( "Letöltések", str ); if( !err ) tr_bencFree( &top ); tr_free( json ); @@ -94,21 +94,21 @@ test1( void ) check( ( headers = tr_bencDictFind( &top, "headers" ) ) ); check( tr_bencIsDict( headers ) ); check( tr_bencDictFindStr( headers, "type", &str ) ); - check( !strcmp( str, "request" ) ); + check_streq( "request", str ); check( tr_bencDictFindInt( headers, "tag", &i ) ); - check( i == 666 ); + check_int_eq( 666, i ); check( ( body = tr_bencDictFind( &top, "body" ) ) ); check( tr_bencDictFindStr( body, "name", &str ) ); - check( !strcmp( str, "torrent-info" ) ); + check_streq( "torrent-info", str ); check( ( args = tr_bencDictFind( body, "arguments" ) ) ); check( tr_bencIsDict( args ) ); check( ( ids = tr_bencDictFind( args, "ids" ) ) ); check( tr_bencIsList( ids ) ); - check( tr_bencListSize( ids ) == 2 ); + check_int_eq( 2, tr_bencListSize( ids ) ); check( tr_bencGetInt( tr_bencListChild( ids, 0 ), &i ) ); - check( i == 7 ); + check_int_eq( 7, i ); check( tr_bencGetInt( tr_bencListChild( ids, 1 ), &i ) ); - check( i == 10 ); + check_int_eq( 10, i ); tr_bencFree( &top ); return 0; @@ -144,7 +144,7 @@ test3( void ) const int err = tr_jsonParse( NULL, in, strlen( in ), &top, NULL ); check( !err ); check( tr_bencDictFindStr( &top, "errorString", &str ) ); - check( !strcmp( str, "torrent not registered with this tracker 6UHsVW'*C" ) ); + check_streq( "torrent not registered with this tracker 6UHsVW'*C", str ); tr_bencFree( &top ); return 0; diff --git a/libtransmission/magnet-test.c b/libtransmission/magnet-test.c index efd95e4b5..90236a08f 100644 --- a/libtransmission/magnet-test.c +++ b/libtransmission/magnet-test.c @@ -25,12 +25,12 @@ test1( void ) "&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile"; info = tr_magnetParse( uri ); check( info != NULL ); - check( info->trackerCount == 2 ); - check( !strcmp( info->trackers[0], "http://tracker.openbittorrent.com/announce" ) ); - check( !strcmp( info->trackers[1], "http://tracker.opentracker.org/announce" ) ); - check( info->webseedCount == 1 ); - check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) ); - check( !strcmp( info->displayName, "Display Name" ) ); + check_int_eq( 2, info->trackerCount ); + check_streq( info->trackers[0], "http://tracker.openbittorrent.com/announce" ); + check_streq( info->trackers[1], "http://tracker.opentracker.org/announce" ); + check_int_eq( 1, info->webseedCount ); + check_streq( "http://server.webseed.org/path/to/file", info->webseeds[0] ); + check_streq( "Display Name", info->displayName ); for( i=0; i<20; ++i ) check( info->hash[i] == dec[i] ); tr_magnetFree( info ); @@ -45,12 +45,12 @@ test1( void ) "&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce"; info = tr_magnetParse( uri ); check( info != NULL ); - check( info->trackerCount == 2 ); - check( !strcmp( info->trackers[0], "http://tracker.openbittorrent.com/announce" ) ); - check( !strcmp( info->trackers[1], "http://tracker.opentracker.org/announce" ) ); - check( info->webseedCount == 1 ); - check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) ); - check( !strcmp( info->displayName, "Display Name" ) ); + check_int_eq( 2, info->trackerCount ); + check_streq( "http://tracker.openbittorrent.com/announce", info->trackers[0] ); + check_streq( "http://tracker.opentracker.org/announce", info->trackers[1] ); + check_int_eq( 1, info->webseedCount ); + check_streq( "http://server.webseed.org/path/to/file", info->webseeds[0] ); + check_streq( "Display Name", info->displayName ); for( i=0; i<20; ++i ) check( info->hash[i] == dec[i] ); tr_magnetFree( info ); diff --git a/libtransmission/rpc-test.c b/libtransmission/rpc-test.c index f7ffd6560..38e8ef3d7 100644 --- a/libtransmission/rpc-test.c +++ b/libtransmission/rpc-test.c @@ -18,41 +18,41 @@ test_list( void ) tr_rpc_parse_list_str( &top, "12", -1 ); check( tr_bencIsInt( &top ) ); check( tr_bencGetInt( &top, &i ) ); - check( i == 12 ); + check_int_eq ( 12, i ); tr_bencFree( &top ); tr_rpc_parse_list_str( &top, "12", 1 ); check( tr_bencIsInt( &top ) ); check( tr_bencGetInt( &top, &i ) ); - check( i == 1 ); + check_int_eq ( 1, i ); tr_bencFree( &top ); tr_rpc_parse_list_str( &top, "6,7", -1 ); check( tr_bencIsList( &top ) ); check( tr_bencListSize( &top ) == 2 ); check( tr_bencGetInt( tr_bencListChild( &top, 0 ), &i ) ); - check( i == 6 ); + check_int_eq ( 6, i ); check( tr_bencGetInt( tr_bencListChild( &top, 1 ), &i ) ); - check( i == 7 ); + check_int_eq ( 7, i ); tr_bencFree( &top ); tr_rpc_parse_list_str( &top, "asdf", -1 ); check( tr_bencIsString( &top ) ); check( tr_bencGetStr( &top, &str ) ); - check( !strcmp( str, "asdf" ) ); + check_streq( "asdf", str ); tr_bencFree( &top ); tr_rpc_parse_list_str( &top, "1,3-5", -1 ); check( tr_bencIsList( &top ) ); check( tr_bencListSize( &top ) == 4 ); check( tr_bencGetInt( tr_bencListChild( &top, 0 ), &i ) ); - check( i == 1 ); + check_int_eq( 1, i ); check( tr_bencGetInt( tr_bencListChild( &top, 1 ), &i ) ); - check( i == 3 ); + check_int_eq( 3, i ); check( tr_bencGetInt( tr_bencListChild( &top, 2 ), &i ) ); - check( i == 4 ); + check_int_eq( 4, i ); check( tr_bencGetInt( tr_bencListChild( &top, 3 ), &i ) ); - check( i == 5 ); + check_int_eq( 5, i ); tr_bencFree( &top ); return 0; diff --git a/libtransmission/utils-test.c b/libtransmission/utils-test.c index 07a213dce..2944b524c 100644 --- a/libtransmission/utils-test.c +++ b/libtransmission/utils-test.c @@ -31,18 +31,16 @@ test_base64( void ) /* base64 */ out = tr_base64_encode( "YOYO!", -1, &len ); - check( out ); - check( !strcmp( out, "WU9ZTyE=" ) ); - check( len == 8 ); + check_streq ("WU9ZTyE=", out); + check_int_eq (8, len); in = tr_base64_decode( out, -1, &len ); - check( in ); - check( !strcmp( in, "YOYO!" ) ); - check( len == 5 ); + check_streq ("YOYO!", in); + check_int_eq (5, len); tr_free( in ); tr_free( out ); out = tr_base64_encode( NULL, 0, &len ); check( out == NULL ); - check( len == 0 ); + check_int_eq (0, len); return 0; } @@ -155,14 +153,12 @@ test_strip_positional_args( void ) in = "Hello %1$s foo %2$.*f"; expected = "Hello %s foo %.*f"; out = tr_strip_positional_args( in ); - check( out != NULL ); - check( !strcmp( out, expected ) ); + check_streq (expected, out); in = "Hello %1$'d foo %2$'f"; expected = "Hello %d foo %f"; out = tr_strip_positional_args( in ); - check( out != NULL ); - check( !strcmp( out, expected ) ); + check_streq (expected, out); return 0; } @@ -176,21 +172,21 @@ test_strstrip( void ) in = tr_strdup( " test " ); out = tr_strstrip( in ); check( in == out ); - check( !strcmp( in, "test" ) ); + check_streq ("test", out); tr_free( in ); /* strstrip */ in = tr_strdup( " test test " ); out = tr_strstrip( in ); check( in == out ); - check( !strcmp( in, "test test" ) ); + check_streq ("test test", out); tr_free( in ); /* strstrip */ in = tr_strdup( "test" ); out = tr_strstrip( in ); check( in == out ); - check( !strcmp( in, "test" ) ); + check_streq ("test", out); tr_free( in ); return 0; @@ -202,11 +198,11 @@ test_buildpath( void ) char * out; out = tr_buildPath( "foo", "bar", NULL ); - check( !strcmp( out, "foo" TR_PATH_DELIMITER_STR "bar" ) ); + check_streq ("foo" TR_PATH_DELIMITER_STR "bar", out); tr_free( out ); out = tr_buildPath( "", "foo", "bar", NULL ); - check( !strcmp( out, TR_PATH_DELIMITER_STR "foo" TR_PATH_DELIMITER_STR "bar" ) ); + check_streq (TR_PATH_DELIMITER_STR "foo" TR_PATH_DELIMITER_STR "bar", out); tr_free( out ); return 0; @@ -220,14 +216,12 @@ test_utf8( void ) in = "hello world"; out = tr_utf8clean( in, -1 ); - check( out != NULL ); - check( !strcmp( out, in ) ); + check_streq (in, out); tr_free( out ); in = "hello world"; out = tr_utf8clean( in, 5 ); - check( out != NULL ); - check( !strcmp( out, "hello" ) ); + check_streq ("hello", out); tr_free( out ); /* this version is not utf-8 */ @@ -243,7 +237,7 @@ test_utf8( void ) out = tr_utf8clean( in, -1 ); check( out != NULL ); check( tr_utf8_validate( out, -1, NULL ) ); - check ( !strcmp( in, out ) ); + check_streq (in, out); tr_free( out ); return 0; @@ -257,33 +251,32 @@ test_numbers( void ) int * numbers; numbers = tr_parseNumberRange( "1-10,13,16-19", -1, &count ); - check( count == 15 ); - check( numbers != NULL ); - check( numbers[0] == 1 ); - check( numbers[5] == 6 ); - check( numbers[9] == 10 ); - check( numbers[10] == 13 ); - check( numbers[11] == 16 ); - check( numbers[14] == 19 ); + check_int_eq( 15, count ); + check_int_eq( 1, numbers[0] ); + check_int_eq( 6, numbers[5] ); + check_int_eq( 10, numbers[9] ); + check_int_eq( 13, numbers[10] ); + check_int_eq( 16, numbers[11] ); + check_int_eq( 19, numbers[14] ); tr_free( numbers ); numbers = tr_parseNumberRange( "1-5,3-7,2-6", -1, &count ); check( count == 7 ); check( numbers != NULL ); for( i=0; i