1 | #include <stdio.h> |
---|
2 | #include <string.h> |
---|
3 | #include "transmission.h" |
---|
4 | #include "magnet.h" |
---|
5 | #include "utils.h" |
---|
6 | |
---|
7 | /* #define VERBOSE */ |
---|
8 | #undef VERBOSE |
---|
9 | #include "libtransmission-test.h" |
---|
10 | |
---|
11 | static int |
---|
12 | test1( void ) |
---|
13 | { |
---|
14 | int i; |
---|
15 | const char * uri; |
---|
16 | tr_magnet_info * info; |
---|
17 | const int dec[] = { 210, 53, 64, 16, 163, 202, 74, 222, 91, 116, |
---|
18 | 39, 187, 9, 58, 98, 163, 137, 159, 243, 129 }; |
---|
19 | |
---|
20 | uri = "magnet:?xt=urn:btih:" |
---|
21 | "d2354010a3ca4ade5b7427bb093a62a3899ff381" |
---|
22 | "&dn=Display%20Name" |
---|
23 | "&tr=http%3A%2F%2Ftracker.openbittorrent.com%2Fannounce" |
---|
24 | "&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce" |
---|
25 | "&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile"; |
---|
26 | info = tr_magnetParse( uri ); |
---|
27 | check( info != NULL ); |
---|
28 | check_int_eq( 2, info->trackerCount ); |
---|
29 | check_streq( info->trackers[0], "http://tracker.openbittorrent.com/announce" ); |
---|
30 | check_streq( info->trackers[1], "http://tracker.opentracker.org/announce" ); |
---|
31 | check_int_eq( 1, info->webseedCount ); |
---|
32 | check_streq( "http://server.webseed.org/path/to/file", info->webseeds[0] ); |
---|
33 | check_streq( "Display Name", info->displayName ); |
---|
34 | for( i=0; i<20; ++i ) |
---|
35 | check( info->hash[i] == dec[i] ); |
---|
36 | tr_magnetFree( info ); |
---|
37 | info = NULL; |
---|
38 | |
---|
39 | /* same thing but in base32 encoding */ |
---|
40 | uri = "magnet:?xt=urn:btih:" |
---|
41 | "2I2UAEFDZJFN4W3UE65QSOTCUOEZ744B" |
---|
42 | "&dn=Display%20Name" |
---|
43 | "&tr=http%3A%2F%2Ftracker.openbittorrent.com%2Fannounce" |
---|
44 | "&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile" |
---|
45 | "&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce"; |
---|
46 | info = tr_magnetParse( uri ); |
---|
47 | check( info != NULL ); |
---|
48 | check_int_eq( 2, info->trackerCount ); |
---|
49 | check_streq( "http://tracker.openbittorrent.com/announce", info->trackers[0] ); |
---|
50 | check_streq( "http://tracker.opentracker.org/announce", info->trackers[1] ); |
---|
51 | check_int_eq( 1, info->webseedCount ); |
---|
52 | check_streq( "http://server.webseed.org/path/to/file", info->webseeds[0] ); |
---|
53 | check_streq( "Display Name", info->displayName ); |
---|
54 | for( i=0; i<20; ++i ) |
---|
55 | check( info->hash[i] == dec[i] ); |
---|
56 | tr_magnetFree( info ); |
---|
57 | info = NULL; |
---|
58 | |
---|
59 | return 0; |
---|
60 | } |
---|
61 | |
---|
62 | int |
---|
63 | main( void ) |
---|
64 | { |
---|
65 | const testFunc tests[] = { test1 }; |
---|
66 | int ret; |
---|
67 | |
---|
68 | if( (ret = runTests(tests, 1)) ) |
---|
69 | return ret; |
---|
70 | |
---|
71 | #ifdef VERBOSE |
---|
72 | fprintf( stderr, "magnet-test passed\n" ); |
---|
73 | #endif |
---|
74 | |
---|
75 | return 0; |
---|
76 | } |
---|
77 | |
---|