File: XmlRpcRequestParserControllerTest.cc

package info (click to toggle)
aria2 1.18.8-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 19,392 kB
  • ctags: 16,036
  • sloc: cpp: 115,823; sh: 12,015; ansic: 7,394; makefile: 1,445; ruby: 462; python: 216; xml: 176; asm: 58; sed: 16
file content (162 lines) | stat: -rw-r--r-- 5,209 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "XmlRpcRequestParserController.h"

#include <cppunit/extensions/HelperMacros.h>

namespace aria2 {

namespace rpc {

class XmlRpcRequestParserControllerTest:public CppUnit::TestFixture {

  CPPUNIT_TEST_SUITE(XmlRpcRequestParserControllerTest);
  CPPUNIT_TEST(testPopStructFrame);
  CPPUNIT_TEST(testPopStructFrame_noName);
  CPPUNIT_TEST(testPopStructFrame_noValue);
  CPPUNIT_TEST(testPopArrayFrame);
  CPPUNIT_TEST(testPopArrayFrame_noValue);
  CPPUNIT_TEST(testPopArrayFrame_compound);
  CPPUNIT_TEST_SUITE_END();
public:
  void setUp() {}

  void tearDown() {}

  void testPopStructFrame();
  void testPopStructFrame_noName();
  void testPopStructFrame_noValue();
  void testPopArrayFrame();
  void testPopArrayFrame_noValue();
  void testPopArrayFrame_compound();
};


CPPUNIT_TEST_SUITE_REGISTRATION(XmlRpcRequestParserControllerTest);

void XmlRpcRequestParserControllerTest::testPopStructFrame()
{
  XmlRpcRequestParserController controller;
  controller.setCurrentFrameValue(Dict::g());
  controller.pushFrame();
  controller.setCurrentFrameValue(String::g("Hello, aria2"));
  controller.setCurrentFrameName("greeting");
  controller.popStructFrame();
  const Dict* structValue = downcast<Dict>(controller.getCurrentFrameValue());
  CPPUNIT_ASSERT_EQUAL((size_t)1, structValue->size());
  CPPUNIT_ASSERT_EQUAL(std::string("Hello, aria2"),
                       downcast<String>(structValue->get("greeting"))->s());
}

void XmlRpcRequestParserControllerTest::testPopStructFrame_noName()
{
  XmlRpcRequestParserController controller;
  controller.setCurrentFrameValue(Dict::g());
  controller.pushFrame();
  controller.setCurrentFrameValue(String::g("Hello, aria2"));
  controller.popStructFrame();
  const Dict* structValue = downcast<Dict>(controller.getCurrentFrameValue());
  CPPUNIT_ASSERT(structValue->empty());
}

void XmlRpcRequestParserControllerTest::testPopStructFrame_noValue()
{
  XmlRpcRequestParserController controller;
  controller.setCurrentFrameValue(Dict::g());
  controller.pushFrame();
  controller.setCurrentFrameName("greeting");
  controller.popStructFrame();
  const Dict* structValue = downcast<Dict>(controller.getCurrentFrameValue());
  CPPUNIT_ASSERT(structValue->empty());
}

void XmlRpcRequestParserControllerTest::testPopArrayFrame()
{
  XmlRpcRequestParserController controller;
  controller.setCurrentFrameValue(List::g());
  controller.pushFrame();
  controller.setCurrentFrameValue(Integer::g(100));
  controller.popArrayFrame();
  const List* array = downcast<List>(controller.getCurrentFrameValue());
  CPPUNIT_ASSERT_EQUAL((size_t)1, array->size());
  CPPUNIT_ASSERT_EQUAL((Integer::ValueType)100, downcast<Integer>(array->get(0))->i());
}

void XmlRpcRequestParserControllerTest::testPopArrayFrame_noValue()
{
  XmlRpcRequestParserController controller;
  controller.setCurrentFrameValue(List::g());
  controller.pushFrame();
  controller.popArrayFrame();
  const List* array = downcast<List>(controller.getCurrentFrameValue());
  CPPUNIT_ASSERT(array->empty());
}

void XmlRpcRequestParserControllerTest::testPopArrayFrame_compound()
{
  XmlRpcRequestParserController controller;

  // We are making following structs. [] = array, {key:value .. } = dict

  // [ { "uris":["http://example.org/aria2","http://aria2.sf.net/"],
  //     "options":{ "timeout":120 } },
  //   [ "jp","us" ] ]

  controller.setCurrentFrameValue(List::g());
  controller.pushFrame();

  controller.setCurrentFrameValue(Dict::g());
  controller.pushFrame();

  controller.setCurrentFrameName("uris");
  controller.setCurrentFrameValue(List::g());
  controller.pushFrame();

  controller.setCurrentFrameValue(String::g("http://example.org/aria2"));
  controller.popArrayFrame();
  controller.pushFrame();

  controller.setCurrentFrameValue(String::g("http://aria2.sf.net/"));
  controller.popArrayFrame();

  controller.popStructFrame();
  controller.pushFrame();

  controller.setCurrentFrameName("options");
  controller.setCurrentFrameValue(Dict::g());
  controller.pushFrame();

  controller.setCurrentFrameName("timeout");
  controller.setCurrentFrameValue(Integer::g(120));
  controller.popStructFrame();

  controller.popStructFrame();

  controller.popArrayFrame();
  controller.pushFrame();

  controller.setCurrentFrameValue(List::g());
  controller.pushFrame();

  controller.setCurrentFrameValue(String::g("jp"));
  controller.popArrayFrame();
  controller.pushFrame();

  controller.setCurrentFrameValue(String::g("us"));
  controller.popArrayFrame();

  controller.popArrayFrame();

  const List* result = downcast<List>(controller.getCurrentFrameValue());
  const Dict* dict = downcast<Dict>(result->get(0));
  const List* uris = downcast<List>(dict->get("uris"));
  const Dict* options = downcast<Dict>(dict->get("options"));
  const List* countryList = downcast<List>(result->get(1));
  CPPUNIT_ASSERT_EQUAL(std::string("http://aria2.sf.net/"),
                       downcast<String>(uris->get(1))->s());
  CPPUNIT_ASSERT_EQUAL((Integer::ValueType)120,
                       downcast<Integer>(options->get("timeout"))->i());
  CPPUNIT_ASSERT_EQUAL(std::string("jp"), downcast<String>(countryList->get(0))->s());
}

} // namespace rpc

} // namespace aria2