Add unit tests for Dart entrypoint arguments on Linux (flutter/engine#26951)

This commit is contained in:
George Wright
2021-06-25 11:05:24 -07:00
committed by GitHub
parent 3b90e054ef
commit f4aa3aad88
4 changed files with 68 additions and 0 deletions

View File

@@ -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();

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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_