6 #include "gtest/gtest.h"
13 g_autoptr(GError)
error =
nullptr;
15 EXPECT_EQ(
error,
nullptr);
16 return static_cast<gchar*
>(g_steal_pointer(&
result));
23 g_autoptr(GError)
error =
nullptr;
25 EXPECT_TRUE(g_error_matches(
error, domain, code));
26 EXPECT_EQ(
result,
nullptr);
32 g_autoptr(GError)
error =
nullptr;
34 EXPECT_EQ(
error,
nullptr);
35 EXPECT_NE(
value,
nullptr);
43 g_autoptr(GError)
error =
nullptr;
45 EXPECT_TRUE(g_error_matches(
error, domain, code));
46 EXPECT_EQ(
value,
nullptr);
49 TEST(FlJsonMessageCodecTest, EncodeNullptr) {
51 EXPECT_STREQ(text,
"null");
54 TEST(FlJsonMessageCodecTest, EncodeNull) {
57 EXPECT_STREQ(text,
"null");
60 TEST(FlJsonMessageCodecTest, DecodeNull) {
70 TEST(FlJsonMessageCodecTest, EncodeBoolFalse) {
72 EXPECT_STREQ(text,
"false");
75 TEST(FlJsonMessageCodecTest, EncodeBoolTrue) {
77 EXPECT_STREQ(text,
"true");
80 TEST(FlJsonMessageCodecTest, DecodeBoolFalse) {
86 TEST(FlJsonMessageCodecTest, DecodeBoolTrue) {
97 TEST(FlJsonMessageCodecTest, EncodeIntZero) {
99 EXPECT_STREQ(text,
"0");
102 TEST(FlJsonMessageCodecTest, EncodeIntOne) {
104 EXPECT_STREQ(text,
"1");
107 TEST(FlJsonMessageCodecTest, EncodeInt12345) {
109 EXPECT_STREQ(text,
"12345");
112 TEST(FlJsonMessageCodecTest, EncodeIntMin) {
113 g_autofree gchar* text =
encode_int(G_MININT64);
114 EXPECT_STREQ(text,
"-9223372036854775808");
117 TEST(FlJsonMessageCodecTest, EncodeIntMax) {
118 g_autofree gchar* text =
encode_int(G_MAXINT64);
119 EXPECT_STREQ(text,
"9223372036854775807");
122 TEST(FlJsonMessageCodecTest, DecodeIntZero) {
128 TEST(FlJsonMessageCodecTest, DecodeIntOne) {
134 TEST(FlJsonMessageCodecTest, DecodeInt12345) {
140 TEST(FlJsonMessageCodecTest, DecodeIntMin) {
146 TEST(FlJsonMessageCodecTest, DecodeIntMax) {
152 TEST(FlJsonMessageCodecTest, DecodeUintMax) {
160 TEST(FlJsonMessageCodecTest, DecodeHugeNumber) {
168 TEST(FlJsonMessageCodecTest, DecodeIntLeadingZero1) {
173 TEST(FlJsonMessageCodecTest, DecodeIntLeadingZero2) {
178 TEST(FlJsonMessageCodecTest, DecodeIntDoubleNegative) {
183 TEST(FlJsonMessageCodecTest, DecodeIntPositiveSign) {
188 TEST(FlJsonMessageCodecTest, DecodeIntHexChar) {
198 TEST(FlJsonMessageCodecTest, EncodeFloatZero) {
200 EXPECT_STREQ(text,
"0.0");
203 TEST(FlJsonMessageCodecTest, EncodeFloatOne) {
205 EXPECT_STREQ(text,
"1.0");
208 TEST(FlJsonMessageCodecTest, EncodeFloatMinusOne) {
210 EXPECT_STREQ(text,
"-1.0");
213 TEST(FlJsonMessageCodecTest, EncodeFloatHalf) {
215 EXPECT_STREQ(text,
"0.5");
218 TEST(FlJsonMessageCodecTest, EncodeFloatPi) {
220 EXPECT_STREQ(text,
"3.141592653589793");
223 TEST(FlJsonMessageCodecTest, EncodeFloatMinusZero) {
225 EXPECT_STREQ(text,
"-0.0");
231 TEST(FlJsonMessageCodecTest, DecodeFloatZero) {
237 TEST(FlJsonMessageCodecTest, DecodeFloatOne) {
243 TEST(FlJsonMessageCodecTest, DecodeFloatMinusOne) {
249 TEST(FlJsonMessageCodecTest, DecodeFloatHalf) {
255 TEST(FlJsonMessageCodecTest, DecodeFloatPi) {
261 TEST(FlJsonMessageCodecTest, DecodeFloatMinusZero) {
267 TEST(FlJsonMessageCodecTest, DecodeFloatMissingFraction) {
272 TEST(FlJsonMessageCodecTest, DecodeFloatInvalidFraction) {
282 TEST(FlJsonMessageCodecTest, EncodeStringEmpty) {
284 EXPECT_STREQ(text,
"\"\"");
287 TEST(FlJsonMessageCodecTest, EncodeStringHello) {
289 EXPECT_STREQ(text,
"\"hello\"");
292 TEST(FlJsonMessageCodecTest, EncodeStringEmptySized) {
295 EXPECT_STREQ(text,
"\"\"");
298 TEST(FlJsonMessageCodecTest, EncodeStringHelloSized) {
301 EXPECT_STREQ(text,
"\"Hello\"");
304 TEST(FlJsonMessageCodecTest, EncodeStringEscapeQuote) {
306 EXPECT_STREQ(text,
"\"\\\"\"");
309 TEST(FlJsonMessageCodecTest, EncodeStringEscapeBackslash) {
311 EXPECT_STREQ(text,
"\"\\\\\"");
314 TEST(FlJsonMessageCodecTest, EncodeStringEscapeBackspace) {
316 EXPECT_STREQ(text,
"\"\\b\"");
319 TEST(FlJsonMessageCodecTest, EncodeStringEscapeFormFeed) {
321 EXPECT_STREQ(text,
"\"\\f\"");
324 TEST(FlJsonMessageCodecTest, EncodeStringEscapeNewline) {
326 EXPECT_STREQ(text,
"\"\\n\"");
329 TEST(FlJsonMessageCodecTest, EncodeStringEscapeCarriageReturn) {
331 EXPECT_STREQ(text,
"\"\\r\"");
334 TEST(FlJsonMessageCodecTest, EncodeStringEscapeTab) {
336 EXPECT_STREQ(text,
"\"\\t\"");
339 TEST(FlJsonMessageCodecTest, EncodeStringEscapeUnicode) {
341 EXPECT_STREQ(text,
"\"\\u0001\"");
344 TEST(FlJsonMessageCodecTest, EncodeStringEmoji) {
346 EXPECT_STREQ(text,
"\"😀\"");
349 TEST(FlJsonMessageCodecTest, DecodeStringEmpty) {
355 TEST(FlJsonMessageCodecTest, DecodeStringHello) {
361 TEST(FlJsonMessageCodecTest, DecodeStringEscapeQuote) {
367 TEST(FlJsonMessageCodecTest, DecodeStringEscapeBackslash) {
373 TEST(FlJsonMessageCodecTest, DecodeStringEscapeSlash) {
379 TEST(FlJsonMessageCodecTest, DecodeStringEscapeBackspace) {
385 TEST(FlJsonMessageCodecTest, DecodeStringEscapeFormFeed) {
391 TEST(FlJsonMessageCodecTest, DecodeStringEscapeNewline) {
397 TEST(FlJsonMessageCodecTest, DecodeStringEscapeCarriageReturn) {
403 TEST(FlJsonMessageCodecTest, DecodeStringEscapeTab) {
409 TEST(FlJsonMessageCodecTest, DecodeStringEscapeUnicode) {
415 TEST(FlJsonMessageCodecTest, DecodeStringEmoji) {
421 TEST(FlJsonMessageCodecTest, DecodeInvalidUTF8) {
426 TEST(FlJsonMessageCodecTest, DecodeStringInvalidUTF8) {
431 TEST(FlJsonMessageCodecTest, DecodeStringBinary) {
436 TEST(FlJsonMessageCodecTest, DecodeStringNewline) {
441 TEST(FlJsonMessageCodecTest, DecodeStringCarriageReturn) {
446 TEST(FlJsonMessageCodecTest, DecodeStringTab) {
451 TEST(FlJsonMessageCodecTest, DecodeStringUnterminatedEmpty) {
456 TEST(FlJsonMessageCodecTest, DecodeStringExtraQuote) {
461 TEST(FlJsonMessageCodecTest, DecodeStringEscapedClosingQuote) {
466 TEST(FlJsonMessageCodecTest, DecodeStringUnknownEscape) {
471 TEST(FlJsonMessageCodecTest, DecodeStringInvalidEscapeUnicode) {
476 TEST(FlJsonMessageCodecTest, DecodeStringEscapeUnicodeNoData) {
481 TEST(FlJsonMessageCodecTest, DecodeStringEscapeUnicodeShortData) {
486 TEST(FlJsonMessageCodecTest, EncodeUint8ListEmpty) {
489 EXPECT_STREQ(text,
"[]");
492 TEST(FlJsonMessageCodecTest, EncodeUint8List) {
493 uint8_t data[] = {0, 1, 2, 3, 4};
496 EXPECT_STREQ(text,
"[0,1,2,3,4]");
499 TEST(FlJsonMessageCodecTest, EncodeInt32ListEmpty) {
502 EXPECT_STREQ(text,
"[]");
505 TEST(FlJsonMessageCodecTest, EncodeInt32List) {
506 int32_t data[] = {0, -1, 2, -3, 4};
509 EXPECT_STREQ(text,
"[0,-1,2,-3,4]");
512 TEST(FlJsonMessageCodecTest, EncodeInt64ListEmpty) {
515 EXPECT_STREQ(text,
"[]");
518 TEST(FlJsonMessageCodecTest, EncodeInt64List) {
519 int64_t data[] = {0, -1, 2, -3, 4};
522 EXPECT_STREQ(text,
"[0,-1,2,-3,4]");
525 TEST(FlJsonMessageCodecTest, EncodeFloatListEmpty) {
528 EXPECT_STREQ(text,
"[]");
531 TEST(FlJsonMessageCodecTest, EncodeFloatList) {
532 double data[] = {0, -0.5, 0.25, -0.125, 0.0625};
535 EXPECT_STREQ(text,
"[0.0,-0.5,0.25,-0.125,0.0625]");
538 TEST(FlJsonMessageCodecTest, EncodeListEmpty) {
541 EXPECT_STREQ(text,
"[]");
544 TEST(FlJsonMessageCodecTest, EncodeListTypes) {
554 EXPECT_STREQ(text,
"[null,true,42,-1.5,\"hello\",[],{}]");
557 TEST(FlJsonMessageCodecTest, EncodeListNested) {
560 for (
int i = 0;
i < 10;
i++) {
571 EXPECT_STREQ(text,
"[[0,2,4,6,8],[1,3,5,7,9]]");
574 TEST(FlJsonMessageCodecTest, DecodeListEmpty) {
580 TEST(FlJsonMessageCodecTest, DecodeListNoComma) {
585 TEST(FlJsonMessageCodecTest, DecodeListUnterminatedEmpty) {
590 TEST(FlJsonMessageCodecTest, DecodeListStartUnterminate) {
595 TEST(FlJsonMessageCodecTest, DecodeListUnterminated) {
600 TEST(FlJsonMessageCodecTest, DecodeListDoubleTerminated) {
605 TEST(FlJsonMessageCodecTest, EncodeMapEmpty) {
608 EXPECT_STREQ(text,
"{}");
611 TEST(FlJsonMessageCodecTest, EncodeMapNullKey) {
618 TEST(FlJsonMessageCodecTest, EncodeMapBoolKey) {
626 TEST(FlJsonMessageCodecTest, EncodeMapIntKey) {
633 TEST(FlJsonMessageCodecTest, EncodeMapFloatKey) {
641 TEST(FlJsonMessageCodecTest, EncodeMapUint8ListKey) {
649 TEST(FlJsonMessageCodecTest, EncodeMapInt32ListKey) {
657 TEST(FlJsonMessageCodecTest, EncodeMapInt64ListKey) {
665 TEST(FlJsonMessageCodecTest, EncodeMapFloatListKey) {
673 TEST(FlJsonMessageCodecTest, EncodeMapListKey) {
680 TEST(FlJsonMessageCodecTest, EncodeMapMapKey) {
687 TEST(FlJsonMessageCodecTest, EncodeMapValueTypes) {
701 "{\"null\":null,\"bool\":true,\"int\":42,\"float\":-"
702 "1.5,\"string\":\"hello\",\"list\":[],\"map\":{}}");
705 TEST(FlJsonMessageCodecTest, EncodeMapNested) {
707 const char* numbers[] = {
"zero",
"one",
"two",
"three",
nullptr};
708 for (
int i = 0; numbers[
i] !=
nullptr;
i++) {
716 "{\"str-to-int\":{\"zero\":0,\"one\":1,\"two\":2,\"three\":3}}");
719 TEST(FlJsonMessageCodecTest, DecodeMapEmpty) {
725 TEST(FlJsonMessageCodecTest, DecodeMapUnterminatedEmpty) {
730 TEST(FlJsonMessageCodecTest, DecodeMapStartUnterminate) {
735 TEST(FlJsonMessageCodecTest, DecodeMapNoComma) {
740 TEST(FlJsonMessageCodecTest, DecodeMapNoColon) {
745 TEST(FlJsonMessageCodecTest, DecodeMapUnterminated) {
750 TEST(FlJsonMessageCodecTest, DecodeMapDoubleTerminated) {
755 TEST(FlJsonMessageCodecTest, DecodeUnknownWord) {
760 TEST(FlJsonMessageCodecTest, EncodeDecode) {
772 g_autoptr(GError)
error =
nullptr;
773 g_autofree gchar* message =
775 ASSERT_NE(message,
nullptr);
776 EXPECT_EQ(
error,
nullptr);
780 EXPECT_EQ(
error,
nullptr);
781 EXPECT_NE(output,
nullptr);