2014-01-19 01:09:44 +00:00
|
|
|
|
/*
|
|
|
|
|
* This file Copyright (C) 2013-2014 Mnemosyne LLC
|
|
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2014-06-09 02:53:04 +00:00
|
|
|
|
#include "libtransmission-test.h"
|
|
|
|
|
|
2012-10-14 18:02:47 +00:00
|
|
|
|
#include "transmission.h"
|
|
|
|
|
|
2014-06-09 02:53:04 +00:00
|
|
|
|
#include <errno.h>
|
2012-10-14 18:02:47 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
static int test_magnet_link(void)
|
2014-06-09 02:53:04 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_info inf;
|
|
|
|
|
tr_ctor* ctor;
|
2017-04-20 16:02:19 +00:00
|
|
|
|
char const* magnet_link;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_parse_result parse_result;
|
|
|
|
|
|
|
|
|
|
/* background info @ http://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding */
|
|
|
|
|
magnet_link =
|
|
|
|
|
"magnet:?"
|
|
|
|
|
"xt=urn:btih:14FFE5DD23188FD5CB53A1D47F1289DB70ABF31E"
|
|
|
|
|
"&dn=ubuntu+12+04+1+desktop+32+bit"
|
|
|
|
|
"&tr=http%3A%2F%2Ftracker.publicbt.com%2Fannounce"
|
|
|
|
|
"&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80"
|
|
|
|
|
"&ws=http://transmissionbt.com ";
|
|
|
|
|
ctor = tr_ctorNew(NULL);
|
|
|
|
|
tr_ctorSetMetainfoFromMagnetLink(ctor, magnet_link);
|
|
|
|
|
parse_result = tr_torrentParse(ctor, &inf);
|
|
|
|
|
check_int_eq(inf.fileCount, 0); /* cos it's a magnet link */
|
|
|
|
|
check_int_eq(parse_result, TR_PARSE_OK);
|
|
|
|
|
check_int_eq(inf.trackerCount, 2);
|
|
|
|
|
check_streq("http://tracker.publicbt.com/announce", inf.trackers[0].announce);
|
|
|
|
|
check_streq("udp://tracker.publicbt.com:80", inf.trackers[1].announce);
|
|
|
|
|
check_int_eq(inf.webseedCount, 1);
|
|
|
|
|
check_streq("http://transmissionbt.com", inf.webseeds[0]);
|
|
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
|
tr_metainfoFree(&inf);
|
|
|
|
|
tr_ctorFree(ctor);
|
|
|
|
|
return 0;
|
2014-06-09 02:53:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
#define BEFORE_PATH \
|
|
|
|
|
"d10:created by25:Transmission/2.82 (14160)13:creation datei1402280218e8:encoding5:UTF-84:infod5:filesld6:lengthi2e4:pathl"
|
|
|
|
|
#define AFTER_PATH \
|
|
|
|
|
"eed6:lengthi2e4:pathl5:b.txteee4:name3:foo12:piece lengthi32768e6:pieces20:ÞÉ`âMs¡Å;˺¬.åÂà7:privatei0eee"
|
2014-06-09 02:53:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
static int test_metainfo(void)
|
2014-06-09 02:53:04 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
size_t i;
|
2017-04-20 16:02:19 +00:00
|
|
|
|
struct
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
|
|
|
|
int expected_benc_err;
|
|
|
|
|
int expected_parse_result;
|
|
|
|
|
const void* benc;
|
|
|
|
|
}
|
2017-04-20 16:02:19 +00:00
|
|
|
|
const metainfo[] =
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
|
|
|
|
{ 0, TR_PARSE_OK, BEFORE_PATH "5:a.txt" AFTER_PATH },
|
2014-06-09 02:53:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
/* allow empty components, but not =all= empty components, see bug #5517 */
|
|
|
|
|
{ 0, TR_PARSE_OK, BEFORE_PATH "0:5:a.txt" AFTER_PATH },
|
|
|
|
|
{ 0, TR_PARSE_ERR, BEFORE_PATH "0:0:" AFTER_PATH },
|
2014-06-09 02:53:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
/* don't allow path components in a filename */
|
|
|
|
|
{ 0, TR_PARSE_ERR, BEFORE_PATH "7:a/a.txt" AFTER_PATH },
|
2014-06-09 02:53:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
/* fail on "." components */
|
|
|
|
|
{ 0, TR_PARSE_ERR, BEFORE_PATH "1:.5:a.txt" AFTER_PATH },
|
|
|
|
|
{ 0, TR_PARSE_ERR, BEFORE_PATH "5:a.txt1:." AFTER_PATH },
|
2014-06-09 02:53:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
/* fail on ".." components */
|
|
|
|
|
{ 0, TR_PARSE_ERR, BEFORE_PATH "2:..5:a.txt" AFTER_PATH },
|
|
|
|
|
{ 0, TR_PARSE_ERR, BEFORE_PATH "5:a.txt2:.." AFTER_PATH },
|
2014-06-09 02:53:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
/* fail on empty string */
|
|
|
|
|
{ EILSEQ, TR_PARSE_ERR, "" }
|
|
|
|
|
};
|
2014-06-09 02:53:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_logSetLevel(0); /* yes, we already know these will generate errors, thank you... */
|
2014-06-09 02:53:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
for (i = 0; i < (sizeof(metainfo) / sizeof(metainfo[0])); i++)
|
2014-06-09 02:53:04 +00:00
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
tr_ctor* ctor = tr_ctorNew(NULL);
|
2017-04-20 16:02:19 +00:00
|
|
|
|
int const err = tr_ctorSetMetainfo(ctor, metainfo[i].benc, strlen(metainfo[i].benc));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
check_int_eq(metainfo[i].expected_benc_err, err);
|
|
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
|
if (err == 0)
|
2014-06-09 02:53:04 +00:00
|
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
|
tr_parse_result const parse_result = tr_torrentParse(ctor, NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
check_int_eq(metainfo[i].expected_parse_result, parse_result);
|
2014-06-09 02:53:04 +00:00
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
tr_ctorFree(ctor);
|
2014-06-09 02:53:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
return 0;
|
2014-06-09 02:53:04 +00:00
|
|
|
|
}
|
2015-01-02 11:15:31 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
int main(void)
|
2012-10-14 18:02:47 +00:00
|
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
|
testFunc const tests[] =
|
2017-04-19 12:04:45 +00:00
|
|
|
|
{
|
|
|
|
|
test_magnet_link,
|
|
|
|
|
test_metainfo
|
|
|
|
|
};
|
2014-06-09 02:53:04 +00:00
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
|
return runTests(tests, NUM_TESTS(tests));
|
2012-10-14 18:02:47 +00:00
|
|
|
|
}
|