|
@@ -59,8 +59,8 @@ class BittorrentHelperTest:public CppUnit::TestFixture {
|
|
|
CPPUNIT_TEST(testCreatecompact);
|
|
|
CPPUNIT_TEST(testCheckBitfield);
|
|
|
CPPUNIT_TEST(testMetadata);
|
|
|
- CPPUNIT_TEST(testParseMagnetLink);
|
|
|
- CPPUNIT_TEST(testParseMagnetLink_base32);
|
|
|
+ CPPUNIT_TEST(testParseMagnet);
|
|
|
+ CPPUNIT_TEST(testParseMagnet_base32);
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
public:
|
|
|
void setUp() {
|
|
@@ -100,8 +100,8 @@ public:
|
|
|
void testCreatecompact();
|
|
|
void testCheckBitfield();
|
|
|
void testMetadata();
|
|
|
- void testParseMagnetLink();
|
|
|
- void testParseMagnetLink_base32();
|
|
|
+ void testParseMagnet();
|
|
|
+ void testParseMagnet_base32();
|
|
|
};
|
|
|
|
|
|
|
|
@@ -700,33 +700,37 @@ void BittorrentHelperTest::testMetadata() {
|
|
|
(size_t)attrs[bittorrent::METADATA_SIZE].i());
|
|
|
}
|
|
|
|
|
|
-void BittorrentHelperTest::testParseMagnetLink()
|
|
|
+void BittorrentHelperTest::testParseMagnet()
|
|
|
{
|
|
|
- SharedHandle<DownloadContext> dctx(new DownloadContext());
|
|
|
std::string magnet =
|
|
|
- "magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c&dn=aria2";
|
|
|
- bittorrent::parseMagnetLink(magnet, dctx);
|
|
|
+ "magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c&dn=aria2"
|
|
|
+ "&tr=http://tracker1&tr=http://tracker2";
|
|
|
+ BDE attrs = bittorrent::parseMagnet(magnet);
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
|
|
- bittorrent::getInfoHashString(dctx));
|
|
|
- BDE attrs = dctx->getAttribute(bittorrent::BITTORRENT);
|
|
|
+ util::toHex(attrs[bittorrent::INFO_HASH].s()));
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), attrs[bittorrent::NAME].s());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("http://tracker1"),
|
|
|
+ attrs[bittorrent::ANNOUNCE_LIST][0][0].s());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("http://tracker2"),
|
|
|
+ attrs[bittorrent::ANNOUNCE_LIST][0][1].s());
|
|
|
|
|
|
magnet = "magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c";
|
|
|
- bittorrent::parseMagnetLink(magnet, dctx);
|
|
|
- attrs = dctx->getAttribute(bittorrent::BITTORRENT);
|
|
|
- CPPUNIT_ASSERT_EQUAL(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
|
|
- attrs[bittorrent::NAME].s());
|
|
|
+ attrs = bittorrent::parseMagnet(magnet);
|
|
|
+ CPPUNIT_ASSERT_EQUAL
|
|
|
+ (std::string("[METADATA]248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
|
|
+ attrs[bittorrent::NAME].s());
|
|
|
+ CPPUNIT_ASSERT(attrs[bittorrent::ANNOUNCE_LIST].size() == 0);
|
|
|
}
|
|
|
|
|
|
-void BittorrentHelperTest::testParseMagnetLink_base32()
|
|
|
+void BittorrentHelperTest::testParseMagnet_base32()
|
|
|
{
|
|
|
std::string infoHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c";
|
|
|
std::string base32InfoHash = base32::encode(util::fromHex(infoHash));
|
|
|
- SharedHandle<DownloadContext> dctx(new DownloadContext());
|
|
|
std::string magnet = "magnet:?xt=urn:btih:"+base32InfoHash+"&dn=aria2";
|
|
|
- bittorrent::parseMagnetLink(magnet, dctx);
|
|
|
- CPPUNIT_ASSERT_EQUAL(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
|
|
- bittorrent::getInfoHashString(dctx));
|
|
|
+ BDE attrs = bittorrent::parseMagnet(magnet);
|
|
|
+ CPPUNIT_ASSERT_EQUAL
|
|
|
+ (std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
|
|
+ util::toHex(attrs[bittorrent::INFO_HASH].s()));
|
|
|
}
|
|
|
|
|
|
} // namespace bittorrent
|