5#include "flutter/shell/platform/common/json_method_codec.h"
7#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_result_functions.h"
8#include "gtest/gtest.h"
16bool 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 =
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 =
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);
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);
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);
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");
152 EXPECT_EQ(std::string((*details)[0].GetString()),
"a");
153 EXPECT_EQ((*details)[1].GetInt(), 42);
static const JsonMethodCodec & GetInstance()
std::unique_ptr< MethodCall< T > > DecodeMethodCall(const uint8_t *message, size_t message_size) const
bool DecodeAndProcessResponseEnvelope(const uint8_t *response, size_t response_size, MethodResult< T > *result) const
std::unique_ptr< std::vector< uint8_t > > EncodeErrorEnvelope(const std::string &error_code, const std::string &error_message="", const T *error_details=nullptr) const
std::unique_ptr< std::vector< uint8_t > > EncodeMethodCall(const MethodCall< T > &method_call) const
std::unique_ptr< std::vector< uint8_t > > EncodeSuccessEnvelope(const T *result=nullptr) const
TEST(FrameTimingsRecorderTest, RecordVsync)
#define EXPECT_TRUE(handle)