Use std::unique_ptr for ValueBase object hierarchy

This commit is contained in:
Tatsuhiro Tsujikawa 2013-07-11 21:09:51 +09:00
parent 7a57ecc5f8
commit 7c06b903f3
77 changed files with 1242 additions and 1265 deletions

View file

@ -26,18 +26,17 @@ void RpcResponseTest::testToJson()
{
std::vector<RpcResponse> results;
{
std::shared_ptr<List> param = List::g();
auto param = List::g();
param->append(Integer::g(1));
std::shared_ptr<String> id = String::g("9");
RpcResponse res(0, param, id);
results.push_back(res);
std::string s = toJson(res, "", false);
RpcResponse res(0, std::move(param), String::g("9"));
results.push_back(std::move(res));
std::string s = toJson(results.back(), "", false);
CPPUNIT_ASSERT_EQUAL(std::string("{\"id\":\"9\","
"\"jsonrpc\":\"2.0\","
"\"result\":[1]}"),
s);
// with callback
s = toJson(res, "cb", false);
s = toJson(results.back(), "cb", false);
CPPUNIT_ASSERT_EQUAL(std::string("cb({\"id\":\"9\","
"\"jsonrpc\":\"2.0\","
"\"result\":[1]})"),
@ -45,24 +44,24 @@ void RpcResponseTest::testToJson()
}
{
// error response
std::shared_ptr<Dict> param = Dict::g();
auto param = Dict::g();
param->put("code", Integer::g(1));
param->put("message", "HELLO ERROR");
RpcResponse res(1, param, Null::g());
results.push_back(res);
std::string s = toJson(res, "", false);
CPPUNIT_ASSERT_EQUAL(std::string("{\"error\":{\"code\":1,"
"\"message\":\"HELLO ERROR\"},"
"\"id\":null,"
"\"jsonrpc\":\"2.0\""
RpcResponse res(1, std::move(param), Null::g());
results.push_back(std::move(res));
std::string s = toJson(results.back(), "", false);
CPPUNIT_ASSERT_EQUAL(std::string("{\"id\":null,"
"\"jsonrpc\":\"2.0\","
"\"error\":{\"code\":1,"
"\"message\":\"HELLO ERROR\"}"
"}"),
s);
// with callback
s = toJson(res, "cb", false);
CPPUNIT_ASSERT_EQUAL(std::string("cb({\"error\":{\"code\":1,"
"\"message\":\"HELLO ERROR\"},"
"\"id\":null,"
"\"jsonrpc\":\"2.0\""
s = toJson(results.back(), "cb", false);
CPPUNIT_ASSERT_EQUAL(std::string("cb({\"id\":null,"
"\"jsonrpc\":\"2.0\","
"\"error\":{\"code\":1,"
"\"message\":\"HELLO ERROR\"}"
"})"),
s);
}
@ -73,10 +72,10 @@ void RpcResponseTest::testToJson()
"{\"id\":\"9\","
"\"jsonrpc\":\"2.0\","
"\"result\":[1]},"
"{\"error\":{\"code\":1,"
"\"message\":\"HELLO ERROR\"},"
"\"id\":null,"
"\"jsonrpc\":\"2.0\""
"{\"id\":null,"
"\"jsonrpc\":\"2.0\","
"\"error\":{\"code\":1,"
"\"message\":\"HELLO ERROR\"}"
"}"
"]"),
s);
@ -86,10 +85,10 @@ void RpcResponseTest::testToJson()
"{\"id\":\"9\","
"\"jsonrpc\":\"2.0\","
"\"result\":[1]},"
"{\"error\":{\"code\":1,"
"\"message\":\"HELLO ERROR\"},"
"\"id\":null,"
"\"jsonrpc\":\"2.0\""
"{\"id\":null,"
"\"jsonrpc\":\"2.0\","
"\"error\":{\"code\":1,"
"\"message\":\"HELLO ERROR\"}"
"}"
"])"),
s);
@ -99,10 +98,10 @@ void RpcResponseTest::testToJson()
#ifdef ENABLE_XML_RPC
void RpcResponseTest::testToXml()
{
std::shared_ptr<Dict> param = Dict::g();
auto param = Dict::g();
param->put("faultCode", Integer::g(1));
param->put("faultString", "No such method: make.hamburger");
RpcResponse res(1, param, Null::g());
RpcResponse res(1, std::move(param), Null::g());
std::string s = toXml(res, false);
CPPUNIT_ASSERT_EQUAL
(std::string("<?xml version=\"1.0\"?>"