2009-11-20 04:38:19 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "transmission.h"
|
|
|
|
#include "magnet.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
/* #define VERBOSE */
|
|
|
|
#undef VERBOSE
|
2012-08-18 16:07:05 +00:00
|
|
|
#include "libtransmission-test.h"
|
2009-11-20 04:38:19 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
test1( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const char * uri;
|
|
|
|
tr_magnet_info * info;
|
|
|
|
const int dec[] = { 210, 53, 64, 16, 163, 202, 74, 222, 91, 116,
|
|
|
|
39, 187, 9, 58, 98, 163, 137, 159, 243, 129 };
|
|
|
|
|
|
|
|
uri = "magnet:?xt=urn:btih:"
|
|
|
|
"d2354010a3ca4ade5b7427bb093a62a3899ff381"
|
|
|
|
"&dn=Display%20Name"
|
|
|
|
"&tr=http%3A%2F%2Ftracker.openbittorrent.com%2Fannounce"
|
2009-11-29 17:49:58 +00:00
|
|
|
"&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce"
|
|
|
|
"&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile";
|
2009-11-20 04:38:19 +00:00
|
|
|
info = tr_magnetParse( uri );
|
2012-08-18 16:07:05 +00:00
|
|
|
check( info != NULL );
|
2009-11-29 17:49:58 +00:00
|
|
|
check( info->trackerCount == 2 );
|
2012-08-18 16:07:05 +00:00
|
|
|
check( !strcmp( info->trackers[0], "http://tracker.openbittorrent.com/announce" ) );
|
|
|
|
check( !strcmp( info->trackers[1], "http://tracker.opentracker.org/announce" ) );
|
2009-11-29 17:49:58 +00:00
|
|
|
check( info->webseedCount == 1 );
|
2012-08-18 16:07:05 +00:00
|
|
|
check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) );
|
|
|
|
check( !strcmp( info->displayName, "Display Name" ) );
|
2009-11-20 04:38:19 +00:00
|
|
|
for( i=0; i<20; ++i )
|
|
|
|
check( info->hash[i] == dec[i] );
|
|
|
|
tr_magnetFree( info );
|
|
|
|
info = NULL;
|
|
|
|
|
|
|
|
/* same thing but in base32 encoding */
|
|
|
|
uri = "magnet:?xt=urn:btih:"
|
|
|
|
"2I2UAEFDZJFN4W3UE65QSOTCUOEZ744B"
|
|
|
|
"&dn=Display%20Name"
|
|
|
|
"&tr=http%3A%2F%2Ftracker.openbittorrent.com%2Fannounce"
|
2009-11-29 17:49:58 +00:00
|
|
|
"&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile"
|
2009-11-20 04:38:19 +00:00
|
|
|
"&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce";
|
|
|
|
info = tr_magnetParse( uri );
|
2012-08-18 16:07:05 +00:00
|
|
|
check( info != NULL );
|
2009-11-29 17:49:58 +00:00
|
|
|
check( info->trackerCount == 2 );
|
2012-08-18 16:07:05 +00:00
|
|
|
check( !strcmp( info->trackers[0], "http://tracker.openbittorrent.com/announce" ) );
|
|
|
|
check( !strcmp( info->trackers[1], "http://tracker.opentracker.org/announce" ) );
|
2009-11-29 17:49:58 +00:00
|
|
|
check( info->webseedCount == 1 );
|
2012-08-18 16:07:05 +00:00
|
|
|
check( !strcmp( info->webseeds[0], "http://server.webseed.org/path/to/file" ) );
|
|
|
|
check( !strcmp( info->displayName, "Display Name" ) );
|
2009-11-20 04:38:19 +00:00
|
|
|
for( i=0; i<20; ++i )
|
|
|
|
check( info->hash[i] == dec[i] );
|
|
|
|
tr_magnetFree( info );
|
|
|
|
info = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main( void )
|
|
|
|
{
|
2012-08-18 16:07:05 +00:00
|
|
|
const testFunc tests[] = { test1 };
|
|
|
|
int ret;
|
2009-11-20 04:38:19 +00:00
|
|
|
|
2012-08-18 16:07:05 +00:00
|
|
|
if( (ret = runTests(tests, 1)) )
|
|
|
|
return ret;
|
2009-11-20 04:38:19 +00:00
|
|
|
|
|
|
|
#ifdef VERBOSE
|
|
|
|
fprintf( stderr, "magnet-test passed\n" );
|
|
|
|
#endif
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2009-11-20 04:38:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|