| Flutter Linux Embedder |

Functions
fl_basic_message_channel_test.cc File Reference
`#include "gtest/gtest.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h"`
`#include "flutter/shell/platform/embedder/embedder.h"`
`#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.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/public/flutter_linux/fl_message_codec.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h"`
`#include "flutter/shell/platform/linux/testing/fl_test.h"`
`#include "flutter/shell/platform/linux/testing/mock_renderer.h"`

Go to the source code of this file.

## Functions
| TEST (FlBasicMessageChannelTest, SendMessageWithoutResponse)
static void | echo_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
| TEST (FlBasicMessageChannelTest, SendMessageWithResponse)
static void | failure_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
| TEST (FlBasicMessageChannelTest, SendFailure)
static void | message_cb (FlBasicMessageChannel *channel, FlValue *message, FlBasicMessageChannelResponseHandle *response_handle, gpointer user_data)
static void | response_cb (FlBasicMessageChannel *channel, FlValue *message, FlBasicMessageChannelResponseHandle *response_handle, gpointer user_data)
| TEST (FlBasicMessageChannelTest, ReceiveMessage)
static void | null_message_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
| TEST (FlBasicMessageChannelTest, SendNullMessageWithResponse)

## Function Documentation

## ◆ echo_response_cb()

static void echo_response_cb | ( | GObject * | object,
|  | GAsyncResult * | result,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 67 of file fl_basic_message_channel_test.cc.

69 {
70 g_autoptr(GError) error = nullptr;
71 g_autoptr(FlValue) message = fl_basic_message_channel_send_finish(
72 FL_BASIC_MESSAGE_CHANNEL(object), result, &error);
73 EXPECT_NE(message, nullptr);
74 EXPECT_EQ(error, nullptr);
75
76 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_STRING);
77 EXPECT_STREQ(fl_value_get_string(message), "Hello World!");
78
79 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
80 }

References error, fl_basic_message_channel_send_finish(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, result, and user_data.

Referenced by TEST().

## ◆ failure_response_cb()

static void failure_response_cb | ( | GObject * | object,
|  | GAsyncResult * | result,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 100 of file fl_basic_message_channel_test.cc.

102 {
103 g_autoptr(GError) error = nullptr;
104 g_autoptr(FlValue) message = fl_basic_message_channel_send_finish(
105 FL_BASIC_MESSAGE_CHANNEL(object), result, &error);
106 EXPECT_EQ(message, nullptr);
107 EXPECT_NE(error, nullptr);
108
109 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
110 }

References error, fl_basic_message_channel_send_finish(), result, and user_data.

Referenced by TEST().

## ◆ message_cb()

static void message_cb | ( | FlBasicMessageChannel * | channel,
|  | FlValue * | message,
|  | FlBasicMessageChannelResponseHandle * | response_handle,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 130 of file fl_basic_message_channel_test.cc.

133 {
134 EXPECT_NE(message, nullptr);
135 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_STRING);
136 EXPECT_STREQ(fl_value_get_string(message), "Marco!");
137
138 g_autoptr(GError) error = nullptr;
139 g_autoptr(FlValue) response = fl_value_new_string("Polo!");
140 EXPECT_TRUE(fl_basic_message_channel_respond(channel, response_handle,
141 response, &error));
142 EXPECT_EQ(error, nullptr);
143 }

References error, fl_basic_message_channel_respond(), fl_value_get_string(), fl_value_get_type(), fl_value_new_string(), and FL_VALUE_TYPE_STRING.

Referenced by TEST().

## ◆ null_message_response_cb()

static void null_message_response_cb | ( | GObject * | object,
|  | GAsyncResult * | result,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 196 of file fl_basic_message_channel_test.cc.

198 {
199 g_autoptr(GError) error = nullptr;
200 g_autoptr(FlValue) message = fl_basic_message_channel_send_finish(
201 FL_BASIC_MESSAGE_CHANNEL(object), result, &error);
202 EXPECT_NE(message, nullptr);
203 EXPECT_EQ(error, nullptr);
204
205 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_NULL);
206
207 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
208 }

References error, fl_basic_message_channel_send_finish(), fl_value_get_type(), FL_VALUE_TYPE_NULL, result, and user_data.

Referenced by TEST().

## ◆ response_cb()

static void response_cb | ( | FlBasicMessageChannel * | channel,
|  | FlValue * | message,
|  | FlBasicMessageChannelResponseHandle * | response_handle,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 147 of file fl_basic_message_channel_test.cc.

150 {
151 EXPECT_NE(message, nullptr);
152 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_STRING);
153 EXPECT_STREQ(fl_value_get_string(message), "Polo!");
154
155 fl_basic_message_channel_respond(channel, response_handle, nullptr, nullptr);
156
157 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
158 }

References fl_basic_message_channel_respond(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, and user_data.

Referenced by TEST().

## ◆ TEST() [1/5]

TEST | ( | FlBasicMessageChannelTest | ,
|  | ReceiveMessage |
| ) |  |

Definition at line 161 of file fl_basic_message_channel_test.cc.

161 {
162 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
163
164 g_autoptr(FlEngine) engine = make_mock_engine();
165 g_autoptr(FlBinaryMessenger) messenger = fl_binary_messenger_new(engine);
166
167 // Listen for messages from the engine.
168 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
169 g_autoptr(FlBasicMessageChannel) messages_channel =
170 fl_basic_message_channel_new(messenger, "test/messages",
171 FL_MESSAGE_CODEC(codec));
172 fl_basic_message_channel_set_message_handler(messages_channel, message_cb,
173 nullptr, nullptr);
174
175 // Listen for response from the engine.
176 g_autoptr(FlBasicMessageChannel) responses_channel =
177 fl_basic_message_channel_new(messenger, "test/responses",
178 FL_MESSAGE_CODEC(codec));
179 fl_basic_message_channel_set_message_handler(responses_channel, response_cb,
180 loop, nullptr);
181
182 // Triggger the engine to send a message.
183 g_autoptr(FlBasicMessageChannel) control_channel =
184 fl_basic_message_channel_new(messenger, "test/send-message",
185 FL_MESSAGE_CODEC(codec));
186 g_autoptr(FlValue) message = fl_value_new_string("Marco!");
187 fl_basic_message_channel_send(control_channel, message, nullptr, nullptr,
188 nullptr);
189
190 // Blocks here until response_cb is called.
191 g_main_loop_run(loop);
192 }

References fl_basic_message_channel_new(), fl_basic_message_channel_send(), fl_basic_message_channel_set_message_handler(), fl_binary_messenger_new(), fl_standard_message_codec_new(), fl_value_new_string(), make_mock_engine(), message_cb(), and response_cb().

## ◆ TEST() [2/5]

TEST | ( | FlBasicMessageChannelTest | ,
|  | SendFailure |
| ) |  |

Definition at line 113 of file fl_basic_message_channel_test.cc.

113 {
114 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
115
116 g_autoptr(FlEngine) engine = make_mock_engine();
117 g_autoptr(FlBinaryMessenger) messenger = fl_binary_messenger_new(engine);
118 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
119 g_autoptr(FlBasicMessageChannel) channel = fl_basic_message_channel_new(
120 messenger, "test/failure", FL_MESSAGE_CODEC(codec));
121 g_autoptr(FlValue) message = fl_value_new_string("Hello World!");
122 fl_basic_message_channel_send(channel, message, nullptr, failure_response_cb,
123 loop);
124
125 // Blocks here until failure_response_cb is called.
126 g_main_loop_run(loop);
127 }

References failure_response_cb(), fl_basic_message_channel_new(), fl_basic_message_channel_send(), fl_binary_messenger_new(), fl_standard_message_codec_new(), fl_value_new_string(), and make_mock_engine().

## ◆ TEST() [3/5]

TEST | ( | FlBasicMessageChannelTest | ,
|  | SendMessageWithoutResponse |
| ) |  |

Definition at line 22 of file fl_basic_message_channel_test.cc.

22 {
23 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
24
25 g_autoptr(FlEngine) engine = make_mock_engine();
26 FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
27
28 bool called = false;
29 FlutterEngineSendPlatformMessageFnPtr old_handler =
30 embedder_api->SendPlatformMessage;
31 embedder_api->SendPlatformMessage = MOCK_ENGINE_PROC(
32 SendPlatformMessage,
33 ([&called, old_handler](auto engine,
34 const FlutterPlatformMessage* message) {
35 if (strcmp(message->channel, "test") != 0) {
36 return old_handler(engine, message);
37 }
38
39 called = true;
40 EXPECT_EQ(message->response_handle, nullptr);
41
42 g_autoptr(GBytes) message_bytes =
43 g_bytes_new(message->message, message->message_size);
44 g_autoptr(FlStandardMessageCodec) codec =
45 fl_standard_message_codec_new();
46 FlValue* message_value = fl_message_codec_decode_message(
47 FL_MESSAGE_CODEC(codec), message_bytes, nullptr);
48 EXPECT_EQ(fl_value_get_type(message_value), FL_VALUE_TYPE_STRING);
49 EXPECT_STREQ(fl_value_get_string(message_value), "Hello World!");
50
51 return kSuccess;
52 }));
53
54 g_autoptr(FlBinaryMessenger) messenger = fl_binary_messenger_new(engine);
55 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
56 g_autoptr(FlBasicMessageChannel) channel =
57 fl_basic_message_channel_new(messenger, "test", FL_MESSAGE_CODEC(codec));
58 g_autoptr(FlValue) message = fl_value_new_string("Hello World!");
59 fl_basic_message_channel_send(channel, message, nullptr, nullptr, loop);
60
61 EXPECT_TRUE(called);
62 }

References fl_basic_message_channel_new(), fl_basic_message_channel_send(), fl_binary_messenger_new(), fl_engine_get_embedder_api(), fl_message_codec_decode_message(), fl_standard_message_codec_new(), fl_value_get_string(), fl_value_get_type(), fl_value_new_string(), FL_VALUE_TYPE_STRING, and make_mock_engine().

## ◆ TEST() [4/5]

TEST | ( | FlBasicMessageChannelTest | ,
|  | SendMessageWithResponse |
| ) |  |

Definition at line 83 of file fl_basic_message_channel_test.cc.

83 {
84 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
85
86 g_autoptr(FlEngine) engine = make_mock_engine();
87 g_autoptr(FlBinaryMessenger) messenger = fl_binary_messenger_new(engine);
88 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
89 g_autoptr(FlBasicMessageChannel) channel = fl_basic_message_channel_new(
90 messenger, "test/echo", FL_MESSAGE_CODEC(codec));
91 g_autoptr(FlValue) message = fl_value_new_string("Hello World!");
92 fl_basic_message_channel_send(channel, message, nullptr, echo_response_cb,
93 loop);
94
95 // Blocks here until echo_response_cb is called.
96 g_main_loop_run(loop);
97 }

References echo_response_cb(), fl_basic_message_channel_new(), fl_basic_message_channel_send(), fl_binary_messenger_new(), fl_standard_message_codec_new(), fl_value_new_string(), and make_mock_engine().

## ◆ TEST() [5/5]

TEST | ( | FlBasicMessageChannelTest | ,
|  | SendNullMessageWithResponse |
| ) |  |

Definition at line 211 of file fl_basic_message_channel_test.cc.

211 {
212 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
213
214 g_autoptr(FlEngine) engine = make_mock_engine();
215 g_autoptr(FlBinaryMessenger) messenger = fl_binary_messenger_new(engine);
216 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
217 g_autoptr(FlBasicMessageChannel) channel = fl_basic_message_channel_new(
218 messenger, "test/echo", FL_MESSAGE_CODEC(codec));
219 fl_basic_message_channel_send(channel, nullptr, nullptr,
220 null_message_response_cb, loop);
221
222 // Blocks here until null_message_response_cb is called.
223 g_main_loop_run(loop);
224 }

References fl_basic_message_channel_new(), fl_basic_message_channel_send(), fl_binary_messenger_new(), fl_standard_message_codec_new(), make_mock_engine(), and null_message_response_cb().

fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:637
response_cb
static void response_cb(FlBasicMessageChannel *channel, FlValue *message, FlBasicMessageChannelResponseHandle *response_handle, gpointer user_data)
Definition: fl_basic_message_channel_test.cc:147
fl_standard_message_codec_new
G_MODULE_EXPORT FlStandardMessageCodec * fl_standard_message_codec_new()
Definition: fl_standard_message_codec.cc:637
fl_basic_message_channel_send
G_MODULE_EXPORT void fl_basic_message_channel_send(FlBasicMessageChannel *self, FlValue *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_basic_message_channel.cc:226
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
failure_response_cb
static void failure_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_basic_message_channel_test.cc:100
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
null_message_response_cb
static void null_message_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_basic_message_channel_test.cc:196
fl_value_get_string
const G_MODULE_EXPORT gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
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_basic_message_channel_set_message_handler
G_MODULE_EXPORT void fl_basic_message_channel_set_message_handler(FlBasicMessageChannel *self, FlBasicMessageChannelMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_basic_message_channel.cc:176
fl_message_codec_decode_message
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)
Definition: fl_message_codec.cc:33
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:69
echo_response_cb
static void echo_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_basic_message_channel_test.cc:67
result
GAsyncResult * result
Definition: fl_text_input_handler.cc:106
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_basic_message_channel_respond
G_MODULE_EXPORT gboolean fl_basic_message_channel_respond(FlBasicMessageChannel *self, FlBasicMessageChannelResponseHandle *response_handle, FlValue *message, GError **error)
Definition: fl_basic_message_channel.cc:204
fl_basic_message_channel_send_finish
G_MODULE_EXPORT FlValue * fl_basic_message_channel_send_finish(FlBasicMessageChannel *self, GAsyncResult *result, GError **error)
Definition: fl_basic_message_channel.cc:253
fl_basic_message_channel_new
G_MODULE_EXPORT FlBasicMessageChannel * fl_basic_message_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMessageCodec *codec)
Definition: fl_basic_message_channel.cc:154
message_cb
static void message_cb(FlBasicMessageChannel *channel, FlValue *message, FlBasicMessageChannelResponseHandle *response_handle, gpointer user_data)
Definition: fl_basic_message_channel_test.cc:130
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276