diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-07-26 21:07:10 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-07-26 21:07:10 +0900 |
| commit | 01e1fdaf495342ae8735ec74eb57f912fa67d535 (patch) | |
| tree | e5573e8aa7f3786d8364c76cabf5397f7473ed2f /test/Bencode2Test.cc | |
| parent | 7176107414f73d7fe0cfd7d5ce516aa41a2f0b22 (diff) | |
Parse torrent file on the fly if --follow-torrent=mem is given
In this changes, Bencode parser in bencode2 is removed and the request
is delegated to BencodeParser.
Diffstat (limited to 'test/Bencode2Test.cc')
| -rw-r--r-- | test/Bencode2Test.cc | 175 |
1 files changed, 0 insertions, 175 deletions
diff --git a/test/Bencode2Test.cc b/test/Bencode2Test.cc index 88b0e5eb..5916bd76 100644 --- a/test/Bencode2Test.cc +++ b/test/Bencode2Test.cc @@ -9,191 +9,16 @@ namespace aria2 { class Bencode2Test:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(Bencode2Test); - CPPUNIT_TEST(testDecode); - CPPUNIT_TEST(testDecode_overflow); CPPUNIT_TEST(testEncode); CPPUNIT_TEST_SUITE_END(); private: public: - void testDecode(); - void testDecode_overflow(); void testEncode(); }; CPPUNIT_TEST_SUITE_REGISTRATION( Bencode2Test ); -void Bencode2Test::testDecode() -{ - { - // string, integer and list in dict - std::string src = "d4:name5:aria24:sizei12345678900e5:filesl3:bin3:docee"; - SharedHandle<ValueBase> r = bencode2::decode(src.begin(), src.end()); - const Dict* dict = downcast<Dict>(r); - CPPUNIT_ASSERT(dict); - CPPUNIT_ASSERT_EQUAL(std::string("aria2"), - downcast<String>(dict->get("name"))->s()); - CPPUNIT_ASSERT_EQUAL(static_cast<Integer::ValueType>(12345678900LL), - downcast<Integer>(dict->get("size"))->i()); - const List* list = downcast<List>(dict->get("files")); - CPPUNIT_ASSERT(list); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), list->size()); - CPPUNIT_ASSERT_EQUAL(std::string("bin"), - downcast<String>(list->get(0))->s()); - CPPUNIT_ASSERT_EQUAL(std::string("doc"), - downcast<String>(list->get(1))->s()); - } - { - // dict in list - std::string src = "ld1:ki123eee"; - SharedHandle<ValueBase> r = bencode2::decode(src.begin(), src.end()); - const List* list = downcast<List>(r); - CPPUNIT_ASSERT(list); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), list->size()); - const Dict* dict = downcast<Dict>(list->get(0)); - CPPUNIT_ASSERT(dict); - CPPUNIT_ASSERT_EQUAL(static_cast<Integer::ValueType>(123), - downcast<Integer>(dict->get("k"))->i()); - } - { - // empty key is allowed - std::string src = "d0:1:ve"; - SharedHandle<ValueBase> s = bencode2::decode(src.begin(), src.end()); - } - { - // empty string - std::string src = "0:"; - SharedHandle<ValueBase> s = bencode2::decode(src.begin(), src.end()); - CPPUNIT_ASSERT_EQUAL(std::string(""), downcast<String>(s)->s()); - } - { - // empty dict - std::string src = "de"; - SharedHandle<ValueBase> d = bencode2::decode(src.begin(), src.end()); - CPPUNIT_ASSERT(downcast<Dict>(d)->empty()); - } - { - // empty list - std::string src = "le"; - SharedHandle<ValueBase> l = bencode2::decode(src.begin(), src.end()); - CPPUNIT_ASSERT(downcast<List>(l)->empty()); - } - { - // integer, without ending 'e' - std::string src = "i3"; - try { - bencode2::decode(src.begin(), src.end()); - CPPUNIT_FAIL("exception must be thrown."); - } catch(RecoverableException& e) { - CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:" - " Integer expected but none found"), - std::string(e.what())); - } - } - { - // dict, without ending 'e' - std::string src = "d"; - try { - bencode2::decode(src.begin(), src.end()); - CPPUNIT_FAIL("exception must be thrown."); - } catch(RecoverableException& e) { - CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:" - " Unexpected EOF in dict context." - " 'e' expected."), - std::string(e.what())); - } - } - { - // list, without ending 'e' - try { - std::string src = "l"; - bencode2::decode(src.begin(), src.end()); - CPPUNIT_FAIL("exception must be thrown."); - } catch(RecoverableException& e) { - CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:" - " Unexpected EOF in list context." - " 'e' expected."), - std::string(e.what())); - } - } - { - // string, less than the specified length. - try { - std::string src = "3:ab"; - bencode2::decode(src.begin(), src.end()); - CPPUNIT_FAIL("exception must be thrown."); - } catch(RecoverableException& e) { - CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:" - " Expected 3 bytes of data," - " but only 2 read."), - std::string(e.what())); - } - } - { - // string, but length is invalid - try { - std::string src = "x:abc"; - bencode2::decode(src.begin(), src.end()); - CPPUNIT_FAIL("exception must be thrown."); - } catch(RecoverableException& e) { - CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:" - " A positive integer expected" - " but none found."), - std::string(e.what())); - } - } - { - // string with minus length - std::string src = "-1:a"; - try { - bencode2::decode(src.begin(), src.end()); - CPPUNIT_FAIL("exception must be thrown."); - } catch(RecoverableException& e) { - CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:" - " A positive integer expected" - " but none found."), - std::string(e.what())); - } - } - { - // empty encoded data - std::string src = ""; - CPPUNIT_ASSERT(!bencode2::decode(src.begin(), src.end())); - } - { - // ignore trailing garbage at the end of the input. - std::string src = "5:aria2trail"; - SharedHandle<ValueBase> s = bencode2::decode(src.begin(), src.end()); - CPPUNIT_ASSERT_EQUAL(std::string("aria2"), downcast<String>(s)->s()); - } - { - // Get trailing garbage position - std::string src = "5:aria2trail"; - size_t end; - SharedHandle<ValueBase> s = bencode2::decode(src.begin(), src.end(), end); - CPPUNIT_ASSERT_EQUAL(std::string("aria2"), downcast<String>(s)->s()); - CPPUNIT_ASSERT_EQUAL((size_t)7, end); - } -} - -void Bencode2Test::testDecode_overflow() -{ - std::string s; - size_t depth = bencode2::MAX_STRUCTURE_DEPTH+1; - for(size_t i = 0; i < depth; ++i) { - s += "l"; - } - for(size_t i = 0; i < depth; ++i) { - s += "e"; - } - try { - bencode2::decode(s.begin(), s.end()); - CPPUNIT_FAIL("exception must be thrown."); - } catch(RecoverableException& e) { - // success - } -} - void Bencode2Test::testEncode() { { |
