Flutter Linux Embedder
fl_event_channel_test.cc File Reference

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 282 of file fl_event_channel_test.cc.

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

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 272 of file fl_event_channel_test.cc.

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

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 166 of file fl_event_channel_test.cc.

168  {
170 
171  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
172 
173  return nullptr;
174 }

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 54 of file fl_event_channel_test.cc.

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

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 199 of file fl_event_channel_test.cc.

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

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 209 of file fl_event_channel_test.cc.

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

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 37 of file fl_event_channel_test.cc.

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

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 103 of file fl_event_channel_test.cc.

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

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 113 of file fl_event_channel_test.cc.

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

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 71 of file fl_event_channel_test.cc.

73  {
75 
76  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
77 
78  return nullptr;
79 }

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 =
28  fl_engine_new_with_renderer(project, FL_RENDERER(renderer));
29  g_autoptr(GError) engine_error = nullptr;
30  EXPECT_TRUE(fl_engine_start(engine, &engine_error));
31  EXPECT_EQ(engine_error, nullptr);
32 
33  return static_cast<FlEngine*>(g_object_ref(engine));
34 }

References fl_dart_project_new(), fl_engine_new_with_renderer(), 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 334 of file fl_event_channel_test.cc.

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

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 318 of file fl_event_channel_test.cc.

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

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 294 of file fl_event_channel_test.cc.

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

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 177 of file fl_event_channel_test.cc.

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

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 242 of file fl_event_channel_test.cc.

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

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 82 of file fl_event_channel_test.cc.

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

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 141 of file fl_event_channel_test.cc.

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

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 433 of file fl_event_channel_test.cc.

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

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 397 of file fl_event_channel_test.cc.

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

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 367 of file fl_event_channel_test.cc.

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

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:272
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:113
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:54
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:199
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_engine_new_with_renderer
FlEngine * fl_engine_new_with_renderer(FlDartProject *project, FlRenderer *renderer)
Definition: fl_engine.cc:479
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:282
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
listen_exception_listen_cb
static FlMethodErrorResponse * listen_exception_listen_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
Definition: fl_event_channel_test.cc:103
listen_listen_cb
static FlMethodErrorResponse * listen_listen_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
Definition: fl_event_channel_test.cc:71
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:318
result
GAsyncResult * result
Definition: fl_text_input_handler.cc:106
cancel_cancel_cb
static FlMethodErrorResponse * cancel_cancel_cb(FlEventChannel *channel, FlValue *args, gpointer user_data)
Definition: fl_event_channel_test.cc:166
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:37
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:334
fl_engine_start
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:509
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:209
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