| Flutter Linux Embedder |

fl_standard_method_codec_test.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
6 #include "flutter/shell/platform/linux/fl_method_codec_private.h"
7 #include "flutter/shell/platform/linux/public/flutter_linux/fl_message_codec.h"
8 #include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h"
9 #include "flutter/shell/platform/linux/testing/fl_test.h"
10 #include "gtest/gtest.h"
11
12 G_DECLARE_FINAL_TYPE(FlTestMethodMessageCodec,
13 fl_test_method_message_codec,
14 FL,
15 TEST_METHOD_MESSAGE_CODEC,
16 FlStandardMessageCodec)
17
18 struct _FlTestMethodMessageCodec {
19 FlStandardMessageCodec parent_instance;
20 };
21
22 G_DEFINE_TYPE(FlTestMethodMessageCodec,
23 fl_test_method_message_codec,
24 fl_standard_message_codec_get_type())
25
26 static gboolean write_custom_value(FlStandardMessageCodec* codec,
27 GByteArray* buffer,
28 FlValue* value,
29 GError** error) {
30 const gchar* text =
31 static_cast<const gchar*>(fl_value_get_custom_value(value));
32 size_t length = strlen(text);
33
34 uint8_t type = 128;
35 g_byte_array_append(buffer, &type, sizeof(uint8_t));
36 fl_standard_message_codec_write_size(codec, buffer, length);
37 g_byte_array_append(buffer, reinterpret_cast<const uint8_t*>(text), length);
38 return TRUE;
39 }
40
41 static gboolean fl_test_method_message_codec_write_value(
42 FlStandardMessageCodec* codec,
43 GByteArray* buffer,
44 FlValue* value,
45 GError** error) {
46 if (fl_value_get_type(value) == FL_VALUE_TYPE_CUSTOM &&
47 fl_value_get_custom_type(value) == 128) {
48 return write_custom_value(codec, buffer, value, error);
49 } else {
50 return FL_STANDARD_MESSAGE_CODEC_CLASS(
51 fl_test_method_message_codec_parent_class)
52 ->write_value(codec, buffer, value, error);
53 }
54 }
55
56 static FlValue* read_custom_value(FlStandardMessageCodec* codec,
57 GBytes* buffer,
58 size_t* offset,
59 GError** error) {
60 uint32_t length;
61 if (!fl_standard_message_codec_read_size(codec, buffer, offset, &length,
62 error)) {
63 return nullptr;
64 }
65 if (*offset + length > g_bytes_get_size(buffer)) {
66 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
67 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA, "Unexpected end of data");
68 return nullptr;
69 }
70 FlValue* value = fl_value_new_custom(
71 128,
72 g_strndup(static_cast<const gchar*>(g_bytes_get_data(buffer, nullptr)) +
73 *offset,
74 length),
75 g_free);
76 *offset += length;
77
78 return value;
79 }
80
81 static FlValue* fl_test_method_message_codec_read_value_of_type(
82 FlStandardMessageCodec* codec,
83 GBytes* buffer,
84 size_t* offset,
85 int type,
86 GError** error) {
87 if (type == 128) {
88 return read_custom_value(codec, buffer, offset, error);
89 } else {
90 return FL_STANDARD_MESSAGE_CODEC_CLASS(
91 fl_test_method_message_codec_parent_class)
92 ->read_value_of_type(codec, buffer, offset, type, error);
93 }
94 }
95
96 static void fl_test_method_message_codec_class_init(
97 FlTestMethodMessageCodecClass* klass) {
98 FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->write_value =
99 fl_test_method_message_codec_write_value;
100 FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->read_value_of_type =
101 fl_test_method_message_codec_read_value_of_type;
102 }
103
104 static void fl_test_method_message_codec_init(FlTestMethodMessageCodec* self) {
105 // The following line suppresses a warning for unused function
106 FL_IS_TEST_METHOD_MESSAGE_CODEC(self);
107 }
108
109 static FlTestMethodMessageCodec* fl_test_method_message_codec_new() {
110 return FL_TEST_METHOD_MESSAGE_CODEC(
111 g_object_new(fl_test_method_message_codec_get_type(), nullptr));
112 }
113
114 // NOTE(robert-ancell) These test cases assumes a little-endian architecture.
115 // These tests will need to be updated if tested on a big endian architecture.
116
117 // Encodes a method call using StandardMethodCodec to a hex string.
118 static gchar* encode_method_call(const gchar* name, FlValue* args) {
119 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
120 g_autoptr(GError) error = nullptr;
121 g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
122 FL_METHOD_CODEC(codec), name, args, &error);
123 EXPECT_NE(message, nullptr);
124 EXPECT_EQ(error, nullptr);
125
126 return bytes_to_hex_string(message);
127 }
128
129 // Encodes a success envelope response using StandardMethodCodec to a hex
130 // string.
131 static gchar* encode_success_envelope(FlValue* result) {
132 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
133 g_autoptr(GError) error = nullptr;
134 g_autoptr(GBytes) message = fl_method_codec_encode_success_envelope(
135 FL_METHOD_CODEC(codec), result, &error);
136 EXPECT_NE(message, nullptr);
137 EXPECT_EQ(error, nullptr);
138
139 return bytes_to_hex_string(message);
140 }
141
142 // Encodes a error envelope response using StandardMethodCodec to a hex string.
143 static gchar* encode_error_envelope(const gchar* error_code,
144 const gchar* error_message,
145 FlValue* details) {
146 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
147 g_autoptr(GError) error = nullptr;
148 g_autoptr(GBytes) message = fl_method_codec_encode_error_envelope(
149 FL_METHOD_CODEC(codec), error_code, error_message, details, &error);
150 EXPECT_NE(message, nullptr);
151 EXPECT_EQ(error, nullptr);
152
153 return bytes_to_hex_string(message);
154 }
155
156 // Decodes a method call using StandardMethodCodec with a hex string.
157 static void decode_method_call(const char* hex_string,
158 gchar** name,
159 FlValue** args) {
160 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
161 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
162 g_autoptr(GError) error = nullptr;
163 gboolean result = fl_method_codec_decode_method_call(
164 FL_METHOD_CODEC(codec), message, name, args, &error);
165 EXPECT_TRUE(result);
166 EXPECT_EQ(error, nullptr);
167 }
168
169 // Decodes a method call using StandardMethodCodec. Expect the given error.
170 static void decode_error_method_call(const char* hex_string,
171 GQuark domain,
172 gint code) {
173 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
174 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
175 g_autoptr(GError) error = nullptr;
176 g_autofree gchar* name = nullptr;
177 g_autoptr(FlValue) args = nullptr;
178 gboolean result = fl_method_codec_decode_method_call(
179 FL_METHOD_CODEC(codec), message, &name, &args, &error);
180 EXPECT_FALSE(result);
181 EXPECT_EQ(name, nullptr);
182 EXPECT_EQ(args, nullptr);
183 EXPECT_TRUE(g_error_matches(error, domain, code));
184 }
185
186 // Decodes a response using StandardMethodCodec. Expect the response is a
187 // result.
188 static void decode_response_with_success(const char* hex_string,
189 FlValue* result) {
190 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
191 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
192 g_autoptr(GError) error = nullptr;
193 g_autoptr(FlMethodResponse) response =
194 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
195 ASSERT_NE(response, nullptr);
196 EXPECT_EQ(error, nullptr);
197 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
198 EXPECT_TRUE(fl_value_equal(fl_method_success_response_get_result(
199 FL_METHOD_SUCCESS_RESPONSE(response)),
200 result));
201 }
202
203 // Decodes a response using StandardMethodCodec. Expect the response contains
204 // the given error.
205 static void decode_response_with_error(const char* hex_string,
206 const gchar* code,
207 const gchar* error_message,
208 FlValue* details) {
209 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
210 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
211 g_autoptr(GError) error = nullptr;
212 g_autoptr(FlMethodResponse) response =
213 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
214 ASSERT_NE(response, nullptr);
215 EXPECT_EQ(error, nullptr);
216 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
217 EXPECT_STREQ(
218 fl_method_error_response_get_code(FL_METHOD_ERROR_RESPONSE(response)),
219 code);
220 if (error_message == nullptr) {
221 EXPECT_EQ(fl_method_error_response_get_message(
222 FL_METHOD_ERROR_RESPONSE(response)),
223 nullptr);
224 } else {
225 EXPECT_STREQ(fl_method_error_response_get_message(
226 FL_METHOD_ERROR_RESPONSE(response)),
227 error_message);
228 }
229 if (details == nullptr) {
230 EXPECT_EQ(fl_method_error_response_get_details(
231 FL_METHOD_ERROR_RESPONSE(response)),
232 nullptr);
233 } else {
234 EXPECT_TRUE(fl_value_equal(fl_method_error_response_get_details(
235 FL_METHOD_ERROR_RESPONSE(response)),
236 details));
237 }
238 }
239
240 static void decode_error_response(const char* hex_string,
241 GQuark domain,
242 gint code) {
243 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
244 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
245 g_autoptr(GError) error = nullptr;
246 g_autoptr(FlMethodResponse) response =
247 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
248 EXPECT_EQ(response, nullptr);
249 EXPECT_TRUE(g_error_matches(error, domain, code));
250 }
251
252 TEST(FlStandardMethodCodecTest, EncodeMethodCallNullptrArgs) {
253 g_autofree gchar* hex_string = encode_method_call("hello", nullptr);
254 EXPECT_STREQ(hex_string, "070568656c6c6f00");
255 }
256
257 TEST(FlStandardMethodCodecTest, EncodeMethodCallNullArgs) {
258 g_autoptr(FlValue) value = fl_value_new_null();
259 g_autofree gchar* hex_string = encode_method_call("hello", value);
260 EXPECT_STREQ(hex_string, "070568656c6c6f00");
261 }
262
263 TEST(FlStandardMethodCodecTest, EncodeMethodCallStringArgs) {
264 g_autoptr(FlValue) args = fl_value_new_string("world");
265 g_autofree gchar* hex_string = encode_method_call("hello", args);
266 EXPECT_STREQ(hex_string, "070568656c6c6f0705776f726c64");
267 }
268
269 TEST(FlStandardMethodCodecTest, EncodeMethodCallListArgs) {
270 g_autoptr(FlValue) args = fl_value_new_list();
271 fl_value_append_take(args, fl_value_new_string("count"));
272 fl_value_append_take(args, fl_value_new_int(42));
273 g_autofree gchar* hex_string = encode_method_call("hello", args);
274 EXPECT_STREQ(hex_string, "070568656c6c6f0c020705636f756e74032a000000");
275 }
276
277 TEST(FlStandardMethodCodecTest, DecodeMethodCallNullArgs) {
278 g_autofree gchar* name = nullptr;
279 g_autoptr(FlValue) args = nullptr;
280 decode_method_call("070568656c6c6f00", &name, &args);
281 EXPECT_STREQ(name, "hello");
282 ASSERT_EQ(fl_value_get_type(args), FL_VALUE_TYPE_NULL);
283 }
284
285 TEST(FlStandardMethodCodecTest, DecodeMethodCallStringArgs) {
286 g_autofree gchar* name = nullptr;
287 g_autoptr(FlValue) args = nullptr;
288 decode_method_call("070568656c6c6f0705776f726c64", &name, &args);
289 EXPECT_STREQ(name, "hello");
290 ASSERT_EQ(fl_value_get_type(args), FL_VALUE_TYPE_STRING);
291 EXPECT_STREQ(fl_value_get_string(args), "world");
292 }
293
294 TEST(FlStandardMethodCodecTest, DecodeMethodCallListArgs) {
295 g_autofree gchar* name = nullptr;
296 g_autoptr(FlValue) args = nullptr;
297 decode_method_call("070568656c6c6f0c020705636f756e74032a000000", &name,
298 &args);
299 EXPECT_STREQ(name, "hello");
300 ASSERT_EQ(fl_value_get_type(args), FL_VALUE_TYPE_LIST);
301 EXPECT_EQ(fl_value_get_length(args), static_cast<size_t>(2));
302
303 FlValue* arg0 = fl_value_get_list_value(args, 0);
304 ASSERT_EQ(fl_value_get_type(arg0), FL_VALUE_TYPE_STRING);
305 EXPECT_STREQ(fl_value_get_string(arg0), "count");
306
307 FlValue* arg1 = fl_value_get_list_value(args, 1);
308 ASSERT_EQ(fl_value_get_type(arg1), FL_VALUE_TYPE_INT);
309 EXPECT_EQ(fl_value_get_int(arg1), 42);
310 }
311
312 TEST(FlStandardMethodCodecTest, DecodeMethodCallNoData) {
313 decode_error_method_call("", FL_MESSAGE_CODEC_ERROR,
314 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
315 }
316
317 TEST(FlStandardMethodCodecTest, DecodeMethodCallNullMethodName) {
318 decode_error_method_call("000000", FL_MESSAGE_CODEC_ERROR,
319 FL_MESSAGE_CODEC_ERROR_FAILED);
320 }
321
322 TEST(FlStandardMethodCodecTest, DecodeMethodCallMissingArgs) {
323 decode_error_method_call("070568656c6c6f", FL_MESSAGE_CODEC_ERROR,
324 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
325 }
326
327 TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeNullptr) {
328 g_autofree gchar* hex_string = encode_success_envelope(nullptr);
329 EXPECT_STREQ(hex_string, "0000");
330 }
331
332 TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeNull) {
333 g_autoptr(FlValue) result = fl_value_new_null();
334 g_autofree gchar* hex_string = encode_success_envelope(result);
335 EXPECT_STREQ(hex_string, "0000");
336 }
337
338 TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeString) {
339 g_autoptr(FlValue) result = fl_value_new_string("hello");
340 g_autofree gchar* hex_string = encode_success_envelope(result);
341 EXPECT_STREQ(hex_string, "00070568656c6c6f");
342 }
343
344 TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeList) {
345 g_autoptr(FlValue) result = fl_value_new_list();
346 fl_value_append_take(result, fl_value_new_string("count"));
347 fl_value_append_take(result, fl_value_new_int(42));
348 g_autofree gchar* hex_string = encode_success_envelope(result);
349 EXPECT_STREQ(hex_string, "000c020705636f756e74032a000000");
350 }
351
352 TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeEmptyCode) {
353 g_autofree gchar* hex_string = encode_error_envelope("", nullptr, nullptr);
354 EXPECT_STREQ(hex_string, "0107000000");
355 }
356
357 TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeNonMessageOrDetails) {
358 g_autofree gchar* hex_string =
359 encode_error_envelope("error", nullptr, nullptr);
360 EXPECT_STREQ(hex_string, "0107056572726f720000");
361 }
362
363 TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeMessage) {
364 g_autofree gchar* hex_string =
365 encode_error_envelope("error", "message", nullptr);
366 EXPECT_STREQ(hex_string, "0107056572726f7207076d65737361676500");
367 }
368
369 TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeDetails) {
370 g_autoptr(FlValue) details = fl_value_new_list();
371 fl_value_append_take(details, fl_value_new_string("count"));
372 fl_value_append_take(details, fl_value_new_int(42));
373 g_autofree gchar* hex_string =
374 encode_error_envelope("error", nullptr, details);
375 EXPECT_STREQ(hex_string, "0107056572726f72000c020705636f756e74032a000000");
376 }
377
378 TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeMessageAndDetails) {
379 g_autoptr(FlValue) details = fl_value_new_list();
380 fl_value_append_take(details, fl_value_new_string("count"));
381 fl_value_append_take(details, fl_value_new_int(42));
382 g_autofree gchar* hex_string =
383 encode_error_envelope("error", "message", details);
384 EXPECT_STREQ(
385 hex_string,
386 "0107056572726f7207076d6573736167650c020705636f756e74032a000000");
387 }
388
389 TEST(FlStandardMethodCodecTest, DecodeResponseSuccessNull) {
390 g_autoptr(FlValue) result = fl_value_new_null();
391 decode_response_with_success("0000", result);
392 }
393
394 TEST(FlStandardMethodCodecTest, DecodeResponseSuccessString) {
395 g_autoptr(FlValue) result = fl_value_new_string("hello");
396 decode_response_with_success("00070568656c6c6f", result);
397 }
398
399 TEST(FlStandardMethodCodecTest, DecodeResponseSuccessList) {
400 g_autoptr(FlValue) result = fl_value_new_list();
401 fl_value_append_take(result, fl_value_new_string("count"));
402 fl_value_append_take(result, fl_value_new_int(42));
403 decode_response_with_success("000c020705636f756e74032a000000", result);
404 }
405
406 TEST(FlStandardMethodCodecTest, DecodeResponseErrorEmptyCode) {
407 decode_response_with_error("0107000000", "", nullptr, nullptr);
408 }
409
410 TEST(FlStandardMethodCodecTest, DecodeResponseErrorNoMessageOrDetails) {
411 decode_response_with_error("0107056572726f720000", "error", nullptr, nullptr);
412 }
413
414 TEST(FlStandardMethodCodecTest, DecodeResponseErrorMessage) {
415 decode_response_with_error("0107056572726f7207076d65737361676500", "error",
416 "message", nullptr);
417 }
418
419 TEST(FlStandardMethodCodecTest, DecodeResponseErrorDetails) {
420 g_autoptr(FlValue) details = fl_value_new_list();
421 fl_value_append_take(details, fl_value_new_string("count"));
422 fl_value_append_take(details, fl_value_new_int(42));
423 decode_response_with_error("0107056572726f72000c020705636f756e74032a000000",
424 "error", nullptr, details);
425 }
426
427 TEST(FlStandardMethodCodecTest, DecodeResponseErrorMessageAndDetails) {
428 g_autoptr(FlValue) details = fl_value_new_list();
429 fl_value_append_take(details, fl_value_new_string("count"));
430 fl_value_append_take(details, fl_value_new_int(42));
431 decode_response_with_error(
432 "0107056572726f7207076d6573736167650c020705636f756e74032a000000", "error",
433 "message", details);
434 }
435
436 TEST(FlStandardMethodCodecTest, DecodeResponseSuccessNoData) {
437 decode_error_response("00", FL_MESSAGE_CODEC_ERROR,
438 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
439 }
440
441 TEST(FlStandardMethodCodecTest, DecodeResponseSuccessExtraData) {
442 decode_error_response("000000", FL_MESSAGE_CODEC_ERROR,
443 FL_MESSAGE_CODEC_ERROR_FAILED);
444 }
445
446 TEST(FlStandardMethodCodecTest, DecodeResponseErrorNoData) {
447 decode_error_response("01", FL_MESSAGE_CODEC_ERROR,
448 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
449 }
450
451 TEST(FlStandardMethodCodecTest, DecodeResponseErrorMissingMessageAndDetails) {
452 decode_error_response("0107056572726f72", FL_MESSAGE_CODEC_ERROR,
453 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
454 }
455
456 TEST(FlStandardMethodCodecTest, DecodeResponseErrorMissingDetails) {
457 decode_error_response("0107056572726f7200", FL_MESSAGE_CODEC_ERROR,
458 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
459 }
460
461 TEST(FlStandardMethodCodecTest, DecodeResponseErrorExtraData) {
462 decode_error_response("0107056572726f72000000", FL_MESSAGE_CODEC_ERROR,
463 FL_MESSAGE_CODEC_ERROR_FAILED);
464 }
465
466 TEST(FlStandardMethodCodecTest, DecodeResponseNotImplemented) {
467 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
468 g_autoptr(GBytes) message = g_bytes_new(nullptr, 0);
469 g_autoptr(GError) error = nullptr;
470 g_autoptr(FlMethodResponse) response =
471 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
472 ASSERT_NE(response, nullptr);
473 EXPECT_EQ(error, nullptr);
474 EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
475 }
476
477 TEST(FlStandardMethodCodecTest, DecodeResponseUnknownEnvelope) {
478 decode_error_response("02", FL_MESSAGE_CODEC_ERROR,
479 FL_MESSAGE_CODEC_ERROR_FAILED);
480 }
481
482 TEST(FlStandardMethodCodecTest, CustomMessageCodec) {
483 g_autoptr(FlTestMethodMessageCodec) message_codec =
484 fl_test_method_message_codec_new();
485 g_autoptr(FlStandardMethodCodec) codec =
486 fl_standard_method_codec_new_with_message_codec(
487 FL_STANDARD_MESSAGE_CODEC(message_codec));
488
489 g_autoptr(GError) error = nullptr;
490 g_autoptr(FlValue) value = fl_value_new_custom(128, "hello", nullptr);
491 g_autoptr(GBytes) message = fl_method_codec_encode_success_envelope(
492 FL_METHOD_CODEC(codec), value, &error);
493 EXPECT_NE(message, nullptr);
494 EXPECT_EQ(error, nullptr);
495 g_autofree gchar* hex_string = bytes_to_hex_string(message);
496 EXPECT_STREQ(hex_string, "00800568656c6c6f");
497
498 g_autoptr(FlMethodResponse) response =
499 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
500 EXPECT_NE(response, nullptr);
501 EXPECT_EQ(error, nullptr);
502 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
503 FlValue* result = fl_method_success_response_get_result(
504 FL_METHOD_SUCCESS_RESPONSE(response));
505 ASSERT_EQ(fl_value_get_type(result), FL_VALUE_TYPE_CUSTOM);
506 ASSERT_EQ(fl_value_get_custom_type(result), 128);
507 EXPECT_STREQ(static_cast<const gchar*>(fl_value_get_custom_value(result)),
508 "hello");
509 }
FL
FL
Definition: fl_binary_messenger.cc:27
g_autoptr
g_autoptr(GMutexLocker) locker
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
fl_message_codec.h
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
@ FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
Definition: fl_message_codec.h:34
FL_MESSAGE_CODEC_ERROR_FAILED
@ FL_MESSAGE_CODEC_ERROR_FAILED
Definition: fl_message_codec.h:33
FL_MESSAGE_CODEC_ERROR
#define FL_MESSAGE_CODEC_ERROR
Definition: fl_message_codec.h:30
fl_method_codec_encode_success_envelope
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)
Definition: fl_method_codec.cc:41
fl_method_codec_encode_error_envelope
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
Definition: fl_method_codec.cc:50
fl_method_codec_encode_method_call
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
Definition: fl_method_codec.cc:16
fl_method_codec_decode_method_call
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)
Definition: fl_method_codec.cc:27
fl_method_codec_decode_response
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
Definition: fl_method_codec.cc:88
fl_method_codec_private.h
fl_method_error_response_get_code
G_MODULE_EXPORT const gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:160
fl_method_error_response_get_message
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:166
fl_method_success_response_get_result
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
Definition: fl_method_response.cc:138
fl_method_error_response_get_details
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:172
fl_standard_message_codec_read_size
G_MODULE_EXPORT gboolean fl_standard_message_codec_read_size(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
Definition: fl_standard_message_codec.cc:657
fl_standard_message_codec.h
fl_standard_method_codec_new_with_message_codec
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new_with_message_codec(FlStandardMessageCodec *message_codec)
Definition: fl_standard_method_codec.cc:298
fl_standard_method_codec_new
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
Definition: fl_standard_method_codec.cc:291
fl_standard_method_codec.h
encode_method_call
static gchar * encode_method_call(const gchar *name, FlValue *args)
Definition: fl_standard_method_codec_test.cc:118
decode_method_call
static void decode_method_call(const char *hex_string, gchar **name, FlValue **args)
Definition: fl_standard_method_codec_test.cc:157
type
uint8_t type
Definition: fl_standard_method_codec_test.cc:34
G_DECLARE_FINAL_TYPE
G_DECLARE_FINAL_TYPE(FlTestMethodMessageCodec, fl_test_method_message_codec, FL, TEST_METHOD_MESSAGE_CODEC, FlStandardMessageCodec) struct _FlTestMethodMessageCodec
Definition: fl_standard_method_codec_test.cc:12
decode_error_method_call
static void decode_error_method_call(const char *hex_string, GQuark domain, gint code)
Definition: fl_standard_method_codec_test.cc:170
fl_test_method_message_codec_new
static FlTestMethodMessageCodec * fl_test_method_message_codec_new()
Definition: fl_standard_method_codec_test.cc:109
fl_standard_message_codec_write_size
fl_standard_message_codec_write_size(codec, buffer, length)
decode_response_with_error
static void decode_response_with_error(const char *hex_string, const gchar *code, const gchar *error_message, FlValue *details)
Definition: fl_standard_method_codec_test.cc:205
fl_test_method_message_codec_init
static void fl_test_method_message_codec_init(FlTestMethodMessageCodec *self)
Definition: fl_standard_method_codec_test.cc:104
TRUE
return TRUE
Definition: fl_standard_method_codec_test.cc:38
TEST
TEST(FlStandardMethodCodecTest, EncodeMethodCallNullptrArgs)
Definition: fl_standard_method_codec_test.cc:252
buffer
GByteArray * buffer
Definition: fl_standard_method_codec_test.cc:27
error
GByteArray FlValue GError ** error
Definition: fl_standard_method_codec_test.cc:29
encode_success_envelope
static gchar * encode_success_envelope(FlValue *result)
Definition: fl_standard_method_codec_test.cc:131
value
GByteArray FlValue * value
Definition: fl_standard_method_codec_test.cc:28
G_DEFINE_TYPE
G_DEFINE_TYPE(FlTestMethodMessageCodec, fl_test_method_message_codec, fl_standard_message_codec_get_type()) static gboolean write_custom_value(FlStandardMessageCodec *codec
encode_error_envelope
static gchar * encode_error_envelope(const gchar *error_code, const gchar *error_message, FlValue *details)
Definition: fl_standard_method_codec_test.cc:143
read_custom_value
static FlValue * read_custom_value(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, GError **error)
Definition: fl_standard_method_codec_test.cc:56
fl_test_method_message_codec_read_value_of_type
static FlValue * fl_test_method_message_codec_read_value_of_type(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, int type, GError **error)
Definition: fl_standard_method_codec_test.cc:81
decode_response_with_success
static void decode_response_with_success(const char *hex_string, FlValue *result)
Definition: fl_standard_method_codec_test.cc:188
g_byte_array_append
g_byte_array_append(buffer, &type, sizeof(uint8_t))
decode_error_response
static void decode_error_response(const char *hex_string, GQuark domain, gint code)
Definition: fl_standard_method_codec_test.cc:240
length
size_t length
Definition: fl_standard_method_codec_test.cc:32
fl_test_method_message_codec_write_value
static gboolean fl_test_method_message_codec_write_value(FlStandardMessageCodec *codec, GByteArray *buffer, FlValue *value, GError **error)
Definition: fl_standard_method_codec_test.cc:41
fl_test_method_message_codec_class_init
static void fl_test_method_message_codec_class_init(FlTestMethodMessageCodecClass *klass)
Definition: fl_standard_method_codec_test.cc:96
fl_value_new_custom
G_MODULE_EXPORT FlValue * fl_value_new_custom(int type, gconstpointer value, GDestroyNotify destroy_notify)
Definition: fl_value.cc:374
fl_value_get_list_value
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition: fl_value.cc:776
fl_value_get_int
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:668
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
fl_value_get_custom_type
G_MODULE_EXPORT int fl_value_get_custom_type(FlValue *self)
Definition: fl_value.cc:822
fl_value_new_list
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:349
fl_value_append_take
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:600
fl_value_get_custom_value
G_MODULE_EXPORT gconstpointer fl_value_get_custom_value(FlValue *self)
Definition: fl_value.cc:830
fl_value_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251
fl_value_equal
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
fl_value_get_string
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
fl_value_get_length
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:724
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:68
FL_VALUE_TYPE_NULL
@ FL_VALUE_TYPE_NULL
Definition: fl_value.h:64
FL_VALUE_TYPE_INT
@ FL_VALUE_TYPE_INT
Definition: fl_value.h:66
FL_VALUE_TYPE_LIST
@ FL_VALUE_TYPE_LIST
Definition: fl_value.h:73
FL_VALUE_TYPE_CUSTOM
@ FL_VALUE_TYPE_CUSTOM
Definition: fl_value.h:76