 |
Flutter Linux Embedder
|
|
Go to the source code of this file.
|
| TEST (FlEngineTest, WindowMetrics) |
|
| TEST (FlEngineTest, MousePointer) |
|
| TEST (FlEngineTest, PointerPanZoom) |
|
| TEST (FlEngineTest, DispatchSemanticsAction) |
|
| TEST (FlEngineTest, PlatformMessage) |
|
| TEST (FlEngineTest, PlatformMessageResponse) |
|
| TEST (FlEngineTest, SettingsPlugin) |
|
void | on_pre_engine_restart_cb (FlEngine *engine, gpointer user_data) |
|
void | on_pre_engine_restart_destroy_notify (gpointer user_data) |
|
| TEST (FlEngineTest, OnPreEngineRestart) |
|
| TEST (FlEngineTest, DartEntrypointArgs) |
|
| TEST (FlEngineTest, Locales) |
|
| TEST (FlEngineTest, SwitchesEmpty) |
|
| TEST (FlEngineTest, SendWindowStateEvent) |
|
| TEST (FlEngineTest, Switches) |
|
◆ on_pre_engine_restart_cb()
void on_pre_engine_restart_cb |
( |
FlEngine * |
engine, |
|
|
gpointer |
user_data |
|
) |
| |
◆ on_pre_engine_restart_destroy_notify()
void on_pre_engine_restart_destroy_notify |
( |
gpointer |
user_data | ) |
|
◆ TEST() [1/13]
TEST |
( |
FlEngineTest |
, |
|
|
DartEntrypointArgs |
|
|
) |
| |
Definition at line 329 of file fl_engine_test.cc.
332 GPtrArray* args_array = g_ptr_array_new();
333 g_ptr_array_add(args_array,
const_cast<char*
>(
"arg_one"));
334 g_ptr_array_add(args_array,
const_cast<char*
>(
"arg_two"));
335 g_ptr_array_add(args_array,
const_cast<char*
>(
"arg_three"));
336 g_ptr_array_add(args_array,
nullptr);
337 gchar**
args =
reinterpret_cast<gchar**
>(g_ptr_array_free(args_array,
false));
341 g_autoptr(FlEngine)
engine = make_mock_engine_with_project(project);
345 embedder_api->Initialize = MOCK_ENGINE_PROC(
346 Initialize, ([&called, &set_args =
args](
347 size_t version,
const FlutterRendererConfig* config,
349 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
351 EXPECT_NE(set_args,
args->dart_entrypoint_argv);
352 EXPECT_EQ(
args->dart_entrypoint_argc, 3);
357 g_autoptr(GError)
error =
nullptr;
359 EXPECT_EQ(
error,
nullptr);
References args, engine, error, fl_dart_project_new(), fl_dart_project_set_dart_entrypoint_arguments(), fl_engine_get_embedder_api(), fl_engine_start(), and user_data.
◆ TEST() [2/13]
TEST |
( |
FlEngineTest |
, |
|
|
DispatchSemanticsAction |
|
|
) |
| |
Definition at line 117 of file fl_engine_test.cc.
122 embedder_api->DispatchSemanticsAction = MOCK_ENGINE_PROC(
123 DispatchSemanticsAction,
124 ([&called](
auto engine, uint64_t
id, FlutterSemanticsAction action,
125 const uint8_t* data,
size_t data_length) {
126 EXPECT_EQ(
id,
static_cast<uint64_t
>(42));
127 EXPECT_EQ(action, kFlutterSemanticsActionTap);
128 EXPECT_EQ(data_length,
static_cast<size_t>(4));
129 EXPECT_EQ(data[0],
't');
130 EXPECT_EQ(data[1],
'e');
131 EXPECT_EQ(data[2],
's');
132 EXPECT_EQ(data[3],
't');
138 g_autoptr(GError)
error =
nullptr;
140 EXPECT_EQ(
error,
nullptr);
141 g_autoptr(GBytes) data = g_bytes_new_static(
"test", 4);
References engine, error, fl_engine_dispatch_semantics_action(), fl_engine_get_embedder_api(), fl_engine_start(), and make_mock_engine().
◆ TEST() [3/13]
TEST |
( |
FlEngineTest |
, |
|
|
Locales |
|
|
) |
| |
Definition at line 364 of file fl_engine_test.cc.
365 gchar* initial_language = g_strdup(g_getenv(
"LANGUAGE"));
366 g_setenv(
"LANGUAGE",
"de:en_US",
TRUE);
369 g_autoptr(FlEngine)
engine = make_mock_engine_with_project(project);
373 embedder_api->UpdateLocales = MOCK_ENGINE_PROC(
374 UpdateLocales, ([&called](
auto engine,
const FlutterLocale** locales,
375 size_t locales_count) {
378 EXPECT_EQ(locales_count,
static_cast<size_t>(4));
380 EXPECT_STREQ(locales[0]->language_code,
"de");
381 EXPECT_STREQ(locales[0]->country_code,
nullptr);
382 EXPECT_STREQ(locales[0]->script_code,
nullptr);
383 EXPECT_STREQ(locales[0]->variant_code,
nullptr);
385 EXPECT_STREQ(locales[1]->language_code,
"en");
386 EXPECT_STREQ(locales[1]->country_code,
"US");
387 EXPECT_STREQ(locales[1]->script_code,
nullptr);
388 EXPECT_STREQ(locales[1]->variant_code,
nullptr);
390 EXPECT_STREQ(locales[2]->language_code,
"en");
391 EXPECT_STREQ(locales[2]->country_code,
nullptr);
392 EXPECT_STREQ(locales[2]->script_code,
nullptr);
393 EXPECT_STREQ(locales[2]->variant_code,
nullptr);
395 EXPECT_STREQ(locales[3]->language_code,
"C");
396 EXPECT_STREQ(locales[3]->country_code,
nullptr);
397 EXPECT_STREQ(locales[3]->script_code,
nullptr);
398 EXPECT_STREQ(locales[3]->variant_code,
nullptr);
403 g_autoptr(GError)
error =
nullptr;
405 EXPECT_EQ(
error,
nullptr);
409 if (initial_language) {
410 g_setenv(
"LANGUAGE", initial_language,
TRUE);
412 g_unsetenv(
"LANGUAGE");
414 g_free(initial_language);
References engine, error, fl_dart_project_new(), fl_engine_get_embedder_api(), fl_engine_start(), and TRUE.
◆ TEST() [4/13]
TEST |
( |
FlEngineTest |
, |
|
|
MousePointer |
|
|
) |
| |
Definition at line 45 of file fl_engine_test.cc.
50 embedder_api->SendPointerEvent = MOCK_ENGINE_PROC(
52 ([&called](
auto engine,
const FlutterPointerEvent* events,
53 size_t events_count) {
55 EXPECT_EQ(events_count,
static_cast<size_t>(1));
56 EXPECT_EQ(events[0].phase, kDown);
57 EXPECT_EQ(events[0].timestamp,
static_cast<size_t>(1234567890));
58 EXPECT_EQ(events[0].x, 800);
59 EXPECT_EQ(events[0].y, 600);
60 EXPECT_EQ(events[0].device,
static_cast<int32_t
>(0));
61 EXPECT_EQ(events[0].signal_kind, kFlutterPointerSignalKindScroll);
62 EXPECT_EQ(events[0].scroll_delta_x, 1.2);
63 EXPECT_EQ(events[0].scroll_delta_y, -3.4);
64 EXPECT_EQ(events[0].device_kind, kFlutterPointerDeviceKindMouse);
65 EXPECT_EQ(events[0].buttons, kFlutterPointerButtonMouseSecondary);
70 g_autoptr(GError)
error =
nullptr;
72 EXPECT_EQ(
error,
nullptr);
74 -3.4, kFlutterPointerButtonMouseSecondary);
References engine, error, fl_engine_get_embedder_api(), fl_engine_send_mouse_pointer_event(), fl_engine_start(), and make_mock_engine().
◆ TEST() [5/13]
TEST |
( |
FlEngineTest |
, |
|
|
OnPreEngineRestart |
|
|
) |
| |
Definition at line 281 of file fl_engine_test.cc.
285 OnPreEngineRestartCallback
callback;
286 void* callback_user_data;
289 embedder_api->Initialize = MOCK_ENGINE_PROC(
290 Initialize, ([&
callback, &callback_user_data, &called](
291 size_t version,
const FlutterRendererConfig* config,
293 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
301 g_autoptr(GError)
error =
nullptr;
303 EXPECT_EQ(
error,
nullptr);
326 EXPECT_EQ(count, 11);
References args, callback, engine, error, fl_engine_get_embedder_api(), fl_engine_set_on_pre_engine_restart_handler(), fl_engine_start(), make_mock_engine(), on_pre_engine_restart_cb(), on_pre_engine_restart_destroy_notify(), and user_data.
◆ TEST() [6/13]
TEST |
( |
FlEngineTest |
, |
|
|
PlatformMessage |
|
|
) |
| |
Definition at line 149 of file fl_engine_test.cc.
154 FlutterEngineSendPlatformMessageFnPtr old_handler =
155 embedder_api->SendPlatformMessage;
156 embedder_api->SendPlatformMessage = MOCK_ENGINE_PROC(
158 ([&called, old_handler](
auto engine,
159 const FlutterPlatformMessage* message) {
160 if (strcmp(message->channel,
"test") != 0) {
161 return old_handler(engine, message);
166 EXPECT_EQ(message->message_size,
static_cast<size_t>(4));
167 EXPECT_EQ(message->message[0],
't');
168 EXPECT_EQ(message->message[1],
'e');
169 EXPECT_EQ(message->message[2],
's');
170 EXPECT_EQ(message->message[3],
't');
175 g_autoptr(GError)
error =
nullptr;
177 EXPECT_EQ(
error,
nullptr);
178 g_autoptr(GBytes) message = g_bytes_new_static(
"test", 4);
References engine, error, fl_engine_get_embedder_api(), fl_engine_send_platform_message(), fl_engine_start(), and make_mock_engine().
◆ TEST() [7/13]
TEST |
( |
FlEngineTest |
, |
|
|
PlatformMessageResponse |
|
|
) |
| |
Definition at line 186 of file fl_engine_test.cc.
191 embedder_api->SendPlatformMessageResponse = MOCK_ENGINE_PROC(
192 SendPlatformMessageResponse,
194 const FlutterPlatformMessageResponseHandle* handle,
195 const uint8_t* data,
size_t data_length) {
200 reinterpret_cast<const FlutterPlatformMessageResponseHandle*
>(42));
201 EXPECT_EQ(data_length,
static_cast<size_t>(4));
202 EXPECT_EQ(data[0],
't');
203 EXPECT_EQ(data[1],
'e');
204 EXPECT_EQ(data[2],
's');
205 EXPECT_EQ(data[3],
't');
210 g_autoptr(GError)
error =
nullptr;
212 EXPECT_EQ(
error,
nullptr);
213 g_autoptr(GBytes) response = g_bytes_new_static(
"test", 4);
215 engine,
reinterpret_cast<const FlutterPlatformMessageResponseHandle*
>(42),
217 EXPECT_EQ(
error,
nullptr);
References engine, error, fl_engine_get_embedder_api(), fl_engine_send_platform_message_response(), fl_engine_start(), and make_mock_engine().
◆ TEST() [8/13]
TEST |
( |
FlEngineTest |
, |
|
|
PointerPanZoom |
|
|
) |
| |
Definition at line 80 of file fl_engine_test.cc.
85 embedder_api->SendPointerEvent = MOCK_ENGINE_PROC(
87 ([&called](
auto engine,
const FlutterPointerEvent* events,
88 size_t events_count) {
90 EXPECT_EQ(events_count,
static_cast<size_t>(1));
91 EXPECT_EQ(events[0].phase, kPanZoomUpdate);
92 EXPECT_EQ(events[0].timestamp,
static_cast<size_t>(1234567890));
93 EXPECT_EQ(events[0].x, 800);
94 EXPECT_EQ(events[0].y, 600);
95 EXPECT_EQ(events[0].device,
static_cast<int32_t
>(1));
96 EXPECT_EQ(events[0].signal_kind, kFlutterPointerSignalKindNone);
97 EXPECT_EQ(events[0].pan_x, 1.5);
98 EXPECT_EQ(events[0].pan_y, 2.5);
99 EXPECT_EQ(events[0].scale, 3.5);
100 EXPECT_EQ(events[0].rotation, 4.5);
101 EXPECT_EQ(events[0].device_kind, kFlutterPointerDeviceKindTrackpad);
102 EXPECT_EQ(events[0].buttons, 0);
107 g_autoptr(GError)
error =
nullptr;
109 EXPECT_EQ(
error,
nullptr);
111 kPanZoomUpdate, 1.5, 2.5, 3.5, 4.5);
References engine, error, fl_engine_get_embedder_api(), fl_engine_send_pointer_pan_zoom_event(), fl_engine_start(), and make_mock_engine().
◆ TEST() [9/13]
TEST |
( |
FlEngineTest |
, |
|
|
SendWindowStateEvent |
|
|
) |
| |
Definition at line 428 of file fl_engine_test.cc.
434 embedder_api->SendPlatformMessage = MOCK_ENGINE_PROC(
436 ([&called, &
state](
auto engine,
const FlutterPlatformMessage* message) {
437 EXPECT_STREQ(message->channel,
"flutter/lifecycle");
440 g_autoptr(GBytes) data =
441 g_bytes_new(message->message, message->message_size);
442 g_autoptr(GError)
error =
nullptr;
444 FL_MESSAGE_CODEC(codec), data, &
error);
References flutter::AppLifecycleStateToString(), engine, error, fl_engine_get_embedder_api(), fl_engine_send_window_state_event(), fl_message_codec_decode_message(), fl_string_codec_new(), fl_value_get_string(), flutter::kHidden, flutter::kInactive, flutter::kResumed, make_mock_engine(), and state.
◆ TEST() [10/13]
TEST |
( |
FlEngineTest |
, |
|
|
SettingsPlugin |
|
|
) |
| |
Definition at line 223 of file fl_engine_test.cc.
228 embedder_api->SendPlatformMessage = MOCK_ENGINE_PROC(
230 ([&called](
auto engine,
const FlutterPlatformMessage* message) {
233 EXPECT_STREQ(message->channel,
"flutter/settings");
236 g_autoptr(GBytes) data =
237 g_bytes_new(message->message, message->message_size);
238 g_autoptr(GError)
error =
nullptr;
240 FL_MESSAGE_CODEC(codec), data, &
error);
241 EXPECT_NE(settings,
nullptr);
242 EXPECT_EQ(
error,
nullptr);
246 EXPECT_NE(text_scale_factor,
nullptr);
249 FlValue* always_use_24hr_format =
251 EXPECT_NE(always_use_24hr_format,
nullptr);
257 EXPECT_NE(platform_brightness,
nullptr);
263 g_autoptr(GError)
error =
nullptr;
265 EXPECT_EQ(
error,
nullptr);
References engine, error, fl_engine_get_embedder_api(), fl_engine_start(), fl_json_message_codec_new(), fl_message_codec_decode_message(), fl_value_get_type(), fl_value_lookup_string(), FL_VALUE_TYPE_BOOL, FL_VALUE_TYPE_FLOAT, FL_VALUE_TYPE_STRING, and make_mock_engine().
◆ TEST() [11/13]
TEST |
( |
FlEngineTest |
, |
|
|
Switches |
|
|
) |
| |
Definition at line 465 of file fl_engine_test.cc.
468 setenv(
"FLUTTER_ENGINE_SWITCHES",
"2", 1);
469 setenv(
"FLUTTER_ENGINE_SWITCH_1",
"abc", 1);
470 setenv(
"FLUTTER_ENGINE_SWITCH_2",
"foo=\"bar, baz\"", 1);
473 EXPECT_EQ(switches->len, 2U);
474 EXPECT_STREQ(
static_cast<const char*
>(g_ptr_array_index(switches, 0)),
476 EXPECT_STREQ(
static_cast<const char*
>(g_ptr_array_index(switches, 1)),
477 "--foo=\"bar, baz\"");
479 unsetenv(
"FLUTTER_ENGINE_SWITCHES");
480 unsetenv(
"FLUTTER_ENGINE_SWITCH_1");
481 unsetenv(
"FLUTTER_ENGINE_SWITCH_2");
References engine, fl_engine_get_switches(), and make_mock_engine().
◆ TEST() [12/13]
TEST |
( |
FlEngineTest |
, |
|
|
SwitchesEmpty |
|
|
) |
| |
◆ TEST() [13/13]
TEST |
( |
FlEngineTest |
, |
|
|
WindowMetrics |
|
|
) |
| |
Definition at line 20 of file fl_engine_test.cc.
25 embedder_api->SendWindowMetricsEvent = MOCK_ENGINE_PROC(
26 SendWindowMetricsEvent,
27 ([&called](
auto engine,
const FlutterWindowMetricsEvent*
event) {
29 EXPECT_EQ(
event->width,
static_cast<size_t>(3840));
30 EXPECT_EQ(
event->height,
static_cast<size_t>(2160));
31 EXPECT_EQ(
event->pixel_ratio, 2.0);
36 g_autoptr(GError)
error =
nullptr;
38 EXPECT_EQ(
error,
nullptr);
References engine, error, event, fl_engine_get_embedder_api(), fl_engine_send_window_metrics_event(), fl_engine_start(), and make_mock_engine().
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
void fl_engine_send_mouse_pointer_event(FlEngine *self, FlutterPointerPhase phase, size_t timestamp, double x, double y, double scroll_delta_x, double scroll_delta_y, int64_t buttons)
void on_pre_engine_restart_destroy_notify(gpointer user_data)
typedefG_BEGIN_DECLS struct _FlValue FlValue
G_MODULE_EXPORT FlJsonMessageCodec * fl_json_message_codec_new()
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
void fl_engine_dispatch_semantics_action(FlEngine *self, uint64_t id, FlutterSemanticsAction action, GBytes *data)
void fl_engine_send_window_metrics_event(FlEngine *self, size_t width, size_t height, double pixel_ratio)
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
const G_MODULE_EXPORT gchar * fl_value_get_string(FlValue *self)
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)
void fl_engine_send_pointer_pan_zoom_event(FlEngine *self, size_t timestamp, double x, double y, FlutterPointerPhase phase, double pan_x, double pan_y, double scale, double rotation)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(FlDartProject *self, char **argv)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
void fl_engine_send_platform_message(FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
void on_pre_engine_restart_cb(FlEngine *engine, gpointer user_data)
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
gboolean fl_engine_start(FlEngine *self, GError **error)
void fl_engine_send_window_state_event(FlEngine *self, gboolean visible, gboolean focused)
constexpr const char * AppLifecycleStateToString(AppLifecycleState state)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
GPtrArray * fl_engine_get_switches(FlEngine *self)
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
void fl_engine_set_on_pre_engine_restart_handler(FlEngine *self, FlEngineOnPreEngineRestartHandler handler, gpointer user_data, GDestroyNotify destroy_notify)