Flutter Engine
 
Loading...
Searching...
No Matches
fl_json_method_codec_test.cc File Reference

Go to the source code of this file.

Functions

static gchar * message_to_text (GBytes *message)
 
static GBytes * text_to_message (const gchar *text)
 
static gchar * encode_method_call (const gchar *name, FlValue *args)
 
static gchar * encode_success_envelope (FlValue *result)
 
static gchar * encode_error_envelope (const gchar *error_code, const gchar *error_message, FlValue *details)
 
static void decode_method_call (const char *text, gchar **name, FlValue **args)
 
static void decode_error_method_call (const char *text, GQuark domain, gint code)
 
static void decode_response_with_success (const char *text, FlValue *result)
 
static void decode_response_with_error (const char *text, const gchar *code, const gchar *error_message, FlValue *details)
 
static void decode_error_response (const char *text, GQuark domain, gint code)
 
 TEST (FlJsonMethodCodecTest, EncodeMethodCallNullptrArgs)
 
 TEST (FlJsonMethodCodecTest, EncodeMethodCallNullArgs)
 
 TEST (FlJsonMethodCodecTest, EncodeMethodCallStringArgs)
 
 TEST (FlJsonMethodCodecTest, EncodeMethodCallListArgs)
 
 TEST (FlJsonMethodCodecTest, DecodeMethodCallNoArgs)
 
 TEST (FlJsonMethodCodecTest, DecodeMethodCallNullArgs)
 
 TEST (FlJsonMethodCodecTest, DecodeMethodCallStringArgs)
 
 TEST (FlJsonMethodCodecTest, DecodeMethodCallListArgs)
 
 TEST (FlJsonMethodCodecTest, DecodeMethodCallNoData)
 
 TEST (FlJsonMethodCodecTest, DecodeMethodCallNoMethodOrArgs)
 
 TEST (FlJsonMethodCodecTest, DecodeMethodCallInvalidJson)
 
 TEST (FlJsonMethodCodecTest, DecodeMethodCallWrongType)
 
 TEST (FlJsonMethodCodecTest, DecodeMethodCallNoMethod)
 
 TEST (FlJsonMethodCodecTest, DecodeMethodCallNoTerminator)
 
 TEST (FlJsonMethodCodecTest, DecodeMethodCallExtraData)
 
 TEST (FlJsonMethodCodecTest, EncodeSuccessEnvelopeNullptr)
 
 TEST (FlJsonMethodCodecTest, EncodeSuccessEnvelopeNull)
 
 TEST (FlJsonMethodCodecTest, EncodeSuccessEnvelopeString)
 
 TEST (FlJsonMethodCodecTest, EncodeSuccessEnvelopeList)
 
 TEST (FlJsonMethodCodecTest, EncodeErrorEnvelopeEmptyCode)
 
 TEST (FlJsonMethodCodecTest, EncodeErrorEnvelopeNonMessageOrDetails)
 
 TEST (FlJsonMethodCodecTest, EncodeErrorEnvelopeMessage)
 
 TEST (FlJsonMethodCodecTest, EncodeErrorEnvelopeDetails)
 
 TEST (FlJsonMethodCodecTest, EncodeErrorEnvelopeMessageAndDetails)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseSuccessNull)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseSuccessString)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseSuccessList)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseErrorEmptyCode)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseErrorNoMessageOrDetails)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseErrorMessage)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseErrorDetails)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseErrorMessageAndDetails)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseNotImplemented)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseNoTerminator)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseInvalidJson)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseMissingDetails)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseExtraDetails)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseSuccessExtraData)
 
 TEST (FlJsonMethodCodecTest, DecodeResponseErrorExtraData)
 

Function Documentation

◆ decode_error_method_call()

static void decode_error_method_call ( const char *  text,
GQuark  domain,
gint  code 
)
static

Definition at line 77 of file fl_json_method_codec_test.cc.

79 {
80 g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
82 g_autoptr(GError) error = nullptr;
83 g_autofree gchar* name = nullptr;
84 g_autoptr(FlValue) args = nullptr;
85 gboolean result = fl_method_codec_decode_method_call(
86 FL_METHOD_CODEC(codec), data, &name, &args, &error);
87 EXPECT_FALSE(result);
88 EXPECT_EQ(name, nullptr);
89 EXPECT_EQ(args, nullptr);
90 EXPECT_TRUE(g_error_matches(error, domain, code));
91}
g_autoptr(GMutexLocker) locker
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_MODULE_EXPORT FlJsonMethodCodec * fl_json_method_codec_new()
static GBytes * text_to_message(const gchar *text)
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)
const uint8_t uint32_t uint32_t GError ** error
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition fl_value.h:42
const char * name
Definition fuchsia.cc:49
std::u16string text
std::shared_ptr< const fml::Mapping > data

References args, data, error, fl_json_method_codec_new(), fl_method_codec_decode_method_call(), g_autoptr(), name, text, and text_to_message().

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ decode_error_response()

static void decode_error_response ( const char *  text,
GQuark  domain,
gint  code 
)
static

Definition at line 146 of file fl_json_method_codec_test.cc.

146 {
147 g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
149 g_autoptr(GError) error = nullptr;
150 g_autoptr(FlMethodResponse) response =
151 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
152 EXPECT_EQ(response, nullptr);
153 EXPECT_TRUE(g_error_matches(error, domain, code));
154}
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
G_BEGIN_DECLS GBytes * message

References error, fl_json_method_codec_new(), fl_method_codec_decode_response(), g_autoptr(), message, text, and text_to_message().

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ decode_method_call()

static void decode_method_call ( const char *  text,
gchar **  name,
FlValue **  args 
)
static

Definition at line 66 of file fl_json_method_codec_test.cc.

66 {
67 g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
69 g_autoptr(GError) error = nullptr;
70 gboolean result = fl_method_codec_decode_method_call(
71 FL_METHOD_CODEC(codec), data, name, args, &error);
72 EXPECT_TRUE(result);
73 EXPECT_EQ(error, nullptr);
74}

References args, data, error, fl_json_method_codec_new(), fl_method_codec_decode_method_call(), g_autoptr(), name, text, and text_to_message().

Referenced by TEST(), TEST(), TEST(), and TEST().

◆ decode_response_with_error()

static void decode_response_with_error ( const char *  text,
const gchar *  code,
const gchar *  error_message,
FlValue details 
)
static

Definition at line 110 of file fl_json_method_codec_test.cc.

113 {
114 g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
116 g_autoptr(GError) error = nullptr;
117 g_autoptr(FlMethodResponse) response =
118 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
119 ASSERT_NE(response, nullptr);
120 EXPECT_EQ(error, nullptr);
121 ASSERT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
122 EXPECT_STREQ(
123 fl_method_error_response_get_code(FL_METHOD_ERROR_RESPONSE(response)),
124 code);
125 if (error_message == nullptr) {
127 FL_METHOD_ERROR_RESPONSE(response)),
128 nullptr);
129 } else {
131 FL_METHOD_ERROR_RESPONSE(response)),
132 error_message);
133 }
134 if (details == nullptr) {
136 FL_METHOD_ERROR_RESPONSE(response)),
137 nullptr);
138 } else {
140 FL_METHOD_ERROR_RESPONSE(response)),
141 details));
142 }
143}
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)
G_MODULE_EXPORT const gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition fl_value.cc:471

References error, fl_json_method_codec_new(), fl_method_codec_decode_response(), fl_method_error_response_get_code(), fl_method_error_response_get_details(), fl_method_error_response_get_message(), fl_value_equal(), g_autoptr(), message, text, and text_to_message().

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ decode_response_with_success()

static void decode_response_with_success ( const char *  text,
FlValue result 
)
static

Definition at line 94 of file fl_json_method_codec_test.cc.

94 {
95 g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
97 g_autoptr(GError) error = nullptr;
98 g_autoptr(FlMethodResponse) response =
99 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
100 ASSERT_NE(response, nullptr);
101 EXPECT_EQ(error, nullptr);
102 ASSERT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
104 FL_METHOD_SUCCESS_RESPONSE(response)),
105 result));
106}
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)

References error, fl_json_method_codec_new(), fl_method_codec_decode_response(), fl_method_success_response_get_result(), fl_value_equal(), g_autoptr(), message, text, and text_to_message().

Referenced by TEST(), TEST(), and TEST().

◆ encode_error_envelope()

static gchar * encode_error_envelope ( const gchar *  error_code,
const gchar *  error_message,
FlValue details 
)
static

Definition at line 52 of file fl_json_method_codec_test.cc.

54 {
55 g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
56 g_autoptr(GError) error = nullptr;
58 FL_METHOD_CODEC(codec), error_code, error_message, details, &error);
59 EXPECT_NE(message, nullptr);
60 EXPECT_EQ(error, nullptr);
61
63}
static gchar * message_to_text(GBytes *message)
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)

References error, fl_json_method_codec_new(), fl_method_codec_encode_error_envelope(), g_autoptr(), message, and message_to_text().

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ encode_method_call()

static gchar * encode_method_call ( const gchar *  name,
FlValue args 
)
static

Definition at line 28 of file fl_json_method_codec_test.cc.

28 {
29 g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
30 g_autoptr(GError) error = nullptr;
32 FL_METHOD_CODEC(codec), name, args, &error);
33 EXPECT_NE(message, nullptr);
34 EXPECT_EQ(error, nullptr);
35
37}
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)

References args, error, fl_json_method_codec_new(), fl_method_codec_encode_method_call(), g_autoptr(), message, message_to_text(), and name.

Referenced by TEST(), TEST(), TEST(), and TEST().

◆ encode_success_envelope()

static gchar * encode_success_envelope ( FlValue result)
static

Definition at line 40 of file fl_json_method_codec_test.cc.

40 {
41 g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
42 g_autoptr(GError) error = nullptr;
44 FL_METHOD_CODEC(codec), result, &error);
45 EXPECT_NE(message, nullptr);
46 EXPECT_EQ(error, nullptr);
47
49}
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)

References error, fl_json_method_codec_new(), fl_method_codec_encode_success_envelope(), g_autoptr(), message, and message_to_text().

Referenced by TEST(), TEST(), TEST(), and TEST().

◆ message_to_text()

static gchar * message_to_text ( GBytes *  message)
static

Definition at line 15 of file fl_json_method_codec_test.cc.

15 {
16 size_t data_length;
17 const gchar* data =
18 static_cast<const gchar*>(g_bytes_get_data(message, &data_length));
19 return g_strndup(data, data_length);
20}

References data, and message.

Referenced by encode_error_envelope(), encode_method_call(), encode_success_envelope(), fl_test_codec_decode_method_call(), fl_test_codec_decode_response(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ TEST() [1/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallExtraData   
)

Definition at line 255 of file fl_json_method_codec_test.cc.

255 {
256 decode_error_method_call("{\"method\":\"hello\"}XXX",
259}
@ FL_JSON_MESSAGE_CODEC_ERROR_INVALID_JSON
#define FL_JSON_MESSAGE_CODEC_ERROR
static void decode_error_method_call(const char *text, GQuark domain, gint code)

References decode_error_method_call(), FL_JSON_MESSAGE_CODEC_ERROR, and FL_JSON_MESSAGE_CODEC_ERROR_INVALID_JSON.

◆ TEST() [2/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallInvalidJson   
)

◆ TEST() [3/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallListArgs   
)

Definition at line 206 of file fl_json_method_codec_test.cc.

206 {
207 g_autofree gchar* name = nullptr;
208 g_autoptr(FlValue) args = nullptr;
209 decode_method_call("{\"method\":\"hello\",\"args\":[\"count\",42]}", &name,
210 &args);
211 EXPECT_STREQ(name, "hello");
213 EXPECT_EQ(fl_value_get_length(args), static_cast<size_t>(2));
214
216 ASSERT_EQ(fl_value_get_type(arg0), FL_VALUE_TYPE_STRING);
217 EXPECT_STREQ(fl_value_get_string(arg0), "count");
218
220 ASSERT_EQ(fl_value_get_type(arg1), FL_VALUE_TYPE_INT);
221 EXPECT_EQ(fl_value_get_int(arg1), 42);
222}
static void decode_method_call(const char *text, gchar **name, FlValue **args)
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition fl_value.cc:668
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition fl_value.cc:466
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition fl_value.cc:682
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition fl_value.cc:776
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition fl_value.cc:724
@ FL_VALUE_TYPE_STRING
Definition fl_value.h:68
@ FL_VALUE_TYPE_INT
Definition fl_value.h:66
@ FL_VALUE_TYPE_LIST
Definition fl_value.h:73

References args, decode_method_call(), fl_value_get_int(), fl_value_get_length(), fl_value_get_list_value(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_INT, FL_VALUE_TYPE_LIST, FL_VALUE_TYPE_STRING, g_autoptr(), and name.

◆ TEST() [4/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallNoArgs   
)

Definition at line 181 of file fl_json_method_codec_test.cc.

181 {
182 g_autofree gchar* name = nullptr;
183 g_autoptr(FlValue) args = nullptr;
184 decode_method_call("{\"method\":\"hello\"}", &name, &args);
185 EXPECT_STREQ(name, "hello");
186 ASSERT_EQ(args, nullptr);
187}

References args, decode_method_call(), g_autoptr(), and name.

◆ TEST() [5/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallNoData   
)

◆ TEST() [6/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallNoMethod   
)

Definition at line 244 of file fl_json_method_codec_test.cc.

244 {
245 decode_error_method_call("{\"args\":\"world\"}", FL_MESSAGE_CODEC_ERROR,
247}
@ FL_MESSAGE_CODEC_ERROR_FAILED
#define FL_MESSAGE_CODEC_ERROR

References decode_error_method_call(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_FAILED.

◆ TEST() [7/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallNoMethodOrArgs   
)

◆ TEST() [8/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallNoTerminator   
)

◆ TEST() [9/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallNullArgs   
)

Definition at line 189 of file fl_json_method_codec_test.cc.

189 {
190 g_autofree gchar* name = nullptr;
191 g_autoptr(FlValue) args = nullptr;
192 decode_method_call("{\"method\":\"hello\",\"args\":null}", &name, &args);
193 EXPECT_STREQ(name, "hello");
195}
@ FL_VALUE_TYPE_NULL
Definition fl_value.h:64

References args, decode_method_call(), fl_value_get_type(), FL_VALUE_TYPE_NULL, g_autoptr(), and name.

◆ TEST() [10/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallStringArgs   
)

Definition at line 197 of file fl_json_method_codec_test.cc.

197 {
198 g_autofree gchar* name = nullptr;
199 g_autoptr(FlValue) args = nullptr;
200 decode_method_call("{\"method\":\"hello\",\"args\":\"world\"}", &name, &args);
201 EXPECT_STREQ(name, "hello");
203 EXPECT_STREQ(fl_value_get_string(args), "world");
204}

References args, decode_method_call(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, g_autoptr(), and name.

◆ TEST() [11/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallWrongType   
)

◆ TEST() [12/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseErrorDetails   
)

Definition at line 348 of file fl_json_method_codec_test.cc.

348 {
350 fl_value_append_take(details, fl_value_new_string("count"));
352 decode_response_with_error("[\"error\",null,[\"count\",42]]", "error",
353 nullptr, details);
354}
static void decode_response_with_error(const char *text, const gchar *code, const gchar *error_message, FlValue *details)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition fl_value.cc:276
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition fl_value.cc:262
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition fl_value.cc:600
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition fl_value.cc:349

References decode_response_with_error(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), fl_value_new_string(), and g_autoptr().

◆ TEST() [13/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseErrorEmptyCode   
)

Definition at line 334 of file fl_json_method_codec_test.cc.

334 {
335 decode_response_with_error("[\"\",null,null]", "", nullptr, nullptr);
336}

References decode_response_with_error().

◆ TEST() [14/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseErrorExtraData   
)

Definition at line 400 of file fl_json_method_codec_test.cc.

400 {
401 decode_error_response("[\"error\",null,null]X", FL_JSON_MESSAGE_CODEC_ERROR,
403}
static void decode_error_response(const char *text, GQuark domain, gint code)

References decode_error_response(), FL_JSON_MESSAGE_CODEC_ERROR, and FL_JSON_MESSAGE_CODEC_ERROR_INVALID_JSON.

◆ TEST() [15/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseErrorMessage   
)

Definition at line 343 of file fl_json_method_codec_test.cc.

343 {
344 decode_response_with_error("[\"error\",\"message\",null]", "error", "message",
345 nullptr);
346}

References decode_response_with_error().

◆ TEST() [16/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseErrorMessageAndDetails   
)

Definition at line 356 of file fl_json_method_codec_test.cc.

356 {
358 fl_value_append_take(details, fl_value_new_string("count"));
360 decode_response_with_error("[\"error\",\"message\",[\"count\",42]]", "error",
361 "message", details);
362}

References decode_response_with_error(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), fl_value_new_string(), and g_autoptr().

◆ TEST() [17/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseErrorNoMessageOrDetails   
)

Definition at line 338 of file fl_json_method_codec_test.cc.

338 {
339 decode_response_with_error("[\"error\",null,null]", "error", nullptr,
340 nullptr);
341}

References decode_response_with_error().

◆ TEST() [18/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseExtraDetails   
)

◆ TEST() [19/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseInvalidJson   
)

◆ TEST() [20/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseMissingDetails   
)

◆ TEST() [21/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseNoTerminator   
)

◆ TEST() [22/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseNotImplemented   
)

Definition at line 364 of file fl_json_method_codec_test.cc.

364 {
365 g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
366 g_autoptr(GBytes) message = g_bytes_new(nullptr, 0);
367 g_autoptr(GError) error = nullptr;
368 g_autoptr(FlMethodResponse) response =
369 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
370 ASSERT_NE(response, nullptr);
371 EXPECT_EQ(error, nullptr);
372 EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
373}

References error, fl_json_method_codec_new(), fl_method_codec_decode_response(), g_autoptr(), and message.

◆ TEST() [23/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseSuccessExtraData   
)

◆ TEST() [24/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseSuccessList   
)

Definition at line 327 of file fl_json_method_codec_test.cc.

327 {
331 decode_response_with_success("[[\"count\",42]]", result);
332}
static void decode_response_with_success(const char *text, FlValue *result)

References decode_response_with_success(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), fl_value_new_string(), and g_autoptr().

◆ TEST() [25/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseSuccessNull   
)

Definition at line 317 of file fl_json_method_codec_test.cc.

317 {
319 decode_response_with_success("[null]", result);
320}
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition fl_value.cc:251

References decode_response_with_success(), fl_value_new_null(), and g_autoptr().

◆ TEST() [26/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseSuccessString   
)

Definition at line 322 of file fl_json_method_codec_test.cc.

322 {
323 g_autoptr(FlValue) result = fl_value_new_string("hello");
324 decode_response_with_success("[\"hello\"]", result);
325}

References decode_response_with_success(), fl_value_new_string(), and g_autoptr().

◆ TEST() [27/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeErrorEnvelopeDetails   
)

Definition at line 301 of file fl_json_method_codec_test.cc.

301 {
303 fl_value_append_take(details, fl_value_new_string("count"));
305 g_autofree gchar* text = encode_error_envelope("error", nullptr, details);
306 EXPECT_STREQ(text, "[\"error\",null,[\"count\",42]]");
307}
static gchar * encode_error_envelope(const gchar *error_code, const gchar *error_message, FlValue *details)

References encode_error_envelope(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), fl_value_new_string(), g_autoptr(), and text.

◆ TEST() [28/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeErrorEnvelopeEmptyCode   
)

Definition at line 286 of file fl_json_method_codec_test.cc.

286 {
287 g_autofree gchar* text = encode_error_envelope("", nullptr, nullptr);
288 EXPECT_STREQ(text, "[\"\",null,null]");
289}

References encode_error_envelope(), and text.

◆ TEST() [29/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeErrorEnvelopeMessage   
)

Definition at line 296 of file fl_json_method_codec_test.cc.

296 {
297 g_autofree gchar* text = encode_error_envelope("error", "message", nullptr);
298 EXPECT_STREQ(text, "[\"error\",\"message\",null]");
299}

References encode_error_envelope(), and text.

◆ TEST() [30/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeErrorEnvelopeMessageAndDetails   
)

Definition at line 309 of file fl_json_method_codec_test.cc.

309 {
311 fl_value_append_take(details, fl_value_new_string("count"));
313 g_autofree gchar* text = encode_error_envelope("error", "message", details);
314 EXPECT_STREQ(text, "[\"error\",\"message\",[\"count\",42]]");
315}

References encode_error_envelope(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), fl_value_new_string(), g_autoptr(), and text.

◆ TEST() [31/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeErrorEnvelopeNonMessageOrDetails   
)

Definition at line 291 of file fl_json_method_codec_test.cc.

291 {
292 g_autofree gchar* text = encode_error_envelope("error", nullptr, nullptr);
293 EXPECT_STREQ(text, "[\"error\",null,null]");
294}

References encode_error_envelope(), and text.

◆ TEST() [32/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeMethodCallListArgs   
)

Definition at line 173 of file fl_json_method_codec_test.cc.

173 {
177 g_autofree gchar* text = encode_method_call("hello", args);
178 EXPECT_STREQ(text, "{\"method\":\"hello\",\"args\":[\"count\",42]}");
179}
static gchar * encode_method_call(const gchar *name, FlValue *args)

References args, encode_method_call(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), fl_value_new_string(), g_autoptr(), and text.

◆ TEST() [33/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeMethodCallNullArgs   
)

Definition at line 161 of file fl_json_method_codec_test.cc.

161 {
163 g_autofree gchar* text = encode_method_call("hello", value);
164 EXPECT_STREQ(text, "{\"method\":\"hello\",\"args\":null}");
165}
int32_t value

References encode_method_call(), fl_value_new_null(), g_autoptr(), text, and value.

◆ TEST() [34/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeMethodCallNullptrArgs   
)

Definition at line 156 of file fl_json_method_codec_test.cc.

156 {
157 g_autofree gchar* text = encode_method_call("hello", nullptr);
158 EXPECT_STREQ(text, "{\"method\":\"hello\",\"args\":null}");
159}

References encode_method_call(), and text.

◆ TEST() [35/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeMethodCallStringArgs   
)

Definition at line 167 of file fl_json_method_codec_test.cc.

167 {
169 g_autofree gchar* text = encode_method_call("hello", args);
170 EXPECT_STREQ(text, "{\"method\":\"hello\",\"args\":\"world\"}");
171}

References args, encode_method_call(), fl_value_new_string(), g_autoptr(), and text.

◆ TEST() [36/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeSuccessEnvelopeList   
)

Definition at line 278 of file fl_json_method_codec_test.cc.

278 {
282 g_autofree gchar* text = encode_success_envelope(result);
283 EXPECT_STREQ(text, "[[\"count\",42]]");
284}
static gchar * encode_success_envelope(FlValue *result)

References encode_success_envelope(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), fl_value_new_string(), g_autoptr(), and text.

◆ TEST() [37/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeSuccessEnvelopeNull   
)

Definition at line 266 of file fl_json_method_codec_test.cc.

266 {
268 g_autofree gchar* text = encode_success_envelope(result);
269 EXPECT_STREQ(text, "[null]");
270}

References encode_success_envelope(), fl_value_new_null(), g_autoptr(), and text.

◆ TEST() [38/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeSuccessEnvelopeNullptr   
)

Definition at line 261 of file fl_json_method_codec_test.cc.

261 {
262 g_autofree gchar* text = encode_success_envelope(nullptr);
263 EXPECT_STREQ(text, "[null]");
264}

References encode_success_envelope(), and text.

◆ TEST() [39/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeSuccessEnvelopeString   
)

Definition at line 272 of file fl_json_method_codec_test.cc.

272 {
273 g_autoptr(FlValue) result = fl_value_new_string("hello");
274 g_autofree gchar* text = encode_success_envelope(result);
275 EXPECT_STREQ(text, "[\"hello\"]");
276}

References encode_success_envelope(), fl_value_new_string(), g_autoptr(), and text.

◆ text_to_message()

static GBytes * text_to_message ( const gchar *  text)
static

Definition at line 23 of file fl_json_method_codec_test.cc.

23 {
24 return g_bytes_new(text, strlen(text));
25}

References text.

Referenced by decode_error_method_call(), decode_error_response(), decode_method_call(), decode_response_with_error(), and decode_response_with_success().