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 =
29 g_autoptr(GError) engine_error =
nullptr;
31 EXPECT_EQ(engine_error,
nullptr);
33 return static_cast<FlEngine*
>(g_object_ref(engine));
40 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
57 messenger,
"test/standard-method", FL_METHOD_CODEC(codec));
76 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
82 TEST(FlEventChannelTest, Listen) {
83 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
89 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
96 g_main_loop_run(loop);
99 g_object_unref(channel);
104 FlEventChannel* channel,
114 FlBinaryMessenger* messenger,
115 const gchar* channel,
117 FlBinaryMessengerResponseHandle* response_handle,
123 g_autoptr(GError)
error =
nullptr;
124 g_autoptr(FlMethodResponse) response =
126 EXPECT_NE(response,
nullptr);
127 EXPECT_EQ(
error,
nullptr);
129 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
135 "LISTEN-ERROR-MESSAGE");
137 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
141 TEST(FlEventChannelTest, ListenException) {
142 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
148 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
150 nullptr, loop,
nullptr);
159 g_main_loop_run(loop);
162 g_object_unref(channel);
171 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
177 TEST(FlEventChannelTest, Cancel) {
178 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
184 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
192 g_main_loop_run(loop);
195 g_object_unref(channel);
200 FlEventChannel* channel,
210 FlBinaryMessenger* messenger,
211 const gchar* channel,
213 FlBinaryMessengerResponseHandle* response_handle,
221 if (data->
count == 2) {
223 g_autoptr(GError)
error =
nullptr;
225 FL_METHOD_CODEC(codec), message, &
error);
226 EXPECT_NE(response,
nullptr);
227 EXPECT_EQ(
error,
nullptr);
229 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
234 FL_METHOD_ERROR_RESPONSE(response)),
235 "CANCEL-ERROR-MESSAGE");
237 g_main_loop_quit(data->
loop);
242 TEST(FlEventChannelTest, CancelException) {
243 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
252 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
265 g_main_loop_run(loop);
268 g_object_unref(channel);
288 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
294 TEST(FlEventChannelTest, Args) {
295 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
301 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
311 g_main_loop_run(loop);
314 g_object_unref(channel);
322 for (
int i = 0;
i < 5;
i++) {
324 g_autoptr(GError)
error =
nullptr;
326 EXPECT_EQ(
error,
nullptr);
335 FlBinaryMessenger* messenger,
336 const gchar* channel,
338 FlBinaryMessengerResponseHandle* response_handle,
343 g_autoptr(GError)
error =
nullptr;
344 g_autoptr(FlMethodResponse) response =
346 EXPECT_NE(response,
nullptr);
347 EXPECT_EQ(
error,
nullptr);
350 EXPECT_NE(
result,
nullptr);
351 EXPECT_EQ(
error,
nullptr);
361 if (data->
count == 5) {
362 g_main_loop_quit(data->
loop);
367 TEST(FlEventChannelTest, Test) {
368 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
377 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
389 g_main_loop_run(loop);
392 g_object_unref(channel);
397 TEST(FlEventChannelTest, ReuseChannel) {
398 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
408 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
413 g_object_unref(channel1);
417 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
429 g_main_loop_run(loop);
433 TEST(FlEventChannelTest, ReplaceChannel) {
434 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
444 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
450 messenger,
"test/standard-event", FL_METHOD_CODEC(codec));
462 g_main_loop_run(loop);