8 #include "gtest/gtest.h"
16 bool MethodCallsAreEqual(
const MethodCall<rapidjson::Document>& a,
17 const MethodCall<rapidjson::Document>& b) {
18 if (a.method_name() != b.method_name()) {
22 if ((!a.arguments() || a.arguments()->IsNull()) &&
23 (!b.arguments() || b.arguments()->IsNull())) {
26 return *a.arguments() == *b.arguments();
36 std::unique_ptr<MethodCall<rapidjson::Document>> decoded =
39 EXPECT_TRUE(MethodCallsAreEqual(call, *decoded));
45 auto arguments = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
46 auto& allocator = arguments->GetAllocator();
47 arguments->PushBack(42, allocator);
48 arguments->PushBack(
"world", allocator);
52 std::unique_ptr<MethodCall<rapidjson::Document>> decoded =
55 EXPECT_TRUE(MethodCallsAreEqual(call, *decoded));
62 std::vector<uint8_t> bytes = {
'[',
'n',
'u',
'l',
'l',
']'};
63 EXPECT_EQ(*encoded, bytes);
65 bool decoded_successfully =
false;
67 [&decoded_successfully](
const rapidjson::Document* result) {
68 decoded_successfully =
true;
69 EXPECT_EQ(result,
nullptr);
74 EXPECT_TRUE(decoded_successfully);
79 rapidjson::Document result;
83 std::vector<uint8_t> bytes = {
'[',
'4',
'2',
']'};
84 EXPECT_EQ(*encoded, bytes);
86 bool decoded_successfully =
false;
88 [&decoded_successfully](
const rapidjson::Document* result) {
89 decoded_successfully =
true;
90 EXPECT_EQ(result->GetInt(), 42);
95 EXPECT_TRUE(decoded_successfully);
101 ASSERT_TRUE(encoded);
102 std::vector<uint8_t> bytes = {
103 '[',
'"',
'e',
'r',
'r',
'o',
'r',
'C',
'o',
'd',
'e',
104 '"',
',',
'"',
'"',
',',
'n',
'u',
'l',
'l',
']',
106 EXPECT_EQ(*encoded, bytes);
108 bool decoded_successfully =
false;
111 [&decoded_successfully](
const std::string& code,
113 const rapidjson::Document* details) {
114 decoded_successfully =
true;
115 EXPECT_EQ(code,
"errorCode");
117 EXPECT_EQ(details,
nullptr);
122 EXPECT_TRUE(decoded_successfully);
128 rapidjson::Document details(rapidjson::kArrayType);
129 auto& allocator = details.GetAllocator();
130 details.PushBack(
"a", allocator);
131 details.PushBack(42, allocator);
134 ASSERT_NE(encoded.get(),
nullptr);
135 std::vector<uint8_t> bytes = {
136 '[',
'"',
'e',
'r',
'r',
'o',
'r',
'C',
'o',
'd',
'e',
'"',
',',
'"',
137 's',
'o',
'm',
'e',
't',
'h',
'i',
'n',
'g',
' ',
'f',
'a',
'i',
'l',
138 'e',
'd',
'"',
',',
'[',
'"',
'a',
'"',
',',
'4',
'2',
']',
']',
140 EXPECT_EQ(*encoded, bytes);
142 bool decoded_successfully =
false;
145 [&decoded_successfully](
const std::string& code,
147 const rapidjson::Document* details) {
148 decoded_successfully =
true;
149 EXPECT_EQ(code,
"errorCode");
150 EXPECT_EQ(
message,
"something failed");
151 EXPECT_TRUE(details->IsArray());
152 EXPECT_EQ(std::string((*details)[0].GetString()),
"a");
153 EXPECT_EQ((*details)[1].GetInt(), 42);
158 EXPECT_TRUE(decoded_successfully);