source: trunk/libtransmission/magnet-test.c @ 9630

Last change on this file since 9630 was 9630, checked in by charles, 12 years ago

(trunk libT) #2631 "Add webseed support to magnet links"

File size: 2.8 KB
Line 
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
10static 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
33
34static int
35test1( void )
36{
37    int i;
38    const char * uri;
39    tr_magnet_info * info;
40    const int dec[] = { 210, 53, 64, 16, 163, 202, 74, 222, 91, 116,
41                        39, 187, 9, 58, 98, 163, 137, 159, 243, 129 };
42
43    uri = "magnet:?xt=urn:btih:"
44          "d2354010a3ca4ade5b7427bb093a62a3899ff381"
45          "&dn=Display%20Name"
46          "&tr=http%3A%2F%2Ftracker.openbittorrent.com%2Fannounce"
47          "&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce"
48          "&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile";
49    info = tr_magnetParse( uri );
50    check( info != NULL )
51    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" ) )
54    check( info->webseedCount == 1 );
55    check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) )
56    check( !strcmp( info->displayName, "Display Name" ) )
57    for( i=0; i<20; ++i )
58        check( info->hash[i] == dec[i] );
59    tr_magnetFree( info );
60    info = NULL;
61
62    /* same thing but in base32 encoding */
63    uri = "magnet:?xt=urn:btih:"
64          "2I2UAEFDZJFN4W3UE65QSOTCUOEZ744B"
65          "&dn=Display%20Name"
66          "&tr=http%3A%2F%2Ftracker.openbittorrent.com%2Fannounce"
67          "&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile"
68          "&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce";
69    info = tr_magnetParse( uri );
70    check( info != NULL )
71    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" ) )
74    check( info->webseedCount == 1 );
75    check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) )
76    check( !strcmp( info->displayName, "Display Name" ) )
77    for( i=0; i<20; ++i )
78        check( info->hash[i] == dec[i] );
79    tr_magnetFree( info );
80    info = NULL;
81
82    return 0;
83}
84
85int
86main( void )
87{
88    int i;
89
90    if( ( i = test1( ) ) )
91        return i;
92
93#ifdef VERBOSE
94    fprintf( stderr, "magnet-test passed\n" );
95#endif
96    return 0;
97}
98
Note: See TracBrowser for help on using the repository browser.