Flutter Engine
The Flutter Engine
switches_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
5#include <initializer_list>
6
7#include "flutter/common/settings.h"
8#include "flutter/fml/command_line.h"
9#include "flutter/shell/common/switches.h"
10
11#include "gtest/gtest.h"
12
13// TODO(zanderso): https://github.com/flutter/flutter/issues/127701
14// NOLINTBEGIN(bugprone-unchecked-optional-access)
15
16namespace flutter {
17namespace testing {
18
19TEST(SwitchesTest, SkiaTraceAllowlistFlag) {
20 fml::CommandLine command_line =
23#if !FLUTTER_RELEASE
24 EXPECT_TRUE(settings.trace_skia);
25 EXPECT_TRUE(settings.trace_skia_allowlist.has_value());
26 EXPECT_EQ(settings.trace_skia_allowlist->size(), 1ul);
27#else
28 EXPECT_FALSE(settings.trace_skia);
29#endif
30
31 command_line =
32 fml::CommandLineFromInitializerList({"command", "--trace-skia"});
33 settings = SettingsFromCommandLine(command_line);
34#if !FLUTTER_RELEASE
35 EXPECT_TRUE(settings.trace_skia);
36 EXPECT_FALSE(settings.trace_skia_allowlist.has_value());
37#else
38 EXPECT_FALSE(settings.trace_skia);
39#endif
40
42 {"command", "--trace-skia-allowlist=aaa,bbb,ccc"});
43 settings = SettingsFromCommandLine(command_line);
44#if !FLUTTER_RELEASE
45 EXPECT_TRUE(settings.trace_skia);
46 EXPECT_TRUE(settings.trace_skia_allowlist.has_value());
47 EXPECT_EQ(settings.trace_skia_allowlist->size(), 3ul);
48 EXPECT_EQ(settings.trace_skia_allowlist->back(), "ccc");
49#else
50 EXPECT_FALSE(settings.trace_skia);
51#endif
52}
53
54TEST(SwitchesTest, TraceToFile) {
56 {"command", "--trace-to-file=trace.binpb"});
57 EXPECT_TRUE(command_line.HasOption("trace-to-file"));
59 EXPECT_EQ(settings.trace_to_file, "trace.binpb");
60}
61
62TEST(SwitchesTest, RouteParsedFlag) {
63 fml::CommandLine command_line =
64 fml::CommandLineFromInitializerList({"command", "--route=/animation"});
66 EXPECT_EQ(settings.route, "/animation");
67 command_line = fml::CommandLineFromInitializerList({"command", "--route"});
68 settings = SettingsFromCommandLine(command_line);
69 EXPECT_TRUE(settings.route.empty());
70}
71
72TEST(SwitchesTest, EnableEmbedderAPI) {
73 {
74 // enable
76 {"command", "--enable-embedder-api"});
78 EXPECT_EQ(settings.enable_embedder_api, true);
79 }
80 {
81 // default
82 fml::CommandLine command_line =
85 EXPECT_EQ(settings.enable_embedder_api, false);
86 }
87}
88
89TEST(SwitchesTest, NoEnableImpeller) {
90 {
91 // enable
92 fml::CommandLine command_line =
93 fml::CommandLineFromInitializerList({"command", "--enable-impeller"});
94 EXPECT_TRUE(command_line.HasOption("enable-impeller"));
96 EXPECT_EQ(settings.enable_impeller, true);
97 }
98 {
99 // disable
101 {"command", "--enable-impeller=false"});
102 EXPECT_TRUE(command_line.HasOption("enable-impeller"));
104 EXPECT_EQ(settings.enable_impeller, false);
105 }
106}
107
108#if !FLUTTER_RELEASE
109TEST(SwitchesTest, EnableAsserts) {
111 {"command", "--dart-flags=--enable-asserts"});
113 ASSERT_EQ(settings.dart_flags.size(), 1ul);
114 EXPECT_EQ(settings.dart_flags[0], "--enable-asserts");
115}
116#endif
117
118} // namespace testing
119} // namespace flutter
120
121// NOLINTEND(bugprone-unchecked-optional-access)
bool HasOption(std::string_view name, size_t *index=nullptr) const
Definition: command_line.cc:40
TEST(DisplayListComplexity, EmptyDisplayList)
Settings SettingsFromCommandLine(const fml::CommandLine &command_line)
Definition: switches.cc:228
CommandLine CommandLineFromInitializerList(std::initializer_list< StringType > argv)
Definition: command_line.h:254
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678