Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions shell/platform/linux/fl_dart_project_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ TEST(FlDartProjectTest, EnableMirrors) {
G_GNUC_END_IGNORE_DEPRECATIONS
}

TEST(FlDartProjectTest, DartEntrypointArgs) {
g_autoptr(FlDartProject) project = fl_dart_project_new();

char** retrieved_args =
fl_dart_project_get_dart_entrypoint_arguments(project);

EXPECT_EQ(g_strv_length(retrieved_args), 0U);

GPtrArray* args_array = g_ptr_array_new();
g_ptr_array_add(args_array, (gpointer) "arg_one");
g_ptr_array_add(args_array, (gpointer) "arg_two");
g_ptr_array_add(args_array, (gpointer) "arg_three");
g_ptr_array_add(args_array, nullptr);
gchar** args = (gchar**)g_ptr_array_free(args_array, false);

fl_dart_project_set_dart_entrypoint_arguments(project, args);

retrieved_args = fl_dart_project_get_dart_entrypoint_arguments(project);

// FlDartProject should have done a deep copy of the args
EXPECT_NE(retrieved_args, args);

EXPECT_EQ(g_strv_length(retrieved_args), 3U);
}

TEST(FlDartProjectTest, SwitchesEmpty) {
g_autoptr(FlDartProject) project = fl_dart_project_new();

Expand Down
35 changes: 35 additions & 0 deletions shell/platform/linux/fl_engine_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,38 @@ TEST(FlEngineTest, SettingsPlugin) {

EXPECT_TRUE(called);
}

TEST(FlEngineTest, DartEntrypointArgs) {
g_autoptr(FlDartProject) project = fl_dart_project_new();

GPtrArray* args_array = g_ptr_array_new();
g_ptr_array_add(args_array, (gpointer) "arg_one");
g_ptr_array_add(args_array, (gpointer) "arg_two");
g_ptr_array_add(args_array, (gpointer) "arg_three");
g_ptr_array_add(args_array, nullptr);
gchar** args = (gchar**)g_ptr_array_free(args_array, false);

fl_dart_project_set_dart_entrypoint_arguments(project, args);

g_autoptr(FlEngine) engine = make_mock_engine_with_project(project);
FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);

bool called = false;
embedder_api->Initialize = MOCK_ENGINE_PROC(
Initialize, ([&called, &set_args = args](
size_t version, const FlutterRendererConfig* config,
const FlutterProjectArgs* args, void* user_data,
FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
called = true;
EXPECT_NE(set_args, args->dart_entrypoint_argv);
EXPECT_EQ(args->dart_entrypoint_argc, 3);

return kSuccess;
}));

g_autoptr(GError) error = nullptr;
EXPECT_TRUE(fl_engine_start(engine, &error));
EXPECT_EQ(error, nullptr);

EXPECT_TRUE(called);
}
4 changes: 4 additions & 0 deletions shell/platform/linux/testing/fl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ gchar* bytes_to_hex_string(GBytes* bytes) {

FlEngine* make_mock_engine() {
g_autoptr(FlDartProject) project = fl_dart_project_new();
return make_mock_engine_with_project(project);
}

FlEngine* make_mock_engine_with_project(FlDartProject* project) {
g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
g_autoptr(FlEngine) engine = fl_engine_new(project, FL_RENDERER(renderer));
g_autoptr(GError) engine_error = nullptr;
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/linux/testing/fl_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ gchar* bytes_to_hex_string(GBytes* bytes);
// Creates a mock engine that responds to platform messages.
FlEngine* make_mock_engine();

// Creates a mock engine using a specified FlDartProject that responds to
// platform messages.
FlEngine* make_mock_engine_with_project(FlDartProject* project);

G_END_DECLS

#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_TEST_H_