| Flutter Linux Embedder |

Functions
fl_method_codec_test.cc File Reference
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h"`
`#include <cstring>`
`#include "flutter/shell/platform/linux/fl_method_codec_private.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
| G_DECLARE_FINAL_TYPE (FlTestMethodCodec, fl_test_method_codec, FL, TEST_METHOD_CODEC, FlMethodCodec) struct _FlTestMethodCodec
| G_DEFINE_TYPE (FlTestMethodCodec, fl_test_method_codec, fl_method_codec_get_type()) static gchar *message_to_text(GBytes *message)
static GBytes * | text_to_message (const gchar *text)
static GBytes * | fl_test_codec_encode_method_call (FlMethodCodec *codec, const gchar *name, FlValue *args, GError **error)
static gboolean | fl_test_codec_decode_method_call (FlMethodCodec *codec, GBytes *message, gchar **name, FlValue **args, GError **error)
static GBytes * | fl_test_codec_encode_success_envelope (FlMethodCodec *codec, FlValue *result, GError **error)
static GBytes * | fl_test_codec_encode_error_envelope (FlMethodCodec *codec, const gchar *code, const gchar *message, FlValue *details, GError **error)
static FlMethodResponse * | fl_test_codec_decode_response (FlMethodCodec *codec, GBytes *message, GError **error)
static void | fl_test_method_codec_class_init (FlTestMethodCodecClass *klass)
static void | fl_test_method_codec_init (FlTestMethodCodec *self)
static FlTestMethodCodec * | fl_test_method_codec_new ()
| TEST (FlMethodCodecTest, EncodeMethodCall)
| TEST (FlMethodCodecTest, EncodeMethodCallEmptyName)
| TEST (FlMethodCodecTest, EncodeMethodCallArgs)
| TEST (FlMethodCodecTest, EncodeMethodCallError)
| TEST (FlMethodCodecTest, DecodeMethodCall)
| TEST (FlMethodCodecTest, EncodeSuccessEnvelope)
| TEST (FlMethodCodecTest, EncodeSuccessEnvelopeEmpty)
| TEST (FlMethodCodecTest, EncodeSuccessEnvelopeError)
| TEST (FlMethodCodecTest, EncodeErrorEnvelopeNoMessageOrDetails)
| TEST (FlMethodCodecTest, EncodeErrorEnvelopeMessage)
| TEST (FlMethodCodecTest, EncodeErrorEnvelopeDetails)
| TEST (FlMethodCodecTest, EncodeErrorEnvelopeMessageAndDetails)
| TEST (FlMethodCodecTest, DecodeResponseSuccess)
| TEST (FlMethodCodecTest, DecodeResponseNotImplemented)
| TEST (FlMethodCodecTest, DecodeResponseCodecError)
| TEST (FlMethodCodecTest, DecodeResponseError)

## Function Documentation

## ◆ fl_test_codec_decode_method_call()

static gboolean fl_test_codec_decode_method_call | ( | FlMethodCodec * | codec,
|  | GBytes * | message,
|  | gchar ** | name,
|  | FlValue ** | args,
|  | GError ** | error
| ) |  |
| static

Definition at line 65 of file fl_method_codec_test.cc.

69 {
70 EXPECT_TRUE(FL_IS_TEST_METHOD_CODEC(codec));
71
72 g_autofree gchar* m = message_to_text(message);
73
74 if (strcmp(m, "error") == 0) {
75 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
76 "ERROR");
77 return FALSE;
78 } else {
79 *name = g_strdup(m);
80 *args = fl_value_new_null();
81 return TRUE;
82 }
83 }
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
message_to_text
static gchar * message_to_text(GBytes *message)
Definition: fl_json_method_codec_test.cc:15
FL_MESSAGE_CODEC_ERROR_FAILED
@ FL_MESSAGE_CODEC_ERROR_FAILED
Definition: fl_message_codec.h:33
FL_MESSAGE_CODEC_ERROR
#define FL_MESSAGE_CODEC_ERROR
Definition: fl_message_codec.h:30
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_value_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251

References args, error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_value_new_null(), message_to_text(), and TRUE.

Referenced by fl_test_method_codec_class_init().

## ◆ fl_test_codec_decode_response()

static FlMethodResponse* fl_test_codec_decode_response | ( | FlMethodCodec * | codec,
|  | GBytes * | message,
|  | GError ** | error
| ) |  |
| static

Definition at line 142 of file fl_method_codec_test.cc.

144 {
145 EXPECT_TRUE(FL_IS_TEST_METHOD_CODEC(codec));
146
147 g_autofree gchar* m = message_to_text(message);
148 if (strcmp(m, "codec-error") == 0) {
149 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
150 "ERROR");
151 return nullptr;
152 } else if (strcmp(m, "error") == 0) {
153 g_autoptr(FlValue) details = fl_value_new_int(42);
154 return FL_METHOD_RESPONSE(
155 fl_method_error_response_new("code", "message", details));
156 } else {
157 g_autoptr(FlValue) result = fl_value_new_string(m);
158 return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
159 }
160 }
fl_method_error_response_new
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)
Definition: fl_method_response.cc:144
fl_method_success_response_new
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
Definition: fl_method_response.cc:126
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42

References error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_method_error_response_new(), fl_method_success_response_new(), fl_value_new_int(), fl_value_new_string(), and message_to_text().

Referenced by fl_test_method_codec_class_init().

## ◆ fl_test_codec_encode_error_envelope()

static GBytes* fl_test_codec_encode_error_envelope | ( | FlMethodCodec * | codec,
|  | const gchar * | code,
|  | const gchar * | message,
|  | FlValue * | details,
|  | GError ** | error
| ) |  |
| static

Definition at line 106 of file fl_method_codec_test.cc.

110 {
111 EXPECT_TRUE(FL_IS_TEST_METHOD_CODEC(codec));
112
113 if (details != nullptr && fl_value_get_type(details) != FL_VALUE_TYPE_INT) {
114 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
115 "ERROR");
116 return nullptr;
117 }
118
119 g_autofree gchar* text = nullptr;
120 if (message == nullptr) {
121 if (details == nullptr ||
122 fl_value_get_type(details) == FL_VALUE_TYPE_NULL) {
123 text = g_strdup_printf("Error_%s()", code);
124 } else {
125 text = g_strdup_printf("Error_%s(%" G_GINT64_FORMAT ")", code,
126 fl_value_get_int(details));
127 }
128 } else {
129 if (details == nullptr ||
130 fl_value_get_type(details) == FL_VALUE_TYPE_NULL) {
131 text = g_strdup_printf("Error_%s(%s)", code, message);
132 } else {
133 text = g_strdup_printf("Error_%s(%s,%" G_GINT64_FORMAT ")", code, message,
134 fl_value_get_int(details));
135 }
136 }
137
138 return text_to_message(text);
139 }
text_to_message
static GBytes * text_to_message(const gchar *text)
Definition: fl_method_codec_test.cc:38
fl_value_get_int
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:668
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
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

References error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_value_get_int(), fl_value_get_type(), FL_VALUE_TYPE_INT, FL_VALUE_TYPE_NULL, and text_to_message().

Referenced by fl_test_method_codec_class_init().

## ◆ fl_test_codec_encode_method_call()

static GBytes* fl_test_codec_encode_method_call | ( | FlMethodCodec * | codec,
|  | const gchar * | name,
|  | FlValue * | args,
|  | GError ** | error
| ) |  |
| static

Definition at line 43 of file fl_method_codec_test.cc.

46 {
47 EXPECT_TRUE(FL_IS_TEST_METHOD_CODEC(codec));
48
49 g_autofree gchar* text = nullptr;
50 if (args == nullptr || fl_value_get_type(args) == FL_VALUE_TYPE_NULL) {
51 text = g_strdup_printf("%s()", name);
52 } else if (fl_value_get_type(args) == FL_VALUE_TYPE_INT) {
53 text = g_strdup_printf("%s(%" G_GINT64_FORMAT ")", name,
54 fl_value_get_int(args));
55 } else {
56 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
57 "ERROR");
58 return nullptr;
59 }
60
61 return text_to_message(text);
62 }

References args, error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_value_get_int(), fl_value_get_type(), FL_VALUE_TYPE_INT, FL_VALUE_TYPE_NULL, and text_to_message().

Referenced by fl_test_method_codec_class_init().

## ◆ fl_test_codec_encode_success_envelope()

static GBytes* fl_test_codec_encode_success_envelope | ( | FlMethodCodec * | codec,
|  | FlValue * | result,
|  | GError ** | error
| ) |  |
| static

Definition at line 86 of file fl_method_codec_test.cc.

88 {
89 EXPECT_TRUE(FL_IS_TEST_METHOD_CODEC(codec));
90
91 g_autofree gchar* text = nullptr;
92 if (result == nullptr || fl_value_get_type(result) == FL_VALUE_TYPE_NULL) {
93 text = g_strdup("(null)");
94 } else if (fl_value_get_type(result) == FL_VALUE_TYPE_INT) {
95 text = g_strdup_printf("%" G_GINT64_FORMAT, fl_value_get_int(result));
96 } else {
97 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
98 "ERROR");
99 return nullptr;
100 }
101
102 return text_to_message(text);
103 }

References error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_value_get_int(), fl_value_get_type(), FL_VALUE_TYPE_INT, FL_VALUE_TYPE_NULL, and text_to_message().

Referenced by fl_test_method_codec_class_init().

## ◆ fl_test_method_codec_class_init()

static void fl_test_method_codec_class_init | ( | FlTestMethodCodecClass * | klass | ) |
| static

Definition at line 162 of file fl_method_codec_test.cc.

162 {
163 FL_METHOD_CODEC_CLASS(klass)->encode_method_call =
164 fl_test_codec_encode_method_call;
165 FL_METHOD_CODEC_CLASS(klass)->decode_method_call =
166 fl_test_codec_decode_method_call;
167 FL_METHOD_CODEC_CLASS(klass)->encode_success_envelope =
168 fl_test_codec_encode_success_envelope;
169 FL_METHOD_CODEC_CLASS(klass)->encode_error_envelope =
170 fl_test_codec_encode_error_envelope;
171 FL_METHOD_CODEC_CLASS(klass)->decode_response = fl_test_codec_decode_response;
172 }
fl_test_codec_encode_error_envelope
static GBytes * fl_test_codec_encode_error_envelope(FlMethodCodec *codec, const gchar *code, const gchar *message, FlValue *details, GError **error)
Definition: fl_method_codec_test.cc:106
fl_test_codec_encode_method_call
static GBytes * fl_test_codec_encode_method_call(FlMethodCodec *codec, const gchar *name, FlValue *args, GError **error)
Definition: fl_method_codec_test.cc:43
fl_test_codec_decode_method_call
static gboolean fl_test_codec_decode_method_call(FlMethodCodec *codec, GBytes *message, gchar **name, FlValue **args, GError **error)
Definition: fl_method_codec_test.cc:65
fl_test_codec_encode_success_envelope
static GBytes * fl_test_codec_encode_success_envelope(FlMethodCodec *codec, FlValue *result, GError **error)
Definition: fl_method_codec_test.cc:86
fl_test_codec_decode_response
static FlMethodResponse * fl_test_codec_decode_response(FlMethodCodec *codec, GBytes *message, GError **error)
Definition: fl_method_codec_test.cc:142

References fl_test_codec_decode_method_call(), fl_test_codec_decode_response(), fl_test_codec_encode_error_envelope(), fl_test_codec_encode_method_call(), and fl_test_codec_encode_success_envelope().

## ◆ fl_test_method_codec_init()

static void fl_test_method_codec_init | ( | FlTestMethodCodec * | self | ) |
| static

Definition at line 174 of file fl_method_codec_test.cc.

174 {}

## ◆ fl_test_method_codec_new()

static FlTestMethodCodec* fl_test_method_codec_new | ( |  | ) |
| static

Definition at line 176 of file fl_method_codec_test.cc.

176 {
177 return FL_TEST_METHOD_CODEC(
178 g_object_new(fl_test_method_codec_get_type(), nullptr));
179 }

Referenced by TEST().

## ◆ G_DECLARE_FINAL_TYPE()

G_DECLARE_FINAL_TYPE | ( | FlTestMethodCodec | ,
|  | fl_test_method_codec | ,
|  | FL | ,
|  | TEST_METHOD_CODEC | ,
|  | FlMethodCodec |
| ) |  |

Definition at line 13 of file fl_method_codec_test.cc.

21 {
22 FlMethodCodec parent_instance;
23 };

## ◆ G_DEFINE_TYPE()

G_DEFINE_TYPE | ( | FlTestMethodCodec | ,
|  | fl_test_method_codec | ,
|  | fl_method_codec_get_type() |
| ) |  |

Definition at line 25 of file fl_method_codec_test.cc.

30 {
31 size_t data_length;
32 const gchar* data =
33 static_cast<const gchar*>(g_bytes_get_data(message, &data_length));
34 return g_strndup(data, data_length);
35 }

## ◆ TEST() [1/16]

TEST | ( | FlMethodCodecTest | ,
|  | DecodeMethodCall |
| ) |  |

Definition at line 233 of file fl_method_codec_test.cc.

233 {
234 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
235
236 g_autoptr(GBytes) message = text_to_message("foo");
237
238 g_autofree gchar* name = nullptr;
239 g_autoptr(FlValue) args = nullptr;
240 g_autoptr(GError) error = nullptr;
241 gboolean result = fl_method_codec_decode_method_call(
242 FL_METHOD_CODEC(codec), message, &name, &args, &error);
243 EXPECT_EQ(error, nullptr);
244 EXPECT_TRUE(result);
245
246 EXPECT_STREQ(name, "foo");
247 ASSERT_EQ(fl_value_get_type(args), FL_VALUE_TYPE_NULL);
248 }
fl_method_codec_decode_method_call
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)
Definition: fl_method_codec.cc:27
fl_test_method_codec_new
static FlTestMethodCodec * fl_test_method_codec_new()
Definition: fl_method_codec_test.cc:176

References args, error, fl_method_codec_decode_method_call(), fl_test_method_codec_new(), fl_value_get_type(), FL_VALUE_TYPE_NULL, and text_to_message().

## ◆ TEST() [2/16]

TEST | ( | FlMethodCodecTest | ,
|  | DecodeResponseCodecError |
| ) |  |

Definition at line 374 of file fl_method_codec_test.cc.

374 {
375 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
376
377 g_autoptr(GBytes) message = text_to_message("codec-error");
378
379 g_autoptr(GError) error = nullptr;
380 g_autoptr(FlMethodResponse) response =
381 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
382 EXPECT_TRUE(g_error_matches(error, FL_MESSAGE_CODEC_ERROR,
383 FL_MESSAGE_CODEC_ERROR_FAILED));
384 EXPECT_EQ(response, nullptr);
385 }
fl_method_codec_decode_response
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
Definition: fl_method_codec.cc:88

References error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_method_codec_decode_response(), fl_test_method_codec_new(), and text_to_message().

## ◆ TEST() [3/16]

TEST | ( | FlMethodCodecTest | ,
|  | DecodeResponseError |
| ) |  |

Definition at line 387 of file fl_method_codec_test.cc.

387 {
388 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
389
390 g_autoptr(GBytes) message = text_to_message("error");
391
392 g_autoptr(GError) error = nullptr;
393 g_autoptr(FlMethodResponse) response =
394 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
395 EXPECT_EQ(error, nullptr);
396 EXPECT_NE(response, nullptr);
397 ASSERT_TRUE(FL_METHOD_ERROR_RESPONSE(response));
398 EXPECT_STREQ(
399 fl_method_error_response_get_code(FL_METHOD_ERROR_RESPONSE(response)),
400 "code");
401 EXPECT_STREQ(
402 fl_method_error_response_get_message(FL_METHOD_ERROR_RESPONSE(response)),
403 "message");
404 FlValue* details =
405 fl_method_error_response_get_details(FL_METHOD_ERROR_RESPONSE(response));
406 ASSERT_NE(details, nullptr);
407 ASSERT_EQ(fl_value_get_type(details), FL_VALUE_TYPE_INT);
408 EXPECT_EQ(fl_value_get_int(details), 42);
409 }
fl_method_error_response_get_code
G_MODULE_EXPORT const gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:160
fl_method_error_response_get_message
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:166
fl_method_error_response_get_details
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:172

References error, fl_method_codec_decode_response(), fl_method_error_response_get_code(), fl_method_error_response_get_details(), fl_method_error_response_get_message(), fl_test_method_codec_new(), fl_value_get_int(), fl_value_get_type(), FL_VALUE_TYPE_INT, and text_to_message().

## ◆ TEST() [4/16]

TEST | ( | FlMethodCodecTest | ,
|  | DecodeResponseNotImplemented |
| ) |  |

Definition at line 361 of file fl_method_codec_test.cc.

361 {
362 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
363
364 g_autoptr(GBytes) message = g_bytes_new(nullptr, 0);
365
366 g_autoptr(GError) error = nullptr;
367 g_autoptr(FlMethodResponse) response =
368 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
369 EXPECT_EQ(error, nullptr);
370 EXPECT_NE(response, nullptr);
371 ASSERT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
372 }

References error, fl_method_codec_decode_response(), and fl_test_method_codec_new().

## ◆ TEST() [5/16]

TEST | ( | FlMethodCodecTest | ,
|  | DecodeResponseSuccess |
| ) |  |

Definition at line 343 of file fl_method_codec_test.cc.

343 {
344 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
345
346 g_autoptr(GBytes) message = text_to_message("echo");
347
348 g_autoptr(GError) error = nullptr;
349 g_autoptr(FlMethodResponse) response =
350 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
351 EXPECT_EQ(error, nullptr);
352 EXPECT_NE(response, nullptr);
353 ASSERT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
354 FlValue* result = fl_method_success_response_get_result(
355 FL_METHOD_SUCCESS_RESPONSE(response));
356 ASSERT_NE(result, nullptr);
357 ASSERT_EQ(fl_value_get_type(result), FL_VALUE_TYPE_STRING);
358 EXPECT_STREQ(fl_value_get_string(result), "echo");
359 }
fl_method_success_response_get_result
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
Definition: fl_method_response.cc:138
fl_value_get_string
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:68

References error, fl_method_codec_decode_response(), fl_method_success_response_get_result(), fl_test_method_codec_new(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, and text_to_message().

## ◆ TEST() [6/16]

TEST | ( | FlMethodCodecTest | ,
|  | EncodeErrorEnvelopeDetails |
| ) |  |

Definition at line 315 of file fl_method_codec_test.cc.

315 {
316 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
317
318 g_autoptr(FlValue) details = fl_value_new_int(42);
319 g_autoptr(GError) error = nullptr;
320 g_autoptr(GBytes) message = fl_method_codec_encode_error_envelope(
321 FL_METHOD_CODEC(codec), "code", nullptr, details, &error);
322 EXPECT_EQ(error, nullptr);
323 EXPECT_NE(message, nullptr);
324
325 g_autofree gchar* message_text = message_to_text(message);
326 EXPECT_STREQ(message_text, "Error_code(42)");
327 }
fl_method_codec_encode_error_envelope
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
Definition: fl_method_codec.cc:50

References error, fl_method_codec_encode_error_envelope(), fl_test_method_codec_new(), fl_value_new_int(), and message_to_text().

## ◆ TEST() [7/16]

TEST | ( | FlMethodCodecTest | ,
|  | EncodeErrorEnvelopeMessage |
| ) |  |

Definition at line 302 of file fl_method_codec_test.cc.

302 {
303 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
304
305 g_autoptr(GError) error = nullptr;
306 g_autoptr(GBytes) message = fl_method_codec_encode_error_envelope(
307 FL_METHOD_CODEC(codec), "code", "message", nullptr, &error);
308 EXPECT_EQ(error, nullptr);
309 EXPECT_NE(message, nullptr);
310
311 g_autofree gchar* message_text = message_to_text(message);
312 EXPECT_STREQ(message_text, "Error_code(message)");
313 }

References error, fl_method_codec_encode_error_envelope(), fl_test_method_codec_new(), and message_to_text().

## ◆ TEST() [8/16]

TEST | ( | FlMethodCodecTest | ,
|  | EncodeErrorEnvelopeMessageAndDetails |
| ) |  |

Definition at line 329 of file fl_method_codec_test.cc.

329 {
330 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
331
332 g_autoptr(FlValue) details = fl_value_new_int(42);
333 g_autoptr(GError) error = nullptr;
334 g_autoptr(GBytes) message = fl_method_codec_encode_error_envelope(
335 FL_METHOD_CODEC(codec), "code", "message", details, &error);
336 EXPECT_EQ(error, nullptr);
337 EXPECT_NE(message, nullptr);
338
339 g_autofree gchar* message_text = message_to_text(message);
340 EXPECT_STREQ(message_text, "Error_code(message,42)");
341 }

References error, fl_method_codec_encode_error_envelope(), fl_test_method_codec_new(), fl_value_new_int(), and message_to_text().

## ◆ TEST() [9/16]

TEST | ( | FlMethodCodecTest | ,
|  | EncodeErrorEnvelopeNoMessageOrDetails |
| ) |  |

Definition at line 289 of file fl_method_codec_test.cc.

289 {
290 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
291
292 g_autoptr(GError) error = nullptr;
293 g_autoptr(GBytes) message = fl_method_codec_encode_error_envelope(
294 FL_METHOD_CODEC(codec), "code", nullptr, nullptr, &error);
295 EXPECT_EQ(error, nullptr);
296 EXPECT_NE(message, nullptr);
297
298 g_autofree gchar* message_text = message_to_text(message);
299 EXPECT_STREQ(message_text, "Error_code()");
300 }

References error, fl_method_codec_encode_error_envelope(), fl_test_method_codec_new(), and message_to_text().

## ◆ TEST() [10/16]

TEST | ( | FlMethodCodecTest | ,
|  | EncodeMethodCall |
| ) |  |

Definition at line 181 of file fl_method_codec_test.cc.

181 {
182 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
183
184 g_autoptr(GError) error = nullptr;
185 g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
186 FL_METHOD_CODEC(codec), "foo", nullptr, &error);
187 EXPECT_EQ(error, nullptr);
188 EXPECT_NE(message, nullptr);
189
190 g_autofree gchar* message_text = message_to_text(message);
191 EXPECT_STREQ(message_text, "foo()");
192 }
fl_method_codec_encode_method_call
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
Definition: fl_method_codec.cc:16

References error, fl_method_codec_encode_method_call(), fl_test_method_codec_new(), and message_to_text().

## ◆ TEST() [11/16]

TEST | ( | FlMethodCodecTest | ,
|  | EncodeMethodCallArgs |
| ) |  |

Definition at line 207 of file fl_method_codec_test.cc.

207 {
208 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
209
210 g_autoptr(FlValue) args = fl_value_new_int(42);
211 g_autoptr(GError) error = nullptr;
212 g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
213 FL_METHOD_CODEC(codec), "foo", args, &error);
214 EXPECT_EQ(error, nullptr);
215 EXPECT_NE(message, nullptr);
216
217 g_autofree gchar* message_text = message_to_text(message);
218 EXPECT_STREQ(message_text, "foo(42)");
219 }

References args, error, fl_method_codec_encode_method_call(), fl_test_method_codec_new(), fl_value_new_int(), and message_to_text().

## ◆ TEST() [12/16]

TEST | ( | FlMethodCodecTest | ,
|  | EncodeMethodCallEmptyName |
| ) |  |

Definition at line 194 of file fl_method_codec_test.cc.

194 {
195 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
196
197 g_autoptr(GError) error = nullptr;
198 g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
199 FL_METHOD_CODEC(codec), "", nullptr, &error);
200 EXPECT_EQ(error, nullptr);
201 EXPECT_NE(message, nullptr);
202
203 g_autofree gchar* message_text = message_to_text(message);
204 EXPECT_STREQ(message_text, "()");
205 }

References error, fl_method_codec_encode_method_call(), fl_test_method_codec_new(), and message_to_text().

## ◆ TEST() [13/16]

TEST | ( | FlMethodCodecTest | ,
|  | EncodeMethodCallError |
| ) |  |

Definition at line 221 of file fl_method_codec_test.cc.

221 {
222 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
223
224 g_autoptr(FlValue) args = fl_value_new_bool(FALSE);
225 g_autoptr(GError) error = nullptr;
226 g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
227 FL_METHOD_CODEC(codec), "foo", args, &error);
228 EXPECT_EQ(message, nullptr);
229 EXPECT_TRUE(g_error_matches(error, FL_MESSAGE_CODEC_ERROR,
230 FL_MESSAGE_CODEC_ERROR_FAILED));
231 }
fl_value_new_bool
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255

References args, error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_method_codec_encode_method_call(), fl_test_method_codec_new(), and fl_value_new_bool().

## ◆ TEST() [14/16]

TEST | ( | FlMethodCodecTest | ,
|  | EncodeSuccessEnvelope |
| ) |  |

Definition at line 250 of file fl_method_codec_test.cc.

250 {
251 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
252
253 g_autoptr(FlValue) result = fl_value_new_int(42);
254 g_autoptr(GError) error = nullptr;
255 g_autoptr(GBytes) message = fl_method_codec_encode_success_envelope(
256 FL_METHOD_CODEC(codec), result, &error);
257 EXPECT_EQ(error, nullptr);
258 EXPECT_NE(message, nullptr);
259
260 g_autofree gchar* message_text = message_to_text(message);
261 EXPECT_STREQ(message_text, "42");
262 }
fl_method_codec_encode_success_envelope
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)
Definition: fl_method_codec.cc:41

References error, fl_method_codec_encode_success_envelope(), fl_test_method_codec_new(), fl_value_new_int(), and message_to_text().

## ◆ TEST() [15/16]

TEST | ( | FlMethodCodecTest | ,
|  | EncodeSuccessEnvelopeEmpty |
| ) |  |

Definition at line 264 of file fl_method_codec_test.cc.

264 {
265 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
266
267 g_autoptr(GError) error = nullptr;
268 g_autoptr(GBytes) message = fl_method_codec_encode_success_envelope(
269 FL_METHOD_CODEC(codec), nullptr, &error);
270 EXPECT_EQ(error, nullptr);
271 EXPECT_NE(message, nullptr);
272
273 g_autofree gchar* message_text = message_to_text(message);
274 EXPECT_STREQ(message_text, "(null)");
275 }

References error, fl_method_codec_encode_success_envelope(), fl_test_method_codec_new(), and message_to_text().

## ◆ TEST() [16/16]

TEST | ( | FlMethodCodecTest | ,
|  | EncodeSuccessEnvelopeError |
| ) |  |

Definition at line 277 of file fl_method_codec_test.cc.

277 {
278 g_autoptr(FlTestMethodCodec) codec = fl_test_method_codec_new();
279
280 g_autoptr(FlValue) result = fl_value_new_string("X");
281 g_autoptr(GError) error = nullptr;
282 g_autoptr(GBytes) message = fl_method_codec_encode_success_envelope(
283 FL_METHOD_CODEC(codec), result, &error);
284 EXPECT_EQ(message, nullptr);
285 EXPECT_TRUE(g_error_matches(error, FL_MESSAGE_CODEC_ERROR,
286 FL_MESSAGE_CODEC_ERROR_FAILED));
287 }

References error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_method_codec_encode_success_envelope(), fl_test_method_codec_new(), and fl_value_new_string().

## ◆ text_to_message()

static GBytes* text_to_message | ( | const gchar * | text | ) |
| static

Definition at line 38 of file fl_method_codec_test.cc.

38 {
39 return g_bytes_new(text, strlen(text));
40 }

Referenced by fl_test_codec_encode_error_envelope(), fl_test_codec_encode_method_call(), fl_test_codec_encode_success_envelope(), and TEST().