• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,FramebufferDefaultSize)23 TEST_F(AmberScriptParserTest, FramebufferDefaultSize) {
24   std::string in = R"(
25 SHADER vertex my_shader PASSTHROUGH
26 SHADER fragment my_fragment GLSL
27 # GLSL Shader
28 END
29 PIPELINE graphics my_pipeline
30   ATTACH my_shader
31   ATTACH my_fragment
32 END
33 )";
34 
35   Parser parser;
36   Result r = parser.Parse(in);
37   ASSERT_TRUE(r.IsSuccess()) << r.Error();
38 
39   auto script = parser.GetScript();
40   const auto& pipelines = script->GetPipelines();
41   ASSERT_EQ(1U, pipelines.size());
42 
43   const auto* pipeline = pipelines[0].get();
44   EXPECT_EQ(250u, pipeline->GetFramebufferWidth());
45   EXPECT_EQ(250u, pipeline->GetFramebufferHeight());
46 }
47 
TEST_F(AmberScriptParserTest,FramebufferSize)48 TEST_F(AmberScriptParserTest, FramebufferSize) {
49   std::string in = R"(
50 SHADER vertex my_shader PASSTHROUGH
51 SHADER fragment my_fragment GLSL
52 # GLSL Shader
53 END
54 PIPELINE graphics my_pipeline
55   ATTACH my_shader
56   ATTACH my_fragment
57   FRAMEBUFFER_SIZE 256 246
58 END
59 )";
60 
61   Parser parser;
62   Result r = parser.Parse(in);
63   ASSERT_TRUE(r.IsSuccess()) << r.Error();
64 
65   auto script = parser.GetScript();
66   const auto& pipelines = script->GetPipelines();
67   ASSERT_EQ(1U, pipelines.size());
68 
69   const auto* pipeline = pipelines[0].get();
70   EXPECT_EQ(256u, pipeline->GetFramebufferWidth());
71   EXPECT_EQ(246u, pipeline->GetFramebufferHeight());
72 }
73 
TEST_F(AmberScriptParserTest,FramebufferSizeMissingSize)74 TEST_F(AmberScriptParserTest, FramebufferSizeMissingSize) {
75   std::string in = R"(
76 SHADER vertex my_shader PASSTHROUGH
77 SHADER fragment my_fragment GLSL
78 # GLSL Shader
79 END
80 PIPELINE graphics my_pipeline
81   ATTACH my_shader
82   ATTACH my_fragment
83   FRAMEBUFFER_SIZE
84 END
85 )";
86 
87   Parser parser;
88   Result r = parser.Parse(in);
89   ASSERT_FALSE(r.IsSuccess());
90 
91   EXPECT_EQ("10: missing size for FRAMEBUFFER_SIZE command", r.Error());
92 }
93 
TEST_F(AmberScriptParserTest,FramebufferSizeMissingHeight)94 TEST_F(AmberScriptParserTest, FramebufferSizeMissingHeight) {
95   std::string in = R"(
96 SHADER vertex my_shader PASSTHROUGH
97 SHADER fragment my_fragment GLSL
98 # GLSL Shader
99 END
100 PIPELINE graphics my_pipeline
101   ATTACH my_shader
102   ATTACH my_fragment
103   FRAMEBUFFER_SIZE 222
104 END
105 )";
106 
107   Parser parser;
108   Result r = parser.Parse(in);
109   ASSERT_FALSE(r.IsSuccess());
110 
111   EXPECT_EQ("10: missing height for FRAMEBUFFER_SIZE command", r.Error());
112 }
113 
TEST_F(AmberScriptParserTest,FramebufferSizeExtraParams)114 TEST_F(AmberScriptParserTest, FramebufferSizeExtraParams) {
115   std::string in = R"(
116 SHADER vertex my_shader PASSTHROUGH
117 SHADER fragment my_fragment GLSL
118 # GLSL Shader
119 END
120 PIPELINE graphics my_pipeline
121   ATTACH my_shader
122   ATTACH my_fragment
123   FRAMEBUFFER_SIZE 222 233 INVALID
124 END
125 )";
126 
127   Parser parser;
128   Result r = parser.Parse(in);
129   ASSERT_FALSE(r.IsSuccess());
130 
131   EXPECT_EQ("9: extra parameters after FRAMEBUFFER_SIZE command: INVALID",
132             r.Error());
133 }
134 
TEST_F(AmberScriptParserTest,FramebufferInvalidWidth)135 TEST_F(AmberScriptParserTest, FramebufferInvalidWidth) {
136   std::string in = R"(
137 SHADER vertex my_shader PASSTHROUGH
138 SHADER fragment my_fragment GLSL
139 # GLSL Shader
140 END
141 PIPELINE graphics my_pipeline
142   ATTACH my_shader
143   ATTACH my_fragment
144   FRAMEBUFFER_SIZE INVALID 245
145 END
146 )";
147 
148   Parser parser;
149   Result r = parser.Parse(in);
150   ASSERT_FALSE(r.IsSuccess());
151 
152   EXPECT_EQ("9: invalid width for FRAMEBUFFER_SIZE command", r.Error());
153 }
154 
TEST_F(AmberScriptParserTest,FramebufferInvalidHeight)155 TEST_F(AmberScriptParserTest, FramebufferInvalidHeight) {
156   std::string in = R"(
157 SHADER vertex my_shader PASSTHROUGH
158 SHADER fragment my_fragment GLSL
159 # GLSL Shader
160 END
161 PIPELINE graphics my_pipeline
162   ATTACH my_shader
163   ATTACH my_fragment
164   FRAMEBUFFER_SIZE 245 INVALID
165 END
166 )";
167 
168   Parser parser;
169   Result r = parser.Parse(in);
170   ASSERT_FALSE(r.IsSuccess());
171 
172   EXPECT_EQ("9: invalid height for FRAMEBUFFER_SIZE command", r.Error());
173 }
174 
175 }  // namespace amberscript
176 }  // namespace amber
177