5#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_method_codec.h"
9#include "flutter/shell/platform/linux/fl_method_codec_private.h"
10#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"
11#include "flutter/shell/platform/linux/public/flutter_linux/fl_message_codec.h"
12#include "gtest/gtest.h"
18 static_cast<const gchar*
>(g_bytes_get_data(
message, &data_length));
19 return g_strndup(
data, data_length);
24 return g_bytes_new(
text, strlen(
text));
30 g_autoptr(GError)
error =
nullptr;
34 EXPECT_EQ(
error,
nullptr);
42 g_autoptr(GError)
error =
nullptr;
46 EXPECT_EQ(
error,
nullptr);
53 const gchar* error_message,
56 g_autoptr(GError)
error =
nullptr;
58 FL_METHOD_CODEC(codec), error_code, error_message, details, &
error);
60 EXPECT_EQ(
error,
nullptr);
69 g_autoptr(GError)
error =
nullptr;
73 EXPECT_EQ(
error,
nullptr);
82 g_autoptr(GError)
error =
nullptr;
83 g_autofree gchar*
name =
nullptr;
88 EXPECT_EQ(
name,
nullptr);
89 EXPECT_EQ(
args,
nullptr);
97 g_autoptr(GError)
error =
nullptr;
98 g_autoptr(FlMethodResponse) response =
100 ASSERT_NE(response,
nullptr);
101 EXPECT_EQ(
error,
nullptr);
102 ASSERT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
104 FL_METHOD_SUCCESS_RESPONSE(response)),
112 const gchar* error_message,
116 g_autoptr(GError)
error =
nullptr;
117 g_autoptr(FlMethodResponse) response =
119 ASSERT_NE(response,
nullptr);
120 EXPECT_EQ(
error,
nullptr);
121 ASSERT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
125 if (error_message ==
nullptr) {
127 FL_METHOD_ERROR_RESPONSE(response)),
131 FL_METHOD_ERROR_RESPONSE(response)),
134 if (details ==
nullptr) {
136 FL_METHOD_ERROR_RESPONSE(response)),
140 FL_METHOD_ERROR_RESPONSE(response)),
149 g_autoptr(GError)
error =
nullptr;
150 g_autoptr(FlMethodResponse) response =
152 EXPECT_EQ(response,
nullptr);
156TEST(FlJsonMethodCodecTest, EncodeMethodCallNullptrArgs) {
158 EXPECT_STREQ(
text,
"{\"method\":\"hello\",\"args\":null}");
161TEST(FlJsonMethodCodecTest, EncodeMethodCallNullArgs) {
164 EXPECT_STREQ(
text,
"{\"method\":\"hello\",\"args\":null}");
167TEST(FlJsonMethodCodecTest, EncodeMethodCallStringArgs) {
170 EXPECT_STREQ(
text,
"{\"method\":\"hello\",\"args\":\"world\"}");
173TEST(FlJsonMethodCodecTest, EncodeMethodCallListArgs) {
178 EXPECT_STREQ(
text,
"{\"method\":\"hello\",\"args\":[\"count\",42]}");
181TEST(FlJsonMethodCodecTest, DecodeMethodCallNoArgs) {
182 g_autofree gchar*
name =
nullptr;
185 EXPECT_STREQ(
name,
"hello");
186 ASSERT_EQ(
args,
nullptr);
189TEST(FlJsonMethodCodecTest, DecodeMethodCallNullArgs) {
190 g_autofree gchar*
name =
nullptr;
193 EXPECT_STREQ(
name,
"hello");
197TEST(FlJsonMethodCodecTest, DecodeMethodCallStringArgs) {
198 g_autofree gchar*
name =
nullptr;
201 EXPECT_STREQ(
name,
"hello");
206TEST(FlJsonMethodCodecTest, DecodeMethodCallListArgs) {
207 g_autofree gchar*
name =
nullptr;
211 EXPECT_STREQ(
name,
"hello");
224TEST(FlJsonMethodCodecTest, DecodeMethodCallNoData) {
229TEST(FlJsonMethodCodecTest, DecodeMethodCallNoMethodOrArgs) {
234TEST(FlJsonMethodCodecTest, DecodeMethodCallInvalidJson) {
239TEST(FlJsonMethodCodecTest, DecodeMethodCallWrongType) {
244TEST(FlJsonMethodCodecTest, DecodeMethodCallNoMethod) {
249TEST(FlJsonMethodCodecTest, DecodeMethodCallNoTerminator) {
255TEST(FlJsonMethodCodecTest, DecodeMethodCallExtraData) {
261TEST(FlJsonMethodCodecTest, EncodeSuccessEnvelopeNullptr) {
263 EXPECT_STREQ(
text,
"[null]");
266TEST(FlJsonMethodCodecTest, EncodeSuccessEnvelopeNull) {
269 EXPECT_STREQ(
text,
"[null]");
272TEST(FlJsonMethodCodecTest, EncodeSuccessEnvelopeString) {
275 EXPECT_STREQ(
text,
"[\"hello\"]");
278TEST(FlJsonMethodCodecTest, EncodeSuccessEnvelopeList) {
283 EXPECT_STREQ(
text,
"[[\"count\",42]]");
286TEST(FlJsonMethodCodecTest, EncodeErrorEnvelopeEmptyCode) {
288 EXPECT_STREQ(
text,
"[\"\",null,null]");
291TEST(FlJsonMethodCodecTest, EncodeErrorEnvelopeNonMessageOrDetails) {
293 EXPECT_STREQ(
text,
"[\"error\",null,null]");
296TEST(FlJsonMethodCodecTest, EncodeErrorEnvelopeMessage) {
298 EXPECT_STREQ(
text,
"[\"error\",\"message\",null]");
301TEST(FlJsonMethodCodecTest, EncodeErrorEnvelopeDetails) {
306 EXPECT_STREQ(
text,
"[\"error\",null,[\"count\",42]]");
309TEST(FlJsonMethodCodecTest, EncodeErrorEnvelopeMessageAndDetails) {
314 EXPECT_STREQ(
text,
"[\"error\",\"message\",[\"count\",42]]");
317TEST(FlJsonMethodCodecTest, DecodeResponseSuccessNull) {
322TEST(FlJsonMethodCodecTest, DecodeResponseSuccessString) {
327TEST(FlJsonMethodCodecTest, DecodeResponseSuccessList) {
334TEST(FlJsonMethodCodecTest, DecodeResponseErrorEmptyCode) {
338TEST(FlJsonMethodCodecTest, DecodeResponseErrorNoMessageOrDetails) {
343TEST(FlJsonMethodCodecTest, DecodeResponseErrorMessage) {
348TEST(FlJsonMethodCodecTest, DecodeResponseErrorDetails) {
356TEST(FlJsonMethodCodecTest, DecodeResponseErrorMessageAndDetails) {
364TEST(FlJsonMethodCodecTest, DecodeResponseNotImplemented) {
366 g_autoptr(GBytes)
message = g_bytes_new(
nullptr, 0);
367 g_autoptr(GError)
error =
nullptr;
368 g_autoptr(FlMethodResponse) response =
370 ASSERT_NE(response,
nullptr);
371 EXPECT_EQ(
error,
nullptr);
372 EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
375TEST(FlJsonMethodCodecTest, DecodeResponseNoTerminator) {
380TEST(FlJsonMethodCodecTest, DecodeResponseInvalidJson) {
385TEST(FlJsonMethodCodecTest, DecodeResponseMissingDetails) {
390TEST(FlJsonMethodCodecTest, DecodeResponseExtraDetails) {
395TEST(FlJsonMethodCodecTest, DecodeResponseSuccessExtraData) {
400TEST(FlJsonMethodCodecTest, DecodeResponseErrorExtraData) {
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
@ FL_JSON_MESSAGE_CODEC_ERROR_INVALID_JSON
#define FL_JSON_MESSAGE_CODEC_ERROR
G_MODULE_EXPORT FlJsonMethodCodec * fl_json_method_codec_new()
static void decode_error_method_call(const char *text, GQuark domain, gint code)
static void decode_error_response(const char *text, GQuark domain, gint code)
TEST(FlJsonMethodCodecTest, EncodeMethodCallNullptrArgs)
static void decode_response_with_success(const char *text, FlValue *result)
static void decode_response_with_error(const char *text, const gchar *code, const gchar *error_message, FlValue *details)
static gchar * encode_method_call(const gchar *name, FlValue *args)
static gchar * encode_error_envelope(const gchar *error_code, const gchar *error_message, FlValue *details)
static gchar * message_to_text(GBytes *message)
static void decode_method_call(const char *text, gchar **name, FlValue **args)
static gchar * encode_success_envelope(FlValue *result)
static GBytes * text_to_message(const gchar *text)
@ 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)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
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 FlValue * fl_value_new_int(int64_t value)
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
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
std::shared_ptr< const fml::Mapping > data
#define EXPECT_TRUE(handle)