| Flutter Linux Embedder |

Classes | Functions
fl_event_channel_test.cc File Reference
`#include "gtest/gtest.h"`
`#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"`
`#include "flutter/shell/platform/linux/fl_engine_private.h"`
`#include "flutter/shell/platform/linux/fl_method_codec_private.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_event_channel.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"`
`#include "flutter/shell/platform/linux/testing/mock_renderer.h"`

Go to the source code of this file.

## Classes
struct | TestData

## Functions
static FlEngine * | make_mock_engine ()
static void | listen_channel (FlBinaryMessenger *messenger, FlValue *args)
static void | cancel_channel (FlBinaryMessenger *messenger, FlValue *args)
static FlMethodErrorResponse * | listen_listen_cb (FlEventChannel *channel, FlValue *args, gpointer user_data)
| TEST (FlEventChannelTest, Listen)
static FlMethodErrorResponse * | listen_exception_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)
| TEST (FlEventChannelTest, ListenException)
static FlMethodErrorResponse * | cancel_cancel_cb (FlEventChannel *channel, FlValue *args, gpointer user_data)
| TEST (FlEventChannelTest, Cancel)
static FlMethodErrorResponse * | cancel_exception_cancel_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)
| TEST (FlEventChannelTest, CancelException)
static FlMethodErrorResponse * | args_listen_cb (FlEventChannel *channel, FlValue *args, gpointer user_data)
static FlMethodErrorResponse * | args_cancel_cb (FlEventChannel *channel, FlValue *args, gpointer user_data)
| TEST (FlEventChannelTest, Args)
static FlMethodErrorResponse * | send_events_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)
| TEST (FlEventChannelTest, Test)
| TEST (FlEventChannelTest, ReuseChannel)
| TEST (FlEventChannelTest, ReplaceChannel)

## Function Documentation

## ◆ args_cancel_cb()

static FlMethodErrorResponse* args_cancel_cb | ( | FlEventChannel * | channel,
|  | FlValue * | args,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 281 of file fl_event_channel_test.cc.

283 {
284 g_autoptr(FlValue) expected_args = fl_value_new_string("CANCEL-ARGS");
285 EXPECT_TRUE(fl_value_equal(args, expected_args));
286
287 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
288
289 return nullptr;
290 }

References args, fl_value_equal(), fl_value_new_string(), and user_data.

Referenced by TEST().

## ◆ args_listen_cb()

static FlMethodErrorResponse* args_listen_cb | ( | FlEventChannel * | channel,
|  | FlValue * | args,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 271 of file fl_event_channel_test.cc.

273 {
274 g_autoptr(FlValue) expected_args = fl_value_new_string("LISTEN-ARGS");
275 EXPECT_TRUE(fl_value_equal(args, expected_args));
276
277 return nullptr;
278 }

References args, fl_value_equal(), and fl_value_new_string().

Referenced by TEST().

## ◆ cancel_cancel_cb()

static FlMethodErrorResponse* cancel_cancel_cb | ( | FlEventChannel * | channel,
|  | FlValue * | args,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 165 of file fl_event_channel_test.cc.

167 {
168 EXPECT_EQ(fl_value_get_type(args), FL_VALUE_TYPE_NULL);
169
170 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
171
172 return nullptr;
173 }

References args, fl_value_get_type(), FL_VALUE_TYPE_NULL, and user_data.

Referenced by TEST().

## ◆ cancel_channel()

static void cancel_channel | ( | FlBinaryMessenger * | messenger,
|  | FlValue * | args
| ) |  |
| static

Definition at line 53 of file fl_event_channel_test.cc.

53 {
54 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
55 g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
56 messenger, "test/standard-method", FL_METHOD_CODEC(codec));
57
58 // Trigger the engine to make a method call.
59 g_autoptr(FlValue) invoke_args = fl_value_new_list();
60 fl_value_append_take(invoke_args, fl_value_new_string("test/standard-event"));
61 fl_value_append_take(invoke_args, fl_value_new_string("cancel"));
62 g_autoptr(FlValue) value =
63 args != nullptr ? fl_value_ref(args) : fl_value_new_null();
64 fl_value_append(invoke_args, value);
65 fl_method_channel_invoke_method(channel, "InvokeMethod", invoke_args, nullptr,
66 nullptr, nullptr);
67 }

References args, fl_method_channel_invoke_method(), fl_method_channel_new(), fl_standard_method_codec_new(), fl_value_append(), fl_value_append_take(), fl_value_new_list(), fl_value_new_null(), fl_value_new_string(), fl_value_ref(), and value.

Referenced by TEST().

## ◆ cancel_exception_cancel_cb()

static FlMethodErrorResponse* cancel_exception_cancel_cb | ( | FlEventChannel * | channel,
|  | FlValue * | args,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 198 of file fl_event_channel_test.cc.

201 {
202 return fl_method_error_response_new("CANCEL-ERROR", "CANCEL-ERROR-MESSAGE",
203 nullptr);
204 }

References fl_method_error_response_new().

Referenced by TEST().

## ◆ cancel_exception_response_cb()

static void cancel_exception_response_cb | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | channel,
|  | GBytes * | message,
|  | FlBinaryMessengerResponseHandle * | response_handle,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 208 of file fl_event_channel_test.cc.

213 {
214 TestData* data = static_cast<TestData*>(user_data);
215
216 fl_binary_messenger_send_response(messenger, response_handle, nullptr,
217 nullptr);
218
219 data->count++;
220 if (data->count == 2) {
221 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
222 g_autoptr(GError) error = nullptr;
223 g_autoptr(FlMethodResponse) response = fl_method_codec_decode_response(
224 FL_METHOD_CODEC(codec), message, &error);
225 EXPECT_NE(response, nullptr);
226 EXPECT_EQ(error, nullptr);
227
228 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
229 EXPECT_STREQ(
230 fl_method_error_response_get_code(FL_METHOD_ERROR_RESPONSE(response)),
231 "CANCEL-ERROR");
232 EXPECT_STREQ(fl_method_error_response_get_message(
233 FL_METHOD_ERROR_RESPONSE(response)),
234 "CANCEL-ERROR-MESSAGE");
235
236 g_main_loop_quit(data->loop);
237 }
238 }

References TestData::count, error, fl_binary_messenger_send_response(), fl_method_codec_decode_response(), fl_method_error_response_get_code(), fl_method_error_response_get_message(), fl_standard_method_codec_new(), TestData::loop, and user_data.

Referenced by TEST().

## ◆ listen_channel()

static void listen_channel | ( | FlBinaryMessenger * | messenger,
|  | FlValue * | args
| ) |  |
| static

Definition at line 36 of file fl_event_channel_test.cc.

36 {
37 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
38 g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
39 messenger, "test/standard-method", FL_METHOD_CODEC(codec));
40
41 // Trigger the engine to make a method call.
42 g_autoptr(FlValue) invoke_args = fl_value_new_list();
43 fl_value_append_take(invoke_args, fl_value_new_string("test/standard-event"));
44 fl_value_append_take(invoke_args, fl_value_new_string("listen"));
45 g_autoptr(FlValue) value =
46 args != nullptr ? fl_value_ref(args) : fl_value_new_null();
47 fl_value_append(invoke_args, value);
48 fl_method_channel_invoke_method(channel, "InvokeMethod", invoke_args, nullptr,
49 nullptr, nullptr);
50 }

References args, fl_method_channel_invoke_method(), fl_method_channel_new(), fl_standard_method_codec_new(), fl_value_append(), fl_value_append_take(), fl_value_new_list(), fl_value_new_null(), fl_value_new_string(), fl_value_ref(), and value.

Referenced by TEST().

## ◆ listen_exception_listen_cb()

static FlMethodErrorResponse* listen_exception_listen_cb | ( | FlEventChannel * | channel,
|  | FlValue * | args,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 102 of file fl_event_channel_test.cc.

105 {
106 return fl_method_error_response_new("LISTEN-ERROR", "LISTEN-ERROR-MESSAGE",
107 nullptr);
108 }

References fl_method_error_response_new().

Referenced by TEST().

## ◆ listen_exception_response_cb()

static void listen_exception_response_cb | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | channel,
|  | GBytes * | message,
|  | FlBinaryMessengerResponseHandle * | response_handle,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 112 of file fl_event_channel_test.cc.

117 {
118 fl_binary_messenger_send_response(messenger, response_handle, nullptr,
119 nullptr);
120
121 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
122 g_autoptr(GError) error = nullptr;
123 g_autoptr(FlMethodResponse) response =
124 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
125 EXPECT_NE(response, nullptr);
126 EXPECT_EQ(error, nullptr);
127
128 EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
129 EXPECT_STREQ(
130 fl_method_error_response_get_code(FL_METHOD_ERROR_RESPONSE(response)),
131 "LISTEN-ERROR");
132 EXPECT_STREQ(
133 fl_method_error_response_get_message(FL_METHOD_ERROR_RESPONSE(response)),
134 "LISTEN-ERROR-MESSAGE");
135
136 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
137 }

References error, fl_binary_messenger_send_response(), fl_method_codec_decode_response(), fl_method_error_response_get_code(), fl_method_error_response_get_message(), fl_standard_method_codec_new(), and user_data.

Referenced by TEST().

## ◆ listen_listen_cb()

static FlMethodErrorResponse* listen_listen_cb | ( | FlEventChannel * | channel,
|  | FlValue * | args,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 70 of file fl_event_channel_test.cc.

72 {
73 EXPECT_EQ(fl_value_get_type(args), FL_VALUE_TYPE_NULL);
74
75 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
76
77 return nullptr;
78 }

References args, fl_value_get_type(), FL_VALUE_TYPE_NULL, and user_data.

Referenced by TEST().

## ◆ make_mock_engine()

static FlEngine* make_mock_engine | ( |  | ) |
| static

Definition at line 24 of file fl_event_channel_test.cc.

24 {
25 g_autoptr(FlDartProject) project = fl_dart_project_new();
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;
29 EXPECT_TRUE(fl_engine_start(engine, &engine_error));
30 EXPECT_EQ(engine_error, nullptr);
31
32 return static_cast<FlEngine*>(g_object_ref(engine));
33 }

References fl_dart_project_new(), fl_engine_new(), and fl_engine_start().

Referenced by TEST(), and test_lock_event().

## ◆ send_events_events_cb()

static void send_events_events_cb | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | channel,
|  | GBytes * | message,
|  | FlBinaryMessengerResponseHandle * | response_handle,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 333 of file fl_event_channel_test.cc.

338 {
339 TestData* data = static_cast<TestData*>(user_data);
340
341 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
342 g_autoptr(GError) error = nullptr;
343 g_autoptr(FlMethodResponse) response =
344 fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
345 EXPECT_NE(response, nullptr);
346 EXPECT_EQ(error, nullptr);
347
348 FlValue* result = fl_method_response_get_result(response, &error);
349 EXPECT_NE(result, nullptr);
350 EXPECT_EQ(error, nullptr);
351
352 EXPECT_EQ(fl_value_get_type(result), FL_VALUE_TYPE_INT);
353 EXPECT_EQ(fl_value_get_int(result), data->count);
354 data->count++;
355
356 fl_binary_messenger_send_response(messenger, response_handle, nullptr,
357 nullptr);
358
359 // Got all the results!
360 if (data->count == 5) {
361 g_main_loop_quit(data->loop);
362 }
363 }

References TestData::count, error, fl_binary_messenger_send_response(), fl_method_codec_decode_response(), fl_method_response_get_result(), fl_standard_method_codec_new(), fl_value_get_int(), fl_value_get_type(), FL_VALUE_TYPE_INT, TestData::loop, result, and user_data.

Referenced by TEST().

## ◆ send_events_listen_cb()

static FlMethodErrorResponse* send_events_listen_cb | ( | FlEventChannel * | channel,
|  | FlValue * | args,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 317 of file fl_event_channel_test.cc.

319 {
320 // Send some events.
321 for (int i = 0; i < 5; i++) {
322 g_autoptr(FlValue) event = fl_value_new_int(i);
323 g_autoptr(GError) error = nullptr;
324 EXPECT_TRUE(fl_event_channel_send(channel, event, nullptr, &error));
325 EXPECT_EQ(error, nullptr);
326 }
327
328 return nullptr;
329 }

References error, event, fl_event_channel_send(), fl_value_new_int(), and i.

Referenced by TEST().

## ◆ TEST() [1/8]

TEST | ( | FlEventChannelTest | ,
|  | Args |
| ) |  |

Definition at line 293 of file fl_event_channel_test.cc.

293 {
294 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
295
296 g_autoptr(FlEngine) engine = make_mock_engine();
297 FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
298 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
299 FlEventChannel* channel = fl_event_channel_new(
300 messenger, "test/standard-event", FL_METHOD_CODEC(codec));
301 fl_event_channel_set_stream_handlers(channel, args_listen_cb, args_cancel_cb,
302 loop, nullptr);
303
304 g_autoptr(FlValue) listen_args = fl_value_new_string("LISTEN-ARGS");
305 listen_channel(messenger, listen_args);
306 g_autoptr(FlValue) cancel_args = fl_value_new_string("CANCEL-ARGS");
307 cancel_channel(messenger, cancel_args);
308
309 // Blocks here until args_cancel_cb called.
310 g_main_loop_run(loop);
311
312 // Manually unref because the compiler complains 'channel' is unused.
313 g_object_unref(channel);
314 }

References args_cancel_cb(), args_listen_cb(), cancel_channel(), fl_binary_messenger_new(), fl_event_channel_new(), fl_event_channel_set_stream_handlers(), fl_standard_method_codec_new(), fl_value_new_string(), listen_channel(), and make_mock_engine().

## ◆ TEST() [2/8]

TEST | ( | FlEventChannelTest | ,
|  | Cancel |
| ) |  |

Definition at line 176 of file fl_event_channel_test.cc.

176 {
177 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
178
179 g_autoptr(FlEngine) engine = make_mock_engine();
180 FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
181 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
182 FlEventChannel* channel = fl_event_channel_new(
183 messenger, "test/standard-event", FL_METHOD_CODEC(codec));
184 fl_event_channel_set_stream_handlers(channel, nullptr, cancel_cancel_cb, loop,
185 nullptr);
186
187 listen_channel(messenger, nullptr);
188 cancel_channel(messenger, nullptr);
189
190 // Blocks here until cancel_cancel_cb called.
191 g_main_loop_run(loop);
192
193 // Manually unref because the compiler complains 'channel' is unused.
194 g_object_unref(channel);
195 }

References cancel_cancel_cb(), cancel_channel(), fl_binary_messenger_new(), fl_event_channel_new(), fl_event_channel_set_stream_handlers(), fl_standard_method_codec_new(), listen_channel(), and make_mock_engine().

## ◆ TEST() [3/8]

TEST | ( | FlEventChannelTest | ,
|  | CancelException |
| ) |  |

Definition at line 241 of file fl_event_channel_test.cc.

241 {
242 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
243 TestData data;
244 data.loop = loop;
245 data.count = 0;
246
247 g_autoptr(FlEngine) engine = make_mock_engine();
248 FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
249 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
250 FlEventChannel* channel = fl_event_channel_new(
251 messenger, "test/standard-event", FL_METHOD_CODEC(codec));
252 fl_event_channel_set_stream_handlers(
253 channel, nullptr, cancel_exception_cancel_cb, &data, nullptr);
254
255 // Listen for response to the engine.
256 fl_binary_messenger_set_message_handler_on_channel(
257 messenger, "test/responses", cancel_exception_response_cb, &data,
258 nullptr);
259
260 listen_channel(messenger, nullptr);
261 cancel_channel(messenger, nullptr);
262
263 // Blocks here until cancel_exception_response_cb called.
264 g_main_loop_run(loop);
265
266 // Manually unref because the compiler complains 'channel' is unused.
267 g_object_unref(channel);
268 }

References cancel_channel(), cancel_exception_cancel_cb(), cancel_exception_response_cb(), TestData::count, fl_binary_messenger_new(), fl_binary_messenger_set_message_handler_on_channel(), fl_event_channel_new(), fl_event_channel_set_stream_handlers(), fl_standard_method_codec_new(), listen_channel(), TestData::loop, and make_mock_engine().

## ◆ TEST() [4/8]

TEST | ( | FlEventChannelTest | ,
|  | Listen |
| ) |  |

Definition at line 81 of file fl_event_channel_test.cc.

81 {
82 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
83
84 g_autoptr(FlEngine) engine = make_mock_engine();
85 FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
86 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
87 FlEventChannel* channel = fl_event_channel_new(
88 messenger, "test/standard-event", FL_METHOD_CODEC(codec));
89 fl_event_channel_set_stream_handlers(channel, listen_listen_cb, nullptr, loop,
90 nullptr);
91
92 listen_channel(messenger, nullptr);
93
94 // Blocks here until listen_listen_cb called.
95 g_main_loop_run(loop);
96
97 // Manually unref because the compiler complains 'channel' is unused.
98 g_object_unref(channel);
99 }

References fl_binary_messenger_new(), fl_event_channel_new(), fl_event_channel_set_stream_handlers(), fl_standard_method_codec_new(), listen_channel(), listen_listen_cb(), and make_mock_engine().

## ◆ TEST() [5/8]

TEST | ( | FlEventChannelTest | ,
|  | ListenException |
| ) |  |

Definition at line 140 of file fl_event_channel_test.cc.

140 {
141 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
142
143 g_autoptr(FlEngine) engine = make_mock_engine();
144 FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
145 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
146 FlEventChannel* channel = fl_event_channel_new(
147 messenger, "test/standard-event", FL_METHOD_CODEC(codec));
148 fl_event_channel_set_stream_handlers(channel, listen_exception_listen_cb,
149 nullptr, loop, nullptr);
150
151 // Listen for response to the engine.
152 fl_binary_messenger_set_message_handler_on_channel(
153 messenger, "test/responses", listen_exception_response_cb, loop, nullptr);
154
155 listen_channel(messenger, nullptr);
156
157 // Blocks here until listen_exception_response_cb called.
158 g_main_loop_run(loop);
159
160 // Manually unref because the compiler complains 'channel' is unused.
161 g_object_unref(channel);
162 }

References fl_binary_messenger_new(), fl_binary_messenger_set_message_handler_on_channel(), fl_event_channel_new(), fl_event_channel_set_stream_handlers(), fl_standard_method_codec_new(), listen_channel(), listen_exception_listen_cb(), listen_exception_response_cb(), and make_mock_engine().

## ◆ TEST() [6/8]

TEST | ( | FlEventChannelTest | ,
|  | ReplaceChannel |
| ) |  |

Definition at line 432 of file fl_event_channel_test.cc.

432 {
433 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
434 TestData data;
435 data.loop = loop;
436 data.count = 0;
437
438 // Register an event channel.
439 g_autoptr(FlEngine) engine = make_mock_engine();
440 FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
441 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
442 FlEventChannel* channel1 = fl_event_channel_new(
443 messenger, "test/standard-event", FL_METHOD_CODEC(codec));
444 fl_event_channel_set_stream_handlers(channel1, send_events_listen_cb, nullptr,
445 &data, nullptr);
446
447 // Register a second channel with the same name.
448 g_autoptr(FlEventChannel) channel2 = fl_event_channel_new(
449 messenger, "test/standard-event", FL_METHOD_CODEC(codec));
450 fl_event_channel_set_stream_handlers(channel2, send_events_listen_cb, nullptr,
451 &data, nullptr);
452
453 // Listen for events from the engine.
454 fl_binary_messenger_set_message_handler_on_channel(
455 messenger, "test/events", send_events_events_cb, &data, nullptr);
456
457 listen_channel(messenger, nullptr);
458 cancel_channel(messenger, nullptr);
459
460 // Blocks here until send_events_events_cb receives the last event.
461 g_main_loop_run(loop);
462 }

References cancel_channel(), TestData::count, fl_binary_messenger_new(), fl_binary_messenger_set_message_handler_on_channel(), fl_event_channel_new(), fl_event_channel_set_stream_handlers(), fl_standard_method_codec_new(), listen_channel(), TestData::loop, make_mock_engine(), send_events_events_cb(), and send_events_listen_cb().

## ◆ TEST() [7/8]

TEST | ( | FlEventChannelTest | ,
|  | ReuseChannel |
| ) |  |

Definition at line 396 of file fl_event_channel_test.cc.

396 {
397 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
398 TestData data;
399 data.loop = loop;
400 data.count = 0;
401
402 // Register an event channel.
403 g_autoptr(FlEngine) engine = make_mock_engine();
404 FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
405 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
406 FlEventChannel* channel1 = fl_event_channel_new(
407 messenger, "test/standard-event", FL_METHOD_CODEC(codec));
408 fl_event_channel_set_stream_handlers(channel1, send_events_listen_cb, nullptr,
409 &data, nullptr);
410
411 // Remove this channel
412 g_object_unref(channel1);
413
414 // Register a second channel with the same name.
415 g_autoptr(FlEventChannel) channel2 = fl_event_channel_new(
416 messenger, "test/standard-event", FL_METHOD_CODEC(codec));
417 fl_event_channel_set_stream_handlers(channel2, send_events_listen_cb, nullptr,
418 &data, nullptr);
419
420 // Listen for events from the engine.
421 fl_binary_messenger_set_message_handler_on_channel(
422 messenger, "test/events", send_events_events_cb, &data, nullptr);
423
424 listen_channel(messenger, nullptr);
425 cancel_channel(messenger, nullptr);
426
427 // Blocks here until send_events_events_cb receives the last event.
428 g_main_loop_run(loop);
429 }

References cancel_channel(), TestData::count, fl_binary_messenger_new(), fl_binary_messenger_set_message_handler_on_channel(), fl_event_channel_new(), fl_event_channel_set_stream_handlers(), fl_standard_method_codec_new(), listen_channel(), TestData::loop, make_mock_engine(), send_events_events_cb(), and send_events_listen_cb().

## ◆ TEST() [8/8]

TEST | ( | FlEventChannelTest | ,
|  | Test |
| ) |  |

Definition at line 366 of file fl_event_channel_test.cc.

366 {
367 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
368 TestData data;
369 data.loop = loop;
370 data.count = 0;
371
372 g_autoptr(FlEngine) engine = make_mock_engine();
373 FlBinaryMessenger* messenger = fl_binary_messenger_new(engine);
374 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
375 FlEventChannel* channel = fl_event_channel_new(
376 messenger, "test/standard-event", FL_METHOD_CODEC(codec));
377 fl_event_channel_set_stream_handlers(channel, send_events_listen_cb, nullptr,
378 &data, nullptr);
379
380 // Listen for events from the engine.
381 fl_binary_messenger_set_message_handler_on_channel(
382 messenger, "test/events", send_events_events_cb, &data, nullptr);
383
384 listen_channel(messenger, nullptr);
385 cancel_channel(messenger, nullptr);
386
387 // Blocks here until send_events_events_cb receives the last event.
388 g_main_loop_run(loop);
389
390 // Manually unref because the compiler complains 'channel' is unused.
391 g_object_unref(channel);
392 }

References cancel_channel(), TestData::count, fl_binary_messenger_new(), fl_binary_messenger_set_message_handler_on_channel(), fl_event_channel_new(), fl_event_channel_set_stream_handlers(), fl_standard_method_codec_new(), listen_channel(), TestData::loop, make_mock_engine(), send_events_events_cb(), and send_events_listen_cb().

args_listen_cb
static FlMethodErrorResponse * args_listen_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
Definition: fl_event_channel_test.cc:271
event
FlKeyEvent * event
Definition: fl_key_channel_responder.cc:118
TestData::loop
GMainLoop * loop
Definition: fl_event_channel_test.cc:19
fl_method_channel_new
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
Definition: fl_method_channel.cc:112
fl_method_error_response_new
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)
Definition: fl_method_response.cc:144
listen_exception_response_cb
static void listen_exception_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
Definition: fl_event_channel_test.cc:112
TestData::count
int count
Definition: fl_event_channel_test.cc:20
fl_standard_method_codec_new
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
Definition: fl_standard_method_codec.cc:291
fl_value_new_list
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:349
i
int i
Definition: fl_socket_accessible.cc:18
cancel_channel
static void cancel_channel(FlBinaryMessenger *messenger, FlValue *args)
Definition: fl_event_channel_test.cc:53
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
fl_value_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251
cancel_exception_cancel_cb
static FlMethodErrorResponse * cancel_exception_cancel_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
Definition: fl_event_channel_test.cc:198
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:50
fl_method_response_get_result
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)
Definition: fl_method_response.cc:82
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
fl_event_channel_send
G_MODULE_EXPORT gboolean fl_event_channel_send(FlEventChannel *self, FlValue *event, GCancellable *cancellable, GError **error)
Definition: fl_event_channel.cc:196
fl_method_error_response_get_message
const G_MODULE_EXPORT gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:166
fl_binary_messenger_new
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
Definition: fl_binary_messenger.cc:399
FL_VALUE_TYPE_NULL
@ FL_VALUE_TYPE_NULL
Definition: fl_value.h:65
make_mock_engine
static FlEngine * make_mock_engine()
Definition: fl_event_channel_test.cc:24
fl_value_get_int
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:668
fl_value_ref
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
Definition: fl_value.cc:394
args_cancel_cb
static FlMethodErrorResponse * args_cancel_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
Definition: fl_event_channel_test.cc:281
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
fl_engine_new
FlEngine * fl_engine_new(FlDartProject *project, FlRenderer *renderer)
Definition: fl_engine.cc:458
listen_exception_listen_cb
static FlMethodErrorResponse * listen_exception_listen_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
Definition: fl_event_channel_test.cc:102
listen_listen_cb
static FlMethodErrorResponse * listen_listen_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
Definition: fl_event_channel_test.cc:70
fl_event_channel_new
G_MODULE_EXPORT FlEventChannel * fl_event_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
Definition: fl_event_channel.cc:159
fl_binary_messenger_set_message_handler_on_channel
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)
Definition: fl_binary_messenger.cc:416
fl_value_append_take
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:600
fl_method_codec_decode_response
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
Definition: fl_method_codec.cc:62
fl_method_channel_invoke_method
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_method_channel.cc:162
fl_value_equal
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
FL_VALUE_TYPE_INT
@ FL_VALUE_TYPE_INT
Definition: fl_value.h:67
send_events_listen_cb
static FlMethodErrorResponse * send_events_listen_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
Definition: fl_event_channel_test.cc:317
result
GAsyncResult * result
Definition: fl_text_input_plugin.cc:106
cancel_cancel_cb
static FlMethodErrorResponse * cancel_cancel_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
Definition: fl_event_channel_test.cc:165
fl_event_channel_set_stream_handlers
G_MODULE_EXPORT void fl_event_channel_set_stream_handlers(FlEventChannel *self, FlEventChannelHandler listen_handler, FlEventChannelHandler cancel_handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_event_channel.cc:181
fl_method_error_response_get_code
const G_MODULE_EXPORT gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:160
TestData
Definition: fl_event_channel_test.cc:18
listen_channel
static void listen_channel(FlBinaryMessenger *messenger, FlValue *args)
Definition: fl_event_channel_test.cc:36
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
send_events_events_cb
static void send_events_events_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
Definition: fl_event_channel_test.cc:333
fl_engine_start
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:474
fl_value_append
G_MODULE_EXPORT void fl_value_append(FlValue *self, FlValue *value)
Definition: fl_value.cc:592
fl_binary_messenger_send_response
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(FlBinaryMessenger *self, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
Definition: fl_binary_messenger.cc:430
cancel_exception_response_cb
static void cancel_exception_response_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
Definition: fl_event_channel_test.cc:208
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276