MCPcopy Create free account
hub / github.com/aria2/aria2 / testParseUpdate

Method testParseUpdate

test/ValueBaseBencodeParserTest.cc:34–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32} // namespace
33
34void ValueBaseBencodeParserTest::testParseUpdate()
35{
36 bittorrent::ValueBaseBencodeParser parser;
37 ssize_t error;
38 {
39 // empty string
40 std::string src = "0:";
41 std::shared_ptr<ValueBase> s =
42 parser.parseFinal(src.c_str(), src.size(), error);
43 CPPUNIT_ASSERT_EQUAL(std::string(""), downcast<String>(s)->s());
44 }
45 {
46 // integer 0
47 std::string src = "i0e";
48 std::shared_ptr<ValueBase> s =
49 parser.parseFinal(src.c_str(), src.size(), error);
50 CPPUNIT_ASSERT_EQUAL((int64_t)0, downcast<Integer>(s)->i());
51 }
52 {
53 // empty dict
54 std::string src = "de";
55 std::shared_ptr<ValueBase> d =
56 parser.parseFinal(src.c_str(), src.size(), error);
57 CPPUNIT_ASSERT(downcast<Dict>(d)->empty());
58 }
59 {
60 // empty list
61 std::string src = "le";
62 std::shared_ptr<ValueBase> l =
63 parser.parseFinal(src.c_str(), src.size(), error);
64 CPPUNIT_ASSERT(downcast<List>(l)->empty());
65 }
66 {
67 // string
68 std::string src = "3:foo";
69 std::shared_ptr<ValueBase> s =
70 parser.parseFinal(src.c_str(), src.size(), error);
71 CPPUNIT_ASSERT_EQUAL(std::string("foo"), downcast<String>(s)->s());
72 }
73 {
74 // integer
75 std::string src = "i9223372036854775807e";
76 std::shared_ptr<ValueBase> s =
77 parser.parseFinal(src.c_str(), src.size(), error);
78 CPPUNIT_ASSERT_EQUAL((int64_t)9223372036854775807LL,
79 downcast<Integer>(s)->i());
80 }
81 {
82 // float number, ignored and always 0.
83 std::string src = "i+343243.342E-1333e";
84 auto s = parser.parseFinal(src.c_str(), src.size(), error);
85 CPPUNIT_ASSERT_EQUAL((int64_t)0, downcast<Integer>(s)->i());
86 }
87 {
88 // dict, size 1
89 std::string src = "d3:fooi123ee";
90 std::shared_ptr<ValueBase> d =
91 parser.parseFinal(src.c_str(), src.size(), error);

Callers

nothing calls this directly

Calls 6

iMethod · 0.80
checkDecodeErrorFunction · 0.70
parseFinalMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected