Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bf3dd15

Browse files
author
George Wright
committed
Fix unit test
1 parent b174d63 commit bf3dd15

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

shell/platform/windows/client_wrapper/flutter_engine_unittests.cc

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ class TestFlutterWindowsApi : public testing::StubFlutterWindowsApi {
2020
FlutterDesktopEngineRef EngineCreate(
2121
const FlutterDesktopEngineProperties& engine_properties) {
2222
create_called_ = true;
23-
engine_properties_ = engine_properties;
23+
24+
// dart_entrypoint_argv is only guaranteed to exist until this method returns, so copy it here for unit test validation
25+
for (int i = 0; i < engine_properties.dart_entrypoint_argc; i++) {
26+
dart_entrypoint_arguments_.push_back(std::string(engine_properties.dart_entrypoint_argv[i]));
27+
}
2428
return reinterpret_cast<FlutterDesktopEngineRef>(1);
2529
}
2630

@@ -50,14 +54,14 @@ class TestFlutterWindowsApi : public testing::StubFlutterWindowsApi {
5054

5155
bool reload_fonts_called() { return reload_fonts_called_; }
5256

53-
FlutterDesktopEngineProperties& engine_properties() { return engine_properties_; }
57+
const std::vector<std::string>& dart_entrypoint_arguments() { return dart_entrypoint_arguments_; }
5458

5559
private:
5660
bool create_called_ = false;
5761
bool run_called_ = false;
5862
bool destroy_called_ = false;
5963
bool reload_fonts_called_ = false;
60-
FlutterDesktopEngineProperties engine_properties_;
64+
std::vector<std::string> dart_entrypoint_arguments_;
6165
};
6266

6367
} // namespace
@@ -127,18 +131,19 @@ TEST(FlutterEngineTest, GetMessenger) {
127131

128132
TEST(FlutterEngineTest, DartEntrypointArgs) {
129133
DartProject project(L"data");
130-
std::vector<std::string> arguments;
131-
arguments.push_back("one");
132-
arguments.push_back("two");
134+
std::vector<std::string> arguments(2);
135+
arguments[0] = "one";
136+
arguments[1] = "two";
133137
project.set_dart_entrypoint_arguments(arguments);
134138
testing::ScopedStubFlutterWindowsApi scoped_api_stub(
135139
std::make_unique<TestFlutterWindowsApi>());
136140
auto test_api = static_cast<TestFlutterWindowsApi*>(scoped_api_stub.stub());
137141

138142
FlutterEngine engine(project);
139-
EXPECT_TRUE(arguments[0] == test_api->engine_properties().dart_entrypoint_argv[0]);
140-
EXPECT_TRUE(arguments[1] == test_api->engine_properties().dart_entrypoint_argv[1]);
141-
EXPECT_EQ(2, test_api->engine_properties().dart_entrypoint_argc);
143+
const std::vector<std::string>& arguments_ref = test_api->dart_entrypoint_arguments();
144+
EXPECT_TRUE(arguments[0] == arguments_ref[0]);
145+
EXPECT_TRUE(arguments[1] == arguments_ref[1]);
146+
EXPECT_EQ(2, arguments_ref.size());
142147
}
143148

144149
} // namespace flutter

0 commit comments

Comments
 (0)