6 #include "gtest/gtest.h"
15 #include "flutter/shell/platform/linux/testing/mock_renderer.h"
26 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
27 g_autoptr(FlEngine) engine =
fl_engine_new(project, FL_RENDERER(renderer));
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));
81 TEST(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));
140 TEST(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));
176 TEST(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;
224 FL_METHOD_CODEC(codec), message, &
error);
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);
241 TEST(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));
293 TEST(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);
366 TEST(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);
396 TEST(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);
432 TEST(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);