6#include "gtest/gtest.h"
8#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
9#include "flutter/shell/platform/linux/fl_engine_private.h"
10#include "flutter/shell/platform/linux/fl_method_codec_private.h"
11#include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h"
12#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"
13#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
14#include "flutter/shell/platform/linux/testing/fl_test.h"
15#include "flutter/shell/platform/linux/testing/mock_renderer.h"
22 g_autoptr(GError)
error =
nullptr;
25 EXPECT_NE(response,
nullptr);
26 EXPECT_EQ(
error,
nullptr);
29 EXPECT_NE(r,
nullptr);
30 EXPECT_EQ(
error,
nullptr);
35 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
39TEST(FlMethodChannelTest, InvokeMethod) {
40 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
46 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
53 g_main_loop_run(loop);
61 g_autoptr(GError)
error =
nullptr;
64 EXPECT_NE(response,
nullptr);
65 EXPECT_EQ(
error,
nullptr);
68 EXPECT_NE(r,
nullptr);
69 EXPECT_EQ(
error,
nullptr);
72 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
76TEST(FlMethodChannelTest, InvokeMethodNullptrArgsMessage) {
77 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
83 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
89 g_main_loop_run(loop);
97 g_autoptr(GError)
error =
nullptr;
100 EXPECT_NE(response,
nullptr);
101 EXPECT_EQ(
error,
nullptr);
103 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
112 EXPECT_NE(details,
nullptr);
116 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
120TEST(FlMethodChannelTest, InvokeMethodError) {
121 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
127 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
137 g_main_loop_run(loop);
145 g_autoptr(GError)
error =
nullptr;
148 EXPECT_NE(response,
nullptr);
149 EXPECT_EQ(
error,
nullptr);
151 EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
153 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
157TEST(FlMethodChannelTest, InvokeMethodNotImplemented) {
158 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
164 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
170 g_main_loop_run(loop);
178 g_autoptr(GError)
error =
nullptr;
181 EXPECT_EQ(response,
nullptr);
182 EXPECT_NE(
error,
nullptr);
184 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
188TEST(FlMethodChannelTest, InvokeMethodFailure) {
189 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
194 g_autoptr(FlMethodChannel) channel =
201 g_main_loop_run(loop);
216 g_autoptr(GError)
error =
nullptr;
218 EXPECT_EQ(
error,
nullptr);
224 FlBinaryMessenger* messenger,
225 const gchar* channel,
227 FlBinaryMessengerResponseHandle* response_handle,
230 g_autoptr(GError)
error =
nullptr;
231 g_autoptr(FlMethodResponse) response =
233 EXPECT_NE(response,
nullptr);
234 EXPECT_EQ(
error,
nullptr);
236 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
238 FL_METHOD_SUCCESS_RESPONSE(response));
245 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
249TEST(FlMethodChannelTest, ReceiveMethodCallRespondSuccess) {
250 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
256 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
274 g_main_loop_run(loop);
289 g_autoptr(GError)
error =
nullptr;
292 EXPECT_EQ(
error,
nullptr);
298 FlBinaryMessenger* messenger,
299 const gchar* channel,
301 FlBinaryMessengerResponseHandle* response_handle,
304 g_autoptr(GError)
error =
nullptr;
305 g_autoptr(FlMethodResponse) response =
307 EXPECT_NE(response,
nullptr);
308 EXPECT_EQ(
error,
nullptr);
310 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
325 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
329TEST(FlMethodChannelTest, ReceiveMethodCallRespondError) {
330 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
336 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
354 g_main_loop_run(loop);
368 g_autoptr(GError)
error =
nullptr;
370 EXPECT_EQ(
error,
nullptr);
376 FlBinaryMessenger* messenger,
377 const gchar* channel,
379 FlBinaryMessengerResponseHandle* response_handle,
382 g_autoptr(GError)
error =
nullptr;
383 g_autoptr(FlMethodResponse) response =
385 EXPECT_NE(response,
nullptr);
386 EXPECT_EQ(
error,
nullptr);
388 EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
393 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
397TEST(FlMethodChannelTest, ReceiveMethodCallRespondNotImplemented) {
398 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
404 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
422 g_main_loop_run(loop);
432struct _TestMethodCodec {
433 FlMethodCodec parent_instance;
435 FlStandardMethodCodec* wrapped_codec;
438G_DEFINE_TYPE(TestMethodCodec, test_method_codec, fl_method_codec_get_type())
441 TestMethodCodec*
self = TEST_METHOD_CODEC(
object);
443 g_clear_object(&
self->wrapped_codec);
445 G_OBJECT_CLASS(test_method_codec_parent_class)->dispose(
object);
454 TestMethodCodec*
self = TEST_METHOD_CODEC(codec);
466 TestMethodCodec*
self = TEST_METHOD_CODEC(codec);
496 TestMethodCodec*
self = TEST_METHOD_CODEC(codec);
503 FL_METHOD_CODEC_CLASS(klass)->encode_method_call =
505 FL_METHOD_CODEC_CLASS(klass)->decode_method_call =
507 FL_METHOD_CODEC_CLASS(klass)->encode_success_envelope =
509 FL_METHOD_CODEC_CLASS(klass)->encode_error_envelope =
511 FL_METHOD_CODEC_CLASS(klass)->decode_response =
520 return TEST_METHOD_CODEC(g_object_new(test_method_codec_get_type(),
nullptr));
529 g_autoptr(GError) response_error =
nullptr;
532 EXPECT_NE(response_error,
nullptr);
537 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
542TEST(FlMethodChannelTest, ReceiveMethodCallRespondSuccessError) {
543 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
549 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
562 g_main_loop_run(loop);
571 g_autoptr(GError) response_error =
nullptr;
573 details, &response_error));
574 EXPECT_NE(response_error,
nullptr);
579 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
584TEST(FlMethodChannelTest, ReceiveMethodCallRespondErrorError) {
585 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
591 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
604 g_main_loop_run(loop);
616 gpointer raw_user_data) {
622 g_autoptr(GError)
error =
nullptr;
624 EXPECT_EQ(
error,
nullptr);
636TEST(FlMethodChannelTest, ReplaceADisposedMethodChannel) {
637 const char* method_name =
"test/standard-method";
640 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
655 FlMethodChannel* channel1 =
658 &user_data1,
nullptr);
662 g_main_loop_run(loop);
663 EXPECT_EQ(user_data1.count, 101);
666 g_object_unref(channel1);
673 g_autoptr(FlMethodChannel) channel2 =
676 &user_data2,
nullptr);
680 g_main_loop_run(loop);
682 EXPECT_EQ(user_data1.count, 101);
683 EXPECT_EQ(user_data2.count, 101);
693TEST(FlMethodChannelTest, DisposeAReplacedMethodChannel) {
694 const char* method_name =
"test/standard-method";
697 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
712 FlMethodChannel* channel1 =
715 &user_data1,
nullptr);
719 g_main_loop_run(loop);
720 EXPECT_EQ(user_data1.count, 101);
727 g_autoptr(FlMethodChannel) channel2 =
730 &user_data2,
nullptr);
734 g_main_loop_run(loop);
735 EXPECT_EQ(user_data1.count, 101);
736 EXPECT_EQ(user_data2.count, 101);
739 g_object_unref(channel1);
743 g_main_loop_run(loop);
744 EXPECT_EQ(user_data1.count, 101);
745 EXPECT_EQ(user_data2.count, 102);
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
G_MODULE_EXPORT void fl_binary_messenger_set_message_handler_on_channel(FlBinaryMessenger *self, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(FlBinaryMessenger *self, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static FlEngine * make_mock_engine()
@ FL_MESSAGE_CODEC_ERROR_FAILED
#define FL_MESSAGE_CODEC_ERROR
G_MODULE_EXPORT gboolean fl_method_call_respond_error(FlMethodCall *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
G_MODULE_EXPORT const gchar * fl_method_call_get_name(FlMethodCall *self)
G_MODULE_EXPORT gboolean fl_method_call_respond_success(FlMethodCall *self, FlValue *result, GError **error)
G_MODULE_EXPORT gboolean fl_method_call_respond_not_implemented(FlMethodCall *self, GError **error)
G_MODULE_EXPORT FlValue * fl_method_call_get_args(FlMethodCall *self)
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
TEST(FlMethodChannelTest, InvokeMethod)
static GBytes * test_method_codec_encode_method_call(FlMethodCodec *codec, const gchar *name, FlValue *args, GError **error)
static void method_call_success_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
static void test_method_codec_dispose(GObject *object)
static void error_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
TestMethodCodec * test_method_codec_new()
static GBytes * test_method_codec_encode_success_envelope(FlMethodCodec *codec, FlValue *result, GError **error)
static void method_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
static void method_call_not_implemented_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
static void method_call_error_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
static FlMethodResponse * test_method_codec_decode_response(FlMethodCodec *codec, GBytes *message, GError **error)
static void reassign_method_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer raw_user_data)
static void method_call_not_implemented_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
static void method_call_success_error_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
static gboolean test_method_codec_decode_method_call(FlMethodCodec *codec, GBytes *message, gchar **name, FlValue **args, GError **error)
static void method_call_error_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
static void method_call_success_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
static void not_implemented_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
static void test_method_codec_class_init(TestMethodCodecClass *klass)
static void test_method_codec_init(TestMethodCodec *self)
static GBytes * test_method_codec_encode_error_envelope(FlMethodCodec *codec, const gchar *code, const gchar *message, FlValue *details, GError **error)
static void failure_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
static void method_call_error_error_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
static void nullptr_args_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
G_DECLARE_FINAL_TYPE(TestMethodCodec, test_method_codec, TEST, METHOD_CODEC, FlMethodCodec) struct _TestMethodCodec
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_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, 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 FlStandardMethodCodec * fl_standard_method_codec_new()
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
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_new_list()
typedefG_BEGIN_DECLS struct _FlValue FlValue
DEF_SWITCHES_START aot vmservice shared library name
#define EXPECT_TRUE(handle)