8 #include "flutter/shell/platform/linux/testing/fl_test.h"
9 #include "gtest/gtest.h"
17 g_autoptr(GError)
error =
nullptr;
19 FL_METHOD_CODEC(codec), name,
args, &
error);
20 EXPECT_NE(message,
nullptr);
21 EXPECT_EQ(
error,
nullptr);
23 return bytes_to_hex_string(message);
30 g_autoptr(GError)
error =
nullptr;
33 EXPECT_NE(message,
nullptr);
34 EXPECT_EQ(
error,
nullptr);
36 return bytes_to_hex_string(message);
41 const gchar* error_message,
44 g_autoptr(GError)
error =
nullptr;
46 FL_METHOD_CODEC(codec), error_code, error_message, details, &
error);
47 EXPECT_NE(message,
nullptr);
48 EXPECT_EQ(
error,
nullptr);
50 return bytes_to_hex_string(message);
58 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
59 g_autoptr(GError)
error =
nullptr;
61 FL_METHOD_CODEC(codec), message, name,
args, &
error);
63 EXPECT_EQ(
error,
nullptr);
71 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
72 g_autoptr(GError)
error =
nullptr;
73 g_autofree gchar* name =
nullptr;
76 FL_METHOD_CODEC(codec), message, &name, &
args, &
error);
78 EXPECT_EQ(name,
nullptr);
79 EXPECT_EQ(
args,
nullptr);
80 EXPECT_TRUE(g_error_matches(
error, domain, code));
88 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
89 g_autoptr(GError)
error =
nullptr;
90 g_autoptr(FlMethodResponse) response =
92 ASSERT_NE(response,
nullptr);
93 EXPECT_EQ(
error,
nullptr);
94 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
96 FL_METHOD_SUCCESS_RESPONSE(response)),
104 const gchar* error_message,
107 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
108 g_autoptr(GError)
error =
nullptr;
109 g_autoptr(FlMethodResponse) response =
111 ASSERT_NE(response,
nullptr);
112 EXPECT_EQ(
error,
nullptr);
113 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
117 if (error_message ==
nullptr) {
119 FL_METHOD_ERROR_RESPONSE(response)),
123 FL_METHOD_ERROR_RESPONSE(response)),
126 if (details ==
nullptr) {
128 FL_METHOD_ERROR_RESPONSE(response)),
132 FL_METHOD_ERROR_RESPONSE(response)),
141 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
142 g_autoptr(GError)
error =
nullptr;
143 g_autoptr(FlMethodResponse) response =
145 EXPECT_EQ(response,
nullptr);
146 EXPECT_TRUE(g_error_matches(
error, domain, code));
149 TEST(FlStandardMethodCodecTest, EncodeMethodCallNullptrArgs) {
151 EXPECT_STREQ(hex_string,
"070568656c6c6f00");
154 TEST(FlStandardMethodCodecTest, EncodeMethodCallNullArgs) {
157 EXPECT_STREQ(hex_string,
"070568656c6c6f00");
160 TEST(FlStandardMethodCodecTest, EncodeMethodCallStringArgs) {
163 EXPECT_STREQ(hex_string,
"070568656c6c6f0705776f726c64");
166 TEST(FlStandardMethodCodecTest, EncodeMethodCallListArgs) {
171 EXPECT_STREQ(hex_string,
"070568656c6c6f0c020705636f756e74032a000000");
174 TEST(FlStandardMethodCodecTest, DecodeMethodCallNullArgs) {
175 g_autofree gchar* name =
nullptr;
178 EXPECT_STREQ(name,
"hello");
182 TEST(FlStandardMethodCodecTest, DecodeMethodCallStringArgs) {
183 g_autofree gchar* name =
nullptr;
186 EXPECT_STREQ(name,
"hello");
191 TEST(FlStandardMethodCodecTest, DecodeMethodCallListArgs) {
192 g_autofree gchar* name =
nullptr;
196 EXPECT_STREQ(name,
"hello");
209 TEST(FlStandardMethodCodecTest, DecodeMethodCallNoData) {
214 TEST(FlStandardMethodCodecTest, DecodeMethodCallNullMethodName) {
219 TEST(FlStandardMethodCodecTest, DecodeMethodCallMissingArgs) {
224 TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeNullptr) {
226 EXPECT_STREQ(hex_string,
"0000");
229 TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeNull) {
232 EXPECT_STREQ(hex_string,
"0000");
235 TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeString) {
238 EXPECT_STREQ(hex_string,
"00070568656c6c6f");
241 TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeList) {
246 EXPECT_STREQ(hex_string,
"000c020705636f756e74032a000000");
249 TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeEmptyCode) {
251 EXPECT_STREQ(hex_string,
"0107000000");
254 TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeNonMessageOrDetails) {
255 g_autofree gchar* hex_string =
257 EXPECT_STREQ(hex_string,
"0107056572726f720000");
260 TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeMessage) {
261 g_autofree gchar* hex_string =
263 EXPECT_STREQ(hex_string,
"0107056572726f7207076d65737361676500");
266 TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeDetails) {
270 g_autofree gchar* hex_string =
272 EXPECT_STREQ(hex_string,
"0107056572726f72000c020705636f756e74032a000000");
275 TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeMessageAndDetails) {
279 g_autofree gchar* hex_string =
283 "0107056572726f7207076d6573736167650c020705636f756e74032a000000");
286 TEST(FlStandardMethodCodecTest, DecodeResponseSuccessNull) {
291 TEST(FlStandardMethodCodecTest, DecodeResponseSuccessString) {
296 TEST(FlStandardMethodCodecTest, DecodeResponseSuccessList) {
303 TEST(FlStandardMethodCodecTest, DecodeResponseErrorEmptyCode) {
307 TEST(FlStandardMethodCodecTest, DecodeResponseErrorNoMessageOrDetails) {
311 TEST(FlStandardMethodCodecTest, DecodeResponseErrorMessage) {
316 TEST(FlStandardMethodCodecTest, DecodeResponseErrorDetails) {
321 "error",
nullptr, details);
324 TEST(FlStandardMethodCodecTest, DecodeResponseErrorMessageAndDetails) {
329 "0107056572726f7207076d6573736167650c020705636f756e74032a000000",
"error",
333 TEST(FlStandardMethodCodecTest, DecodeResponseSuccessNoData) {
338 TEST(FlStandardMethodCodecTest, DecodeResponseSuccessExtraData) {
343 TEST(FlStandardMethodCodecTest, DecodeResponseErrorNoData) {
348 TEST(FlStandardMethodCodecTest, DecodeResponseErrorMissingMessageAndDetails) {
353 TEST(FlStandardMethodCodecTest, DecodeResponseErrorMissingDetails) {
358 TEST(FlStandardMethodCodecTest, DecodeResponseErrorExtraData) {
363 TEST(FlStandardMethodCodecTest, DecodeResponseNotImplemented) {
365 g_autoptr(GBytes) message = g_bytes_new(
nullptr, 0);
366 g_autoptr(GError)
error =
nullptr;
367 g_autoptr(FlMethodResponse) response =
369 ASSERT_NE(response,
nullptr);
370 EXPECT_EQ(
error,
nullptr);
371 EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
374 TEST(FlStandardMethodCodecTest, DecodeResponseUnknownEnvelope) {