Flutter Linux Embedder
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;
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 }

References args, error, fl_method_codec_decode_method_call(), fl_standard_method_codec_new(), and result.

Referenced by 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 }

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

Referenced by 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;
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(), and result.

Referenced by 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 }

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(), and fl_value_equal().

Referenced by 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 }

References error, fl_method_codec_decode_response(), fl_method_success_response_get_result(), fl_standard_method_codec_new(), fl_value_equal(), and result.

Referenced by 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;
148  g_autoptr(GBytes) message = fl_method_codec_encode_error_envelope(
149  FL_METHOD_CODEC(codec), error_code, error_message, details, &error);
150  EXPECT_NE(message, nullptr);
151  EXPECT_EQ(error, nullptr);
152 
153  return bytes_to_hex_string(message);
154 }

References error, fl_method_codec_encode_error_envelope(), and fl_standard_method_codec_new().

Referenced by 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;
121  g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
122  FL_METHOD_CODEC(codec), name, args, &error);
123  EXPECT_NE(message, nullptr);
124  EXPECT_EQ(error, nullptr);
125 
126  return bytes_to_hex_string(message);
127 }

References args, error, fl_method_codec_encode_method_call(), and fl_standard_method_codec_new().

Referenced by 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;
134  g_autoptr(GBytes) message = fl_method_codec_encode_success_envelope(
135  FL_METHOD_CODEC(codec), result, &error);
136  EXPECT_NE(message, nullptr);
137  EXPECT_EQ(error, nullptr);
138 
139  return bytes_to_hex_string(message);
140 }

References error, fl_method_codec_encode_success_envelope(), fl_standard_method_codec_new(), and result.

Referenced by 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 }

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 }

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

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 }

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 }

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);
491  g_autoptr(GBytes) message = fl_method_codec_encode_success_envelope(
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));
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 }

References 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, result, 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 }

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, and FL_VALUE_TYPE_STRING.

◆ TEST() [3/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallMissingArgs   
)

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

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

◆ 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(), and FL_VALUE_TYPE_STRING.

◆ TEST() [8/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorDetails   
)

Definition at line 419 of file fl_standard_method_codec_test.cc.

419  {
420  g_autoptr(FlValue) details = fl_value_new_list();
421  fl_value_append_take(details, fl_value_new_string("count"));
423  decode_response_with_error("0107056572726f72000c020705636f756e74032a000000",
424  "error", nullptr, details);
425 }

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

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

◆ 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  {
428  g_autoptr(FlValue) details = fl_value_new_list();
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(), and fl_value_new_string().

◆ 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(), and fl_standard_method_codec_new().

◆ TEST() [18/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessExtraData   
)

◆ TEST() [19/36]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessList   
)

◆ 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  {
390  g_autoptr(FlValue) result = fl_value_new_null();
392 }

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

◆ 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 result.

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

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

◆ 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  {
379  g_autoptr(FlValue) details = fl_value_new_list();
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(), and fl_value_new_string().

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

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

◆ TEST() [30/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeMethodCallNullArgs   
)

Definition at line 257 of file fl_standard_method_codec_test.cc.

257  {
258  g_autoptr(FlValue) value = fl_value_new_null();
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(), 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  {
264  g_autoptr(FlValue) args = fl_value_new_string("world");
265  g_autofree gchar* hex_string = encode_method_call("hello", args);
266  EXPECT_STREQ(hex_string, "070568656c6c6f0705776f726c64");
267 }

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

◆ TEST() [33/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeSuccessEnvelopeList   
)

Definition at line 344 of file fl_standard_method_codec_test.cc.

344  {
345  g_autoptr(FlValue) result = fl_value_new_list();
348  g_autofree gchar* hex_string = encode_success_envelope(result);
349  EXPECT_STREQ(hex_string, "000c020705636f756e74032a000000");
350 }

References encode_success_envelope(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), fl_value_new_string(), and result.

◆ TEST() [34/36]

TEST ( FlStandardMethodCodecTest  ,
EncodeSuccessEnvelopeNull   
)

Definition at line 332 of file fl_standard_method_codec_test.cc.

332  {
333  g_autoptr(FlValue) result = fl_value_new_null();
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 result.

◆ 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 result.

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
read_custom_value
static FlValue * read_custom_value(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, GError **error)
Definition: fl_standard_method_codec_test.cc:56
buffer
GByteArray * buffer
Definition: fl_standard_method_codec_test.cc:27
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
decode_error_response
static void decode_error_response(const char *hex_string, GQuark domain, gint code)
Definition: fl_standard_method_codec_test.cc:240
decode_response_with_success
static void decode_response_with_success(const char *hex_string, FlValue *result)
Definition: fl_standard_method_codec_test.cc:188
error
GByteArray FlValue GError ** error
Definition: fl_standard_method_codec_test.cc:29
fl_standard_method_codec_new
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
Definition: fl_standard_method_codec.cc:291
encode_method_call
static gchar * encode_method_call(const gchar *name, FlValue *args)
Definition: fl_standard_method_codec_test.cc:118
fl_value_new_list
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:349
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)
Definition: fl_standard_method_codec_test.cc:81
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
fl_test_method_message_codec_write_value
static gboolean fl_test_method_message_codec_write_value(FlStandardMessageCodec *codec, GByteArray *buffer, FlValue *value, GError **error)
Definition: fl_standard_method_codec_test.cc:41
fl_standard_method_codec_new_with_message_codec
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new_with_message_codec(FlStandardMessageCodec *message_codec)
Definition: fl_standard_method_codec.cc:298
fl_value_new_custom
G_MODULE_EXPORT FlValue * fl_value_new_custom(int type, gconstpointer value, GDestroyNotify destroy_notify)
Definition: fl_value.cc:374
fl_value_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251
FL_VALUE_TYPE_LIST
@ FL_VALUE_TYPE_LIST
Definition: fl_value.h:74
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
fl_value_get_string
const G_MODULE_EXPORT gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
fl_method_error_response_get_message
const G_MODULE_EXPORT gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:166
FL_VALUE_TYPE_NULL
@ FL_VALUE_TYPE_NULL
Definition: fl_value.h:65
decode_method_call
static void decode_method_call(const char *hex_string, gchar **name, FlValue **args)
Definition: fl_standard_method_codec_test.cc:157
decode_error_method_call
static void decode_error_method_call(const char *hex_string, GQuark domain, gint code)
Definition: fl_standard_method_codec_test.cc:170
fl_value_get_int
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:668
fl_test_method_message_codec_new
static FlTestMethodMessageCodec * fl_test_method_message_codec_new()
Definition: fl_standard_method_codec_test.cc:109
FL_VALUE_TYPE_CUSTOM
@ FL_VALUE_TYPE_CUSTOM
Definition: fl_value.h:77
fl_method_error_response_get_details
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:172
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
fl_value_get_list_value
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition: fl_value.cc:776
type
uint8_t type
Definition: fl_standard_method_codec_test.cc:34
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:69
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_value_get_custom_value
G_MODULE_EXPORT gconstpointer fl_value_get_custom_value(FlValue *self)
Definition: fl_value.cc:830
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_MESSAGE_CODEC_ERROR_FAILED
@ FL_MESSAGE_CODEC_ERROR_FAILED
Definition: fl_message_codec.h:34
fl_value_append_take
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:600
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
fl_value_get_length
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:724
fl_method_codec_decode_response
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
Definition: fl_method_codec.cc:62
fl_value_equal
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
fl_standard_message_codec_read_size
G_MODULE_EXPORT gboolean fl_standard_message_codec_read_size(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
Definition: fl_standard_message_codec.cc:657
FL_VALUE_TYPE_INT
@ FL_VALUE_TYPE_INT
Definition: fl_value.h:67
result
GAsyncResult * result
Definition: fl_text_input_plugin.cc:106
length
size_t length
Definition: fl_standard_method_codec_test.cc:32
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
@ FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
Definition: fl_message_codec.h:35
fl_method_error_response_get_code
const G_MODULE_EXPORT gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:160
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
decode_response_with_error
static void decode_response_with_error(const char *hex_string, const gchar *code, const gchar *error_message, FlValue *details)
Definition: fl_standard_method_codec_test.cc:205
fl_value_get_custom_type
G_MODULE_EXPORT int fl_value_get_custom_type(FlValue *self)
Definition: fl_value.cc:822
encode_error_envelope
static gchar * encode_error_envelope(const gchar *error_code, const gchar *error_message, FlValue *details)
Definition: fl_standard_method_codec_test.cc:143
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
encode_success_envelope
static gchar * encode_success_envelope(FlValue *result)
Definition: fl_standard_method_codec_test.cc:131
value
GByteArray FlValue * value
Definition: fl_standard_method_codec_test.cc:28
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
FL_MESSAGE_CODEC_ERROR
#define FL_MESSAGE_CODEC_ERROR
Definition: fl_message_codec.h:30