File: MagnetTest.cc

package info (click to toggle)
aria2 1.37.0%2Bdebian-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,128 kB
  • sloc: cpp: 115,006; ansic: 9,140; makefile: 1,466; ruby: 475; python: 373; sh: 260; xml: 176
file content (46 lines) | stat: -rw-r--r-- 1,136 bytes parent folder | download | duplicates (6)
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