5#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"
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;
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;
46 EXPECT_EQ(
value,
nullptr);
49TEST(FlJsonMessageCodecTest, EncodeNullptr) {
51 EXPECT_STREQ(
text,
"null");
54TEST(FlJsonMessageCodecTest, EncodeNull) {
57 EXPECT_STREQ(
text,
"null");
60TEST(FlJsonMessageCodecTest, DecodeNull) {
70TEST(FlJsonMessageCodecTest, EncodeBoolFalse) {
72 EXPECT_STREQ(
text,
"false");
75TEST(FlJsonMessageCodecTest, EncodeBoolTrue) {
77 EXPECT_STREQ(
text,
"true");
80TEST(FlJsonMessageCodecTest, DecodeBoolFalse) {
86TEST(FlJsonMessageCodecTest, DecodeBoolTrue) {
97TEST(FlJsonMessageCodecTest, EncodeIntZero) {
99 EXPECT_STREQ(
text,
"0");
102TEST(FlJsonMessageCodecTest, EncodeIntOne) {
104 EXPECT_STREQ(
text,
"1");
107TEST(FlJsonMessageCodecTest, EncodeInt12345) {
109 EXPECT_STREQ(
text,
"12345");
112TEST(FlJsonMessageCodecTest, EncodeIntMin) {
114 EXPECT_STREQ(
text,
"-9223372036854775808");
117TEST(FlJsonMessageCodecTest, EncodeIntMax) {
119 EXPECT_STREQ(
text,
"9223372036854775807");
122TEST(FlJsonMessageCodecTest, DecodeIntZero) {
128TEST(FlJsonMessageCodecTest, DecodeIntOne) {
134TEST(FlJsonMessageCodecTest, DecodeInt12345) {
140TEST(FlJsonMessageCodecTest, DecodeIntMin) {
146TEST(FlJsonMessageCodecTest, DecodeIntMax) {
152TEST(FlJsonMessageCodecTest, DecodeUintMax) {
160TEST(FlJsonMessageCodecTest, DecodeHugeNumber) {
168TEST(FlJsonMessageCodecTest, DecodeIntLeadingZero1) {
173TEST(FlJsonMessageCodecTest, DecodeIntLeadingZero2) {
178TEST(FlJsonMessageCodecTest, DecodeIntDoubleNegative) {
183TEST(FlJsonMessageCodecTest, DecodeIntPositiveSign) {
188TEST(FlJsonMessageCodecTest, DecodeIntHexChar) {
198TEST(FlJsonMessageCodecTest, EncodeFloatZero) {
200 EXPECT_STREQ(
text,
"0.0");
203TEST(FlJsonMessageCodecTest, EncodeFloatOne) {
205 EXPECT_STREQ(
text,
"1.0");
208TEST(FlJsonMessageCodecTest, EncodeFloatMinusOne) {
210 EXPECT_STREQ(
text,
"-1.0");
213TEST(FlJsonMessageCodecTest, EncodeFloatHalf) {
215 EXPECT_STREQ(
text,
"0.5");
218TEST(FlJsonMessageCodecTest, EncodeFloatPi) {
220 EXPECT_STREQ(
text,
"3.141592653589793");
223TEST(FlJsonMessageCodecTest, EncodeFloatMinusZero) {
225 EXPECT_STREQ(
text,
"-0.0");
231TEST(FlJsonMessageCodecTest, DecodeFloatZero) {
237TEST(FlJsonMessageCodecTest, DecodeFloatOne) {
243TEST(FlJsonMessageCodecTest, DecodeFloatMinusOne) {
249TEST(FlJsonMessageCodecTest, DecodeFloatHalf) {
255TEST(FlJsonMessageCodecTest, DecodeFloatPi) {
261TEST(FlJsonMessageCodecTest, DecodeFloatMinusZero) {
267TEST(FlJsonMessageCodecTest, DecodeFloatMissingFraction) {
272TEST(FlJsonMessageCodecTest, DecodeFloatInvalidFraction) {
282TEST(FlJsonMessageCodecTest, EncodeStringEmpty) {
284 EXPECT_STREQ(
text,
"\"\"");
287TEST(FlJsonMessageCodecTest, EncodeStringHello) {
289 EXPECT_STREQ(
text,
"\"hello\"");
292TEST(FlJsonMessageCodecTest, EncodeStringEmptySized) {
295 EXPECT_STREQ(
text,
"\"\"");
298TEST(FlJsonMessageCodecTest, EncodeStringHelloSized) {
301 EXPECT_STREQ(
text,
"\"Hello\"");
304TEST(FlJsonMessageCodecTest, EncodeStringEscapeQuote) {
306 EXPECT_STREQ(
text,
"\"\\\"\"");
309TEST(FlJsonMessageCodecTest, EncodeStringEscapeBackslash) {
311 EXPECT_STREQ(
text,
"\"\\\\\"");
314TEST(FlJsonMessageCodecTest, EncodeStringEscapeBackspace) {
316 EXPECT_STREQ(
text,
"\"\\b\"");
319TEST(FlJsonMessageCodecTest, EncodeStringEscapeFormFeed) {
321 EXPECT_STREQ(
text,
"\"\\f\"");
324TEST(FlJsonMessageCodecTest, EncodeStringEscapeNewline) {
326 EXPECT_STREQ(
text,
"\"\\n\"");
329TEST(FlJsonMessageCodecTest, EncodeStringEscapeCarriageReturn) {
331 EXPECT_STREQ(
text,
"\"\\r\"");
334TEST(FlJsonMessageCodecTest, EncodeStringEscapeTab) {
336 EXPECT_STREQ(
text,
"\"\\t\"");
339TEST(FlJsonMessageCodecTest, EncodeStringEscapeUnicode) {
341 EXPECT_STREQ(
text,
"\"\\u0001\"");
344TEST(FlJsonMessageCodecTest, EncodeStringEmoji) {
346 EXPECT_STREQ(
text,
"\"😀\"");
349TEST(FlJsonMessageCodecTest, DecodeStringEmpty) {
355TEST(FlJsonMessageCodecTest, DecodeStringHello) {
361TEST(FlJsonMessageCodecTest, DecodeStringEscapeQuote) {
367TEST(FlJsonMessageCodecTest, DecodeStringEscapeBackslash) {
373TEST(FlJsonMessageCodecTest, DecodeStringEscapeSlash) {
379TEST(FlJsonMessageCodecTest, DecodeStringEscapeBackspace) {
385TEST(FlJsonMessageCodecTest, DecodeStringEscapeFormFeed) {
391TEST(FlJsonMessageCodecTest, DecodeStringEscapeNewline) {
397TEST(FlJsonMessageCodecTest, DecodeStringEscapeCarriageReturn) {
403TEST(FlJsonMessageCodecTest, DecodeStringEscapeTab) {
409TEST(FlJsonMessageCodecTest, DecodeStringEscapeUnicode) {
415TEST(FlJsonMessageCodecTest, DecodeStringEmoji) {
421TEST(FlJsonMessageCodecTest, DecodeInvalidUTF8) {
426TEST(FlJsonMessageCodecTest, DecodeStringInvalidUTF8) {
431TEST(FlJsonMessageCodecTest, DecodeStringBinary) {
436TEST(FlJsonMessageCodecTest, DecodeStringNewline) {
441TEST(FlJsonMessageCodecTest, DecodeStringCarriageReturn) {
446TEST(FlJsonMessageCodecTest, DecodeStringTab) {
451TEST(FlJsonMessageCodecTest, DecodeStringUnterminatedEmpty) {
456TEST(FlJsonMessageCodecTest, DecodeStringExtraQuote) {
461TEST(FlJsonMessageCodecTest, DecodeStringEscapedClosingQuote) {
466TEST(FlJsonMessageCodecTest, DecodeStringUnknownEscape) {
471TEST(FlJsonMessageCodecTest, DecodeStringInvalidEscapeUnicode) {
476TEST(FlJsonMessageCodecTest, DecodeStringEscapeUnicodeNoData) {
481TEST(FlJsonMessageCodecTest, DecodeStringEscapeUnicodeShortData) {
486TEST(FlJsonMessageCodecTest, EncodeUint8ListEmpty) {
489 EXPECT_STREQ(
text,
"[]");
492TEST(FlJsonMessageCodecTest, EncodeUint8List) {
493 uint8_t
data[] = {0, 1, 2, 3, 4};
496 EXPECT_STREQ(
text,
"[0,1,2,3,4]");
499TEST(FlJsonMessageCodecTest, EncodeInt32ListEmpty) {
502 EXPECT_STREQ(
text,
"[]");
505TEST(FlJsonMessageCodecTest, EncodeInt32List) {
506 int32_t
data[] = {0, -1, 2, -3, 4};
509 EXPECT_STREQ(
text,
"[0,-1,2,-3,4]");
512TEST(FlJsonMessageCodecTest, EncodeInt64ListEmpty) {
515 EXPECT_STREQ(
text,
"[]");
518TEST(FlJsonMessageCodecTest, EncodeInt64List) {
519 int64_t
data[] = {0, -1, 2, -3, 4};
522 EXPECT_STREQ(
text,
"[0,-1,2,-3,4]");
525TEST(FlJsonMessageCodecTest, EncodeFloatListEmpty) {
528 EXPECT_STREQ(
text,
"[]");
531TEST(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]");
538TEST(FlJsonMessageCodecTest, EncodeListEmpty) {
541 EXPECT_STREQ(
text,
"[]");
544TEST(FlJsonMessageCodecTest, EncodeListTypes) {
554 EXPECT_STREQ(
text,
"[null,true,42,-1.5,\"hello\",[],{}]");
557TEST(FlJsonMessageCodecTest, EncodeListNested) {
560 for (
int i = 0;
i < 10;
i++) {
571 EXPECT_STREQ(
text,
"[[0,2,4,6,8],[1,3,5,7,9]]");
574TEST(FlJsonMessageCodecTest, DecodeListEmpty) {
580TEST(FlJsonMessageCodecTest, DecodeListNoComma) {
585TEST(FlJsonMessageCodecTest, DecodeListUnterminatedEmpty) {
590TEST(FlJsonMessageCodecTest, DecodeListStartUnterminate) {
595TEST(FlJsonMessageCodecTest, DecodeListUnterminated) {
600TEST(FlJsonMessageCodecTest, DecodeListDoubleTerminated) {
605TEST(FlJsonMessageCodecTest, EncodeMapEmpty) {
608 EXPECT_STREQ(
text,
"{}");
611TEST(FlJsonMessageCodecTest, EncodeMapNullKey) {
618TEST(FlJsonMessageCodecTest, EncodeMapBoolKey) {
626TEST(FlJsonMessageCodecTest, EncodeMapIntKey) {
633TEST(FlJsonMessageCodecTest, EncodeMapFloatKey) {
641TEST(FlJsonMessageCodecTest, EncodeMapUint8ListKey) {
649TEST(FlJsonMessageCodecTest, EncodeMapInt32ListKey) {
657TEST(FlJsonMessageCodecTest, EncodeMapInt64ListKey) {
665TEST(FlJsonMessageCodecTest, EncodeMapFloatListKey) {
673TEST(FlJsonMessageCodecTest, EncodeMapListKey) {
680TEST(FlJsonMessageCodecTest, EncodeMapMapKey) {
687TEST(FlJsonMessageCodecTest, EncodeMapValueTypes) {
701 "{\"null\":null,\"bool\":true,\"int\":42,\"float\":-"
702 "1.5,\"string\":\"hello\",\"list\":[],\"map\":{}}");
705TEST(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}}");
719TEST(FlJsonMessageCodecTest, DecodeMapEmpty) {
725TEST(FlJsonMessageCodecTest, DecodeMapUnterminatedEmpty) {
730TEST(FlJsonMessageCodecTest, DecodeMapStartUnterminate) {
735TEST(FlJsonMessageCodecTest, DecodeMapNoComma) {
740TEST(FlJsonMessageCodecTest, DecodeMapNoColon) {
745TEST(FlJsonMessageCodecTest, DecodeMapUnterminated) {
750TEST(FlJsonMessageCodecTest, DecodeMapDoubleTerminated) {
755TEST(FlJsonMessageCodecTest, DecodeUnknownWord) {
760TEST(FlJsonMessageCodecTest, EncodeDecode) {
772 g_autoptr(GError)
error =
nullptr;
776 EXPECT_EQ(
error,
nullptr);
780 EXPECT_EQ(
error,
nullptr);
781 EXPECT_NE(
output,
nullptr);
G_MODULE_EXPORT FlJsonMessageCodec * fl_json_message_codec_new()
G_MODULE_EXPORT gchar * fl_json_message_codec_encode(FlJsonMessageCodec *codec, FlValue *value, GError **error)
G_MODULE_EXPORT FlValue * fl_json_message_codec_decode(FlJsonMessageCodec *codec, const gchar *text, GError **error)
@ FL_JSON_MESSAGE_CODEC_ERROR_INVALID_OBJECT_KEY_TYPE
@ FL_JSON_MESSAGE_CODEC_ERROR_INVALID_UTF8
@ FL_JSON_MESSAGE_CODEC_ERROR_INVALID_JSON
#define FL_JSON_MESSAGE_CODEC_ERROR
TEST(FlJsonMessageCodecTest, EncodeNullptr)
static gchar * encode_string(const gchar *value)
static gchar * encode_float(double value)
static gchar * encode_int(int64_t value)
static FlValue * decode_message(const char *text)
static void encode_error_message(FlValue *value, GQuark domain, gint code)
static void decode_error_message(const char *text, GQuark domain, gint code)
static gchar * encode_message(FlValue *value)
static gchar * encode_bool(gboolean value)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT void fl_value_set_string(FlValue *self, const gchar *key, FlValue *value)
G_MODULE_EXPORT FlValue * fl_value_new_map()
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_null()
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
G_MODULE_EXPORT FlValue * fl_value_new_int32_list(const int32_t *data, size_t data_length)
G_MODULE_EXPORT void fl_value_append(FlValue *self, FlValue *value)
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
G_MODULE_EXPORT bool fl_value_get_bool(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_list()
G_MODULE_EXPORT FlValue * fl_value_new_uint8_list(const uint8_t *data, size_t data_length)
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
G_MODULE_EXPORT FlValue * fl_value_new_float_list(const double *data, size_t data_length)
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
G_MODULE_EXPORT FlValue * fl_value_new_int64_list(const int64_t *data, size_t data_length)
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
typedefG_BEGIN_DECLS struct _FlValue FlValue
std::shared_ptr< const fml::Mapping > data
#define EXPECT_TRUE(handle)