forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitches_unittests.cc
More file actions
98 lines (81 loc) · 3.57 KB
/
switches_unittests.cc
File metadata and controls
98 lines (81 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 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 <initializer_list>
#include <vector>
#include "flutter/fml/command_line.h"
#include "flutter/fml/file.h"
#include "flutter/testing/testing.h"
#include "impeller/compiler/switches.h"
#include "impeller/compiler/utilities.h"
namespace impeller {
namespace compiler {
namespace testing {
Switches MakeSwitchesDesktopGL(
std::initializer_list<const char*> additional_options = {}) {
std::vector<const char*> options = {"--opengl-desktop", "--input=input.vert",
"--sl=output.vert",
"--spirv=output.spirv"};
options.insert(options.end(), additional_options.begin(),
additional_options.end());
auto cl = fml::CommandLineFromIteratorsWithArgv0("impellerc", options.begin(),
options.end());
return Switches(cl);
}
TEST(SwitchesTest, DoesntMangleUnicodeIncludes) {
const char* directory_name = "test_shader_include_�";
fml::CreateDirectory(flutter::testing::OpenFixturesDirectory(),
{directory_name}, fml::FilePermission::kRead);
auto include_path =
std::string(flutter::testing::GetFixturesPath()) + "/" + directory_name;
auto include_option = "--include=" + include_path;
Switches switches = MakeSwitchesDesktopGL({include_option.c_str()});
ASSERT_TRUE(switches.AreValid(std::cout));
ASSERT_EQ(switches.include_directories.size(), 1u);
ASSERT_NE(switches.include_directories[0].dir, nullptr);
ASSERT_EQ(switches.include_directories[0].name, include_path);
}
TEST(SwitchesTest, SourceLanguageDefaultsToGLSL) {
Switches switches = MakeSwitchesDesktopGL();
ASSERT_TRUE(switches.AreValid(std::cout));
ASSERT_EQ(switches.source_language, SourceLanguage::kGLSL);
}
TEST(SwitchesTest, SourceLanguageCanBeSetToHLSL) {
Switches switches = MakeSwitchesDesktopGL({"--source-language=hLsL"});
ASSERT_TRUE(switches.AreValid(std::cout));
ASSERT_EQ(switches.source_language, SourceLanguage::kHLSL);
}
TEST(SwitchesTest, DefaultEntryPointIsMain) {
Switches switches = MakeSwitchesDesktopGL({});
ASSERT_TRUE(switches.AreValid(std::cout));
ASSERT_EQ(switches.entry_point, "main");
}
TEST(SwitchesTest, EntryPointCanBeSetForHLSL) {
Switches switches = MakeSwitchesDesktopGL({"--entry-point=CustomEntryPoint"});
ASSERT_TRUE(switches.AreValid(std::cout));
ASSERT_EQ(switches.entry_point, "CustomEntryPoint");
}
TEST(SwitchesTEst, ConvertToEntrypointName) {
ASSERT_EQ(ConvertToEntrypointName("mandelbrot_unrolled"),
"mandelbrot_unrolled");
ASSERT_EQ(ConvertToEntrypointName("mandelbrot-unrolled"),
"mandelbrotunrolled");
ASSERT_EQ(ConvertToEntrypointName("7_"), "i_7_");
ASSERT_EQ(ConvertToEntrypointName("415"), "i_415");
ASSERT_EQ(ConvertToEntrypointName("#$%"), "i_");
ASSERT_EQ(ConvertToEntrypointName(""), "");
}
TEST(SwitchesTest, ShaderBundleModeValid) {
// Shader bundles process multiple shaders, and so the single-file input/spirv
// flags are not required.
std::vector<const char*> options = {
"--shader-bundle={}", "--sl=test.shaderbundle", "--runtime-stage-metal"};
auto cl = fml::CommandLineFromIteratorsWithArgv0("impellerc", options.begin(),
options.end());
Switches switches(cl);
ASSERT_TRUE(switches.AreValid(std::cout));
ASSERT_EQ(switches.shader_bundle, "{}");
}
} // namespace testing
} // namespace compiler
} // namespace impeller