| Flutter Linux Embedder |

fl_standard_message_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_message_codec.h"
6 #include "flutter/shell/platform/linux/testing/fl_test.h"
7 #include "gtest/gtest.h"
8
9 // NOTE(robert-ancell) These test cases assumes a little-endian architecture.
10 // These tests will need to be updated if tested on a big endian architecture.
11
12 // Encodes a message using the supplied codec. Return a hex string with
13 // the encoded binary output.
14 static gchar* encode_message_with_codec(FlValue* value, FlMessageCodec* codec) {
15 g_autoptr(GError) error = nullptr;
16 g_autoptr(GBytes) message =
17 fl_message_codec_encode_message(codec, value, &error);
18 EXPECT_NE(message, nullptr);
19 EXPECT_EQ(error, nullptr);
20
21 return bytes_to_hex_string(message);
22 }
23
24 // Encodes a message using a FlStandardMessageCodec. Return a hex string with
25 // the encoded binary output.
26 static gchar* encode_message(FlValue* value) {
27 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
28 return encode_message_with_codec(value, FL_MESSAGE_CODEC(codec));
29 }
30
31 // Decodes a message using the supplied codec. The binary data is given in
32 // the form of a hex string.
33 static FlValue* decode_message_with_codec(const char* hex_string,
34 FlMessageCodec* codec) {
35 g_autoptr(GBytes) data = hex_string_to_bytes(hex_string);
36 g_autoptr(GError) error = nullptr;
37 g_autoptr(FlValue) value =
38 fl_message_codec_decode_message(codec, data, &error);
39 EXPECT_EQ(error, nullptr);
40 EXPECT_NE(value, nullptr);
41 return fl_value_ref(value);
42 }
43
44 // Decodes a message using a FlStandardMessageCodec. The binary data is given in
45 // the form of a hex string.
46 static FlValue* decode_message(const char* hex_string) {
47 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
48 return decode_message_with_codec(hex_string, FL_MESSAGE_CODEC(codec));
49 }
50
51 // Decodes a message using a FlStandardMessageCodec. The binary data is given in
52 // the form of a hex string. Expect the given error.
53 static void decode_error_value(const char* hex_string,
54 GQuark domain,
55 gint code) {
56 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
57 g_autoptr(GBytes) data = hex_string_to_bytes(hex_string);
58 g_autoptr(GError) error = nullptr;
59 g_autoptr(FlValue) value =
60 fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), data, &error);
61 EXPECT_TRUE(value == nullptr);
62 EXPECT_TRUE(g_error_matches(error, domain, code));
63 }
64
65 TEST(FlStandardMessageCodecTest, EncodeNullptr) {
66 g_autofree gchar* hex_string = encode_message(nullptr);
67 EXPECT_STREQ(hex_string, "00");
68 }
69
70 TEST(FlStandardMessageCodecTest, EncodeNull) {
71 g_autoptr(FlValue) value = fl_value_new_null();
72 g_autofree gchar* hex_string = encode_message(value);
73 EXPECT_STREQ(hex_string, "00");
74 }
75
76 TEST(FlStandardMessageCodecTest, DecodeNull) {
77 // Regression test for https://github.com/flutter/flutter/issues/128704.
78
79 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
80 g_autoptr(GBytes) data = g_bytes_new(nullptr, 0);
81 g_autoptr(GError) error = nullptr;
82 g_autoptr(FlValue) value =
83 fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), data, &error);
84
85 EXPECT_FALSE(value == nullptr);
86 EXPECT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_NULL);
87 }
88
89 static gchar* encode_bool(gboolean value) {
90 g_autoptr(FlValue) v = fl_value_new_bool(value);
91 return encode_message(v);
92 }
93
94 TEST(FlStandardMessageCodecTest, EncodeBoolFalse) {
95 g_autofree gchar* hex_string = encode_bool(FALSE);
96 EXPECT_STREQ(hex_string, "02");
97 }
98
99 TEST(FlStandardMessageCodecTest, EncodeBoolTrue) {
100 g_autofree gchar* hex_string = encode_bool(TRUE);
101 EXPECT_STREQ(hex_string, "01");
102 }
103
104 static gchar* encode_int(int64_t value) {
105 g_autoptr(FlValue) v = fl_value_new_int(value);
106 return encode_message(v);
107 }
108
109 TEST(FlStandardMessageCodecTest, EncodeIntZero) {
110 g_autofree gchar* hex_string = encode_int(0);
111 EXPECT_STREQ(hex_string, "0300000000");
112 }
113
114 TEST(FlStandardMessageCodecTest, EncodeIntOne) {
115 g_autofree gchar* hex_string = encode_int(1);
116 EXPECT_STREQ(hex_string, "0301000000");
117 }
118
119 TEST(FlStandardMessageCodecTest, EncodeInt32) {
120 g_autofree gchar* hex_string = encode_int(0x01234567);
121 EXPECT_STREQ(hex_string, "0367452301");
122 }
123
124 TEST(FlStandardMessageCodecTest, EncodeInt32Min) {
125 g_autofree gchar* hex_string = encode_int(G_MININT32);
126 EXPECT_STREQ(hex_string, "0300000080");
127 }
128
129 TEST(FlStandardMessageCodecTest, EncodeInt32Max) {
130 g_autofree gchar* hex_string = encode_int(G_MAXINT32);
131 EXPECT_STREQ(hex_string, "03ffffff7f");
132 }
133
134 TEST(FlStandardMessageCodecTest, EncodeInt64) {
135 g_autofree gchar* hex_string = encode_int(0x0123456789abcdef);
136 EXPECT_STREQ(hex_string, "04efcdab8967452301");
137 }
138
139 TEST(FlStandardMessageCodecTest, EncodeInt64Min) {
140 g_autofree gchar* hex_string = encode_int(G_MININT64);
141 EXPECT_STREQ(hex_string, "040000000000000080");
142 }
143
144 TEST(FlStandardMessageCodecTest, EncodeInt64Max) {
145 g_autofree gchar* hex_string = encode_int(G_MAXINT64);
146 EXPECT_STREQ(hex_string, "04ffffffffffffff7f");
147 }
148
149 TEST(FlStandardMessageCodecTest, DecodeIntZero) {
150 g_autoptr(FlValue) value = decode_message("0300000000");
151 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
152 EXPECT_EQ(fl_value_get_int(value), 0);
153 }
154
155 TEST(FlStandardMessageCodecTest, DecodeIntOne) {
156 g_autoptr(FlValue) value = decode_message("0301000000");
157 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
158 EXPECT_EQ(fl_value_get_int(value), 1);
159 }
160
161 TEST(FlStandardMessageCodecTest, DecodeInt32) {
162 g_autoptr(FlValue) value = decode_message("0367452301");
163 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
164 EXPECT_EQ(fl_value_get_int(value), 0x01234567);
165 }
166
167 TEST(FlStandardMessageCodecTest, DecodeInt32Min) {
168 g_autoptr(FlValue) value = decode_message("0300000080");
169 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
170 EXPECT_EQ(fl_value_get_int(value), G_MININT32);
171 }
172
173 TEST(FlStandardMessageCodecTest, DecodeInt32Max) {
174 g_autoptr(FlValue) value = decode_message("03ffffff7f");
175 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
176 EXPECT_EQ(fl_value_get_int(value), G_MAXINT32);
177 }
178
179 TEST(FlStandardMessageCodecTest, DecodeInt64) {
180 g_autoptr(FlValue) value = decode_message("04efcdab8967452301");
181 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
182 EXPECT_EQ(fl_value_get_int(value), 0x0123456789abcdef);
183 }
184
185 TEST(FlStandardMessageCodecTest, DecodeInt64Min) {
186 g_autoptr(FlValue) value = decode_message("040000000000000080");
187 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
188 EXPECT_EQ(fl_value_get_int(value), G_MININT64);
189 }
190
191 TEST(FlStandardMessageCodecTest, DecodeInt64Max) {
192 g_autoptr(FlValue) value = decode_message("04ffffffffffffff7f");
193 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
194 EXPECT_EQ(fl_value_get_int(value), G_MAXINT64);
195 }
196
197 TEST(FlStandardMessageCodecTest, DecodeInt32NoData) {
198 decode_error_value("03", FL_MESSAGE_CODEC_ERROR,
199 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
200 }
201
202 TEST(FlStandardMessageCodecTest, DecodeIntShortData1) {
203 decode_error_value("0367", FL_MESSAGE_CODEC_ERROR,
204 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
205 }
206
207 TEST(FlStandardMessageCodecTest, DecodeIntShortData2) {
208 decode_error_value("03674523", FL_MESSAGE_CODEC_ERROR,
209 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
210 }
211
212 TEST(FlStandardMessageCodecTest, DecodeInt64NoData) {
213 decode_error_value("04", FL_MESSAGE_CODEC_ERROR,
214 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
215 }
216
217 TEST(FlStandardMessageCodecTest, DecodeInt64ShortData1) {
218 decode_error_value("04ef", FL_MESSAGE_CODEC_ERROR,
219 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
220 }
221
222 TEST(FlStandardMessageCodecTest, DecodeInt64ShortData2) {
223 decode_error_value("04efcdab89674523", FL_MESSAGE_CODEC_ERROR,
224 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
225 }
226
227 static gchar* encode_float(double value) {
228 g_autoptr(FlValue) v = fl_value_new_float(value);
229 return encode_message(v);
230 }
231
232 TEST(FlStandardMessageCodecTest, EncodeFloatZero) {
233 g_autofree gchar* hex_string = encode_float(0);
234 EXPECT_STREQ(hex_string, "06000000000000000000000000000000");
235 }
236
237 TEST(FlStandardMessageCodecTest, EncodeFloatOne) {
238 g_autofree gchar* hex_string = encode_float(1);
239 EXPECT_STREQ(hex_string, "0600000000000000000000000000f03f");
240 }
241
242 TEST(FlStandardMessageCodecTest, EncodeFloatMinusOne) {
243 g_autofree gchar* hex_string = encode_float(-1);
244 EXPECT_STREQ(hex_string, "0600000000000000000000000000f0bf");
245 }
246
247 TEST(FlStandardMessageCodecTest, EncodeFloatHalf) {
248 g_autofree gchar* hex_string = encode_float(0.5);
249 EXPECT_STREQ(hex_string, "0600000000000000000000000000e03f");
250 }
251
252 TEST(FlStandardMessageCodecTest, EncodeFloatFraction) {
253 g_autofree gchar* hex_string = encode_float(M_PI);
254 EXPECT_STREQ(hex_string, "0600000000000000182d4454fb210940");
255 }
256
257 TEST(FlStandardMessageCodecTest, EncodeFloatMinusZero) {
258 g_autofree gchar* hex_string = encode_float(-0.0);
259 EXPECT_STREQ(hex_string, "06000000000000000000000000000080");
260 }
261
262 TEST(FlStandardMessageCodecTest, EncodeFloatNaN) {
263 g_autofree gchar* hex_string = encode_float(NAN);
264 EXPECT_STREQ(hex_string, "0600000000000000000000000000f87f");
265 }
266
267 TEST(FlStandardMessageCodecTest, EncodeFloatInfinity) {
268 g_autofree gchar* hex_string = encode_float(INFINITY);
269 EXPECT_STREQ(hex_string, "0600000000000000000000000000f07f");
270 }
271
272 TEST(FlStandardMessageCodecTest, DecodeFloatZero) {
273 g_autoptr(FlValue) value = decode_message("06000000000000000000000000000000");
274 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
275 EXPECT_EQ(fl_value_get_float(value), 0.0);
276 }
277
278 TEST(FlStandardMessageCodecTest, DecodeFloatOne) {
279 g_autoptr(FlValue) value = decode_message("0600000000000000000000000000f03f");
280 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
281 EXPECT_EQ(fl_value_get_float(value), 1.0);
282 }
283
284 TEST(FlStandardMessageCodecTest, DecodeFloatMinusOne) {
285 g_autoptr(FlValue) value = decode_message("0600000000000000000000000000f0bf");
286 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
287 EXPECT_EQ(fl_value_get_float(value), -1.0);
288 }
289
290 TEST(FlStandardMessageCodecTest, DecodeFloatHalf) {
291 g_autoptr(FlValue) value = decode_message("0600000000000000000000000000e03f");
292 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
293 EXPECT_EQ(fl_value_get_float(value), 0.5);
294 }
295
296 TEST(FlStandardMessageCodecTest, DecodeFloatPi) {
297 g_autoptr(FlValue) value = decode_message("0600000000000000182d4454fb210940");
298 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
299 EXPECT_EQ(fl_value_get_float(value), M_PI);
300 }
301
302 TEST(FlStandardMessageCodecTest, DecodeFloatMinusZero) {
303 g_autoptr(FlValue) value = decode_message("06000000000000000000000000000080");
304 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
305 EXPECT_EQ(fl_value_get_float(value), -0.0);
306 }
307
308 TEST(FlStandardMessageCodecTest, DecodeFloatNaN) {
309 g_autoptr(FlValue) value = decode_message("0600000000000000000000000000f87f");
310 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
311 EXPECT_TRUE(isnan(fl_value_get_float(value)));
312 }
313
314 TEST(FlStandardMessageCodecTest, DecodeFloatInfinity) {
315 g_autoptr(FlValue) value = decode_message("0600000000000000000000000000f07f");
316 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
317 EXPECT_TRUE(isinf(fl_value_get_float(value)));
318 }
319
320 TEST(FlStandardMessageCodecTest, DecodeFloatNoData) {
321 decode_error_value("060000000000000000", FL_MESSAGE_CODEC_ERROR,
322 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
323 }
324
325 TEST(FlStandardMessageCodecTest, DecodeFloatShortData1) {
326 decode_error_value("060000000000000000", FL_MESSAGE_CODEC_ERROR,
327 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
328 }
329
330 TEST(FlStandardMessageCodecTest, DecodeFloatShortData2) {
331 decode_error_value("060000000000000000000000000000", FL_MESSAGE_CODEC_ERROR,
332 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
333 }
334
335 static gchar* encode_string(const gchar* value) {
336 g_autoptr(FlValue) v = fl_value_new_string(value);
337 return encode_message(v);
338 }
339
340 TEST(FlStandardMessageCodecTest, EncodeStringEmpty) {
341 g_autofree gchar* hex_string = encode_string("");
342 EXPECT_STREQ(hex_string, "0700");
343 }
344
345 TEST(FlStandardMessageCodecTest, EncodeStringHello) {
346 g_autofree gchar* hex_string = encode_string("hello");
347 EXPECT_STREQ(hex_string, "070568656c6c6f");
348 }
349
350 TEST(FlStandardMessageCodecTest, EncodeStringEmptySized) {
351 g_autoptr(FlValue) value = fl_value_new_string_sized(nullptr, 0);
352 g_autofree gchar* hex_string = encode_message(value);
353 EXPECT_STREQ(hex_string, "0700");
354 }
355
356 TEST(FlStandardMessageCodecTest, EncodeStringHelloSized) {
357 g_autoptr(FlValue) value = fl_value_new_string_sized("Hello World", 5);
358 g_autofree gchar* hex_string = encode_message(value);
359 EXPECT_STREQ(hex_string, "070548656c6c6f");
360 }
361
362 TEST(FlStandardMessageCodecTest, DecodeStringEmpty) {
363 g_autoptr(FlValue) value = decode_message("0700");
364 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_STRING);
365 EXPECT_STREQ(fl_value_get_string(value), "");
366 }
367
368 TEST(FlStandardMessageCodecTest, DecodeStringHello) {
369 g_autoptr(FlValue) value = decode_message("070568656c6c6f");
370 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_STRING);
371 EXPECT_STREQ(fl_value_get_string(value), "hello");
372 }
373
374 TEST(FlStandardMessageCodecTest, DecodeStringNoData) {
375 decode_error_value("07", FL_MESSAGE_CODEC_ERROR,
376 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
377 }
378
379 TEST(FlStandardMessageCodecTest, DecodeStringLengthNoData) {
380 decode_error_value("0705", FL_MESSAGE_CODEC_ERROR,
381 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
382 }
383
384 TEST(FlStandardMessageCodecTest, DecodeStringShortData1) {
385 decode_error_value("070568", FL_MESSAGE_CODEC_ERROR,
386 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
387 }
388
389 TEST(FlStandardMessageCodecTest, DecodeStringShortData2) {
390 decode_error_value("070568656c6c", FL_MESSAGE_CODEC_ERROR,
391 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
392 }
393
394 TEST(FlStandardMessageCodecTest, EncodeUint8ListEmpty) {
395 g_autoptr(FlValue) value = fl_value_new_uint8_list(nullptr, 0);
396 g_autofree gchar* hex_string = encode_message(value);
397 EXPECT_STREQ(hex_string, "0800");
398 }
399
400 TEST(FlStandardMessageCodecTest, EncodeUint8List) {
401 uint8_t data[] = {0, 1, 2, 3, 4};
402 g_autoptr(FlValue) value = fl_value_new_uint8_list(data, 5);
403 g_autofree gchar* hex_string = encode_message(value);
404 EXPECT_STREQ(hex_string, "08050001020304");
405 }
406
407 TEST(FlStandardMessageCodecTest, DecodeUint8ListEmpty) {
408 g_autoptr(FlValue) value = decode_message("0800");
409 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_UINT8_LIST);
410 EXPECT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
411 }
412
413 TEST(FlStandardMessageCodecTest, DecodeUint8List) {
414 g_autoptr(FlValue) value = decode_message("08050001020304");
415 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_UINT8_LIST);
416 EXPECT_EQ(fl_value_get_length(value), static_cast<size_t>(5));
417 const uint8_t* data = fl_value_get_uint8_list(value);
418 EXPECT_EQ(data[0], 0);
419 EXPECT_EQ(data[1], 1);
420 EXPECT_EQ(data[2], 2);
421 EXPECT_EQ(data[3], 3);
422 EXPECT_EQ(data[4], 4);
423 }
424
425 TEST(FlStandardMessageCodecTest, DecodeUint8ListNoData) {
426 decode_error_value("08", FL_MESSAGE_CODEC_ERROR,
427 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
428 }
429
430 TEST(FlStandardMessageCodecTest, DecodeUint8ListLengthNoData) {
431 decode_error_value("0805", FL_MESSAGE_CODEC_ERROR,
432 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
433 }
434
435 TEST(FlStandardMessageCodecTest, DecodeUint8ListShortData1) {
436 decode_error_value("080500", FL_MESSAGE_CODEC_ERROR,
437 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
438 }
439
440 TEST(FlStandardMessageCodecTest, DecodeUint8ListShortData2) {
441 decode_error_value("080500010203", FL_MESSAGE_CODEC_ERROR,
442 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
443 }
444
445 TEST(FlStandardMessageCodecTest, EncodeInt32ListEmpty) {
446 g_autoptr(FlValue) value = fl_value_new_int32_list(nullptr, 0);
447 g_autofree gchar* hex_string = encode_message(value);
448 EXPECT_STREQ(hex_string, "09000000");
449 }
450
451 TEST(FlStandardMessageCodecTest, EncodeInt32List) {
452 int32_t data[] = {0, -1, 2, -3, 4};
453 g_autoptr(FlValue) value = fl_value_new_int32_list(data, 5);
454 g_autofree gchar* hex_string = encode_message(value);
455 EXPECT_STREQ(hex_string, "0905000000000000ffffffff02000000fdffffff04000000");
456 }
457
458 TEST(FlStandardMessageCodecTest, DecodeInt32ListEmpty) {
459 g_autoptr(FlValue) value = decode_message("09000000");
460 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT32_LIST);
461 EXPECT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
462 }
463
464 TEST(FlStandardMessageCodecTest, DecodeInt32List) {
465 g_autoptr(FlValue) value =
466 decode_message("0905000000000000ffffffff02000000fdffffff04000000");
467 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT32_LIST);
468 const int32_t* data = fl_value_get_int32_list(value);
469 EXPECT_EQ(data[0], 0);
470 EXPECT_EQ(data[1], -1);
471 EXPECT_EQ(data[2], 2);
472 EXPECT_EQ(data[3], -3);
473 EXPECT_EQ(data[4], 4);
474 }
475
476 TEST(FlStandardMessageCodecTest, DecodeInt32ListNoData) {
477 decode_error_value("09", FL_MESSAGE_CODEC_ERROR,
478 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
479 }
480
481 TEST(FlStandardMessageCodecTest, DecodeInt32ListLengthNoData) {
482 decode_error_value("09050000", FL_MESSAGE_CODEC_ERROR,
483 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
484 }
485
486 TEST(FlStandardMessageCodecTest, DecodeInt32ListShortData1) {
487 decode_error_value("0905000000", FL_MESSAGE_CODEC_ERROR,
488 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
489 }
490
491 TEST(FlStandardMessageCodecTest, DecodeInt32ListShortData2) {
492 decode_error_value("090500000000ffffffff02000000fdffffff040000",
493 FL_MESSAGE_CODEC_ERROR,
494 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
495 }
496
497 TEST(FlStandardMessageCodecTest, EncodeInt64ListEmpty) {
498 g_autoptr(FlValue) value = fl_value_new_int64_list(nullptr, 0);
499 g_autofree gchar* hex_string = encode_message(value);
500 EXPECT_STREQ(hex_string, "0a00000000000000");
501 }
502
503 TEST(FlStandardMessageCodecTest, EncodeInt64List) {
504 int64_t data[] = {0, -1, 2, -3, 4};
505 g_autoptr(FlValue) value = fl_value_new_int64_list(data, 5);
506 g_autofree gchar* hex_string = encode_message(value);
507 EXPECT_STREQ(
508 hex_string,
509 "0a050000000000000000000000000000ffffffffffffffff0200000000000000fdffffff"
510 "ffffffff0400000000000000");
511 }
512
513 TEST(FlStandardMessageCodecTest, DecodeInt64ListEmpty) {
514 g_autoptr(FlValue) value = decode_message("0a00000000000000");
515 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT64_LIST);
516 EXPECT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
517 }
518
519 TEST(FlStandardMessageCodecTest, DecodeInt64List) {
520 g_autoptr(FlValue) value = decode_message(
521 "0a050000000000000000000000000000ffffffffffffffff0200000000000000fdffffff"
522 "ffffffff0400000000000000");
523 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT64_LIST);
524 const int64_t* data = fl_value_get_int64_list(value);
525 EXPECT_EQ(data[0], 0);
526 EXPECT_EQ(data[1], -1);
527 EXPECT_EQ(data[2], 2);
528 EXPECT_EQ(data[3], -3);
529 EXPECT_EQ(data[4], 4);
530 }
531
532 TEST(FlStandardMessageCodecTest, DecodeInt64ListNoData) {
533 decode_error_value("0a", FL_MESSAGE_CODEC_ERROR,
534 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
535 }
536
537 TEST(FlStandardMessageCodecTest, DecodeInt64ListLengthNoData) {
538 decode_error_value("0a05000000000000", FL_MESSAGE_CODEC_ERROR,
539 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
540 }
541
542 TEST(FlStandardMessageCodecTest, DecodeInt64ListShortData1) {
543 decode_error_value("0a0500000000000000", FL_MESSAGE_CODEC_ERROR,
544 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
545 }
546
547 TEST(FlStandardMessageCodecTest, DecodeInt64ListShortData2) {
548 decode_error_value(
549 "0a050000000000000000000000000000ffffffffffffffff0200000000000000fdffffff"
550 "ffffffff0400"
551 "0000000000",
552 FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
553 }
554
555 TEST(FlStandardMessageCodecTest, EncodeFloat32ListEmpty) {
556 g_autoptr(FlValue) value = fl_value_new_float32_list(nullptr, 0);
557 g_autofree gchar* hex_string = encode_message(value);
558 EXPECT_STREQ(hex_string, "0e000000");
559 }
560
561 TEST(FlStandardMessageCodecTest, EncodeFloat32List) {
562 float data[] = {0.0f, -0.5f, 0.25f, -0.125f, 0.00625f};
563 g_autoptr(FlValue) value = fl_value_new_float32_list(data, 5);
564 g_autofree gchar* hex_string = encode_message(value);
565 EXPECT_STREQ(hex_string, "0e05000000000000000000bf0000803e000000becdcccc3b");
566 }
567
568 TEST(FlStandardMessageCodecTest, DecodeFloat32ListEmpty) {
569 g_autoptr(FlValue) value = decode_message("0e000000");
570 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT32_LIST);
571 EXPECT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
572 }
573
574 TEST(FlStandardMessageCodecTest, DecodeFloat32List) {
575 g_autoptr(FlValue) value =
576 decode_message("0e05000000000000000000bf0000803e000000becdcccc3b");
577 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT32_LIST);
578 const float* data = fl_value_get_float32_list(value);
579 EXPECT_FLOAT_EQ(data[0], 0.0f);
580 EXPECT_FLOAT_EQ(data[1], -0.5f);
581 EXPECT_FLOAT_EQ(data[2], 0.25f);
582 EXPECT_FLOAT_EQ(data[3], -0.125f);
583 EXPECT_FLOAT_EQ(data[4], 0.00625f);
584 }
585
586 TEST(FlStandardMessageCodecTest, DecodeFloat32ListNoData) {
587 decode_error_value("0e", FL_MESSAGE_CODEC_ERROR,
588 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
589 }
590
591 TEST(FlStandardMessageCodecTest, DecodeFloat32ListLengthNoData) {
592 decode_error_value("0e050000", FL_MESSAGE_CODEC_ERROR,
593 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
594 }
595
596 TEST(FlStandardMessageCodecTest, DecodeFloat32ListShortData1) {
597 decode_error_value("0e05000000", FL_MESSAGE_CODEC_ERROR,
598 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
599 }
600
601 TEST(FlStandardMessageCodecTest, DecodeFloat32ListShortData2) {
602 decode_error_value("0e05000000000000000000bf0000803e000000becdcccc",
603 FL_MESSAGE_CODEC_ERROR,
604 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
605 }
606
607 TEST(FlStandardMessageCodecTest, EncodeFloatListEmpty) {
608 g_autoptr(FlValue) value = fl_value_new_float_list(nullptr, 0);
609 g_autofree gchar* hex_string = encode_message(value);
610 EXPECT_STREQ(hex_string, "0b00000000000000");
611 }
612
613 TEST(FlStandardMessageCodecTest, EncodeFloatList) {
614 double data[] = {0, -0.5, 0.25, -0.125, 0.00625};
615 g_autoptr(FlValue) value = fl_value_new_float_list(data, 5);
616 g_autofree gchar* hex_string = encode_message(value);
617 EXPECT_STREQ(
618 hex_string,
619 "0b050000000000000000000000000000000000000000e0bf000000000000d03f00000000"
620 "0000c0bf9a9999999999793f");
621 }
622
623 TEST(FlStandardMessageCodecTest, DecodeFloatListEmpty) {
624 g_autoptr(FlValue) value = decode_message("0b00000000000000");
625 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT_LIST);
626 EXPECT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
627 }
628
629 TEST(FlStandardMessageCodecTest, DecodeFloatList) {
630 g_autoptr(FlValue) value = decode_message(
631 "0b050000000000000000000000000000000000000000e0bf000000000000d03f00000000"
632 "0000c0bf9a9999999999793f");
633 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT_LIST);
634 const double* data = fl_value_get_float_list(value);
635 EXPECT_FLOAT_EQ(data[0], 0.0);
636 EXPECT_FLOAT_EQ(data[1], -0.5);
637 EXPECT_FLOAT_EQ(data[2], 0.25);
638 EXPECT_FLOAT_EQ(data[3], -0.125);
639 EXPECT_FLOAT_EQ(data[4], 0.00625);
640 }
641
642 TEST(FlStandardMessageCodecTest, DecodeFloatListNoData) {
643 decode_error_value("0b", FL_MESSAGE_CODEC_ERROR,
644 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
645 }
646
647 TEST(FlStandardMessageCodecTest, DecodeFloatListLengthNoData) {
648 decode_error_value("0b05000000000000", FL_MESSAGE_CODEC_ERROR,
649 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
650 }
651
652 TEST(FlStandardMessageCodecTest, DecodeFloatListShortData1) {
653 decode_error_value("0b0500000000000000", FL_MESSAGE_CODEC_ERROR,
654 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
655 }
656
657 TEST(FlStandardMessageCodecTest, DecodeFloatListShortData2) {
658 decode_error_value(
659 "0b050000000000000000000000000000000000000000e0bf000000000000d03f00000000"
660 "0000c0bf9a99"
661 "9999999979",
662 FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
663 }
664
665 TEST(FlStandardMessageCodecTest, EncodeListEmpty) {
666 g_autoptr(FlValue) value = fl_value_new_list();
667 g_autofree gchar* hex_string = encode_message(value);
668 EXPECT_STREQ(hex_string, "0c00");
669 }
670
671 TEST(FlStandardMessageCodecTest, EncodeListTypes) {
672 g_autoptr(FlValue) value = fl_value_new_list();
673 fl_value_append_take(value, fl_value_new_null());
674 fl_value_append_take(value, fl_value_new_bool(TRUE));
675 fl_value_append_take(value, fl_value_new_int(42));
676 fl_value_append_take(value, fl_value_new_float(M_PI));
677 fl_value_append_take(value, fl_value_new_string("hello"));
678 fl_value_append_take(value, fl_value_new_list());
679 fl_value_append_take(value, fl_value_new_map());
680 g_autofree gchar* hex_string = encode_message(value);
681 EXPECT_STREQ(
682 hex_string,
683 "0c070001032a00000006000000000000182d4454fb210940070568656c6c6f0c000d00");
684 }
685
686 TEST(FlStandardMessageCodecTest, EncodeListNested) {
687 g_autoptr(FlValue) even_numbers = fl_value_new_list();
688 g_autoptr(FlValue) odd_numbers = fl_value_new_list();
689 for (int i = 0; i < 10; i++) {
690 if (i % 2 == 0) {
691 fl_value_append_take(even_numbers, fl_value_new_int(i));
692 } else {
693 fl_value_append_take(odd_numbers, fl_value_new_int(i));
694 }
695 }
696 g_autoptr(FlValue) value = fl_value_new_list();
697 fl_value_append(value, even_numbers);
698 fl_value_append(value, odd_numbers);
699 g_autofree gchar* hex_string = encode_message(value);
700 EXPECT_STREQ(hex_string,
701 "0c020c05030000000003020000000304000000030600000003080000000c"
702 "0503010000000303000000030500000003070000000309000000");
703 }
704
705 TEST(FlStandardMessageCodecTest, DecodeListEmpty) {
706 g_autoptr(FlValue) value = decode_message("0c00");
707 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_LIST);
708 EXPECT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
709 }
710
711 TEST(FlStandardMessageCodecTest, DecodeListTypes) {
712 g_autoptr(FlValue) value = decode_message(
713 "0c070001032a00000006000000000000182d4454fb210940070568656c6c6f0c000d00");
714 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_LIST);
715 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(7));
716 ASSERT_EQ(fl_value_get_type(fl_value_get_list_value(value, 0)),
717 FL_VALUE_TYPE_NULL);
718 ASSERT_EQ(fl_value_get_type(fl_value_get_list_value(value, 1)),
719 FL_VALUE_TYPE_BOOL);
720 EXPECT_TRUE(fl_value_get_bool(fl_value_get_list_value(value, 1)));
721 ASSERT_EQ(fl_value_get_type(fl_value_get_list_value(value, 2)),
722 FL_VALUE_TYPE_INT);
723 EXPECT_EQ(fl_value_get_int(fl_value_get_list_value(value, 2)), 42);
724 ASSERT_EQ(fl_value_get_type(fl_value_get_list_value(value, 3)),
725 FL_VALUE_TYPE_FLOAT);
726 EXPECT_FLOAT_EQ(fl_value_get_float(fl_value_get_list_value(value, 3)), M_PI);
727 ASSERT_EQ(fl_value_get_type(fl_value_get_list_value(value, 4)),
728 FL_VALUE_TYPE_STRING);
729 EXPECT_STREQ(fl_value_get_string(fl_value_get_list_value(value, 4)), "hello");
730 ASSERT_EQ(fl_value_get_type(fl_value_get_list_value(value, 5)),
731 FL_VALUE_TYPE_LIST);
732 ASSERT_EQ(fl_value_get_length(fl_value_get_list_value(value, 5)),
733 static_cast<size_t>(0));
734 ASSERT_EQ(fl_value_get_type(fl_value_get_list_value(value, 6)),
735 FL_VALUE_TYPE_MAP);
736 ASSERT_EQ(fl_value_get_length(fl_value_get_list_value(value, 6)),
737 static_cast<size_t>(0));
738 }
739
740 TEST(FlStandardMessageCodecTest, DecodeListNested) {
741 g_autoptr(FlValue) value = decode_message(
742 "0c020c05030000000003020000000304000000030600000003080000000c"
743 "0503010000000303000000030500000003070000000309000000");
744 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_LIST);
745 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(2));
746 FlValue* even_list = fl_value_get_list_value(value, 0);
747 ASSERT_EQ(fl_value_get_type(even_list), FL_VALUE_TYPE_LIST);
748 ASSERT_EQ(fl_value_get_length(even_list), static_cast<size_t>(5));
749 FlValue* odd_list = fl_value_get_list_value(value, 1);
750 ASSERT_EQ(fl_value_get_type(odd_list), FL_VALUE_TYPE_LIST);
751 ASSERT_EQ(fl_value_get_length(odd_list), static_cast<size_t>(5));
752 for (int i = 0; i < 5; i++) {
753 FlValue* v = fl_value_get_list_value(even_list, i);
754 ASSERT_EQ(fl_value_get_type(v), FL_VALUE_TYPE_INT);
755 EXPECT_EQ(fl_value_get_int(v), i * 2);
756
757 v = fl_value_get_list_value(odd_list, i);
758 ASSERT_EQ(fl_value_get_type(v), FL_VALUE_TYPE_INT);
759 EXPECT_EQ(fl_value_get_int(v), i * 2 + 1);
760 }
761 }
762
763 TEST(FlStandardMessageCodecTest, DecodeListNoData) {
764 decode_error_value("0c", FL_MESSAGE_CODEC_ERROR,
765 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
766 }
767
768 TEST(FlStandardMessageCodecTest, DecodeListLengthNoData) {
769 decode_error_value("0c07", FL_MESSAGE_CODEC_ERROR,
770 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
771 }
772
773 TEST(FlStandardMessageCodecTest, DecodeListShortData1) {
774 decode_error_value("0c0700", FL_MESSAGE_CODEC_ERROR,
775 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
776 }
777
778 TEST(FlStandardMessageCodecTest, DecodeListShortData2) {
779 decode_error_value(
780 "0c070001032a00000006000000000000182d4454fb210940070568656c6c6f0c000d",
781 FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
782 }
783
784 TEST(FlStandardMessageCodecTest, EncodeDecodeLargeList) {
785 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
786
787 g_autoptr(FlValue) value = fl_value_new_list();
788 for (int i = 0; i < 65535; i++) {
789 fl_value_append_take(value, fl_value_new_int(i));
790 }
791
792 g_autoptr(GError) error = nullptr;
793 g_autoptr(GBytes) message =
794 fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), value, &error);
795 EXPECT_NE(message, nullptr);
796 EXPECT_EQ(error, nullptr);
797
798 g_autoptr(FlValue) decoded_value =
799 fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), message, &error);
800 EXPECT_EQ(error, nullptr);
801 EXPECT_NE(value, nullptr);
802
803 ASSERT_TRUE(fl_value_equal(value, decoded_value));
804 }
805
806 TEST(FlStandardMessageCodecTest, EncodeMapEmpty) {
807 g_autoptr(FlValue) value = fl_value_new_map();
808 g_autofree gchar* hex_string = encode_message(value);
809 EXPECT_STREQ(hex_string, "0d00");
810 }
811
812 TEST(FlStandardMessageCodecTest, EncodeMapKeyTypes) {
813 g_autoptr(FlValue) value = fl_value_new_map();
814 fl_value_set_take(value, fl_value_new_null(), fl_value_new_string("null"));
815 fl_value_set_take(value, fl_value_new_bool(TRUE),
816 fl_value_new_string("bool"));
817 fl_value_set_take(value, fl_value_new_int(42), fl_value_new_string("int"));
818 fl_value_set_take(value, fl_value_new_float(M_PI),
819 fl_value_new_string("float"));
820 fl_value_set_take(value, fl_value_new_string("hello"),
821 fl_value_new_string("string"));
822 fl_value_set_take(value, fl_value_new_list(), fl_value_new_string("list"));
823 fl_value_set_take(value, fl_value_new_map(), fl_value_new_string("map"));
824 g_autofree gchar* hex_string = encode_message(value);
825 EXPECT_STREQ(hex_string,
826 "0d070007046e756c6c010704626f6f6c032a0000000703696e7406000000000"
827 "0182d4454fb2109400705666c6f6174070568656c6c6f0706737472696e670c"
828 "0007046c6973740d0007036d6170");
829 }
830
831 TEST(FlStandardMessageCodecTest, EncodeMapValueTypes) {
832 g_autoptr(FlValue) value = fl_value_new_map();
833 fl_value_set_take(value, fl_value_new_string("null"), fl_value_new_null());
834 fl_value_set_take(value, fl_value_new_string("bool"),
835 fl_value_new_bool(TRUE));
836 fl_value_set_take(value, fl_value_new_string("int"), fl_value_new_int(42));
837 fl_value_set_take(value, fl_value_new_string("float"),
838 fl_value_new_float(M_PI));
839 fl_value_set_take(value, fl_value_new_string("string"),
840 fl_value_new_string("hello"));
841 fl_value_set_take(value, fl_value_new_string("list"), fl_value_new_list());
842 fl_value_set_take(value, fl_value_new_string("map"), fl_value_new_map());
843 g_autofree gchar* hex_string = encode_message(value);
844 EXPECT_STREQ(hex_string,
845 "0d0707046e756c6c000704626f6f6c010703696e74032a0000000705666c6f6"
846 "17406000000000000182d4454fb2109400706737472696e67070568656c6c6f"
847 "07046c6973740c0007036d61700d00");
848 }
849
850 TEST(FlStandardMessageCodecTest, EncodeMapNested) {
851 g_autoptr(FlValue) str_to_int = fl_value_new_map();
852 g_autoptr(FlValue) int_to_str = fl_value_new_map();
853 const char* numbers[] = {"zero", "one", "two", "three", nullptr};
854 for (int i = 0; numbers[i] != nullptr; i++) {
855 fl_value_set_take(str_to_int, fl_value_new_string(numbers[i]),
856 fl_value_new_int(i));
857 fl_value_set_take(int_to_str, fl_value_new_int(i),
858 fl_value_new_string(numbers[i]));
859 }
860 g_autoptr(FlValue) value = fl_value_new_map();
861 fl_value_set_string(value, "str-to-int", str_to_int);
862 fl_value_set_string(value, "int-to-str", int_to_str);
863 g_autofree gchar* hex_string = encode_message(value);
864 EXPECT_STREQ(hex_string,
865 "0d02070a7374722d746f2d696e740d0407047a65726f030000000007036f6e6"
866 "50301000000070374776f0302000000070574687265650303000000070a696e"
867 "742d746f2d7374720d04030000000007047a65726f030100000007036f6e650"
868 "302000000070374776f030300000007057468726565");
869 }
870
871 TEST(FlStandardMessageCodecTest, DecodeMapEmpty) {
872 g_autoptr(FlValue) value = decode_message("0d00");
873 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
874 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
875 }
876
877 TEST(FlStandardMessageCodecTest, DecodeMapKeyTypes) {
878 g_autoptr(FlValue) value = decode_message(
879 "0d070007046e756c6c010704626f6f6c032a0000000703696e74060000000000182d4454"
880 "fb2109400705666c6f6174070568656c6c6f0706737472696e670c0007046c6973740d00"
881 "07036d6170");
882 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
883 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(7));
884
885 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 0)),
886 FL_VALUE_TYPE_NULL);
887 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 0)),
888 FL_VALUE_TYPE_STRING);
889 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_value(value, 0)), "null");
890
891 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 1)),
892 FL_VALUE_TYPE_BOOL);
893 EXPECT_TRUE(fl_value_get_bool(fl_value_get_map_key(value, 1)));
894 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 1)),
895 FL_VALUE_TYPE_STRING);
896 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_value(value, 1)), "bool");
897
898 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 2)),
899 FL_VALUE_TYPE_INT);
900 EXPECT_EQ(fl_value_get_int(fl_value_get_map_key(value, 2)), 42);
901 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 2)),
902 FL_VALUE_TYPE_STRING);
903 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_value(value, 2)), "int");
904
905 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 3)),
906 FL_VALUE_TYPE_FLOAT);
907 EXPECT_FLOAT_EQ(fl_value_get_float(fl_value_get_map_key(value, 3)), M_PI);
908 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 3)),
909 FL_VALUE_TYPE_STRING);
910 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_value(value, 3)), "float");
911
912 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 4)),
913 FL_VALUE_TYPE_STRING);
914 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 4)), "hello");
915 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 4)),
916 FL_VALUE_TYPE_STRING);
917 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_value(value, 4)), "string");
918
919 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 5)),
920 FL_VALUE_TYPE_LIST);
921 ASSERT_EQ(fl_value_get_length(fl_value_get_map_key(value, 5)),
922 static_cast<size_t>(0));
923 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 5)),
924 FL_VALUE_TYPE_STRING);
925 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_value(value, 5)), "list");
926
927 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 6)),
928 FL_VALUE_TYPE_MAP);
929 ASSERT_EQ(fl_value_get_length(fl_value_get_map_key(value, 6)),
930 static_cast<size_t>(0));
931 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 6)),
932 FL_VALUE_TYPE_STRING);
933 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_value(value, 6)), "map");
934 }
935
936 TEST(FlStandardMessageCodecTest, DecodeMapValueTypes) {
937 g_autoptr(FlValue) value = decode_message(
938 "0d0707046e756c6c000704626f6f6c010703696e74032a0000000705666c6f6174060000"
939 "00000000182d4454fb2109400706737472696e67070568656c6c6f07046c6973740c0007"
940 "036d61700d00");
941 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
942 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(7));
943
944 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 0)),
945 FL_VALUE_TYPE_STRING);
946 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 0)), "null");
947 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 0)),
948 FL_VALUE_TYPE_NULL);
949
950 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 1)),
951 FL_VALUE_TYPE_STRING);
952 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 1)), "bool");
953 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 1)),
954 FL_VALUE_TYPE_BOOL);
955 EXPECT_TRUE(fl_value_get_bool(fl_value_get_map_value(value, 1)));
956
957 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 2)),
958 FL_VALUE_TYPE_STRING);
959 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 2)), "int");
960 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 2)),
961 FL_VALUE_TYPE_INT);
962 EXPECT_EQ(fl_value_get_int(fl_value_get_map_value(value, 2)), 42);
963
964 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 3)),
965 FL_VALUE_TYPE_STRING);
966 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 3)), "float");
967 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 3)),
968 FL_VALUE_TYPE_FLOAT);
969 EXPECT_FLOAT_EQ(fl_value_get_float(fl_value_get_map_value(value, 3)), M_PI);
970
971 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 4)),
972 FL_VALUE_TYPE_STRING);
973 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 4)), "string");
974 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 4)),
975 FL_VALUE_TYPE_STRING);
976 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_value(value, 4)), "hello");
977
978 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 5)),
979 FL_VALUE_TYPE_STRING);
980 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 5)), "list");
981 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 5)),
982 FL_VALUE_TYPE_LIST);
983 ASSERT_EQ(fl_value_get_length(fl_value_get_map_value(value, 5)),
984 static_cast<size_t>(0));
985
986 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 6)),
987 FL_VALUE_TYPE_STRING);
988 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 6)), "map");
989 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 6)),
990 FL_VALUE_TYPE_MAP);
991 ASSERT_EQ(fl_value_get_length(fl_value_get_map_value(value, 6)),
992 static_cast<size_t>(0));
993 }
994
995 TEST(FlStandardMessageCodecTest, DecodeMapNested) {
996 g_autoptr(FlValue) value = decode_message(
997 "0d02070a7374722d746f2d696e740d0407047a65726f030000000007036f6e6503010000"
998 "00070374776f0302000000070574687265650303000000070a696e742d746f2d7374720d"
999 "04030000000007047a65726f030100000007036f6e650302000000070374776f03030000"
1000 "0007057468726565");
1001 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
1002 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(2));
1003
1004 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 0)),
1005 FL_VALUE_TYPE_STRING);
1006 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 0)),
1007 "str-to-int");
1008 FlValue* str_to_int = fl_value_get_map_value(value, 0);
1009 ASSERT_EQ(fl_value_get_type(str_to_int), FL_VALUE_TYPE_MAP);
1010 ASSERT_EQ(fl_value_get_length(str_to_int), static_cast<size_t>(4));
1011
1012 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 1)),
1013 FL_VALUE_TYPE_STRING);
1014 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 1)),
1015 "int-to-str");
1016 FlValue* int_to_str = fl_value_get_map_value(value, 1);
1017 ASSERT_EQ(fl_value_get_type(int_to_str), FL_VALUE_TYPE_MAP);
1018 ASSERT_EQ(fl_value_get_length(int_to_str), static_cast<size_t>(4));
1019
1020 const char* numbers[] = {"zero", "one", "two", "three", nullptr};
1021 for (int i = 0; numbers[i] != nullptr; i++) {
1022 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(str_to_int, i)),
1023 FL_VALUE_TYPE_STRING);
1024 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(str_to_int, i)),
1025 numbers[i]);
1026
1027 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(str_to_int, i)),
1028 FL_VALUE_TYPE_INT);
1029 EXPECT_EQ(fl_value_get_int(fl_value_get_map_value(str_to_int, i)), i);
1030
1031 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(int_to_str, i)),
1032 FL_VALUE_TYPE_INT);
1033 EXPECT_EQ(fl_value_get_int(fl_value_get_map_key(int_to_str, i)), i);
1034
1035 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(int_to_str, i)),
1036 FL_VALUE_TYPE_STRING);
1037 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_value(int_to_str, i)),
1038 numbers[i]);
1039 }
1040 }
1041
1042 TEST(FlStandardMessageCodecTest, DecodeMapNoData) {
1043 decode_error_value("0d", FL_MESSAGE_CODEC_ERROR,
1044 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
1045 }
1046
1047 TEST(FlStandardMessageCodecTest, DecodeMapLengthNoData) {
1048 decode_error_value("0d07", FL_MESSAGE_CODEC_ERROR,
1049 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
1050 }
1051
1052 TEST(FlStandardMessageCodecTest, DecodeMapShortData1) {
1053 decode_error_value("0d0707", FL_MESSAGE_CODEC_ERROR,
1054 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
1055 }
1056
1057 TEST(FlStandardMessageCodecTest, DecodeMapShortData2) {
1058 decode_error_value(
1059 "0d0707046e756c6c000704626f6f6c010703696e74032a0000000705666c6f6174060000"
1060 "00000000182d4454fb2109400706737472696e67070568656c6c6f07046c6973740c0007"
1061 "036d61700d",
1062 FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA);
1063 }
1064
1065 TEST(FlStandardMessageCodecTest, EncodeDecodeLargeMap) {
1066 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
1067
1068 g_autoptr(FlValue) value = fl_value_new_map();
1069 for (int i = 0; i < 512; i++) {
1070 g_autofree gchar* key = g_strdup_printf("key%d", i);
1071 fl_value_set_string_take(value, key, fl_value_new_int(i));
1072 }
1073
1074 g_autoptr(GError) error = nullptr;
1075 g_autoptr(GBytes) message =
1076 fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), value, &error);
1077 EXPECT_NE(message, nullptr);
1078 EXPECT_EQ(error, nullptr);
1079
1080 g_autoptr(FlValue) decoded_value =
1081 fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), message, &error);
1082 EXPECT_EQ(error, nullptr);
1083 EXPECT_NE(value, nullptr);
1084
1085 ASSERT_TRUE(fl_value_equal(value, decoded_value));
1086 }
1087
1088 TEST(FlStandardMessageCodecTest, DecodeUnknownType) {
1089 decode_error_value("0f", FL_MESSAGE_CODEC_ERROR,
1090 FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE);
1091 }
1092
1093 G_DECLARE_FINAL_TYPE(FlTestStandardMessageCodec,
1094 fl_test_standard_message_codec,
1095 FL,
1096 TEST_STANDARD_MESSAGE_CODEC,
1097 FlStandardMessageCodec)
1098
1099 struct _FlTestStandardMessageCodec {
1100 FlStandardMessageCodec parent_instance;
1101 };
1102
1103 G_DEFINE_TYPE(FlTestStandardMessageCodec,
1104 fl_test_standard_message_codec,
1105 fl_standard_message_codec_get_type())
1106
1107 static gboolean write_custom_value1(FlStandardMessageCodec* codec,
1108 GByteArray* buffer,
1109 FlValue* value,
1110 GError** error) {
1111 const gchar* text =
1112 static_cast<const gchar*>(fl_value_get_custom_value(value));
1113 size_t length = strlen(text);
1114
1115 uint8_t type = 128;
1116 g_byte_array_append(buffer, &type, sizeof(uint8_t));
1117 fl_standard_message_codec_write_size(codec, buffer, length);
1118 g_byte_array_append(buffer, reinterpret_cast<const uint8_t*>(text), length);
1119 return TRUE;
1120 }
1121
1122 static gboolean write_custom_value2(FlStandardMessageCodec* codec,
1123 GByteArray* buffer,
1124 FlValue* value,
1125 GError** error) {
1126 uint8_t type = 129;
1127 g_byte_array_append(buffer, &type, sizeof(uint8_t));
1128 return TRUE;
1129 }
1130
1131 static gboolean fl_test_standard_message_codec_write_value(
1132 FlStandardMessageCodec* codec,
1133 GByteArray* buffer,
1134 FlValue* value,
1135 GError** error) {
1136 if (fl_value_get_type(value) == FL_VALUE_TYPE_CUSTOM &&
1137 fl_value_get_custom_type(value) == 128) {
1138 return write_custom_value1(codec, buffer, value, error);
1139 } else if (fl_value_get_type(value) == FL_VALUE_TYPE_CUSTOM &&
1140 fl_value_get_custom_type(value) == 129) {
1141 return write_custom_value2(codec, buffer, value, error);
1142 } else {
1143 return FL_STANDARD_MESSAGE_CODEC_CLASS(
1144 fl_test_standard_message_codec_parent_class)
1145 ->write_value(codec, buffer, value, error);
1146 }
1147 }
1148
1149 static FlValue* read_custom_value1(FlStandardMessageCodec* codec,
1150 GBytes* buffer,
1151 size_t* offset,
1152 GError** error) {
1153 uint32_t length;
1154 if (!fl_standard_message_codec_read_size(codec, buffer, offset, &length,
1155 error)) {
1156 return nullptr;
1157 }
1158 if (*offset + length > g_bytes_get_size(buffer)) {
1159 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
1160 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA, "Unexpected end of data");
1161 return nullptr;
1162 }
1163 FlValue* value = fl_value_new_custom(
1164 128,
1165 g_strndup(static_cast<const gchar*>(g_bytes_get_data(buffer, nullptr)) +
1166 *offset,
1167 length),
1168 g_free);
1169 *offset += length;
1170
1171 return value;
1172 }
1173
1174 static FlValue* read_custom_value2(FlStandardMessageCodec* codec,
1175 GBytes* buffer,
1176 size_t* offset,
1177 GError** error) {
1178 return fl_value_new_custom(129, nullptr, nullptr);
1179 }
1180
1181 static FlValue* fl_test_standard_message_codec_read_value_of_type(
1182 FlStandardMessageCodec* codec,
1183 GBytes* buffer,
1184 size_t* offset,
1185 int type,
1186 GError** error) {
1187 if (type == 128) {
1188 return read_custom_value1(codec, buffer, offset, error);
1189 } else if (type == 129) {
1190 return read_custom_value2(codec, buffer, offset, error);
1191 } else {
1192 return FL_STANDARD_MESSAGE_CODEC_CLASS(
1193 fl_test_standard_message_codec_parent_class)
1194 ->read_value_of_type(codec, buffer, offset, type, error);
1195 }
1196 }
1197
1198 static void fl_test_standard_message_codec_class_init(
1199 FlTestStandardMessageCodecClass* klass) {
1200 FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->write_value =
1201 fl_test_standard_message_codec_write_value;
1202 FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->read_value_of_type =
1203 fl_test_standard_message_codec_read_value_of_type;
1204 }
1205
1206 static void fl_test_standard_message_codec_init(
1207 FlTestStandardMessageCodec* self) {
1208 // The following line suppresses a warning for unused function
1209 FL_IS_TEST_STANDARD_MESSAGE_CODEC(self);
1210 }
1211
1212 static FlTestStandardMessageCodec* fl_test_standard_message_codec_new() {
1213 return FL_TEST_STANDARD_MESSAGE_CODEC(
1214 g_object_new(fl_test_standard_message_codec_get_type(), nullptr));
1215 }
1216
1217 TEST(FlStandardMessageCodecTest, DecodeCustomType) {
1218 g_autoptr(FlTestStandardMessageCodec) codec =
1219 fl_test_standard_message_codec_new();
1220 g_autoptr(FlValue) value =
1221 decode_message_with_codec("800568656c6c6f", FL_MESSAGE_CODEC(codec));
1222 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_CUSTOM);
1223 ASSERT_EQ(fl_value_get_custom_type(value), 128);
1224 EXPECT_STREQ(static_cast<const gchar*>(fl_value_get_custom_value(value)),
1225 "hello");
1226 }
1227
1228 TEST(FlStandardMessageCodecTest, DecodeCustomTypes) {
1229 g_autoptr(FlTestStandardMessageCodec) codec =
1230 fl_test_standard_message_codec_new();
1231 g_autoptr(FlValue) value = decode_message_with_codec("0c02800568656c6c6f81",
1232 FL_MESSAGE_CODEC(codec));
1233 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_LIST);
1234 EXPECT_EQ(fl_value_get_length(value), static_cast<size_t>(2));
1235 FlValue* value1 = fl_value_get_list_value(value, 0);
1236 ASSERT_EQ(fl_value_get_type(value1), FL_VALUE_TYPE_CUSTOM);
1237 ASSERT_EQ(fl_value_get_custom_type(value1), 128);
1238 EXPECT_STREQ(static_cast<const gchar*>(fl_value_get_custom_value(value1)),
1239 "hello");
1240 FlValue* value2 = fl_value_get_list_value(value, 1);
1241 ASSERT_EQ(fl_value_get_type(value2), FL_VALUE_TYPE_CUSTOM);
1242 ASSERT_EQ(fl_value_get_custom_type(value2), 129);
1243 }
1244
1245 TEST(FlStandardMessageCodecTest, EncodeCustomType) {
1246 g_autoptr(FlValue) value = fl_value_new_custom(128, "hello", nullptr);
1247 g_autoptr(FlTestStandardMessageCodec) codec =
1248 fl_test_standard_message_codec_new();
1249 g_autofree gchar* hex_string =
1250 encode_message_with_codec(value, FL_MESSAGE_CODEC(codec));
1251 EXPECT_STREQ(hex_string, "800568656c6c6f");
1252 }
1253
1254 TEST(FlStandardMessageCodecTest, EncodeCustomTypes) {
1255 g_autoptr(FlValue) value = fl_value_new_list();
1256 fl_value_append_take(value, fl_value_new_custom(128, "hello", nullptr));
1257 fl_value_append_take(value, fl_value_new_custom(129, nullptr, nullptr));
1258 g_autoptr(FlTestStandardMessageCodec) codec =
1259 fl_test_standard_message_codec_new();
1260 g_autofree gchar* hex_string =
1261 encode_message_with_codec(value, FL_MESSAGE_CODEC(codec));
1262 EXPECT_STREQ(hex_string, "0c02800568656c6c6f81");
1263 }
1264
1265 TEST(FlStandardMessageCodecTest, EncodeDecode) {
1266 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
1267
1268 g_autoptr(FlValue) input = fl_value_new_list();
1269 fl_value_append_take(input, fl_value_new_null());
1270 fl_value_append_take(input, fl_value_new_bool(TRUE));
1271 fl_value_append_take(input, fl_value_new_int(42));
1272 fl_value_append_take(input, fl_value_new_float(M_PI));
1273 fl_value_append_take(input, fl_value_new_string("hello"));
1274 fl_value_append_take(input, fl_value_new_list());
1275 fl_value_append_take(input, fl_value_new_map());
1276
1277 g_autoptr(GError) error = nullptr;
1278 g_autoptr(GBytes) message =
1279 fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), input, &error);
1280 EXPECT_NE(message, nullptr);
1281 EXPECT_EQ(error, nullptr);
1282
1283 g_autoptr(FlValue) output =
1284 fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), message, &error);
1285 EXPECT_EQ(error, nullptr);
1286 EXPECT_NE(output, nullptr);
1287
1288 ASSERT_TRUE(fl_value_equal(input, output));
1289 }
FL
FL
Definition: fl_binary_messenger.cc:27
fl_message_codec_encode_message
G_MODULE_EXPORT GBytes * fl_message_codec_encode_message(FlMessageCodec *self, FlValue *message, GError **error)
Definition: fl_message_codec.cc:17
fl_message_codec_decode_message
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)
Definition: fl_message_codec.cc:33
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
@ FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
Definition: fl_message_codec.h:34
FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
@ FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
Definition: fl_message_codec.h:36
FL_MESSAGE_CODEC_ERROR
#define FL_MESSAGE_CODEC_ERROR
Definition: fl_message_codec.h:30
i
int i
Definition: fl_socket_accessible.cc:18
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_new
G_MODULE_EXPORT FlStandardMessageCodec * fl_standard_message_codec_new()
Definition: fl_standard_message_codec.cc:637
fl_standard_message_codec.h
encode_message_with_codec
static gchar * encode_message_with_codec(FlValue *value, FlMessageCodec *codec)
Definition: fl_standard_message_codec_test.cc:14
encode_string
static gchar * encode_string(const gchar *value)
Definition: fl_standard_message_codec_test.cc:335
decode_error_value
static void decode_error_value(const char *hex_string, GQuark domain, gint code)
Definition: fl_standard_message_codec_test.cc:53
type
uint8_t type
Definition: fl_standard_message_codec_test.cc:1115
encode_message
static gchar * encode_message(FlValue *value)
Definition: fl_standard_message_codec_test.cc:26
G_DECLARE_FINAL_TYPE
G_DECLARE_FINAL_TYPE(FlTestStandardMessageCodec, fl_test_standard_message_codec, FL, TEST_STANDARD_MESSAGE_CODEC, FlStandardMessageCodec) struct _FlTestStandardMessageCodec
Definition: fl_standard_message_codec_test.cc:1093
encode_float
static gchar * encode_float(double value)
Definition: fl_standard_message_codec_test.cc:227
fl_test_standard_message_codec_class_init
static void fl_test_standard_message_codec_class_init(FlTestStandardMessageCodecClass *klass)
Definition: fl_standard_message_codec_test.cc:1198
fl_standard_message_codec_write_size
fl_standard_message_codec_write_size(codec, buffer, length)
read_custom_value2
static FlValue * read_custom_value2(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, GError **error)
Definition: fl_standard_message_codec_test.cc:1174
read_custom_value1
static FlValue * read_custom_value1(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, GError **error)
Definition: fl_standard_message_codec_test.cc:1149
encode_bool
static gchar * encode_bool(gboolean value)
Definition: fl_standard_message_codec_test.cc:89
fl_test_standard_message_codec_new
static FlTestStandardMessageCodec * fl_test_standard_message_codec_new()
Definition: fl_standard_message_codec_test.cc:1212
TRUE
return TRUE
Definition: fl_standard_message_codec_test.cc:1119
decode_message_with_codec
static FlValue * decode_message_with_codec(const char *hex_string, FlMessageCodec *codec)
Definition: fl_standard_message_codec_test.cc:33
buffer
GByteArray * buffer
Definition: fl_standard_message_codec_test.cc:1108
error
GByteArray FlValue GError ** error
Definition: fl_standard_message_codec_test.cc:1110
encode_int
static gchar * encode_int(int64_t value)
Definition: fl_standard_message_codec_test.cc:104
fl_test_standard_message_codec_write_value
static gboolean fl_test_standard_message_codec_write_value(FlStandardMessageCodec *codec, GByteArray *buffer, FlValue *value, GError **error)
Definition: fl_standard_message_codec_test.cc:1131
value
GByteArray FlValue * value
Definition: fl_standard_message_codec_test.cc:1109
fl_test_standard_message_codec_read_value_of_type
static FlValue * fl_test_standard_message_codec_read_value_of_type(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, int type, GError **error)
Definition: fl_standard_message_codec_test.cc:1181
G_DEFINE_TYPE
G_DEFINE_TYPE(FlTestStandardMessageCodec, fl_test_standard_message_codec, fl_standard_message_codec_get_type()) static gboolean write_custom_value1(FlStandardMessageCodec *codec
TEST
TEST(FlStandardMessageCodecTest, EncodeNullptr)
Definition: fl_standard_message_codec_test.cc:65
g_byte_array_append
g_byte_array_append(buffer, &type, sizeof(uint8_t))
decode_message
static FlValue * decode_message(const char *hex_string)
Definition: fl_standard_message_codec_test.cc:46
length
size_t length
Definition: fl_standard_message_codec_test.cc:1113
write_custom_value2
static gboolean write_custom_value2(FlStandardMessageCodec *codec, GByteArray *buffer, FlValue *value, GError **error)
Definition: fl_standard_message_codec_test.cc:1122
fl_test_standard_message_codec_init
static void fl_test_standard_message_codec_init(FlTestStandardMessageCodec *self)
Definition: fl_standard_message_codec_test.cc:1206
fl_value_new_int32_list
G_MODULE_EXPORT FlValue * fl_value_new_int32_list(const int32_t *data, size_t data_length)
Definition: fl_value.cc:309
fl_value_get_map_value
G_MODULE_EXPORT FlValue * fl_value_get_map_value(FlValue *self, size_t index)
Definition: fl_value.cc:792
fl_value_set_string
G_MODULE_EXPORT void fl_value_set_string(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:639
fl_value_new_float
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition: fl_value.cc:269
fl_value_set_string_take
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:650
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_float_list
G_MODULE_EXPORT const double * fl_value_get_float_list(FlValue *self)
Definition: fl_value.cc:717
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_new_int64_list
G_MODULE_EXPORT FlValue * fl_value_new_int64_list(const int64_t *data, size_t data_length)
Definition: fl_value.cc:319
fl_value_get_uint8_list
G_MODULE_EXPORT const uint8_t * fl_value_get_uint8_list(FlValue *self)
Definition: fl_value.cc:689
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_new_bool
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255
fl_value_ref
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
Definition: fl_value.cc:394
fl_value_get_float32_list
G_MODULE_EXPORT const float * fl_value_get_float32_list(FlValue *self)
Definition: fl_value.cc:710
fl_value_append
G_MODULE_EXPORT void fl_value_append(FlValue *self, FlValue *value)
Definition: fl_value.cc:592
fl_value_set_take
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:618
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_new_string_sized
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition: fl_value.cc:283
fl_value_get_custom_value
G_MODULE_EXPORT gconstpointer fl_value_get_custom_value(FlValue *self)
Definition: fl_value.cc:830
fl_value_get_bool
G_MODULE_EXPORT bool fl_value_get_bool(FlValue *self)
Definition: fl_value.cc:661
fl_value_new_float_list
G_MODULE_EXPORT FlValue * fl_value_new_float_list(const double *data, size_t data_length)
Definition: fl_value.cc:339
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_map_key
G_MODULE_EXPORT FlValue * fl_value_get_map_key(FlValue *self, size_t index)
Definition: fl_value.cc:784
fl_value_get_string
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
fl_value_get_int64_list
G_MODULE_EXPORT const int64_t * fl_value_get_int64_list(FlValue *self)
Definition: fl_value.cc:703
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366
fl_value_new_float32_list
G_MODULE_EXPORT FlValue * fl_value_new_float32_list(const float *data, size_t data_length)
Definition: fl_value.cc:329
fl_value_new_uint8_list
G_MODULE_EXPORT FlValue * fl_value_new_uint8_list(const uint8_t *data, size_t data_length)
Definition: fl_value.cc:292
fl_value_get_float
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
Definition: fl_value.cc:675
fl_value_get_int32_list
G_MODULE_EXPORT const int32_t * fl_value_get_int32_list(FlValue *self)
Definition: fl_value.cc:696
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_BOOL
@ FL_VALUE_TYPE_BOOL
Definition: fl_value.h:65
FL_VALUE_TYPE_FLOAT32_LIST
@ FL_VALUE_TYPE_FLOAT32_LIST
Definition: fl_value.h:75
FL_VALUE_TYPE_INT32_LIST
@ FL_VALUE_TYPE_INT32_LIST
Definition: fl_value.h:70
FL_VALUE_TYPE_UINT8_LIST
@ FL_VALUE_TYPE_UINT8_LIST
Definition: fl_value.h:69
FL_VALUE_TYPE_LIST
@ FL_VALUE_TYPE_LIST
Definition: fl_value.h:73
FL_VALUE_TYPE_MAP
@ FL_VALUE_TYPE_MAP
Definition: fl_value.h:74
FL_VALUE_TYPE_INT64_LIST
@ FL_VALUE_TYPE_INT64_LIST
Definition: fl_value.h:71
FL_VALUE_TYPE_FLOAT_LIST
@ FL_VALUE_TYPE_FLOAT_LIST
Definition: fl_value.h:72
FL_VALUE_TYPE_CUSTOM
@ FL_VALUE_TYPE_CUSTOM
Definition: fl_value.h:76
FL_VALUE_TYPE_FLOAT
@ FL_VALUE_TYPE_FLOAT
Definition: fl_value.h:67