summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-03-14 15:31:26 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-03-14 15:31:26 +0900
commit5a1fb3875fdb27076e71a87e35359aad0aba108c (patch)
treea57453976740a43727882fcc22005ae1a88da1e1 /test
parentbf01bb84b6b96fe2cba529f588e29a9038c0daf6 (diff)
Added XmlRpcResponseTest. Set null as id if id is not sent.
Removed unused XmlRpcResponse::toJsonBatch(). Set default value false to gzip argument of xmlrpc::toJsonBatch().
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am3
-rw-r--r--test/XmlRpcResponseTest.cc68
2 files changed, 70 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 7b2d1b33..d86c759c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -77,7 +77,8 @@ aria2c_SOURCES = AllTest.cc\
MockSegment.h\
TripletTest.cc\
CookieHelperTest.cc\
- JsonTest.cc
+ JsonTest.cc\
+ XmlRpcResponseTest.cc
if ENABLE_XML_RPC
aria2c_SOURCES += XmlRpcRequestParserControllerTest.cc\
diff --git a/test/XmlRpcResponseTest.cc b/test/XmlRpcResponseTest.cc
new file mode 100644
index 00000000..3c94b40e
--- /dev/null
+++ b/test/XmlRpcResponseTest.cc
@@ -0,0 +1,68 @@
+#include "XmlRpcResponse.h"
+
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace aria2 {
+
+namespace xmlrpc {
+
+class XmlRpcResponseTest:public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(XmlRpcResponseTest);
+ CPPUNIT_TEST(testToJson);
+ CPPUNIT_TEST_SUITE_END();
+public:
+ void testToJson();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(XmlRpcResponseTest);
+
+void XmlRpcResponseTest::testToJson()
+{
+ std::vector<XmlRpcResponse> results;
+ {
+ SharedHandle<List> param = List::g();
+ param->append(Integer::g(1));
+ SharedHandle<String> id = String::g("9");
+ XmlRpcResponse res(0, param, id);
+ results.push_back(res);
+ std::string s = res.toJson("", false);
+ CPPUNIT_ASSERT_EQUAL(std::string("{\"id\":\"9\","
+ "\"jsonrpc\":\"2.0\","
+ "\"result\":[1]}"),
+ s);
+ }
+ {
+ // error response
+ SharedHandle<Dict> param = Dict::g();
+ param->put("code", Integer::g(1));
+ param->put("message", "HELLO ERROR");
+ XmlRpcResponse res(1, param, Null::g());
+ results.push_back(res);
+ std::string s = res.toJson("", false);
+ CPPUNIT_ASSERT_EQUAL(std::string("{\"error\":{\"code\":1,"
+ "\"message\":\"HELLO ERROR\"},"
+ "\"id\":null,"
+ "\"jsonrpc\":\"2.0\""
+ "}"),
+ s);
+ }
+ {
+ // batch response
+ std::string s = toJsonBatch(results, "", false);
+ CPPUNIT_ASSERT_EQUAL(std::string("["
+ "{\"id\":\"9\","
+ "\"jsonrpc\":\"2.0\","
+ "\"result\":[1]},"
+ "{\"error\":{\"code\":1,"
+ "\"message\":\"HELLO ERROR\"},"
+ "\"id\":null,"
+ "\"jsonrpc\":\"2.0\""
+ "}"
+ "]"),
+ s);
+ }
+}
+
+} // namespace xmlrpc
+
+} // namespace aria2