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_event_channel.h"
13#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"
14#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
15#include "flutter/shell/platform/linux/testing/mock_renderer.h"
28 g_autoptr(GError) engine_error =
nullptr;
30 EXPECT_EQ(engine_error,
nullptr);
32 return static_cast<FlEngine*
>(g_object_ref(
engine));
39 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
56 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
75 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
81TEST(FlEventChannelTest, Listen) {
82 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
88 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
95 g_main_loop_run(loop);
98 g_object_unref(channel);
103 FlEventChannel* channel,
113 FlBinaryMessenger* messenger,
114 const gchar* channel,
116 FlBinaryMessengerResponseHandle* response_handle,
122 g_autoptr(GError)
error =
nullptr;
123 g_autoptr(FlMethodResponse) response =
125 EXPECT_NE(response,
nullptr);
126 EXPECT_EQ(
error,
nullptr);
128 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
134 "LISTEN-ERROR-MESSAGE");
136 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
140TEST(FlEventChannelTest, ListenException) {
141 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
147 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
149 nullptr, loop,
nullptr);
158 g_main_loop_run(loop);
161 g_object_unref(channel);
170 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
176TEST(FlEventChannelTest, Cancel) {
177 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
183 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
191 g_main_loop_run(loop);
194 g_object_unref(channel);
199 FlEventChannel* channel,
209 FlBinaryMessenger* messenger,
210 const gchar* channel,
212 FlBinaryMessengerResponseHandle* response_handle,
220 if (
data->count == 2) {
222 g_autoptr(GError)
error =
nullptr;
225 EXPECT_NE(response,
nullptr);
226 EXPECT_EQ(
error,
nullptr);
228 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
233 FL_METHOD_ERROR_RESPONSE(response)),
234 "CANCEL-ERROR-MESSAGE");
236 g_main_loop_quit(
data->loop);
241TEST(FlEventChannelTest, CancelException) {
242 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
251 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
264 g_main_loop_run(loop);
267 g_object_unref(channel);
287 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
293TEST(FlEventChannelTest, Args) {
294 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
300 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
310 g_main_loop_run(loop);
313 g_object_unref(channel);
321 for (
int i = 0;
i < 5;
i++) {
323 g_autoptr(GError)
error =
nullptr;
325 EXPECT_EQ(
error,
nullptr);
334 FlBinaryMessenger* messenger,
335 const gchar* channel,
337 FlBinaryMessengerResponseHandle* response_handle,
342 g_autoptr(GError)
error =
nullptr;
343 g_autoptr(FlMethodResponse) response =
345 EXPECT_NE(response,
nullptr);
346 EXPECT_EQ(
error,
nullptr);
349 EXPECT_NE(
result,
nullptr);
350 EXPECT_EQ(
error,
nullptr);
360 if (
data->count == 5) {
361 g_main_loop_quit(
data->loop);
366TEST(FlEventChannelTest, Test) {
367 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
376 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
388 g_main_loop_run(loop);
391 g_object_unref(channel);
396TEST(FlEventChannelTest, ReuseChannel) {
397 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
407 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
412 g_object_unref(channel1);
416 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
428 g_main_loop_run(loop);
432TEST(FlEventChannelTest, ReplaceChannel) {
433 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
443 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
449 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
461 g_main_loop_run(loop);
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_MODULE_EXPORT FlDartProject * fl_dart_project_new()
FlEngine * fl_engine_new(FlDartProject *project, FlRenderer *renderer)
gboolean fl_engine_start(FlEngine *self, GError **error)
G_MODULE_EXPORT gboolean fl_event_channel_send(FlEventChannel *self, FlValue *event, GCancellable *cancellable, GError **error)
G_MODULE_EXPORT void fl_event_channel_set_stream_handlers(FlEventChannel *self, FlEventChannelHandler listen_handler, FlEventChannelHandler cancel_handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlEventChannel * fl_event_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static FlMethodErrorResponse * send_events_listen_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
static void cancel_exception_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
static FlMethodErrorResponse * args_cancel_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
TEST(FlEventChannelTest, Listen)
static void listen_channel(FlBinaryMessenger *messenger, FlValue *args)
static FlMethodErrorResponse * listen_exception_listen_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
static void send_events_events_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
static FlMethodErrorResponse * listen_listen_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
static FlMethodErrorResponse * args_listen_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
static void listen_exception_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
static FlMethodErrorResponse * cancel_exception_cancel_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
static FlEngine * make_mock_engine()
static void cancel_channel(FlBinaryMessenger *messenger, FlValue *args)
static FlMethodErrorResponse * cancel_cancel_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
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)
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)
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 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 FlValue * fl_value_ref(FlValue *self)
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 void fl_value_append(FlValue *self, FlValue *value)
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()
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
typedefG_BEGIN_DECLS struct _FlValue FlValue
FlMockRenderer * fl_mock_renderer_new(FlMockRendererGetRefreshRate get_refresh_rate)
std::shared_ptr< const fml::Mapping > data
#define EXPECT_TRUE(handle)