From c6d9b0b1e733e51a08f903fe0318fa662f459818 Mon Sep 17 00:00:00 2001 From: George Wright Date: Fri, 16 Jul 2021 16:02:15 -0700 Subject: [PATCH 1/2] Add unit tests for Dart entrypoint arguments on Windows --- .../client_wrapper/dart_project_unittests.cc | 13 +++++++++++++ .../windows/flutter_project_bundle_unittests.cc | 17 +++++++++++++++++ .../windows/flutter_windows_engine_unittests.cc | 9 ++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/shell/platform/windows/client_wrapper/dart_project_unittests.cc b/shell/platform/windows/client_wrapper/dart_project_unittests.cc index 618d131963df7..ff608f7c37aa3 100644 --- a/shell/platform/windows/client_wrapper/dart_project_unittests.cc +++ b/shell/platform/windows/client_wrapper/dart_project_unittests.cc @@ -42,4 +42,17 @@ TEST_F(DartProjectTest, ProjectWithCustomPaths) { EXPECT_EQ(GetProjectAotLibraryPath(project), L"lib\\file.so"); } +TEST_F(DartProjectTest, DartEntrypointArguments) { + DartProject project(L"test"); + + std::vector test_arguments = { "arg1", "arg2", "arg3" }; + project.set_dart_entrypoint_arguments(test_arguments); + + auto returned_arguments = project.dart_entrypoint_arguments(); + EXPECT_EQ(returned_arguments.size(), 3U); + EXPECT_EQ(returned_arguments[0], "arg1"); + EXPECT_EQ(returned_arguments[1], "arg2"); + EXPECT_EQ(returned_arguments[2], "arg3"); +} + } // namespace flutter diff --git a/shell/platform/windows/flutter_project_bundle_unittests.cc b/shell/platform/windows/flutter_project_bundle_unittests.cc index c149fbe85c8b5..8f7257a5d0919 100644 --- a/shell/platform/windows/flutter_project_bundle_unittests.cc +++ b/shell/platform/windows/flutter_project_bundle_unittests.cc @@ -47,6 +47,23 @@ TEST(FlutterProjectBundle, SwitchesEmpty) { EXPECT_EQ(project.GetSwitches().size(), 0); } +TEST(FlutterProjectBundle, DartEntrypointArguments) { + FlutterDesktopEngineProperties properties = {}; + properties.assets_path = L"foo\\flutter_assets"; + properties.icu_data_path = L"foo\\icudtl.dat"; + + std::vector test_arguments = { "arg1", "arg2" }; + properties.dart_entrypoint_argc = test_arguments.size(); + properties.dart_entrypoint_argv = test_arguments.data(); + + FlutterProjectBundle project(properties); + + std::vector retrieved_arguments = project.dart_entrypoint_arguments(); + EXPECT_EQ(retrieved_arguments.size(), 2U); + EXPECT_EQ(retrieved_arguments[0], "arg1"); + EXPECT_EQ(retrieved_arguments[1], "arg2"); +} + #ifndef FLUTTER_RELEASE TEST(FlutterProjectBundle, Switches) { FlutterDesktopEngineProperties properties = {}; diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index 56809ea62c5c0..5f6c3a08a9479 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -19,6 +19,11 @@ std::unique_ptr GetTestEngine() { properties.assets_path = L"C:\\foo\\flutter_assets"; properties.icu_data_path = L"C:\\foo\\icudtl.dat"; properties.aot_library_path = L"C:\\foo\\aot.so"; + + std::vector test_arguments = { "arg1", "arg2" }; + properties.dart_entrypoint_argc = test_arguments.size(); + properties.dart_entrypoint_argv = test_arguments.data(); + FlutterProjectBundle project(properties); auto engine = std::make_unique(project); @@ -52,7 +57,9 @@ TEST(FlutterWindowsEngine, RunDoesExpectedInitialization) { // Spot-check arguments. EXPECT_STREQ(args->assets_path, "C:\\foo\\flutter_assets"); EXPECT_STREQ(args->icu_data_path, "C:\\foo\\icudtl.dat"); - EXPECT_EQ(args->dart_entrypoint_argc, 0); + EXPECT_EQ(args->dart_entrypoint_argc, 2U); + EXPECT_EQ(strcmp(args->dart_entrypoint_argv[0], "arg1"), 0); + EXPECT_EQ(strcmp(args->dart_entrypoint_argv[1], "arg2"), 0); EXPECT_NE(args->platform_message_callback, nullptr); EXPECT_NE(args->custom_task_runners, nullptr); EXPECT_EQ(args->custom_dart_entrypoint, nullptr); From a710242ecfb83cc17e306f14873ce91e87959c58 Mon Sep 17 00:00:00 2001 From: George Wright Date: Mon, 19 Jul 2021 10:29:32 -0700 Subject: [PATCH 2/2] formatting --- .../windows/client_wrapper/dart_project_unittests.cc | 2 +- shell/platform/windows/flutter_project_bundle_unittests.cc | 5 +++-- shell/platform/windows/flutter_windows_engine_unittests.cc | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/shell/platform/windows/client_wrapper/dart_project_unittests.cc b/shell/platform/windows/client_wrapper/dart_project_unittests.cc index ff608f7c37aa3..bfc151947f673 100644 --- a/shell/platform/windows/client_wrapper/dart_project_unittests.cc +++ b/shell/platform/windows/client_wrapper/dart_project_unittests.cc @@ -45,7 +45,7 @@ TEST_F(DartProjectTest, ProjectWithCustomPaths) { TEST_F(DartProjectTest, DartEntrypointArguments) { DartProject project(L"test"); - std::vector test_arguments = { "arg1", "arg2", "arg3" }; + std::vector test_arguments = {"arg1", "arg2", "arg3"}; project.set_dart_entrypoint_arguments(test_arguments); auto returned_arguments = project.dart_entrypoint_arguments(); diff --git a/shell/platform/windows/flutter_project_bundle_unittests.cc b/shell/platform/windows/flutter_project_bundle_unittests.cc index 8f7257a5d0919..607d1cc707d99 100644 --- a/shell/platform/windows/flutter_project_bundle_unittests.cc +++ b/shell/platform/windows/flutter_project_bundle_unittests.cc @@ -52,13 +52,14 @@ TEST(FlutterProjectBundle, DartEntrypointArguments) { properties.assets_path = L"foo\\flutter_assets"; properties.icu_data_path = L"foo\\icudtl.dat"; - std::vector test_arguments = { "arg1", "arg2" }; + std::vector test_arguments = {"arg1", "arg2"}; properties.dart_entrypoint_argc = test_arguments.size(); properties.dart_entrypoint_argv = test_arguments.data(); FlutterProjectBundle project(properties); - std::vector retrieved_arguments = project.dart_entrypoint_arguments(); + std::vector retrieved_arguments = + project.dart_entrypoint_arguments(); EXPECT_EQ(retrieved_arguments.size(), 2U); EXPECT_EQ(retrieved_arguments[0], "arg1"); EXPECT_EQ(retrieved_arguments[1], "arg2"); diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index 5f6c3a08a9479..5e24d26e628b0 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -20,7 +20,7 @@ std::unique_ptr GetTestEngine() { properties.icu_data_path = L"C:\\foo\\icudtl.dat"; properties.aot_library_path = L"C:\\foo\\aot.so"; - std::vector test_arguments = { "arg1", "arg2" }; + std::vector test_arguments = {"arg1", "arg2"}; properties.dart_entrypoint_argc = test_arguments.size(); properties.dart_entrypoint_argv = test_arguments.data();