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