8 #include "flutter/shell/platform/common/client_wrapper/testing/test_codec_extensions.h"
9 #include "gtest/gtest.h"
17 bool MethodCallsAreEqual(
const MethodCall<>& a,
const MethodCall<>& b) {
18 if (a.method_name() != b.method_name()) {
22 if ((!a.arguments() || a.arguments()->IsNull()) &&
23 (!b.arguments() || b.arguments()->IsNull())) {
27 if (!a.arguments() || !b.arguments()) {
30 return *a.arguments() == *b.arguments();
40 EXPECT_EQ(&codec_a, &codec_b);
47 ASSERT_NE(encoded.get(),
nullptr);
49 ASSERT_NE(decoded.get(),
nullptr);
50 EXPECT_TRUE(MethodCallsAreEqual(call, *decoded));
60 ASSERT_NE(encoded.get(),
nullptr);
62 ASSERT_NE(decoded.get(),
nullptr);
63 EXPECT_TRUE(MethodCallsAreEqual(call, *decoded));
69 ASSERT_NE(encoded.get(),
nullptr);
70 std::vector<uint8_t> bytes = {0x00, 0x00};
71 EXPECT_EQ(*encoded, bytes);
73 bool decoded_successfully =
false;
76 decoded_successfully =
true;
77 EXPECT_EQ(result,
nullptr);
82 EXPECT_TRUE(decoded_successfully);
89 ASSERT_NE(encoded.get(),
nullptr);
90 std::vector<uint8_t> bytes = {0x00, 0x03, 0x2a, 0x00, 0x00, 0x00};
91 EXPECT_EQ(*encoded, bytes);
93 bool decoded_successfully =
false;
96 decoded_successfully =
true;
97 EXPECT_EQ(std::get<int32_t>(*result), 42);
102 EXPECT_TRUE(decoded_successfully);
108 ASSERT_NE(encoded.get(),
nullptr);
109 std::vector<uint8_t> bytes = {0x01, 0x07, 0x09, 0x65, 0x72, 0x72, 0x6f,
110 0x72, 0x43, 0x6f, 0x64, 0x65, 0x00, 0x00};
111 EXPECT_EQ(*encoded, bytes);
113 bool decoded_successfully =
false;
116 [&decoded_successfully](
const std::string& code,
119 decoded_successfully =
true;
120 EXPECT_EQ(code,
"errorCode");
122 EXPECT_EQ(details,
nullptr);
127 EXPECT_TRUE(decoded_successfully);
138 ASSERT_NE(encoded.get(),
nullptr);
139 std::vector<uint8_t> bytes = {
140 0x01, 0x07, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f,
141 0x64, 0x65, 0x07, 0x10, 0x73, 0x6f, 0x6d, 0x65, 0x74, 0x68,
142 0x69, 0x6e, 0x67, 0x20, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64,
143 0x0c, 0x02, 0x07, 0x01, 0x61, 0x03, 0x2a, 0x00, 0x00, 0x00,
145 EXPECT_EQ(*encoded, bytes);
147 bool decoded_successfully =
false;
150 [&decoded_successfully](
const std::string& code,
153 decoded_successfully =
true;
154 EXPECT_EQ(code,
"errorCode");
155 EXPECT_EQ(
message,
"something failed");
156 const auto* details_list = std::get_if<EncodableList>(details);
157 ASSERT_NE(details_list,
nullptr);
158 EXPECT_EQ(std::get<std::string>((*details_list)[0]),
"a");
159 EXPECT_EQ(std::get<int32_t>((*details_list)[1]), 42);
164 EXPECT_TRUE(decoded_successfully);
169 &PointExtensionSerializer::GetInstance());
174 ASSERT_NE(encoded.get(),
nullptr);
176 ASSERT_NE(decoded.get(),
nullptr);
178 const Point& decoded_point = std::any_cast<Point>(
179 std::get<CustomEncodableValue>(*decoded->arguments()));
180 EXPECT_EQ(point, decoded_point);