Flutter Windows Embedder
flutter_project_bundle_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 #include "gtest/gtest.h"
7 
8 namespace flutter {
9 namespace testing {
10 
11 TEST(FlutterProjectBundle, BasicPropertiesAbsolutePaths) {
12  FlutterDesktopEngineProperties properties = {};
13  properties.assets_path = L"C:\\foo\\flutter_assets";
14  properties.icu_data_path = L"C:\\foo\\icudtl.dat";
15 
16  FlutterProjectBundle project(properties);
17 
18  EXPECT_TRUE(project.HasValidPaths());
19  EXPECT_EQ(project.assets_path().string(), "C:\\foo\\flutter_assets");
20  EXPECT_EQ(project.icu_path().string(), "C:\\foo\\icudtl.dat");
21 }
22 
23 TEST(FlutterProjectBundle, BasicPropertiesRelativePaths) {
24  FlutterDesktopEngineProperties properties = {};
25  properties.assets_path = L"foo\\flutter_assets";
26  properties.icu_data_path = L"foo\\icudtl.dat";
27 
28  FlutterProjectBundle project(properties);
29 
30  EXPECT_TRUE(project.HasValidPaths());
31  EXPECT_TRUE(project.assets_path().is_absolute());
32  EXPECT_EQ(project.assets_path().filename().string(), "flutter_assets");
33  EXPECT_TRUE(project.icu_path().is_absolute());
34  EXPECT_EQ(project.icu_path().filename().string(), "icudtl.dat");
35 }
36 
37 TEST(FlutterProjectBundle, EnableFlutterGpu) {
38  FlutterDesktopEngineProperties properties = {};
39  properties.assets_path = L"foo\\flutter_assets";
40  properties.icu_data_path = L"foo\\icudtl.dat";
41 
42  FlutterProjectBundle default_project(properties);
43  EXPECT_FALSE(default_project.enable_flutter_gpu());
44 
45  properties.enable_flutter_gpu = true;
46  FlutterProjectBundle project(properties);
47  EXPECT_TRUE(project.enable_flutter_gpu());
48 }
49 
50 TEST(FlutterProjectBundle, SwitchesEmpty) {
51  FlutterDesktopEngineProperties properties = {};
52  properties.assets_path = L"foo\\flutter_assets";
53  properties.icu_data_path = L"foo\\icudtl.dat";
54 
55  // Clear the main environment variable, since test order is not guaranteed.
56  _putenv_s("FLUTTER_ENGINE_SWITCHES", "");
57 
58  FlutterProjectBundle project(properties);
59 
60  EXPECT_EQ(project.GetSwitches().size(), 0);
61 }
62 
63 TEST(FlutterProjectBundle, DartEntrypointArguments) {
64  FlutterDesktopEngineProperties properties = {};
65  properties.assets_path = L"foo\\flutter_assets";
66  properties.icu_data_path = L"foo\\icudtl.dat";
67 
68  std::vector<const char*> test_arguments = {"arg1", "arg2"};
69  properties.dart_entrypoint_argc = test_arguments.size();
70  properties.dart_entrypoint_argv = test_arguments.data();
71 
72  FlutterProjectBundle project(properties);
73 
74  std::vector<std::string> retrieved_arguments =
75  project.dart_entrypoint_arguments();
76  EXPECT_EQ(retrieved_arguments.size(), 2U);
77  EXPECT_EQ(retrieved_arguments[0], "arg1");
78  EXPECT_EQ(retrieved_arguments[1], "arg2");
79 }
80 
81 #ifndef FLUTTER_RELEASE
83  FlutterDesktopEngineProperties properties = {};
84  properties.assets_path = L"foo\\flutter_assets";
85  properties.icu_data_path = L"foo\\icudtl.dat";
86 
87  _putenv_s("FLUTTER_ENGINE_SWITCHES", "2");
88  _putenv_s("FLUTTER_ENGINE_SWITCH_1", "abc");
89  _putenv_s("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"");
90 
91  FlutterProjectBundle project(properties);
92 
93  std::vector<std::string> switches = project.GetSwitches();
94  EXPECT_EQ(switches.size(), 2);
95  EXPECT_EQ(switches[0], "--abc");
96  EXPECT_EQ(switches[1], "--foo=\"bar, baz\"");
97 }
98 #endif // !FLUTTER_RELEASE
99 
100 } // namespace testing
101 } // namespace flutter
const std::filesystem::path & assets_path()
const std::vector< std::string > GetSwitches()
const std::filesystem::path & icu_path()
const std::vector< std::string > & dart_entrypoint_arguments() const
TEST(AccessibilityBridgeWindows, GetParent)