Changeset 13442
- Timestamp:
- Aug 18, 2012, 4:07:05 PM (9 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/Makefile.am
r13199 r13442 87 87 json.h \ 88 88 JSON_parser.h \ 89 libtransmission-test.h \ 89 90 list.h \ 90 91 magnet.h \ … … 175 176 magnet_test_LDFLAGS = ${apps_ldflags} 176 177 178 peer_msgs_test_SOURCES = peer-msgs-test.c 179 peer_msgs_test_LDADD = ${apps_ldadd} 180 peer_msgs_test_LDFLAGS = ${apps_ldflags} 181 177 182 rpc_test_SOURCES = rpc-test.c 178 183 rpc_test_LDADD = ${apps_ldadd} … … 183 188 test_peer_id_LDFLAGS = ${apps_ldflags} 184 189 185 peer_msgs_test_SOURCES = peer-msgs-test.c186 peer_msgs_test_LDADD = ${apps_ldadd}187 peer_msgs_test_LDFLAGS = ${apps_ldflags}188 189 190 utils_test_SOURCES = utils-test.c 190 191 utils_test_LDADD = ${apps_ldadd} -
trunk/libtransmission/bencode-test.c
r13111 r13442 10 10 #include "utils.h" /* tr_free */ 11 11 12 /* #define VERBOSE */ 13 14 static int test = 0; 15 16 #ifdef VERBOSE 17 #define check( A ) \ 18 { \ 19 ++test; \ 20 if( A ){ \ 21 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 22 } else { \ 23 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 24 return test; \ 25 } \ 26 } 12 // #define VERBOSE 13 #include "libtransmission-test.h" 14 15 #ifndef WIN32 16 #define STACK_SMASH_DEPTH (1 * 1000 * 1000) 27 17 #else 28 #define check( A ) \ 29 { \ 30 ++test; \ 31 if( !( A ) ){ \ 32 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 33 return test; \ 34 } \ 35 } 18 #define STACK_SMASH_DEPTH ( 100 * 1000) 36 19 #endif 37 20 … … 424 407 425 408 static int 426 testStackSmash( int depth)409 testStackSmash( void ) 427 410 { 428 411 int i; … … 433 416 tr_benc val; 434 417 char * saved; 418 const int depth = STACK_SMASH_DEPTH; 435 419 436 420 in = tr_new( uint8_t, depth * 2 + 1 ); … … 466 450 tr_bencDictAddInt ( &top, "key3", true ); 467 451 tr_bencDictAddInt ( &top, "key4", 1 ); 468 check( tr_bencDictFindBool( &top, "key1", &boolVal ) ) 469 check( !boolVal ) 470 check( tr_bencDictFindBool( &top, "key2", &boolVal ) ) 471 check( !boolVal ) 472 check( tr_bencDictFindBool( &top, "key3", &boolVal ) ) 473 check( boolVal ) 474 check( tr_bencDictFindBool( &top, "key4", &boolVal ) ) 475 check( boolVal ) 476 check( tr_bencDictFindInt( &top, "key1", &intVal ) ) 477 check( !intVal) 478 check( tr_bencDictFindInt( &top, "key2", &intVal ) ) 479 check( !intVal ) 480 check( tr_bencDictFindInt( &top, "key3", &intVal ) ) 481 check( intVal ) 482 check( tr_bencDictFindInt( &top, "key4", &intVal ) ) 483 check( intVal ) 452 check( tr_bencDictFindBool( &top, "key1", &boolVal ) ); 453 check( !boolVal ); 454 check( tr_bencDictFindBool( &top, "key2", &boolVal ) ); 455 check( !boolVal ); 456 check( tr_bencDictFindBool( &top, "key3", &boolVal ) ); 457 check( boolVal ); 458 check( tr_bencDictFindBool( &top, "key4", &boolVal ) ); 459 check( boolVal ); 460 check( tr_bencDictFindInt( &top, "key1", &intVal ) ); 461 check( !intVal); 462 check( tr_bencDictFindInt( &top, "key2", &intVal ) ); 463 check( !intVal ); 464 check( tr_bencDictFindInt( &top, "key3", &intVal ) ); 465 check( intVal ); 466 check( tr_bencDictFindInt( &top, "key4", &intVal ) ); 467 check( intVal ); 484 468 485 469 tr_bencFree( &top ); … … 507 491 508 492 benc = tr_bencToStr( &top, TR_FMT_BENC, &len ); 509 check( !strcmp( benc, "d14:this-is-a-booli1e14:this-is-a-real8:0.50000016:this-is-a-string16:this-is-a-string14:this-is-an-inti1234ee" ) ) 510 check( !tr_bencParse( benc, benc+len, &top2, &end ) ) 511 check( (char*)end == benc + len ) 512 check( tr_bencIsDict( &top2 ) ) 513 check( tr_bencDictFindInt( &top, "this-is-an-int", &intVal ) ) 514 check( intVal == 1234 ) 515 check( tr_bencDictFindBool( &top, "this-is-a-bool", &boolVal ) ) 516 check( boolVal == true ) 517 check( tr_bencDictFindStr( &top, "this-is-a-string", &strVal ) ) 518 check( !strcmp( strVal, "this-is-a-string" ) ) 519 check( tr_bencDictFindReal( &top, "this-is-a-real", &realVal ) ) 520 check( (int)(realVal*100) == 50 ) 493 check( !strcmp( benc, "d14:this-is-a-booli1e14:this-is-a-real8:0.50000016:this-is-a-string16:this-is-a-string14:this-is-an-inti1234ee" ) ); 494 check( !tr_bencParse( benc, benc+len, &top2, &end ) ); 495 check( (char*)end == benc + len ); 496 check( tr_bencIsDict( &top2 ) ); 497 check( tr_bencDictFindInt( &top, "this-is-an-int", &intVal ) ); 498 check( intVal == 1234 ); 499 check( tr_bencDictFindBool( &top, "this-is-a-bool", &boolVal ) ); 500 check( boolVal == true ); 501 check( tr_bencDictFindStr( &top, "this-is-a-string", &strVal ) ); 502 check( !strcmp( strVal, "this-is-a-string" ) ); 503 check( tr_bencDictFindReal( &top, "this-is-a-real", &realVal ) ); 504 check( (int)(realVal*100) == 50 ); 521 505 522 506 tr_bencFree( &top2 ); … … 530 514 main( void ) 531 515 { 532 int i; 533 534 if(( i = testInt( ))) 535 return i; 536 537 if(( i = testStr( ))) 538 return i; 539 540 if(( i = testParse( ))) 541 return i; 542 543 if(( i = testJSON( ))) 544 return i; 545 546 if(( i = testMerge( ))) 547 return i; 548 549 if(( i = testBool( ))) 550 return i; 551 552 if(( i = testParse2( ))) 553 return i; 554 555 #ifndef WIN32 556 i = testStackSmash( 1000000 ); 557 #else 558 i = testStackSmash( 100000 ); 559 #endif 560 if( i ) 561 return i; 562 563 return 0; 564 } 565 516 static const testFunc tests[] = { 517 testInt, testStr, testParse, testJSON, testMerge, testBool, 518 testParse2, testStackSmash, 519 }; 520 521 return runTests(tests, NUM_TESTS(tests)); 522 } -
trunk/libtransmission/blocklist-test.c
r12229 r13442 6 6 7 7 #undef VERBOSE 8 #include "libtransmission-test.h" 8 9 9 #ifdef VERBOSE 10 #define check( A ) \ 11 { \ 12 ++test; \ 13 if( A ){ \ 14 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 15 } else { \ 16 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 17 return test; \ 18 } \ 19 } 10 #ifndef WIN32 11 #define TEMPDIR_PREFIX "/tmp/" 20 12 #else 21 #define check( A )\ 22 { \ 23 ++test; \ 24 if( !( A ) ){ \ 25 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 26 return test; \ 27 } \ 28 } 13 #define TEMPDIR_PREFIX 29 14 #endif 15 16 #define TEMPFILE_TXT TEMPDIR_PREFIX "transmission-blocklist-test.txt" 17 #define TEMPFILE_BIN TEMPDIR_PREFIX "transmission-blocklist-test.bin" 30 18 31 19 static void … … 47 35 } 48 36 49 int50 main( void )37 static int 38 testBlockList( void ) 51 39 { 52 #ifndef WIN32 53 const char * tmpfile_txt = "/tmp/transmission-blocklist-test.txt"; 54 const char * tmpfile_bin = "/tmp/transmission-blocklist-test.bin"; 55 #else 56 const char * tmpfile_txt = "transmission-blocklist-test.txt"; 57 const char * tmpfile_bin = "transmission-blocklist-test.bin"; 58 #endif 40 const char * tmpfile_txt = TEMPFILE_TXT; 41 const char * tmpfile_bin = TEMPFILE_BIN; 59 42 struct tr_address addr; 60 int test = 0;61 43 tr_blocklist * b; 62 44 … … 102 84 } 103 85 86 MAIN_SINGLE_TEST(testBlockList) 87 -
trunk/libtransmission/clients-test.c
r12223 r13442 5 5 6 6 #undef VERBOSE 7 #include "libtransmission-test.h" 7 8 8 #ifdef VERBOSE9 #define check( A ) \10 { \11 ++test; \12 if( A ){ \13 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \14 } else { \15 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \16 return test; \17 } \18 }19 #else20 #define check( A ) \21 { \22 ++test; \23 if( !( A ) ){ \24 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \25 return test; \26 } \27 }28 #endif29 9 30 10 #define TEST_CLIENT( A, B ) \ … … 35 15 main( void ) 36 16 { 37 int test = 0;38 17 char buf[128]; 39 18 -
trunk/libtransmission/history-test.c
r12328 r13442 6 6 7 7 #undef VERBOSE 8 9 static int test = 0; 10 11 #ifdef VERBOSE 12 #define check( A ) \ 13 { \ 14 ++test; \ 15 if( A ){ \ 16 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 17 } else { \ 18 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 19 return test; \ 20 } \ 21 } 22 #else 23 #define check( A ) \ 24 { \ 25 ++test; \ 26 if( !( A ) ){ \ 27 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 28 return test; \ 29 } \ 30 } 31 #endif 8 #include "libtransmission-test.h" 32 9 33 10 static int … … 39 16 40 17 tr_historyAdd( &h, 10000, 1 ); 41 check( (int)tr_historyGet( &h, 12000, 1000 ) == 0 ) 42 check( (int)tr_historyGet( &h, 12000, 3000 ) == 1 ) 43 check( (int)tr_historyGet( &h, 12000, 5000 ) == 1 ) 18 check( (int)tr_historyGet( &h, 12000, 1000 ) == 0 ); 19 check( (int)tr_historyGet( &h, 12000, 3000 ) == 1 ); 20 check( (int)tr_historyGet( &h, 12000, 5000 ) == 1 ); 44 21 tr_historyAdd( &h, 20000, 1 ); 45 check( (int)tr_historyGet( &h, 22000, 1000 ) == 0 ) 46 check( (int)tr_historyGet( &h, 22000, 3000 ) == 1 ) 47 check( (int)tr_historyGet( &h, 22000, 15000 ) == 2 ) 48 check( (int)tr_historyGet( &h, 22000, 20000 ) == 2 ) 22 check( (int)tr_historyGet( &h, 22000, 1000 ) == 0 ); 23 check( (int)tr_historyGet( &h, 22000, 3000 ) == 1 ); 24 check( (int)tr_historyGet( &h, 22000, 15000 ) == 2 ); 25 check( (int)tr_historyGet( &h, 22000, 20000 ) == 2 ); 49 26 50 27 return 0; 51 28 } 52 29 53 int 54 main( void ) 55 { 56 int i; 57 58 if( ( i = test1( ) ) ) 59 return i; 60 61 return 0; 62 } 63 30 MAIN_SINGLE_TEST(test1) -
trunk/libtransmission/json-test.c
r10487 r13442 7 7 8 8 #undef VERBOSE 9 10 static int test = 0; 11 12 #ifdef VERBOSE 13 #define check( A ) \ 14 { \ 15 ++test; \ 16 if( A ){ \ 17 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 18 } else { \ 19 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 20 return test; \ 21 } \ 22 } 23 #else 24 #define check( A ) \ 25 { \ 26 ++test; \ 27 if( !( A ) ){ \ 28 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 29 return test; \ 30 } \ 31 } 32 #endif 9 #include "libtransmission-test.h" 33 10 34 11 #include "ConvertUTF.h" … … 177 154 main( void ) 178 155 { 179 int i; 180 181 if( ( i = test_utf8( ) ) ) 182 return i; 183 184 if( ( i = test1( ) ) ) 185 return i; 186 187 if( ( i = test2( ) ) ) 188 return i; 189 190 if( ( i = test3( ) ) ) 191 return i; 192 193 return 0; 156 const testFunc tests[] = { test_utf8, test1, test2, test3, }; 157 return runTests(tests, NUM_TESTS(tests)); 194 158 } 195 159 -
trunk/libtransmission/magnet-test.c
r9630 r13442 7 7 /* #define VERBOSE */ 8 8 #undef VERBOSE 9 10 static int test = 0; 11 12 #ifdef VERBOSE 13 #define check( A ) \ 14 { \ 15 ++test; \ 16 if( A ){ \ 17 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 18 } else { \ 19 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 20 return test; \ 21 } \ 22 } 23 #else 24 #define check( A ) \ 25 { \ 26 ++test; \ 27 if( !( A ) ){ \ 28 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 29 return test; \ 30 } \ 31 } 32 #endif 9 #include "libtransmission-test.h" 33 10 34 11 static int … … 48 25 "&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile"; 49 26 info = tr_magnetParse( uri ); 50 check( info != NULL ) 27 check( info != NULL ); 51 28 check( info->trackerCount == 2 ); 52 check( !strcmp( info->trackers[0], "http://tracker.openbittorrent.com/announce" ) ) 53 check( !strcmp( info->trackers[1], "http://tracker.opentracker.org/announce" ) ) 29 check( !strcmp( info->trackers[0], "http://tracker.openbittorrent.com/announce" ) ); 30 check( !strcmp( info->trackers[1], "http://tracker.opentracker.org/announce" ) ); 54 31 check( info->webseedCount == 1 ); 55 check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) ) 56 check( !strcmp( info->displayName, "Display Name" ) ) 32 check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) ); 33 check( !strcmp( info->displayName, "Display Name" ) ); 57 34 for( i=0; i<20; ++i ) 58 35 check( info->hash[i] == dec[i] ); … … 68 45 "&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce"; 69 46 info = tr_magnetParse( uri ); 70 check( info != NULL ) 47 check( info != NULL ); 71 48 check( info->trackerCount == 2 ); 72 check( !strcmp( info->trackers[0], "http://tracker.openbittorrent.com/announce" ) ) 73 check( !strcmp( info->trackers[1], "http://tracker.opentracker.org/announce" ) ) 49 check( !strcmp( info->trackers[0], "http://tracker.openbittorrent.com/announce" ) ); 50 check( !strcmp( info->trackers[1], "http://tracker.opentracker.org/announce" ) ); 74 51 check( info->webseedCount == 1 ); 75 check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) ) 76 check( !strcmp( info->displayName, "Display Name" ) ) 52 check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) ); 53 check( !strcmp( info->displayName, "Display Name" ) ); 77 54 for( i=0; i<20; ++i ) 78 55 check( info->hash[i] == dec[i] ); … … 86 63 main( void ) 87 64 { 88 int i; 65 const testFunc tests[] = { test1 }; 66 int ret; 89 67 90 if( ( i = test1( )) )91 return i;68 if( (ret = runTests(tests, 1)) ) 69 return ret; 92 70 93 71 #ifdef VERBOSE 94 72 fprintf( stderr, "magnet-test passed\n" ); 95 73 #endif 74 96 75 return 0; 97 76 } -
trunk/libtransmission/peer-msgs-test.c
r12230 r13442 5 5 6 6 #undef VERBOSE 7 8 #ifdef VERBOSE 9 #define check( A ) \ 10 { \ 11 ++test; \ 12 if( A ){ \ 13 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 14 } else { \ 15 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 16 return test; \ 17 } \ 18 } 19 #else 20 #define check( A ) \ 21 { \ 22 ++test; \ 23 if( !( A ) ){ \ 24 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 25 return test; \ 26 } \ 27 } 28 #endif 7 #include "libtransmission-test.h" 29 8 30 9 int … … 33 12 #if 0 34 13 uint32_t i; 35 int test = 0;36 14 uint8_t infohash[SHA_DIGEST_LENGTH]; 37 15 struct tr_address addr; -
trunk/libtransmission/rpc-test.c
r7783 r13442 7 7 8 8 #undef VERBOSE 9 10 static int test = 0; 11 12 #ifdef VERBOSE 13 #define check( A ) \ 14 { \ 15 ++test; \ 16 if( A ){ \ 17 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 18 } else { \ 19 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 20 return test; \ 21 } \ 22 } 23 #else 24 #define check( A ) \ 25 { \ 26 ++test; \ 27 if( !( A ) ){ \ 28 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 29 return test; \ 30 } \ 31 } 32 #endif 9 #include "libtransmission-test.h" 33 10 34 11 static int … … 82 59 } 83 60 84 int 85 main( void ) 86 { 87 int i; 88 89 if( ( i = test_list( ) ) ) 90 return i; 91 92 return 0; 93 } 94 61 MAIN_SINGLE_TEST(test_list) -
trunk/libtransmission/test-peer-id.c
r12121 r13442 8 8 9 9 #undef VERBOSE 10 #include "libtransmission-test.h" 10 11 11 #ifdef VERBOSE 12 #define check( A ) \ 13 { \ 14 ++test; \ 15 if( A ){ \ 16 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 17 } else { \ 18 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 19 return test; \ 20 } \ 21 } 22 #else 23 #define check( A ) \ 24 { \ 25 ++test; \ 26 if( !( A ) ){ \ 27 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 28 return test; \ 29 } \ 30 } 31 #endif 32 33 int 34 main( void ) 12 static int 13 testPeerId( void ) 35 14 { 36 15 int i; … … 60 39 } 61 40 41 MAIN_SINGLE_TEST(testPeerId) -
trunk/libtransmission/utils-test.c
r12324 r13442 22 22 #endif 23 23 24 static int test = 0; 25 26 #ifdef VERBOSE 27 #define check( A ) \ 28 { \ 29 ++test; \ 30 if( A ){ \ 31 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 32 } else { \ 33 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 34 return test; \ 35 } \ 36 } 37 #else 38 #define check( A ) \ 39 { \ 40 ++test; \ 41 if( !( A ) ){ \ 42 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 43 return test; \ 44 } \ 45 } 46 #endif 24 #include "libtransmission-test.h" 25 26 static int 27 test_base64( void ) 28 { 29 char *in, *out; 30 int len; 31 32 /* base64 */ 33 out = tr_base64_encode( "YOYO!", -1, &len ); 34 check( out ); 35 check( !strcmp( out, "WU9ZTyE=" ) ); 36 check( len == 8 ); 37 in = tr_base64_decode( out, -1, &len ); 38 check( in ); 39 check( !strcmp( in, "YOYO!" ) ); 40 check( len == 5 ); 41 tr_free( in ); 42 tr_free( out ); 43 out = tr_base64_encode( NULL, 0, &len ); 44 check( out == NULL ); 45 check( len == 0 ); 46 47 return 0; 48 } 47 49 48 50 static int … … 154 156 expected = "Hello %s foo %.*f"; 155 157 out = tr_strip_positional_args( in ); 156 check( out != NULL ) 157 check( !strcmp( out, expected ) ) 158 check( out != NULL ); 159 check( !strcmp( out, expected ) ); 158 160 159 161 in = "Hello %1$'d foo %2$'f"; 160 162 expected = "Hello %d foo %f"; 161 163 out = tr_strip_positional_args( in ); 162 check( out != NULL ) 163 check( !strcmp( out, expected ) ) 164 check( out != NULL ); 165 check( !strcmp( out, expected ) ); 164 166 165 167 return 0; … … 219 221 in = "hello world"; 220 222 out = tr_utf8clean( in, -1 ); 221 check( out != NULL ) 222 check( !strcmp( out, in ) ) 223 check( out != NULL ); 224 check( !strcmp( out, in ) ); 223 225 tr_free( out ); 224 226 225 227 in = "hello world"; 226 228 out = tr_utf8clean( in, 5 ); 227 check( out != NULL ) 228 check( !strcmp( out, "hello" ) ) 229 check( out != NULL ); 230 check( !strcmp( out, "hello" ) ); 229 231 tr_free( out ); 230 232 … … 232 234 in = "Òðóäíî áûòü Áîãîì"; 233 235 out = tr_utf8clean( in, 17 ); 234 check( out != NULL ) 235 check( ( strlen( out ) == 17 ) || ( strlen( out ) == 32 ) ) 236 check( tr_utf8_validate( out, -1, NULL ) ) 236 check( out != NULL ); 237 check( ( strlen( out ) == 17 ) || ( strlen( out ) == 32 ) ); 238 check( tr_utf8_validate( out, -1, NULL ) ); 237 239 tr_free( out ); 238 240 … … 240 242 in = "ÃðóÀÃî áûòÌ Ãîãîì"; 241 243 out = tr_utf8clean( in, -1 ); 242 check( out != NULL ) 243 check( tr_utf8_validate( out, -1, NULL ) ) 244 check ( !strcmp( in, out ) ) 244 check( out != NULL ); 245 check( tr_utf8_validate( out, -1, NULL ) ); 246 check ( !strcmp( in, out ) ); 245 247 tr_free( out ); 246 248 … … 318 320 fprintf( stderr, "which is off the end.\n" ); 319 321 #endif 320 check( pos == expected_pos[i-1] ) 321 check( exact == expected_exact[i-1] ) 322 check( pos == expected_pos[i-1] ); 323 check( exact == expected_exact[i-1] ); 322 324 } 323 325 … … 331 333 char const needle[3] = "cab"; 332 334 333 check( tr_memmem( haystack, sizeof haystack, haystack, sizeof haystack) == haystack ) 334 check( tr_memmem( haystack, sizeof haystack, needle, sizeof needle) == haystack + 2 ) 335 check( tr_memmem( needle, sizeof needle, haystack, sizeof haystack) == NULL ) 335 check( tr_memmem( haystack, sizeof haystack, haystack, sizeof haystack) == haystack ); 336 check( tr_memmem( haystack, sizeof haystack, needle, sizeof needle) == haystack + 2 ); 337 check( tr_memmem( needle, sizeof needle, haystack, sizeof haystack) == NULL ); 336 338 337 339 return 0; … … 349 351 tr_hex_to_sha1( sha1, hex1 ); 350 352 tr_sha1_to_hex( hex2, sha1 ); 351 check( !strcmp( hex1, hex2 ) ) 353 check( !strcmp( hex1, hex2 ) ); 352 354 353 355 return 0; … … 388 390 url = "http://1"; 389 391 check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) ); 390 check( !strcmp( scheme, "http" ) ) 391 check( !strcmp( host, "1" ) ) 392 check( !strcmp( path, "/" ) ) 393 check( port == 80 ) 392 check( !strcmp( scheme, "http" ) ); 393 check( !strcmp( host, "1" ) ); 394 check( !strcmp( path, "/" ) ); 395 check( port == 80 ); 394 396 tr_free( scheme ); 395 397 tr_free( path ); … … 397 399 398 400 url = "http://www.some-tracker.org/some/path"; 399 check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) ) 400 check( !strcmp( scheme, "http" ) ) 401 check( !strcmp( host, "www.some-tracker.org" ) ) 402 check( !strcmp( path, "/some/path" ) ) 403 check( port == 80 ) 401 check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) ); 402 check( !strcmp( scheme, "http" ) ); 403 check( !strcmp( host, "www.some-tracker.org" ) ); 404 check( !strcmp( path, "/some/path" ) ); 405 check( port == 80 ); 404 406 tr_free( scheme ); 405 407 tr_free( path ); … … 407 409 408 410 url = "http://www.some-tracker.org:80/some/path"; 409 check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) ) 410 check( !strcmp( scheme, "http" ) ) 411 check( !strcmp( host, "www.some-tracker.org" ) ) 412 check( !strcmp( path, "/some/path" ) ) 413 check( port == 80 ) 411 check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) ); 412 check( !strcmp( scheme, "http" ) ); 413 check( !strcmp( host, "www.some-tracker.org" ) ); 414 check( !strcmp( path, "/some/path" ) ); 415 check( port == 80 ); 414 416 tr_free( scheme ); 415 417 tr_free( path ); … … 418 420 url = "http%3A%2F%2Fwww.example.com%2F~user%2F%3Ftest%3D1%26test1%3D2"; 419 421 str = tr_http_unescape( url, strlen( url ) ); 420 check( !strcmp( str, "http://www.example.com/~user/?test=1&test1=2" ) ) 422 check( !strcmp( str, "http://www.example.com/~user/?test=1&test1=2" ) ); 421 423 tr_free( str ); 422 424 … … 457 459 } 458 460 459 struct blah 460 { 461 uint8_t hash[SHA_DIGEST_LENGTH]; /* pieces hash */ 462 int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ 463 int8_t dnd; /* "do not download" flag */ 464 time_t timeChecked; /* the last time we tested this piece */ 465 }; 466 467 468 int 469 main( void ) 470 { 471 char *in, *out; 472 int len; 473 int i; 474 int l; 475 476 /* base64 */ 477 out = tr_base64_encode( "YOYO!", -1, &len ); 478 check( out ); 479 check( !strcmp( out, "WU9ZTyE=" ) ); 480 check( len == 8 ); 481 in = tr_base64_decode( out, -1, &len ); 482 check( in ); 483 check( !strcmp( in, "YOYO!" ) ); 484 check( len == 5 ); 485 tr_free( in ); 486 tr_free( out ); 487 out = tr_base64_encode( NULL, 0, &len ); 488 check( out == NULL ); 489 check( len == 0 ); 490 491 if( ( i = test_hex( ) ) ) 492 return i; 493 if( ( i = test_lowerbound( ) ) ) 494 return i; 495 if( ( i = test_strip_positional_args( ) ) ) 496 return i; 497 if( ( i = test_strstrip( ) ) ) 498 return i; 499 if( ( i = test_buildpath( ) ) ) 500 return i; 501 if( ( i = test_utf8( ) ) ) 502 return i; 503 if( ( i = test_numbers( ) ) ) 504 return i; 505 if( ( i = test_memmem( ) ) ) 506 return i; 507 if( ( i = test_array( ) ) ) 508 return i; 509 if( ( i = test_url( ) ) ) 510 return i; 511 if( ( i = test_truncd( ) ) ) 512 return i; 461 static int 462 test_cryptoRand( void ) 463 { 464 int i; 513 465 514 466 /* test that tr_cryptoRandInt() stays in-bounds */ … … 520 472 } 521 473 474 return 0; 475 } 476 477 struct blah 478 { 479 uint8_t hash[SHA_DIGEST_LENGTH]; /* pieces hash */ 480 int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ 481 int8_t dnd; /* "do not download" flag */ 482 time_t timeChecked; /* the last time we tested this piece */ 483 }; 484 485 int 486 main( void ) 487 { 488 const testFunc tests[] = { 489 test_base64, test_hex, test_lowerbound, test_strip_positional_args, 490 test_strstrip, test_buildpath, test_utf8, test_numbers, test_memmem, 491 test_array, test_url, test_truncd, test_cryptoRand, 492 }; 493 int ret; 494 int l; 495 496 if( (ret = runTests(tests, NUM_TESTS(tests))) ) 497 return ret; 498 522 499 /* simple bitfield tests */ 523 500 for( l = 0; l < NUM_LOOPS; ++l ) 524 if( ( i= test_bitfields( ) ) )525 return i;501 if( ( ret = test_bitfields( ) ) ) 502 return ret; 526 503 527 504 /* bitfield count range */ 528 505 for( l=0; l<10000; ++l ) 529 if(( i= test_bitfield_count_range( )))530 return i;531 532 return 0; 533 } 534 506 if(( ret = test_bitfield_count_range( ))) 507 return ret; 508 509 return 0; 510 } 511
Note: See TracChangeset
for help on using the changeset viewer.