fixed bug in magnet link parser, and improved unit test
This commit is contained in:
@@ -728,27 +728,15 @@ int test_main()
|
||||
p.save_path = ".";
|
||||
error_code ec;
|
||||
p.url = "magnet:?xt=urn:btih:cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
|
||||
"&tr=http://1&tr=http://2&tr=http://3&dn=foo&dht=127.0.0.1:43";
|
||||
"&tr=http://1"
|
||||
"&tr=http://2"
|
||||
"&tr=http://3"
|
||||
"&dn=foo"
|
||||
"&dht=127.0.0.1:43";
|
||||
torrent_handle t = s->add_torrent(p, ec);
|
||||
TEST_CHECK(!ec);
|
||||
if (ec) fprintf(stderr, "%s\n", ec.message().c_str());
|
||||
|
||||
p.url = "magnet:"
|
||||
"?tr=http://1&tr=http://2&tr=http://3&dn=foo&dht=127.0.0.1:43"
|
||||
"&xt=urn:btih:c352cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd";
|
||||
torrent_handle t2 = s->add_torrent(p, ec);
|
||||
TEST_CHECK(!ec);
|
||||
if (ec) fprintf(stderr, "%s\n", ec.message().c_str());
|
||||
|
||||
p.url = "magnet:"
|
||||
"?tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80"
|
||||
"&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80"
|
||||
"&tr=udp%3A%2F%2Ftracker.ccc.de%3A80"
|
||||
"&xt=urn:btih:a38d02c287893842a32825aa866e00828a318f07&dn=Ubuntu+11.04+%28Final%29";
|
||||
torrent_handle t3 = s->add_torrent(p, ec);
|
||||
TEST_CHECK(!ec);
|
||||
if (ec) fprintf(stderr, "%s\n", ec.message().c_str());
|
||||
|
||||
std::vector<announce_entry> trackers = t.trackers();
|
||||
TEST_EQUAL(trackers.size(), 3);
|
||||
if (trackers.size() > 0)
|
||||
@@ -767,6 +755,47 @@ int test_main()
|
||||
fprintf(stderr, "3: %s\n", trackers[2].url.c_str());
|
||||
}
|
||||
|
||||
p.url = "magnet:"
|
||||
"?tr=http://1"
|
||||
"&tr=http://2"
|
||||
"&dn=foo"
|
||||
"&dht=127.0.0.1:43"
|
||||
"&xt=urn:btih:c352cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd";
|
||||
torrent_handle t2 = s->add_torrent(p, ec);
|
||||
TEST_CHECK(!ec);
|
||||
if (ec) fprintf(stderr, "%s\n", ec.message().c_str());
|
||||
|
||||
trackers = t2.trackers();
|
||||
TEST_EQUAL(trackers.size(), 2);
|
||||
|
||||
p.url = "magnet:"
|
||||
"?tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80"
|
||||
"&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80"
|
||||
"&tr=udp%3A%2F%2Ftracker.ccc.de%3A80"
|
||||
"&xt=urn:btih:a38d02c287893842a32825aa866e00828a318f07"
|
||||
"&dn=Ubuntu+11.04+%28Final%29";
|
||||
torrent_handle t3 = s->add_torrent(p, ec);
|
||||
TEST_CHECK(!ec);
|
||||
if (ec) fprintf(stderr, "%s\n", ec.message().c_str());
|
||||
|
||||
trackers = t3.trackers();
|
||||
TEST_EQUAL(trackers.size(), 3);
|
||||
if (trackers.size() > 0)
|
||||
{
|
||||
TEST_EQUAL(trackers[0].url, "udp://tracker.openbittorrent.com:80");
|
||||
fprintf(stderr, "1: %s\n", trackers[0].url.c_str());
|
||||
}
|
||||
if (trackers.size() > 1)
|
||||
{
|
||||
TEST_EQUAL(trackers[1].url, "udp://tracker.publicbt.com:80");
|
||||
fprintf(stderr, "2: %s\n", trackers[1].url.c_str());
|
||||
}
|
||||
if (trackers.size() > 2)
|
||||
{
|
||||
TEST_EQUAL(trackers[2].url, "udp://tracker.ccc.de:80");
|
||||
fprintf(stderr, "3: %s\n", trackers[2].url.c_str());
|
||||
}
|
||||
|
||||
TEST_EQUAL(to_hex(t.info_hash().to_string()), "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd");
|
||||
|
||||
delete s;
|
||||
|
Reference in New Issue
Block a user