MagnetTest.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "magnet.h"
  2. #include <iostream>
  3. #include <cppunit/extensions/HelperMacros.h>
  4. namespace aria2 {
  5. namespace magnet {
  6. class MagnetTest:public CppUnit::TestFixture {
  7. CPPUNIT_TEST_SUITE(MagnetTest);
  8. CPPUNIT_TEST(testParse);
  9. CPPUNIT_TEST_SUITE_END();
  10. public:
  11. void testParse();
  12. };
  13. CPPUNIT_TEST_SUITE_REGISTRATION(MagnetTest);
  14. static const std::string& nthStr(const SharedHandle<ValueBase>& v, size_t index)
  15. {
  16. return asString(asList(v)->get(index))->s();
  17. }
  18. void MagnetTest::testParse()
  19. {
  20. SharedHandle<Dict> r = parse
  21. ("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c&dn=aria2"
  22. "&tr=http%3A%2F%2Ftracker1&tr=http://tracker2");
  23. CPPUNIT_ASSERT_EQUAL
  24. (std::string("urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"),
  25. nthStr(r->get("xt"), 0));
  26. CPPUNIT_ASSERT_EQUAL(std::string("aria2"), nthStr(r->get("dn"), 0));
  27. CPPUNIT_ASSERT_EQUAL(std::string("http://tracker1"), nthStr(r->get("tr"), 0));
  28. CPPUNIT_ASSERT_EQUAL(std::string("http://tracker2"), nthStr(r->get("tr"), 1));
  29. CPPUNIT_ASSERT(parse("http://localhost").isNull());
  30. }
  31. } // namespace magnet
  32. } // namespace aria2