| 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/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_mock_binary_messenger.h"`

Go to the source code of this file.

## Functions
| TEST (FlBasicMessageChannelTest, SendMessageWithoutResponse)
| TEST (FlBasicMessageChannelTest, SendMessageWithResponse)
| TEST (FlBasicMessageChannelTest, SendFailure)
| TEST (FlBasicMessageChannelTest, ReceiveMessage)
| TEST (FlBasicMessageChannelTest, SendNullMessageWithResponse)
| TEST (FlBasicMessageChannelTest, CustomType)

## Function Documentation

## ◆ TEST() [1/6]

TEST | ( | FlBasicMessageChannelTest | ,
|  | CustomType |
| ) |  |

Definition at line 193 of file fl_basic_message_channel_test.cc.

193 {
194 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
195
196 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
197 fl_mock_binary_messenger_set_standard_message_channel(
198 messenger, "test",
199 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
200 gpointer user_data) { return fl_value_new_null(); },
201 nullptr);
202
203 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
204 g_autoptr(FlBasicMessageChannel) channel = fl_basic_message_channel_new(
205 FL_BINARY_MESSENGER(messenger), "test", FL_MESSAGE_CODEC(codec));
206 g_autoptr(FlValue) message = fl_value_new_custom(42, nullptr, nullptr);
207 fl_basic_message_channel_send(
208 channel, message, nullptr,
209 [](GObject* object, GAsyncResult* result, gpointer user_data) {
210 g_autoptr(GError) error = nullptr;
211 g_autoptr(FlValue) message = fl_basic_message_channel_send_finish(
212 FL_BASIC_MESSAGE_CHANNEL(object), result, &error);
213 EXPECT_EQ(message, nullptr);
214 EXPECT_NE(error, nullptr);
215 EXPECT_STREQ(error->message, "Custom value not implemented");
216
217 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
218 },
219 loop);
220
221 g_main_loop_run(loop);
222 }
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
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
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_standard_message_codec_new
G_MODULE_EXPORT FlStandardMessageCodec * fl_standard_message_codec_new()
Definition: fl_standard_message_codec.cc:637
fl_value_new_custom
G_MODULE_EXPORT FlValue * fl_value_new_custom(int type, gconstpointer value, GDestroyNotify destroy_notify)
Definition: fl_value.cc:374
fl_value_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42

References error, fl_basic_message_channel_new(), fl_basic_message_channel_send(), fl_basic_message_channel_send_finish(), fl_standard_message_codec_new(), fl_value_new_custom(), fl_value_new_null(), and user_data.

## ◆ TEST() [2/6]

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

Definition at line 116 of file fl_basic_message_channel_test.cc.

116 {
117 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
118
119 // Listen for messages from the engine.
120 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
121 g_autoptr(FlBasicMessageChannel) messages_channel =
122 fl_basic_message_channel_new(FL_BINARY_MESSENGER(messenger), "test",
123 FL_MESSAGE_CODEC(codec));
124 fl_basic_message_channel_set_message_handler(
125 messages_channel,
126 [](FlBasicMessageChannel* channel, FlValue* message,
127 FlBasicMessageChannelResponseHandle* response_handle,
128 gpointer user_data) {
129 EXPECT_NE(message, nullptr);
130 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_STRING);
131 EXPECT_STREQ(fl_value_get_string(message), "Marco!");
132
133 g_autoptr(GError) error = nullptr;
134 g_autoptr(FlValue) response = fl_value_new_string("Polo!");
135 EXPECT_TRUE(fl_basic_message_channel_respond(channel, response_handle,
136 response, &error));
137 EXPECT_EQ(error, nullptr);
138 },
139 nullptr, nullptr);
140
141 // Trigger the engine to send a message.
142 g_autoptr(FlValue) message = fl_value_new_string("Marco!");
143 gboolean called = FALSE;
144 fl_mock_binary_messenger_send_standard_message(
145 messenger, "test", message,
146 [](FlMockBinaryMessenger* messenger, FlValue* response,
147 gpointer user_data) {
148 gboolean* called = static_cast<gboolean*>(user_data);
149 *called = TRUE;
150
151 EXPECT_NE(response, nullptr);
152 EXPECT_EQ(fl_value_get_type(response), FL_VALUE_TYPE_STRING);
153 EXPECT_STREQ(fl_value_get_string(response), "Polo!");
154 },
155 &called);
156
157 EXPECT_TRUE(called);
158 }
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_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
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
fl_value_get_string
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:68

References error, fl_basic_message_channel_new(), fl_basic_message_channel_respond(), fl_basic_message_channel_set_message_handler(), fl_standard_message_codec_new(), fl_value_get_string(), fl_value_get_type(), fl_value_new_string(), FL_VALUE_TYPE_STRING, TRUE, and user_data.

## ◆ TEST() [3/6]

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

Definition at line 87 of file fl_basic_message_channel_test.cc.

87 {
88 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
89
90 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
91 fl_mock_binary_messenger_set_error_channel(messenger, "test", 42, "Error");
92
93 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
94 g_autoptr(FlBasicMessageChannel) channel = fl_basic_message_channel_new(
95 FL_BINARY_MESSENGER(messenger), "test", FL_MESSAGE_CODEC(codec));
96 g_autoptr(FlValue) message = fl_value_new_string("Hello World!");
97 fl_basic_message_channel_send(
98 channel, message, nullptr,
99 [](GObject* object, GAsyncResult* result, gpointer user_data) {
100 g_autoptr(GError) error = nullptr;
101 g_autoptr(FlValue) message = fl_basic_message_channel_send_finish(
102 FL_BASIC_MESSAGE_CHANNEL(object), result, &error);
103 EXPECT_EQ(message, nullptr);
104 EXPECT_NE(error, nullptr);
105 EXPECT_EQ(error->code, 42);
106 EXPECT_STREQ(error->message, "Error");
107
108 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
109 },
110 loop);
111
112 g_main_loop_run(loop);
113 }

References error, fl_basic_message_channel_new(), fl_basic_message_channel_send(), fl_basic_message_channel_send_finish(), fl_standard_message_codec_new(), fl_value_new_string(), and user_data.

## ◆ TEST() [4/6]

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

Definition at line 17 of file fl_basic_message_channel_test.cc.

17 {
18 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
19 gboolean called = FALSE;
20 fl_mock_binary_messenger_set_standard_message_channel(
21 messenger, "test",
22 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
23 gpointer user_data) {
24 gboolean* called = static_cast<gboolean*>(user_data);
25 *called = TRUE;
26
27 EXPECT_NE(message, nullptr);
28 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_STRING);
29 EXPECT_STREQ(fl_value_get_string(message), "Marco!");
30
31 // No response.
32 return static_cast<FlValue*>(nullptr);
33 },
34 &called);
35
36 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
37 g_autoptr(FlBasicMessageChannel) channel = fl_basic_message_channel_new(
38 FL_BINARY_MESSENGER(messenger), "test", FL_MESSAGE_CODEC(codec));
39 g_autoptr(FlValue) message = fl_value_new_string("Marco!");
40 fl_basic_message_channel_send(channel, message, nullptr, nullptr, nullptr);
41
42 EXPECT_TRUE(called);
43 }

References fl_basic_message_channel_new(), fl_basic_message_channel_send(), fl_standard_message_codec_new(), fl_value_get_string(), fl_value_get_type(), fl_value_new_string(), FL_VALUE_TYPE_STRING, TRUE, and user_data.

## ◆ TEST() [5/6]

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

Definition at line 47 of file fl_basic_message_channel_test.cc.

47 {
48 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
49
50 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
51 fl_mock_binary_messenger_set_standard_message_channel(
52 messenger, "test",
53 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
54 gpointer user_data) {
55 EXPECT_NE(message, nullptr);
56 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_STRING);
57 EXPECT_STREQ(fl_value_get_string(message), "Marco!");
58
59 return fl_value_new_string("Polo!");
60 },
61 nullptr);
62
63 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
64 g_autoptr(FlBasicMessageChannel) channel = fl_basic_message_channel_new(
65 FL_BINARY_MESSENGER(messenger), "test", FL_MESSAGE_CODEC(codec));
66 g_autoptr(FlValue) message = fl_value_new_string("Marco!");
67 fl_basic_message_channel_send(
68 channel, message, nullptr,
69 [](GObject* object, GAsyncResult* result, gpointer user_data) {
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), "Polo!");
78
79 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
80 },
81 loop);
82
83 g_main_loop_run(loop);
84 }

References error, fl_basic_message_channel_new(), fl_basic_message_channel_send(), fl_basic_message_channel_send_finish(), fl_standard_message_codec_new(), fl_value_get_string(), fl_value_get_type(), fl_value_new_string(), FL_VALUE_TYPE_STRING, and user_data.

## ◆ TEST() [6/6]

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

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(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
165 fl_mock_binary_messenger_set_standard_message_channel(
166 messenger, "test",
167 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
168 gpointer user_data) { return fl_value_new_null(); },
169 nullptr);
170
171 g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
172 g_autoptr(FlBasicMessageChannel) channel = fl_basic_message_channel_new(
173 FL_BINARY_MESSENGER(messenger), "test", FL_MESSAGE_CODEC(codec));
174 fl_basic_message_channel_send(
175 channel, nullptr, nullptr,
176 [](GObject* object, GAsyncResult* result, gpointer user_data) {
177 g_autoptr(GError) error = nullptr;
178 g_autoptr(FlValue) message = fl_basic_message_channel_send_finish(
179 FL_BASIC_MESSAGE_CHANNEL(object), result, &error);
180 EXPECT_NE(message, nullptr);
181 EXPECT_EQ(error, nullptr);
182
183 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_NULL);
184
185 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
186 },
187 loop);
188
189 g_main_loop_run(loop);
190 }
FL_VALUE_TYPE_NULL
@ FL_VALUE_TYPE_NULL
Definition: fl_value.h:64

References error, fl_basic_message_channel_new(), fl_basic_message_channel_send(), fl_basic_message_channel_send_finish(), fl_standard_message_codec_new(), fl_value_get_type(), fl_value_new_null(), FL_VALUE_TYPE_NULL, and user_data.