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

Go to the source code of this file.

Functions

 G_DECLARE_FINAL_TYPE (FlTestMethodMessageCodec, fl_test_method_message_codec, FL, TEST_METHOD_MESSAGE_CODEC, FlStandardMessageCodec) struct _FlTestMethodMessageCodec
 
 G_DEFINE_TYPE (FlTestMethodMessageCodec, fl_test_method_message_codec, fl_standard_message_codec_get_type()) static gboolean write_custom_value(FlStandardMessageCodec *codec
 
 g_byte_array_append (buffer, &type, sizeof(uint8_t))
 
 fl_standard_message_codec_write_size (codec, buffer, length)
 
 g_byte_array_append (buffer, reinterpret_cast< const uint8_t * >(text), length)
 
static gboolean fl_test_method_message_codec_write_value (FlStandardMessageCodec *codec, GByteArray *buffer, FlValue *value, GError **error)
 
static FlValueread_custom_value (FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, GError **error)
 
static FlValuefl_test_method_message_codec_read_value_of_type (FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, int type, GError **error)
 
static void fl_test_method_message_codec_class_init (FlTestMethodMessageCodecClass *klass)
 
static void fl_test_method_message_codec_init (FlTestMethodMessageCodec *self)
 
static FlTestMethodMessageCodec * fl_test_method_message_codec_new ()
 
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 *hex_string, gchar **name, FlValue **args)
 
static void decode_error_method_call (const char *hex_string, GQuark domain, gint code)
 
static void decode_response_with_success (const char *hex_string, FlValue *result)
 
static void decode_response_with_error (const char *hex_string, const gchar *code, const gchar *error_message, FlValue *details)
 
static void decode_error_response (const char *hex_string, GQuark domain, gint code)
 
 TEST (FlStandardMethodCodecTest, EncodeMethodCallNullptrArgs)
 
 TEST (FlStandardMethodCodecTest, EncodeMethodCallNullArgs)
 
 TEST (FlStandardMethodCodecTest, EncodeMethodCallStringArgs)
 
 TEST (FlStandardMethodCodecTest, EncodeMethodCallListArgs)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallNullArgs)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallStringArgs)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallListArgs)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallNoData)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallNullMethodName)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallMissingArgs)
 
 TEST (FlStandardMethodCodecTest, EncodeSuccessEnvelopeNullptr)
 
 TEST (FlStandardMethodCodecTest, EncodeSuccessEnvelopeNull)
 
 TEST (FlStandardMethodCodecTest, EncodeSuccessEnvelopeString)
 
 TEST (FlStandardMethodCodecTest, EncodeSuccessEnvelopeList)
 
 TEST (FlStandardMethodCodecTest, EncodeErrorEnvelopeEmptyCode)
 
 TEST (FlStandardMethodCodecTest, EncodeErrorEnvelopeNonMessageOrDetails)
 
 TEST (FlStandardMethodCodecTest, EncodeErrorEnvelopeMessage)
 
 TEST (FlStandardMethodCodecTest, EncodeErrorEnvelopeDetails)
 
 TEST (FlStandardMethodCodecTest, EncodeErrorEnvelopeMessageAndDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseSuccessNull)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseSuccessString)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseSuccessList)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorEmptyCode)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorNoMessageOrDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorMessage)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorMessageAndDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseSuccessNoData)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseSuccessExtraData)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorNoData)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorMissingMessageAndDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorMissingDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorExtraData)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseNotImplemented)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseUnknownEnvelope)
 
 TEST (FlStandardMethodCodecTest, CustomMessageCodec)
 

Variables

GByteArray * buffer
 
GByteArray FlValuevalue
 
GByteArray FlValue GError ** error
 
size_t length = strlen(text)
 
uint8_t type = 128
 
return TRUE
 

Function Documentation

◆ decode_error_method_call()

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

Definition at line 170 of file fl_standard_method_codec_test.cc.

172 {
173 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
174 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
175 g_autoptr(GError) error = nullptr;
176 g_autofree gchar* name = nullptr;
177 g_autoptr(FlValue) args = nullptr;
178 gboolean result = fl_method_codec_decode_method_call(
179 FL_METHOD_CODEC(codec), message, &name, &args, &error);
180 EXPECT_FALSE(result);
181 EXPECT_EQ(name, nullptr);
182 EXPECT_EQ(args, nullptr);
183 EXPECT_TRUE(g_error_matches(error, domain, code));
184}
g_autoptr(GMutexLocker) locker
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)
G_BEGIN_DECLS GBytes * message
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
GByteArray FlValue GError ** error
GBytes * hex_string_to_bytes(const gchar *hex_string)
Definition fl_test.cc:43
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition fl_value.h:42
const char * name
Definition fuchsia.cc:49

References args, error, fl_method_codec_decode_method_call(), fl_standard_method_codec_new(), g_autoptr(), hex_string_to_bytes(), message, and name.

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

◆ decode_error_response()

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

Definition at line 240 of file fl_standard_method_codec_test.cc.

242 {
243 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
244 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
245 g_autoptr(GError) error = nullptr;
246 g_autoptr(FlMethodResponse) response =
247 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
248 EXPECT_EQ(response, nullptr);
249 EXPECT_TRUE(g_error_matches(error, domain, code));
250}
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)

References error, fl_method_codec_decode_response(), fl_standard_method_codec_new(), g_autoptr(), hex_string_to_bytes(), and message.

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

◆ decode_method_call()

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

Definition at line 157 of file fl_standard_method_codec_test.cc.

159 {
160 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
161 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
162 g_autoptr(GError) error = nullptr;
163 gboolean result = fl_method_codec_decode_method_call(
164 FL_METHOD_CODEC(codec), message, name, args, &error);
165 EXPECT_TRUE(result);
166 EXPECT_EQ(error, nullptr);
167}

References args, error, fl_method_codec_decode_method_call(), fl_standard_method_codec_new(), g_autoptr(), hex_string_to_bytes(), message, and name.

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

◆ decode_response_with_error()

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

Definition at line 205 of file fl_standard_method_codec_test.cc.

208 {
209 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
210 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
211 g_autoptr(GError) error = nullptr;
212 g_autoptr(FlMethodResponse) response =
213 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
214 ASSERT_NE(response, nullptr);
215 EXPECT_EQ(error, nullptr);
216 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
217 EXPECT_STREQ(
218 fl_method_error_response_get_code(FL_METHOD_ERROR_RESPONSE(response)),
219 code);
220 if (error_message == nullptr) {
222 FL_METHOD_ERROR_RESPONSE(response)),
223 nullptr);
224 } else {
226 FL_METHOD_ERROR_RESPONSE(response)),
227 error_message);
228 }
229 if (details == nullptr) {
231 FL_METHOD_ERROR_RESPONSE(response)),
232 nullptr);
233 } else {
235 FL_METHOD_ERROR_RESPONSE(response)),
236 details));
237 }
238}
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_method_codec_decode_response(), fl_method_error_response_get_code(), fl_method_error_response_get_details(), fl_method_error_response_get_message(), fl_standard_method_codec_new(), fl_value_equal(), g_autoptr(), hex_string_to_bytes(), and message.

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

◆ decode_response_with_success()

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

Definition at line 188 of file fl_standard_method_codec_test.cc.

189 {
190 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
191 g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
192 g_autoptr(GError) error = nullptr;
193 g_autoptr(FlMethodResponse) response =
194 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
195 ASSERT_NE(response, nullptr);
196 EXPECT_EQ(error, nullptr);
197 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
199 FL_METHOD_SUCCESS_RESPONSE(response)),
200 result));
201}
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)

References error, fl_method_codec_decode_response(), fl_method_success_response_get_result(), fl_standard_method_codec_new(), fl_value_equal(), g_autoptr(), hex_string_to_bytes(), and 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 143 of file fl_standard_method_codec_test.cc.

145 {
146 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
147 g_autoptr(GError) error = nullptr;
149 FL_METHOD_CODEC(codec), error_code, error_message, details, &error);
150 EXPECT_NE(message, nullptr);
151 EXPECT_EQ(error, nullptr);
152
154}
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
gchar * bytes_to_hex_string(GBytes *bytes)
Definition fl_test.cc:52

References bytes_to_hex_string(), error, fl_method_codec_encode_error_envelope(), fl_standard_method_codec_new(), g_autoptr(), and message.

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 118 of file fl_standard_method_codec_test.cc.

118 {
119 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
120 g_autoptr(GError) error = nullptr;
122 FL_METHOD_CODEC(codec), name, args, &error);
123 EXPECT_NE(message, nullptr);
124 EXPECT_EQ(error, nullptr);
125
127}
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)

References args, bytes_to_hex_string(), error, fl_method_codec_encode_method_call(), fl_standard_method_codec_new(), g_autoptr(), message, and name.

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

◆ encode_success_envelope()

static gchar * encode_success_envelope ( FlValue result)
static

Definition at line 131 of file fl_standard_method_codec_test.cc.

131 {
132 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
133 g_autoptr(GError) error = nullptr;
135 FL_METHOD_CODEC(codec), result, &error);
136 EXPECT_NE(message, nullptr);
137 EXPECT_EQ(error, nullptr);
138
140}
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)

References bytes_to_hex_string(), error, fl_method_codec_encode_success_envelope(), fl_standard_method_codec_new(), g_autoptr(), and message.

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

◆ fl_standard_message_codec_write_size()

fl_standard_message_codec_write_size ( codec  ,
buffer  ,
length   
)

◆ fl_test_method_message_codec_class_init()

static void fl_test_method_message_codec_class_init ( FlTestMethodMessageCodecClass *  klass)
static

Definition at line 96 of file fl_standard_method_codec_test.cc.

97 {
98 FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->write_value =
100 FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->read_value_of_type =
102}
static FlValue * fl_test_method_message_codec_read_value_of_type(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, int type, GError **error)
static gboolean fl_test_method_message_codec_write_value(FlStandardMessageCodec *codec, GByteArray *buffer, FlValue *value, GError **error)

References fl_test_method_message_codec_read_value_of_type(), and fl_test_method_message_codec_write_value().

◆ fl_test_method_message_codec_init()

static void fl_test_method_message_codec_init ( FlTestMethodMessageCodec *  self)
static

Definition at line 104 of file fl_standard_method_codec_test.cc.

104 {
105 // The following line suppresses a warning for unused function
106 FL_IS_TEST_METHOD_MESSAGE_CODEC(self);
107}

References self.

◆ fl_test_method_message_codec_new()

static FlTestMethodMessageCodec * fl_test_method_message_codec_new ( )
static

Definition at line 109 of file fl_standard_method_codec_test.cc.

109 {
110 return FL_TEST_METHOD_MESSAGE_CODEC(
111 g_object_new(fl_test_method_message_codec_get_type(), nullptr));
112}

Referenced by TEST().

◆ fl_test_method_message_codec_read_value_of_type()

static FlValue * fl_test_method_message_codec_read_value_of_type ( FlStandardMessageCodec *  codec,
GBytes *  buffer,
size_t *  offset,
int  type,
GError **  error 
)
static

Definition at line 81 of file fl_standard_method_codec_test.cc.

86 {
87 if (type == 128) {
88 return read_custom_value(codec, buffer, offset, error);
89 } else {
90 return FL_STANDARD_MESSAGE_CODEC_CLASS(
91 fl_test_method_message_codec_parent_class)
92 ->read_value_of_type(codec, buffer, offset, type, error);
93 }
94}
static FlValue * read_custom_value(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, GError **error)
GByteArray * buffer

References buffer, error, read_custom_value(), and type.

Referenced by fl_test_method_message_codec_class_init().

◆ fl_test_method_message_codec_write_value()

static gboolean fl_test_method_message_codec_write_value ( FlStandardMessageCodec *  codec,
GByteArray *  buffer,
FlValue value,
GError **  error 
)
static

Definition at line 41 of file fl_standard_method_codec_test.cc.

45 {
48 return write_custom_value(codec, buffer, value, error);
49 } else {
50 return FL_STANDARD_MESSAGE_CODEC_CLASS(
51 fl_test_method_message_codec_parent_class)
52 ->write_value(codec, buffer, value, error);
53 }
54}
GByteArray FlValue * value
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition fl_value.cc:466
G_MODULE_EXPORT int fl_value_get_custom_type(FlValue *self)
Definition fl_value.cc:822
@ FL_VALUE_TYPE_CUSTOM
Definition fl_value.h:76

References buffer, error, fl_value_get_custom_type(), fl_value_get_type(), FL_VALUE_TYPE_CUSTOM, and value.

Referenced by fl_test_method_message_codec_class_init().

◆ g_byte_array_append() [1/2]

g_byte_array_append ( buffer  ,
type,
sizeof(uint8_t)   
)

◆ g_byte_array_append() [2/2]

g_byte_array_append ( buffer  ,
reinterpret_cast< const uint8_t * >  text,
length   
)

◆ G_DECLARE_FINAL_TYPE()

G_DECLARE_FINAL_TYPE ( FlTestMethodMessageCodec  ,
fl_test_method_message_codec  ,
FL  ,
TEST_METHOD_MESSAGE_CODEC  ,
FlStandardMessageCodec   
)

Definition at line 12 of file fl_standard_method_codec_test.cc.

18 {
19 FlStandardMessageCodec parent_instance;
20};

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( FlTestMethodMessageCodec  ,
fl_test_method_message_codec  ,
fl_standard_message_codec_get_type()   
)

◆ read_custom_value()

static FlValue * read_custom_value ( FlStandardMessageCodec *  codec,
GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 56 of file fl_standard_method_codec_test.cc.

59 {
60 uint32_t length;
62 error)) {
63 return nullptr;
64 }
65 if (*offset + length > g_bytes_get_size(buffer)) {
66 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
67 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA, "Unexpected end of data");
68 return nullptr;
69 }
71 128,
72 g_strndup(static_cast<const gchar*>(g_bytes_get_data(buffer, nullptr)) +
73 *offset,
74 length),
75 g_free);
76 *offset += length;
77
78 return value;
79}
@ FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
#define FL_MESSAGE_CODEC_ERROR
G_MODULE_EXPORT gboolean fl_standard_message_codec_read_size(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
G_MODULE_EXPORT FlValue * fl_value_new_custom(int type, gconstpointer value, GDestroyNotify destroy_notify)
Definition fl_value.cc:374

References buffer, error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA, fl_standard_message_codec_read_size(), fl_value_new_custom(), length, and value.

Referenced by fl_test_method_message_codec_read_value_of_type().

◆ TEST() [1/36]

TEST ( FlStandardMethodCodecTest  ,
CustomMessageCodec   
)

Definition at line 482 of file fl_standard_method_codec_test.cc.

482 {
483 g_autoptr(FlTestMethodMessageCodec) message_codec =
485 g_autoptr(FlStandardMethodCodec) codec =
487 FL_STANDARD_MESSAGE_CODEC(message_codec));
488
489 g_autoptr(GError) error = nullptr;
490 g_autoptr(FlValue) value = fl_value_new_custom(128, "hello", nullptr);
492 FL_METHOD_CODEC(codec), value, &error);
493 EXPECT_NE(message, nullptr);
494 EXPECT_EQ(error, nullptr);
495 g_autofree gchar* hex_string = bytes_to_hex_string(message);
496 EXPECT_STREQ(hex_string, "00800568656c6c6f");
497
498 g_autoptr(FlMethodResponse) response =
499 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
500 EXPECT_NE(response, nullptr);
501 EXPECT_EQ(error, nullptr);
502 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
504 FL_METHOD_SUCCESS_RESPONSE(response));
505 ASSERT_EQ(fl_value_get_type(result), FL_VALUE_TYPE_CUSTOM);
506 ASSERT_EQ(fl_value_get_custom_type(result), 128);
507 EXPECT_STREQ(static_cast<const gchar*>(fl_value_get_custom_value(result)),
508 "hello");
509}
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new_with_message_codec(FlStandardMessageCodec *message_codec)
static FlTestMethodMessageCodec * fl_test_method_message_codec_new()
G_MODULE_EXPORT gconstpointer fl_value_get_custom_value(FlValue *self)
Definition fl_value.cc:830

References bytes_to_hex_string(), error, fl_method_codec_decode_response(), fl_method_codec_encode_success_envelope(), fl_method_success_response_get_result(), fl_standard_method_codec_new_with_message_codec(), fl_test_method_message_codec_new(), fl_value_get_custom_type(), fl_value_get_custom_value(), fl_value_get_type(), fl_value_new_custom(), FL_VALUE_TYPE_CUSTOM, g_autoptr(), message, and value.

◆ TEST() [2/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallListArgs   
)

Definition at line 294 of file fl_standard_method_codec_test.cc.

294 {
295 g_autofree gchar* name = nullptr;
296 g_autoptr(FlValue) args = nullptr;
297 decode_method_call("070568656c6c6f0c020705636f756e74032a000000", &name,
298 &args);
299 EXPECT_STREQ(name, "hello");
301 EXPECT_EQ(fl_value_get_length(args), static_cast<size_t>(2));
302
304 ASSERT_EQ(fl_value_get_type(arg0), FL_VALUE_TYPE_STRING);
305 EXPECT_STREQ(fl_value_get_string(arg0), "count");
306
308 ASSERT_EQ(fl_value_get_type(arg1), FL_VALUE_TYPE_INT);
309 EXPECT_EQ(fl_value_get_int(arg1), 42);
310}
static void decode_method_call(const char *hex_string, gchar **name, FlValue **args)
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition fl_value.cc:668
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() [3/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallMissingArgs   
)

Definition at line 322 of file fl_standard_method_codec_test.cc.

322 {
325}
static void decode_error_method_call(const char *hex_string, GQuark domain, gint code)

References decode_error_method_call(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA.

◆ TEST() [4/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallNoData   
)

◆ TEST() [5/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallNullArgs   
)

Definition at line 277 of file fl_standard_method_codec_test.cc.

277 {
278 g_autofree gchar* name = nullptr;
279 g_autoptr(FlValue) args = nullptr;
280 decode_method_call("070568656c6c6f00", &name, &args);
281 EXPECT_STREQ(name, "hello");
283}
@ 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() [6/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallNullMethodName   
)

◆ TEST() [7/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallStringArgs   
)

Definition at line 285 of file fl_standard_method_codec_test.cc.

285 {
286 g_autofree gchar* name = nullptr;
287 g_autoptr(FlValue) args = nullptr;
288 decode_method_call("070568656c6c6f0705776f726c64", &name, &args);
289 EXPECT_STREQ(name, "hello");
291 EXPECT_STREQ(fl_value_get_string(args), "world");
292}

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

◆ TEST() [8/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorDetails   
)

Definition at line 419 of file fl_standard_method_codec_test.cc.

419 {
421 fl_value_append_take(details, fl_value_new_string("count"));
423 decode_response_with_error("0107056572726f72000c020705636f756e74032a000000",
424 "error", nullptr, details);
425}
static void decode_response_with_error(const char *hex_string, 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() [9/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorEmptyCode   
)

Definition at line 406 of file fl_standard_method_codec_test.cc.

406 {
407 decode_response_with_error("0107000000", "", nullptr, nullptr);
408}

References decode_response_with_error().

◆ TEST() [10/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorExtraData   
)

Definition at line 461 of file fl_standard_method_codec_test.cc.

461 {
462 decode_error_response("0107056572726f72000000", FL_MESSAGE_CODEC_ERROR,
464}
static void decode_error_response(const char *hex_string, GQuark domain, gint code)

References decode_error_response(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_FAILED.

◆ TEST() [11/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorMessage   
)

Definition at line 414 of file fl_standard_method_codec_test.cc.

414 {
415 decode_response_with_error("0107056572726f7207076d65737361676500", "error",
416 "message", nullptr);
417}

References decode_response_with_error().

◆ TEST() [12/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorMessageAndDetails   
)

Definition at line 427 of file fl_standard_method_codec_test.cc.

427 {
429 fl_value_append_take(details, fl_value_new_string("count"));
432 "0107056572726f7207076d6573736167650c020705636f756e74032a000000", "error",
433 "message", details);
434}

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/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorMissingDetails   
)

◆ TEST() [14/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorMissingMessageAndDetails   
)

◆ TEST() [15/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorNoData   
)

◆ TEST() [16/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorNoMessageOrDetails   
)

Definition at line 410 of file fl_standard_method_codec_test.cc.

410 {
411 decode_response_with_error("0107056572726f720000", "error", nullptr, nullptr);
412}

References decode_response_with_error().

◆ TEST() [17/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseNotImplemented   
)

Definition at line 466 of file fl_standard_method_codec_test.cc.

466 {
467 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
468 g_autoptr(GBytes) message = g_bytes_new(nullptr, 0);
469 g_autoptr(GError) error = nullptr;
470 g_autoptr(FlMethodResponse) response =
471 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
472 ASSERT_NE(response, nullptr);
473 EXPECT_EQ(error, nullptr);
474 EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
475}

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

◆ TEST() [18/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessExtraData   
)

◆ TEST() [19/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessList   
)

Definition at line 399 of file fl_standard_method_codec_test.cc.

399 {
403 decode_response_with_success("000c020705636f756e74032a000000", result);
404}
static void decode_response_with_success(const char *hex_string, 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() [20/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessNoData   
)

◆ TEST() [21/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessNull   
)

Definition at line 389 of file fl_standard_method_codec_test.cc.

389 {
391 decode_response_with_success("0000", result);
392}
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() [22/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessString   
)

Definition at line 394 of file fl_standard_method_codec_test.cc.

394 {
395 g_autoptr(FlValue) result = fl_value_new_string("hello");
396 decode_response_with_success("00070568656c6c6f", result);
397}

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

◆ TEST() [23/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseUnknownEnvelope   
)

◆ TEST() [24/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeErrorEnvelopeDetails   
)

Definition at line 369 of file fl_standard_method_codec_test.cc.

369 {
371 fl_value_append_take(details, fl_value_new_string("count"));
373 g_autofree gchar* hex_string =
374 encode_error_envelope("error", nullptr, details);
375 EXPECT_STREQ(hex_string, "0107056572726f72000c020705636f756e74032a000000");
376}
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(), and g_autoptr().

◆ TEST() [25/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeErrorEnvelopeEmptyCode   
)

Definition at line 352 of file fl_standard_method_codec_test.cc.

352 {
353 g_autofree gchar* hex_string = encode_error_envelope("", nullptr, nullptr);
354 EXPECT_STREQ(hex_string, "0107000000");
355}

References encode_error_envelope().

◆ TEST() [26/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeErrorEnvelopeMessage   
)

Definition at line 363 of file fl_standard_method_codec_test.cc.

363 {
364 g_autofree gchar* hex_string =
365 encode_error_envelope("error", "message", nullptr);
366 EXPECT_STREQ(hex_string, "0107056572726f7207076d65737361676500");
367}

References encode_error_envelope().

◆ TEST() [27/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeErrorEnvelopeMessageAndDetails   
)

Definition at line 378 of file fl_standard_method_codec_test.cc.

378 {
380 fl_value_append_take(details, fl_value_new_string("count"));
382 g_autofree gchar* hex_string =
383 encode_error_envelope("error", "message", details);
384 EXPECT_STREQ(
385 hex_string,
386 "0107056572726f7207076d6573736167650c020705636f756e74032a000000");
387}

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

◆ TEST() [28/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeErrorEnvelopeNonMessageOrDetails   
)

Definition at line 357 of file fl_standard_method_codec_test.cc.

357 {
358 g_autofree gchar* hex_string =
359 encode_error_envelope("error", nullptr, nullptr);
360 EXPECT_STREQ(hex_string, "0107056572726f720000");
361}

References encode_error_envelope().

◆ TEST() [29/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeMethodCallListArgs   
)

Definition at line 269 of file fl_standard_method_codec_test.cc.

269 {
273 g_autofree gchar* hex_string = encode_method_call("hello", args);
274 EXPECT_STREQ(hex_string, "070568656c6c6f0c020705636f756e74032a000000");
275}
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(), and g_autoptr().

◆ TEST() [30/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeMethodCallNullArgs   
)

Definition at line 257 of file fl_standard_method_codec_test.cc.

257 {
259 g_autofree gchar* hex_string = encode_method_call("hello", value);
260 EXPECT_STREQ(hex_string, "070568656c6c6f00");
261}

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

◆ TEST() [31/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeMethodCallNullptrArgs   
)

Definition at line 252 of file fl_standard_method_codec_test.cc.

252 {
253 g_autofree gchar* hex_string = encode_method_call("hello", nullptr);
254 EXPECT_STREQ(hex_string, "070568656c6c6f00");
255}

References encode_method_call().

◆ TEST() [32/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeMethodCallStringArgs   
)

Definition at line 263 of file fl_standard_method_codec_test.cc.

263 {
265 g_autofree gchar* hex_string = encode_method_call("hello", args);
266 EXPECT_STREQ(hex_string, "070568656c6c6f0705776f726c64");
267}

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

◆ TEST() [33/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeSuccessEnvelopeList   
)

Definition at line 344 of file fl_standard_method_codec_test.cc.

344 {
348 g_autofree gchar* hex_string = encode_success_envelope(result);
349 EXPECT_STREQ(hex_string, "000c020705636f756e74032a000000");
350}
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(), and g_autoptr().

◆ TEST() [34/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeSuccessEnvelopeNull   
)

Definition at line 332 of file fl_standard_method_codec_test.cc.

332 {
334 g_autofree gchar* hex_string = encode_success_envelope(result);
335 EXPECT_STREQ(hex_string, "0000");
336}

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

◆ TEST() [35/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeSuccessEnvelopeNullptr   
)

Definition at line 327 of file fl_standard_method_codec_test.cc.

327 {
328 g_autofree gchar* hex_string = encode_success_envelope(nullptr);
329 EXPECT_STREQ(hex_string, "0000");
330}

References encode_success_envelope().

◆ TEST() [36/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeSuccessEnvelopeString   
)

Definition at line 338 of file fl_standard_method_codec_test.cc.

338 {
339 g_autoptr(FlValue) result = fl_value_new_string("hello");
340 g_autofree gchar* hex_string = encode_success_envelope(result);
341 EXPECT_STREQ(hex_string, "00070568656c6c6f");
342}

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

Variable Documentation

◆ buffer

◆ error

◆ length

size_t length = strlen(text)

Definition at line 32 of file fl_standard_method_codec_test.cc.

Referenced by read_custom_value().

◆ TRUE

return TRUE

Definition at line 38 of file fl_standard_method_codec_test.cc.

◆ type

uint8_t type = 128

◆ value

GByteArray FlValue* value