5#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
6#include "flutter/shell/platform/linux/fl_method_codec_private.h"
7#include "flutter/shell/platform/linux/public/flutter_linux/fl_message_codec.h"
8#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h"
9#include "flutter/shell/platform/linux/testing/fl_test.h"
10#include "gtest/gtest.h"
13 fl_test_method_message_codec,
15 TEST_METHOD_MESSAGE_CODEC,
16 FlStandardMessageCodec)
18struct _FlTestMethodMessageCodec {
19 FlStandardMessageCodec parent_instance;
23 fl_test_method_message_codec,
24 fl_standard_message_codec_get_type())
26static gboolean write_custom_value(FlStandardMessageCodec* codec,
42 FlStandardMessageCodec* codec,
50 return FL_STANDARD_MESSAGE_CODEC_CLASS(
51 fl_test_method_message_codec_parent_class)
72 g_strndup(
static_cast<const gchar*
>(g_bytes_get_data(
buffer,
nullptr)) +
82 FlStandardMessageCodec* codec,
90 return FL_STANDARD_MESSAGE_CODEC_CLASS(
91 fl_test_method_message_codec_parent_class)
97 FlTestMethodMessageCodecClass* klass) {
98 FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->write_value =
100 FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->read_value_of_type =
106 FL_IS_TEST_METHOD_MESSAGE_CODEC(
self);
110 return FL_TEST_METHOD_MESSAGE_CODEC(
111 g_object_new(fl_test_method_message_codec_get_type(),
nullptr));
120 g_autoptr(GError)
error =
nullptr;
124 EXPECT_EQ(
error,
nullptr);
133 g_autoptr(GError)
error =
nullptr;
137 EXPECT_EQ(
error,
nullptr);
144 const gchar* error_message,
147 g_autoptr(GError)
error =
nullptr;
149 FL_METHOD_CODEC(codec), error_code, error_message, details, &
error);
151 EXPECT_EQ(
error,
nullptr);
162 g_autoptr(GError)
error =
nullptr;
166 EXPECT_EQ(
error,
nullptr);
175 g_autoptr(GError)
error =
nullptr;
176 g_autofree gchar*
name =
nullptr;
181 EXPECT_EQ(
name,
nullptr);
182 EXPECT_EQ(
args,
nullptr);
192 g_autoptr(GError)
error =
nullptr;
193 g_autoptr(FlMethodResponse) response =
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)),
207 const gchar* error_message,
211 g_autoptr(GError)
error =
nullptr;
212 g_autoptr(FlMethodResponse) response =
214 ASSERT_NE(response,
nullptr);
215 EXPECT_EQ(
error,
nullptr);
216 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
220 if (error_message ==
nullptr) {
222 FL_METHOD_ERROR_RESPONSE(response)),
226 FL_METHOD_ERROR_RESPONSE(response)),
229 if (details ==
nullptr) {
231 FL_METHOD_ERROR_RESPONSE(response)),
235 FL_METHOD_ERROR_RESPONSE(response)),
245 g_autoptr(GError)
error =
nullptr;
246 g_autoptr(FlMethodResponse) response =
248 EXPECT_EQ(response,
nullptr);
252TEST(FlStandardMethodCodecTest, EncodeMethodCallNullptrArgs) {
254 EXPECT_STREQ(hex_string,
"070568656c6c6f00");
257TEST(FlStandardMethodCodecTest, EncodeMethodCallNullArgs) {
260 EXPECT_STREQ(hex_string,
"070568656c6c6f00");
263TEST(FlStandardMethodCodecTest, EncodeMethodCallStringArgs) {
266 EXPECT_STREQ(hex_string,
"070568656c6c6f0705776f726c64");
269TEST(FlStandardMethodCodecTest, EncodeMethodCallListArgs) {
274 EXPECT_STREQ(hex_string,
"070568656c6c6f0c020705636f756e74032a000000");
277TEST(FlStandardMethodCodecTest, DecodeMethodCallNullArgs) {
278 g_autofree gchar*
name =
nullptr;
281 EXPECT_STREQ(
name,
"hello");
285TEST(FlStandardMethodCodecTest, DecodeMethodCallStringArgs) {
286 g_autofree gchar*
name =
nullptr;
289 EXPECT_STREQ(
name,
"hello");
294TEST(FlStandardMethodCodecTest, DecodeMethodCallListArgs) {
295 g_autofree gchar*
name =
nullptr;
299 EXPECT_STREQ(
name,
"hello");
312TEST(FlStandardMethodCodecTest, DecodeMethodCallNoData) {
317TEST(FlStandardMethodCodecTest, DecodeMethodCallNullMethodName) {
322TEST(FlStandardMethodCodecTest, DecodeMethodCallMissingArgs) {
327TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeNullptr) {
329 EXPECT_STREQ(hex_string,
"0000");
332TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeNull) {
335 EXPECT_STREQ(hex_string,
"0000");
338TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeString) {
341 EXPECT_STREQ(hex_string,
"00070568656c6c6f");
344TEST(FlStandardMethodCodecTest, EncodeSuccessEnvelopeList) {
349 EXPECT_STREQ(hex_string,
"000c020705636f756e74032a000000");
352TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeEmptyCode) {
354 EXPECT_STREQ(hex_string,
"0107000000");
357TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeNonMessageOrDetails) {
358 g_autofree gchar* hex_string =
360 EXPECT_STREQ(hex_string,
"0107056572726f720000");
363TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeMessage) {
364 g_autofree gchar* hex_string =
366 EXPECT_STREQ(hex_string,
"0107056572726f7207076d65737361676500");
369TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeDetails) {
373 g_autofree gchar* hex_string =
375 EXPECT_STREQ(hex_string,
"0107056572726f72000c020705636f756e74032a000000");
378TEST(FlStandardMethodCodecTest, EncodeErrorEnvelopeMessageAndDetails) {
382 g_autofree gchar* hex_string =
386 "0107056572726f7207076d6573736167650c020705636f756e74032a000000");
389TEST(FlStandardMethodCodecTest, DecodeResponseSuccessNull) {
394TEST(FlStandardMethodCodecTest, DecodeResponseSuccessString) {
399TEST(FlStandardMethodCodecTest, DecodeResponseSuccessList) {
406TEST(FlStandardMethodCodecTest, DecodeResponseErrorEmptyCode) {
410TEST(FlStandardMethodCodecTest, DecodeResponseErrorNoMessageOrDetails) {
414TEST(FlStandardMethodCodecTest, DecodeResponseErrorMessage) {
419TEST(FlStandardMethodCodecTest, DecodeResponseErrorDetails) {
424 "error",
nullptr, details);
427TEST(FlStandardMethodCodecTest, DecodeResponseErrorMessageAndDetails) {
432 "0107056572726f7207076d6573736167650c020705636f756e74032a000000",
"error",
436TEST(FlStandardMethodCodecTest, DecodeResponseSuccessNoData) {
441TEST(FlStandardMethodCodecTest, DecodeResponseSuccessExtraData) {
446TEST(FlStandardMethodCodecTest, DecodeResponseErrorNoData) {
451TEST(FlStandardMethodCodecTest, DecodeResponseErrorMissingMessageAndDetails) {
456TEST(FlStandardMethodCodecTest, DecodeResponseErrorMissingDetails) {
461TEST(FlStandardMethodCodecTest, DecodeResponseErrorExtraData) {
466TEST(FlStandardMethodCodecTest, DecodeResponseNotImplemented) {
468 g_autoptr(GBytes)
message = g_bytes_new(
nullptr, 0);
469 g_autoptr(GError)
error =
nullptr;
470 g_autoptr(FlMethodResponse) response =
472 ASSERT_NE(response,
nullptr);
473 EXPECT_EQ(
error,
nullptr);
474 EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
477TEST(FlStandardMethodCodecTest, DecodeResponseUnknownEnvelope) {
482TEST(FlStandardMethodCodecTest, CustomMessageCodec) {
483 g_autoptr(FlTestMethodMessageCodec) message_codec =
485 g_autoptr(FlStandardMethodCodec) codec =
487 FL_STANDARD_MESSAGE_CODEC(message_codec));
489 g_autoptr(GError)
error =
nullptr;
494 EXPECT_EQ(
error,
nullptr);
496 EXPECT_STREQ(hex_string,
"00800568656c6c6f");
498 g_autoptr(FlMethodResponse) response =
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));
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
@ FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
@ FL_MESSAGE_CODEC_ERROR_FAILED
#define FL_MESSAGE_CODEC_ERROR
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
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 gboolean fl_standard_message_codec_read_size(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new_with_message_codec(FlStandardMessageCodec *message_codec)
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
static void decode_method_call(const char *hex_string, gchar **name, FlValue **args)
G_DECLARE_FINAL_TYPE(FlTestMethodMessageCodec, fl_test_method_message_codec, FL, TEST_METHOD_MESSAGE_CODEC, FlStandardMessageCodec) struct _FlTestMethodMessageCodec
static void decode_error_method_call(const char *hex_string, GQuark domain, gint code)
fl_standard_message_codec_write_size(codec, buffer, length)
static FlValue * read_custom_value(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, GError **error)
static void decode_response_with_error(const char *hex_string, const gchar *code, const gchar *error_message, FlValue *details)
static void fl_test_method_message_codec_init(FlTestMethodMessageCodec *self)
TEST(FlStandardMethodCodecTest, EncodeMethodCallNullptrArgs)
static FlTestMethodMessageCodec * fl_test_method_message_codec_new()
static gchar * encode_method_call(const gchar *name, FlValue *args)
GByteArray FlValue GError ** error
static gchar * encode_error_envelope(const gchar *error_code, const gchar *error_message, FlValue *details)
GByteArray FlValue * value
G_DEFINE_TYPE(FlTestMethodMessageCodec, fl_test_method_message_codec, fl_standard_message_codec_get_type()) static gboolean write_custom_value(FlStandardMessageCodec *codec
static void decode_response_with_success(const char *hex_string, FlValue *result)
g_byte_array_append(buffer, &type, sizeof(uint8_t))
static void decode_error_response(const char *hex_string, GQuark domain, gint code)
static gchar * encode_success_envelope(FlValue *result)
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)
static void fl_test_method_message_codec_class_init(FlTestMethodMessageCodecClass *klass)
GBytes * hex_string_to_bytes(const gchar *hex_string)
gchar * bytes_to_hex_string(GBytes *bytes)
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_custom(int type, gconstpointer value, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_null()
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
G_MODULE_EXPORT int fl_value_get_custom_type(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
G_MODULE_EXPORT gconstpointer fl_value_get_custom_value(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
G_MODULE_EXPORT FlValue * fl_value_new_list()
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
typedefG_BEGIN_DECLS struct _FlValue FlValue
DEF_SWITCHES_START aot vmservice shared library name
#define EXPECT_TRUE(handle)