blob: d5b1d65279025632d64cb12f3b18ad6d48033d03 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include "magnet.h"
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
namespace magnet {
class MagnetTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(MagnetTest);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST_SUITE_END();
public:
void testParse();
};
CPPUNIT_TEST_SUITE_REGISTRATION(MagnetTest);
namespace {
const std::string& nthStr(const ValueBase* v, size_t index)
{
return downcast<String>(downcast<List>(v)->get(index))->s();
}
} // namespace
void MagnetTest::testParse()
{
auto r = parse(
"magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c&dn=aria2"
"&tr=http%3A%2F%2Ftracker1&tr=http://tracker2");
CPPUNIT_ASSERT_EQUAL(
std::string("urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"),
nthStr(r->get("xt"), 0));
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), nthStr(r->get("dn"), 0));
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker1"), nthStr(r->get("tr"), 0));
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker2"), nthStr(r->get("tr"), 1));
CPPUNIT_ASSERT(!parse("http://localhost"));
}
} // namespace magnet
} // namespace aria2
|