Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
fl_json_method_codec_test.cc File Reference
#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_method_codec.h"
#include <cstring>
#include "flutter/shell/platform/linux/fl_method_codec_private.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_message_codec.h"
#include "gtest/gtest.h"

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();
81 g_autoptr(GBytes) data = text_to_message(text);
82 g_autoptr(GError) error = nullptr;
83 g_autofree gchar* name = nullptr;
84 g_autoptr(FlValue) args = nullptr;
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_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
GAsyncResult * result
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition fl_value.h:42
const char * name
Definition fuchsia.cc:50
std::u16string text
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
#define EXPECT_TRUE(handle)
Definition unit_test.h:685

◆ 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();
148 g_autoptr(GBytes) message = text_to_message(text);
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)
Win32Message message

◆ 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();
68 g_autoptr(GBytes) data = text_to_message(text);
69 g_autoptr(GError) error = nullptr;
71 FL_METHOD_CODEC(codec), data, name, args, &error);
73 EXPECT_EQ(error, nullptr);
74}

◆ 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();
115 g_autoptr(GBytes) message = text_to_message(text);
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

◆ 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();
96 g_autoptr(GBytes) message = text_to_message(text);
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)

◆ 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)

◆ 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)

◆ 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)

◆ 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}

◆ 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)

◆ 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:69
@ FL_VALUE_TYPE_INT
Definition fl_value.h:67
@ FL_VALUE_TYPE_LIST
Definition fl_value.h:74

◆ 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}

◆ 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

◆ TEST() [7/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallNoMethodOrArgs   
)

◆ TEST() [8/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeMethodCallNoTerminator   
)

Definition at line 249 of file fl_json_method_codec_test.cc.

249 {
250 decode_error_method_call("{\"method\":\"hello\",\"args\":\"world\"",
253}

◆ 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:65

◆ 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}

◆ 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 {
349 g_autoptr(FlValue) details = fl_value_new_list();
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

◆ 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}

◆ 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)

◆ 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}

◆ TEST() [16/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseErrorMessageAndDetails   
)

Definition at line 356 of file fl_json_method_codec_test.cc.

356 {
357 g_autoptr(FlValue) details = fl_value_new_list();
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}

◆ 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}

◆ TEST() [18/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseExtraDetails   
)

Definition at line 390 of file fl_json_method_codec_test.cc.

390 {
391 decode_error_response("[\"error\",\"message\",true,42]",
393}

◆ TEST() [19/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseInvalidJson   
)

◆ TEST() [20/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseMissingDetails   
)

Definition at line 385 of file fl_json_method_codec_test.cc.

385 {
386 decode_error_response("[\"error\",\"message\"]", FL_MESSAGE_CODEC_ERROR,
388}

◆ 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}

◆ 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 {
328 g_autoptr(FlValue) result = fl_value_new_list();
331 decode_response_with_success("[[\"count\",42]]", result);
332}
static void decode_response_with_success(const char *text, FlValue *result)

◆ TEST() [25/39]

TEST ( FlJsonMethodCodecTest  ,
DecodeResponseSuccessNull   
)

Definition at line 317 of file fl_json_method_codec_test.cc.

317 {
318 g_autoptr(FlValue) result = fl_value_new_null();
320}
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition fl_value.cc:251

◆ 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}

◆ TEST() [27/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeErrorEnvelopeDetails   
)

Definition at line 301 of file fl_json_method_codec_test.cc.

301 {
302 g_autoptr(FlValue) details = fl_value_new_list();
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)

◆ 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}

◆ 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}

◆ TEST() [30/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeErrorEnvelopeMessageAndDetails   
)

Definition at line 309 of file fl_json_method_codec_test.cc.

309 {
310 g_autoptr(FlValue) details = fl_value_new_list();
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}

◆ 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}

◆ TEST() [32/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeMethodCallListArgs   
)

Definition at line 173 of file fl_json_method_codec_test.cc.

173 {
174 g_autoptr(FlValue) args = fl_value_new_list();
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)

◆ TEST() [33/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeMethodCallNullArgs   
)

Definition at line 161 of file fl_json_method_codec_test.cc.

161 {
162 g_autoptr(FlValue) value = fl_value_new_null();
163 g_autofree gchar* text = encode_method_call("hello", value);
164 EXPECT_STREQ(text, "{\"method\":\"hello\",\"args\":null}");
165}
uint8_t 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}

◆ TEST() [35/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeMethodCallStringArgs   
)

Definition at line 167 of file fl_json_method_codec_test.cc.

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

◆ TEST() [36/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeSuccessEnvelopeList   
)

Definition at line 278 of file fl_json_method_codec_test.cc.

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

◆ TEST() [37/39]

TEST ( FlJsonMethodCodecTest  ,
EncodeSuccessEnvelopeNull   
)

Definition at line 266 of file fl_json_method_codec_test.cc.

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

◆ 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}

◆ 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}

◆ 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}