5#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h"
9#include "flutter/shell/platform/linux/fl_method_codec_private.h"
10#include "flutter/shell/platform/linux/public/flutter_linux/fl_message_codec.h"
11#include "gtest/gtest.h"
21struct _FlTestMethodCodec {
22 FlMethodCodec parent_instance;
27 fl_method_codec_get_type())
33 static_cast<const gchar*
>(g_bytes_get_data(
message, &data_length));
34 return g_strndup(
data, data_length);
39 return g_bytes_new(
text, strlen(
text));
49 g_autofree gchar*
text =
nullptr;
51 text = g_strdup_printf(
"%s()",
name);
53 text = g_strdup_printf(
"%s(%" G_GINT64_FORMAT
")",
name,
74 if (strcmp(
m,
"error") == 0) {
91 g_autofree gchar*
text =
nullptr;
93 text = g_strdup(
"(null)");
119 g_autofree gchar*
text =
nullptr;
121 if (details ==
nullptr ||
123 text = g_strdup_printf(
"Error_%s()",
code);
125 text = g_strdup_printf(
"Error_%s(%" G_GINT64_FORMAT
")",
code,
129 if (details ==
nullptr ||
133 text = g_strdup_printf(
"Error_%s(%s,%" G_GINT64_FORMAT
")",
code,
message,
148 if (strcmp(
m,
"codec-error") == 0) {
152 }
else if (strcmp(
m,
"error") == 0) {
154 return FL_METHOD_RESPONSE(
163 FL_METHOD_CODEC_CLASS(klass)->encode_method_call =
165 FL_METHOD_CODEC_CLASS(klass)->decode_method_call =
167 FL_METHOD_CODEC_CLASS(klass)->encode_success_envelope =
169 FL_METHOD_CODEC_CLASS(klass)->encode_error_envelope =
177 return FL_TEST_METHOD_CODEC(
178 g_object_new(fl_test_method_codec_get_type(),
nullptr));
181TEST(FlMethodCodecTest, EncodeMethodCall) {
184 g_autoptr(GError)
error =
nullptr;
186 FL_METHOD_CODEC(codec),
"foo",
nullptr, &
error);
187 EXPECT_EQ(
error,
nullptr);
191 EXPECT_STREQ(message_text,
"foo()");
194TEST(FlMethodCodecTest, EncodeMethodCallEmptyName) {
197 g_autoptr(GError)
error =
nullptr;
199 FL_METHOD_CODEC(codec),
"",
nullptr, &
error);
200 EXPECT_EQ(
error,
nullptr);
204 EXPECT_STREQ(message_text,
"()");
207TEST(FlMethodCodecTest, EncodeMethodCallArgs) {
211 g_autoptr(GError)
error =
nullptr;
213 FL_METHOD_CODEC(codec),
"foo",
args, &
error);
214 EXPECT_EQ(
error,
nullptr);
218 EXPECT_STREQ(message_text,
"foo(42)");
221TEST(FlMethodCodecTest, EncodeMethodCallError) {
225 g_autoptr(GError)
error =
nullptr;
227 FL_METHOD_CODEC(codec),
"foo",
args, &
error);
233TEST(FlMethodCodecTest, DecodeMethodCall) {
238 g_autofree gchar*
name =
nullptr;
240 g_autoptr(GError)
error =
nullptr;
243 EXPECT_EQ(
error,
nullptr);
246 EXPECT_STREQ(
name,
"foo");
250TEST(FlMethodCodecTest, EncodeSuccessEnvelope) {
254 g_autoptr(GError)
error =
nullptr;
257 EXPECT_EQ(
error,
nullptr);
261 EXPECT_STREQ(message_text,
"42");
264TEST(FlMethodCodecTest, EncodeSuccessEnvelopeEmpty) {
267 g_autoptr(GError)
error =
nullptr;
269 FL_METHOD_CODEC(codec),
nullptr, &
error);
270 EXPECT_EQ(
error,
nullptr);
274 EXPECT_STREQ(message_text,
"(null)");
277TEST(FlMethodCodecTest, EncodeSuccessEnvelopeError) {
281 g_autoptr(GError)
error =
nullptr;
289TEST(FlMethodCodecTest, EncodeErrorEnvelopeNoMessageOrDetails) {
292 g_autoptr(GError)
error =
nullptr;
294 FL_METHOD_CODEC(codec),
"code",
nullptr,
nullptr, &
error);
295 EXPECT_EQ(
error,
nullptr);
299 EXPECT_STREQ(message_text,
"Error_code()");
302TEST(FlMethodCodecTest, EncodeErrorEnvelopeMessage) {
305 g_autoptr(GError)
error =
nullptr;
307 FL_METHOD_CODEC(codec),
"code",
"message",
nullptr, &
error);
308 EXPECT_EQ(
error,
nullptr);
312 EXPECT_STREQ(message_text,
"Error_code(message)");
315TEST(FlMethodCodecTest, EncodeErrorEnvelopeDetails) {
319 g_autoptr(GError)
error =
nullptr;
321 FL_METHOD_CODEC(codec),
"code",
nullptr, details, &
error);
322 EXPECT_EQ(
error,
nullptr);
326 EXPECT_STREQ(message_text,
"Error_code(42)");
329TEST(FlMethodCodecTest, EncodeErrorEnvelopeMessageAndDetails) {
333 g_autoptr(GError)
error =
nullptr;
335 FL_METHOD_CODEC(codec),
"code",
"message", details, &
error);
336 EXPECT_EQ(
error,
nullptr);
340 EXPECT_STREQ(message_text,
"Error_code(message,42)");
343TEST(FlMethodCodecTest, DecodeResponseSuccess) {
348 g_autoptr(GError)
error =
nullptr;
349 g_autoptr(FlMethodResponse) response =
351 EXPECT_EQ(
error,
nullptr);
352 EXPECT_NE(response,
nullptr);
353 ASSERT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
355 FL_METHOD_SUCCESS_RESPONSE(response));
356 ASSERT_NE(
result,
nullptr);
361TEST(FlMethodCodecTest, DecodeResponseNotImplemented) {
364 g_autoptr(GBytes)
message = g_bytes_new(
nullptr, 0);
366 g_autoptr(GError)
error =
nullptr;
367 g_autoptr(FlMethodResponse) response =
369 EXPECT_EQ(
error,
nullptr);
370 EXPECT_NE(response,
nullptr);
371 ASSERT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
374TEST(FlMethodCodecTest, DecodeResponseCodecError) {
379 g_autoptr(GError)
error =
nullptr;
380 g_autoptr(FlMethodResponse) response =
384 EXPECT_EQ(response,
nullptr);
387TEST(FlMethodCodecTest, DecodeResponseError) {
392 g_autoptr(GError)
error =
nullptr;
393 g_autoptr(FlMethodResponse) response =
395 EXPECT_EQ(
error,
nullptr);
396 EXPECT_NE(response,
nullptr);
397 ASSERT_TRUE(FL_METHOD_ERROR_RESPONSE(response));
406 ASSERT_NE(details,
nullptr);
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static gchar * message_to_text(GBytes *message)
@ 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_DECLARE_FINAL_TYPE(FlTestMethodCodec, fl_test_method_codec, FL, TEST_METHOD_CODEC, FlMethodCodec) struct _FlTestMethodCodec
static void fl_test_method_codec_init(FlTestMethodCodec *self)
static GBytes * fl_test_codec_encode_success_envelope(FlMethodCodec *codec, FlValue *result, GError **error)
static FlTestMethodCodec * fl_test_method_codec_new()
static GBytes * fl_test_codec_encode_error_envelope(FlMethodCodec *codec, const gchar *code, const gchar *message, FlValue *details, GError **error)
static void fl_test_method_codec_class_init(FlTestMethodCodecClass *klass)
static gboolean fl_test_codec_decode_method_call(FlMethodCodec *codec, GBytes *message, gchar **name, FlValue **args, GError **error)
static GBytes * fl_test_codec_encode_method_call(FlMethodCodec *codec, const gchar *name, FlValue *args, GError **error)
static FlMethodResponse * fl_test_codec_decode_response(FlMethodCodec *codec, GBytes *message, GError **error)
static GBytes * text_to_message(const gchar *text)
TEST(FlMethodCodecTest, EncodeMethodCall)
G_DEFINE_TYPE(FlTestMethodCodec, fl_test_method_codec, fl_method_codec_get_type()) static gchar *message_to_text(GBytes *message)
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
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 FlValue * fl_value_new_bool(bool value)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
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)