12 #include "gtest/gtest.h"
18 static_cast<const gchar*
>(g_bytes_get_data(message, &data_length));
19 return g_strndup(data, data_length);
24 return g_bytes_new(text, strlen(text));
30 g_autoptr(GError)
error =
nullptr;
32 FL_METHOD_CODEC(codec), name,
args, &
error);
33 EXPECT_NE(message,
nullptr);
34 EXPECT_EQ(
error,
nullptr);
42 g_autoptr(GError)
error =
nullptr;
45 EXPECT_NE(message,
nullptr);
46 EXPECT_EQ(
error,
nullptr);
53 const gchar* error_message,
56 g_autoptr(GError)
error =
nullptr;
58 FL_METHOD_CODEC(codec), error_code, error_message, details, &
error);
59 EXPECT_NE(message,
nullptr);
60 EXPECT_EQ(
error,
nullptr);
69 g_autoptr(GError)
error =
nullptr;
71 FL_METHOD_CODEC(codec), data, name,
args, &
error);
73 EXPECT_EQ(
error,
nullptr);
82 g_autoptr(GError)
error =
nullptr;
83 g_autofree gchar* name =
nullptr;
86 FL_METHOD_CODEC(codec), data, &name, &
args, &
error);
88 EXPECT_EQ(name,
nullptr);
89 EXPECT_EQ(
args,
nullptr);
90 EXPECT_TRUE(g_error_matches(
error, domain, code));
97 g_autoptr(GError)
error =
nullptr;
98 g_autoptr(FlMethodResponse) response =
100 ASSERT_NE(response,
nullptr);
101 EXPECT_EQ(
error,
nullptr);
102 ASSERT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
104 FL_METHOD_SUCCESS_RESPONSE(response)),
112 const gchar* error_message,
116 g_autoptr(GError)
error =
nullptr;
117 g_autoptr(FlMethodResponse) response =
119 ASSERT_NE(response,
nullptr);
120 EXPECT_EQ(
error,
nullptr);
121 ASSERT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
125 if (error_message ==
nullptr) {
127 FL_METHOD_ERROR_RESPONSE(response)),
131 FL_METHOD_ERROR_RESPONSE(response)),
134 if (details ==
nullptr) {
136 FL_METHOD_ERROR_RESPONSE(response)),
140 FL_METHOD_ERROR_RESPONSE(response)),
149 g_autoptr(GError)
error =
nullptr;
150 g_autoptr(FlMethodResponse) response =
152 EXPECT_EQ(response,
nullptr);
153 EXPECT_TRUE(g_error_matches(
error, domain, code));
156 TEST(FlJsonMethodCodecTest, EncodeMethodCallNullptrArgs) {
158 EXPECT_STREQ(text,
"{\"method\":\"hello\",\"args\":null}");
161 TEST(FlJsonMethodCodecTest, EncodeMethodCallNullArgs) {
164 EXPECT_STREQ(text,
"{\"method\":\"hello\",\"args\":null}");
167 TEST(FlJsonMethodCodecTest, EncodeMethodCallStringArgs) {
170 EXPECT_STREQ(text,
"{\"method\":\"hello\",\"args\":\"world\"}");
173 TEST(FlJsonMethodCodecTest, EncodeMethodCallListArgs) {
178 EXPECT_STREQ(text,
"{\"method\":\"hello\",\"args\":[\"count\",42]}");
181 TEST(FlJsonMethodCodecTest, DecodeMethodCallNoArgs) {
182 g_autofree gchar* name =
nullptr;
185 EXPECT_STREQ(name,
"hello");
186 ASSERT_EQ(
args,
nullptr);
189 TEST(FlJsonMethodCodecTest, DecodeMethodCallNullArgs) {
190 g_autofree gchar* name =
nullptr;
193 EXPECT_STREQ(name,
"hello");
197 TEST(FlJsonMethodCodecTest, DecodeMethodCallStringArgs) {
198 g_autofree gchar* name =
nullptr;
201 EXPECT_STREQ(name,
"hello");
206 TEST(FlJsonMethodCodecTest, DecodeMethodCallListArgs) {
207 g_autofree gchar* name =
nullptr;
211 EXPECT_STREQ(name,
"hello");
224 TEST(FlJsonMethodCodecTest, DecodeMethodCallNoData) {
229 TEST(FlJsonMethodCodecTest, DecodeMethodCallNoMethodOrArgs) {
234 TEST(FlJsonMethodCodecTest, DecodeMethodCallInvalidJson) {
239 TEST(FlJsonMethodCodecTest, DecodeMethodCallWrongType) {
244 TEST(FlJsonMethodCodecTest, DecodeMethodCallNoMethod) {
249 TEST(FlJsonMethodCodecTest, DecodeMethodCallNoTerminator) {
255 TEST(FlJsonMethodCodecTest, DecodeMethodCallExtraData) {
261 TEST(FlJsonMethodCodecTest, EncodeSuccessEnvelopeNullptr) {
263 EXPECT_STREQ(text,
"[null]");
266 TEST(FlJsonMethodCodecTest, EncodeSuccessEnvelopeNull) {
269 EXPECT_STREQ(text,
"[null]");
272 TEST(FlJsonMethodCodecTest, EncodeSuccessEnvelopeString) {
275 EXPECT_STREQ(text,
"[\"hello\"]");
278 TEST(FlJsonMethodCodecTest, EncodeSuccessEnvelopeList) {
283 EXPECT_STREQ(text,
"[[\"count\",42]]");
286 TEST(FlJsonMethodCodecTest, EncodeErrorEnvelopeEmptyCode) {
288 EXPECT_STREQ(text,
"[\"\",null,null]");
291 TEST(FlJsonMethodCodecTest, EncodeErrorEnvelopeNonMessageOrDetails) {
293 EXPECT_STREQ(text,
"[\"error\",null,null]");
296 TEST(FlJsonMethodCodecTest, EncodeErrorEnvelopeMessage) {
298 EXPECT_STREQ(text,
"[\"error\",\"message\",null]");
301 TEST(FlJsonMethodCodecTest, EncodeErrorEnvelopeDetails) {
306 EXPECT_STREQ(text,
"[\"error\",null,[\"count\",42]]");
309 TEST(FlJsonMethodCodecTest, EncodeErrorEnvelopeMessageAndDetails) {
314 EXPECT_STREQ(text,
"[\"error\",\"message\",[\"count\",42]]");
317 TEST(FlJsonMethodCodecTest, DecodeResponseSuccessNull) {
322 TEST(FlJsonMethodCodecTest, DecodeResponseSuccessString) {
327 TEST(FlJsonMethodCodecTest, DecodeResponseSuccessList) {
334 TEST(FlJsonMethodCodecTest, DecodeResponseErrorEmptyCode) {
338 TEST(FlJsonMethodCodecTest, DecodeResponseErrorNoMessageOrDetails) {
343 TEST(FlJsonMethodCodecTest, DecodeResponseErrorMessage) {
348 TEST(FlJsonMethodCodecTest, DecodeResponseErrorDetails) {
356 TEST(FlJsonMethodCodecTest, DecodeResponseErrorMessageAndDetails) {
364 TEST(FlJsonMethodCodecTest, DecodeResponseNotImplemented) {
366 g_autoptr(GBytes) message = g_bytes_new(
nullptr, 0);
367 g_autoptr(GError)
error =
nullptr;
368 g_autoptr(FlMethodResponse) response =
370 ASSERT_NE(response,
nullptr);
371 EXPECT_EQ(
error,
nullptr);
372 EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
375 TEST(FlJsonMethodCodecTest, DecodeResponseNoTerminator) {
380 TEST(FlJsonMethodCodecTest, DecodeResponseInvalidJson) {
385 TEST(FlJsonMethodCodecTest, DecodeResponseMissingDetails) {
390 TEST(FlJsonMethodCodecTest, DecodeResponseExtraDetails) {
395 TEST(FlJsonMethodCodecTest, DecodeResponseSuccessExtraData) {
400 TEST(FlJsonMethodCodecTest, DecodeResponseErrorExtraData) {