1 // Copyright 2019 The Amber Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or parseried.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "gtest/gtest.h"
16 #include "src/amberscript/parser.h"
17
18 namespace amber {
19 namespace amberscript {
20
21 using AmberScriptParserTest = testing::Test;
22
TEST_F(AmberScriptParserTest,Clear)23 TEST_F(AmberScriptParserTest, Clear) {
24 std::string in = R"(
25 SHADER vertex my_shader PASSTHROUGH
26 SHADER fragment my_fragment GLSL
27 # GLSL Shader
28 END
29
30 PIPELINE graphics my_pipeline
31 ATTACH my_shader
32 ATTACH my_fragment
33 END
34
35 CLEAR my_pipeline)";
36
37 Parser parser;
38 Result r = parser.Parse(in);
39 ASSERT_TRUE(r.IsSuccess()) << r.Error();
40
41 auto script = parser.GetScript();
42 const auto& commands = script->GetCommands();
43 ASSERT_EQ(1U, commands.size());
44
45 auto* cmd = commands[0].get();
46 ASSERT_TRUE(cmd->IsClear());
47 }
48
TEST_F(AmberScriptParserTest,ClearMissingPipeline)49 TEST_F(AmberScriptParserTest, ClearMissingPipeline) {
50 std::string in = R"(
51 SHADER vertex my_shader PASSTHROUGH
52 SHADER fragment my_fragment GLSL
53 # GLSL Shader
54 END
55
56 PIPELINE graphics my_pipeline
57 ATTACH my_shader
58 ATTACH my_fragment
59 END
60
61 CLEAR)";
62
63 Parser parser;
64 Result r = parser.Parse(in);
65 ASSERT_FALSE(r.IsSuccess());
66 EXPECT_EQ("12: missing pipeline name for CLEAR command", r.Error());
67 }
68
TEST_F(AmberScriptParserTest,ClearInvalidPipeline)69 TEST_F(AmberScriptParserTest, ClearInvalidPipeline) {
70 std::string in = R"(CLEAR other_pipeline)";
71
72 Parser parser;
73 Result r = parser.Parse(in);
74 ASSERT_FALSE(r.IsSuccess());
75 EXPECT_EQ("1: unknown pipeline for CLEAR command: other_pipeline", r.Error());
76 }
77
TEST_F(AmberScriptParserTest,ClearComputePipeline)78 TEST_F(AmberScriptParserTest, ClearComputePipeline) {
79 std::string in = R"(
80 SHADER compute my_shader GLSL
81 void main() {
82 gl_FragColor = vec3(2, 3, 4);
83 }
84 END
85
86 PIPELINE compute my_pipeline
87 ATTACH my_shader
88 END
89
90 CLEAR my_pipeline)";
91
92 Parser parser;
93 Result r = parser.Parse(in);
94 ASSERT_FALSE(r.IsSuccess());
95 ASSERT_EQ("12: CLEAR command requires graphics pipeline", r.Error());
96 }
97
TEST_F(AmberScriptParserTest,ClearExtraParams)98 TEST_F(AmberScriptParserTest, ClearExtraParams) {
99 std::string in = R"(
100 SHADER vertex my_shader PASSTHROUGH
101 SHADER fragment my_fragment GLSL
102 # GLSL Shader
103 END
104
105 PIPELINE graphics my_pipeline
106 ATTACH my_shader
107 ATTACH my_fragment
108 END
109
110 CLEAR my_pipeline EXTRA)";
111
112 Parser parser;
113 Result r = parser.Parse(in);
114 ASSERT_FALSE(r.IsSuccess());
115 EXPECT_EQ("12: extra parameters after CLEAR command: EXTRA", r.Error());
116 }
117
118 } // namespace amberscript
119 } // namespace amber
120