blob: 359e9159932b3b6cd677cade34fa695022ecab47 [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/flutter_project_bundle.h"
#include "gtest/gtest.h"
namespace flutter {
namespace testing {
TEST(FlutterProjectBundle, BasicPropertiesAbsolutePaths) {
FlutterDesktopEngineProperties properties = {};
properties.assets_path = L"C:\\foo\\flutter_assets";
properties.icu_data_path = L"C:\\foo\\icudtl.dat";
FlutterProjectBundle project(properties);
EXPECT_TRUE(project.HasValidPaths());
EXPECT_EQ(project.assets_path().string(), "C:\\foo\\flutter_assets");
EXPECT_EQ(project.icu_path().string(), "C:\\foo\\icudtl.dat");
}
TEST(FlutterProjectBundle, BasicPropertiesRelativePaths) {
FlutterDesktopEngineProperties properties = {};
properties.assets_path = L"foo\\flutter_assets";
properties.icu_data_path = L"foo\\icudtl.dat";
FlutterProjectBundle project(properties);
EXPECT_TRUE(project.HasValidPaths());
EXPECT_TRUE(project.assets_path().is_absolute());
EXPECT_EQ(project.assets_path().filename().string(), "flutter_assets");
EXPECT_TRUE(project.icu_path().is_absolute());
EXPECT_EQ(project.icu_path().filename().string(), "icudtl.dat");
}
TEST(FlutterProjectBundle, SwitchesEmpty) {
FlutterDesktopEngineProperties properties = {};
properties.assets_path = L"foo\\flutter_assets";
properties.icu_data_path = L"foo\\icudtl.dat";
// Clear the main environment variable, since test order is not guaranteed.
_putenv_s("FLUTTER_ENGINE_SWITCHES", "");
FlutterProjectBundle project(properties);
EXPECT_EQ(project.GetSwitches().size(), 0);
}
#ifndef FLUTTER_RELEASE
TEST(FlutterProjectBundle, Switches) {
FlutterDesktopEngineProperties properties = {};
properties.assets_path = L"foo\\flutter_assets";
properties.icu_data_path = L"foo\\icudtl.dat";
_putenv_s("FLUTTER_ENGINE_SWITCHES", "2");
_putenv_s("FLUTTER_ENGINE_SWITCH_1", "abc");
_putenv_s("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"");
FlutterProjectBundle project(properties);
std::vector<std::string> switches = project.GetSwitches();
EXPECT_EQ(switches.size(), 2);
EXPECT_EQ(switches[0], "--abc");
EXPECT_EQ(switches[1], "--foo=\"bar, baz\"");
}
TEST(FlutterProjectBundle, SwitchesExtraValues) {
FlutterDesktopEngineProperties properties = {};
properties.assets_path = L"foo\\flutter_assets";
properties.icu_data_path = L"foo\\icudtl.dat";
_putenv_s("FLUTTER_ENGINE_SWITCHES", "1");
_putenv_s("FLUTTER_ENGINE_SWITCH_1", "abc");
_putenv_s("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"");
FlutterProjectBundle project(properties);
std::vector<std::string> switches = project.GetSwitches();
EXPECT_EQ(switches.size(), 1);
EXPECT_EQ(switches[0], "--abc");
}
TEST(FlutterProjectBundle, SwitchesMissingValues) {
FlutterDesktopEngineProperties properties = {};
properties.assets_path = L"foo\\flutter_assets";
properties.icu_data_path = L"foo\\icudtl.dat";
_putenv_s("FLUTTER_ENGINE_SWITCHES", "4");
_putenv_s("FLUTTER_ENGINE_SWITCH_1", "abc");
_putenv_s("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"");
_putenv_s("FLUTTER_ENGINE_SWITCH_4", "oops");
FlutterProjectBundle project(properties);
std::vector<std::string> switches = project.GetSwitches();
EXPECT_EQ(switches.size(), 3);
EXPECT_EQ(switches[0], "--abc");
EXPECT_EQ(switches[1], "--foo=\"bar, baz\"");
// The missing switch should be skipped, leaving SWITCH_4 as the third
// switch in the array.
EXPECT_EQ(switches[2], "--oops");
}
#endif // !FLUTTER_RELEASE
} // namespace testing
} // namespace flutter