• 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,Set)23 TEST_F(AmberScriptParserTest, Set) {
24   std::string in = "SET ENGINE_DATA fence_timeout_ms 125";
25 
26   Parser parser;
27   Result r = parser.Parse(in);
28   ASSERT_TRUE(r.IsSuccess()) << r.Error();
29 
30   auto script = parser.GetScript();
31   auto& data = script->GetEngineData();
32 
33   EXPECT_EQ(125U, data.fence_timeout_ms);
34 }
35 
TEST_F(AmberScriptParserTest,SetMissingEngineData)36 TEST_F(AmberScriptParserTest, SetMissingEngineData) {
37   std::string in = "SET fence_timeout_ms 125";
38 
39   Parser parser;
40   Result r = parser.Parse(in);
41   ASSERT_FALSE(r.IsSuccess());
42   EXPECT_EQ("1: SET missing ENGINE_DATA", r.Error());
43 }
44 
TEST_F(AmberScriptParserTest,SetMissingVariable)45 TEST_F(AmberScriptParserTest, SetMissingVariable) {
46   std::string in = "SET ENGINE_DATA";
47 
48   Parser parser;
49   Result r = parser.Parse(in);
50   ASSERT_FALSE(r.IsSuccess());
51   EXPECT_EQ("1: SET missing variable to be set", r.Error());
52 }
53 
TEST_F(AmberScriptParserTest,SetInvalidVariable)54 TEST_F(AmberScriptParserTest, SetInvalidVariable) {
55   std::string in = "SET ENGINE_DATA 1234";
56 
57   Parser parser;
58   Result r = parser.Parse(in);
59   ASSERT_FALSE(r.IsSuccess());
60   EXPECT_EQ("1: SET invalid variable to set: 1234", r.Error());
61 }
62 
TEST_F(AmberScriptParserTest,SetWithUnknownVariable)63 TEST_F(AmberScriptParserTest, SetWithUnknownVariable) {
64   std::string in = "SET ENGINE_DATA unknown";
65 
66   Parser parser;
67   Result r = parser.Parse(in);
68   ASSERT_FALSE(r.IsSuccess());
69   EXPECT_EQ("1: SET unknown variable provided: unknown", r.Error());
70 }
71 
TEST_F(AmberScriptParserTest,SetFenceTimeoutMissingValue)72 TEST_F(AmberScriptParserTest, SetFenceTimeoutMissingValue) {
73   std::string in = "SET ENGINE_DATA fence_timeout_ms";
74 
75   Parser parser;
76   Result r = parser.Parse(in);
77   ASSERT_FALSE(r.IsSuccess());
78   EXPECT_EQ("1: SET missing value for fence_timeout_ms", r.Error());
79 }
80 
TEST_F(AmberScriptParserTest,SetFenceTimeInvalidValue)81 TEST_F(AmberScriptParserTest, SetFenceTimeInvalidValue) {
82   std::string in = "SET ENGINE_DATA fence_timeout_ms INVALID";
83 
84   Parser parser;
85   Result r = parser.Parse(in);
86   ASSERT_FALSE(r.IsSuccess());
87   EXPECT_EQ("1: SET invalid value for fence_timeout_ms, must be uint32",
88             r.Error());
89 }
90 
TEST_F(AmberScriptParserTest,SetFenceTimeoutExtraParams)91 TEST_F(AmberScriptParserTest, SetFenceTimeoutExtraParams) {
92   std::string in = "SET ENGINE_DATA fence_timeout_ms 100 EXTRA";
93 
94   Parser parser;
95   Result r = parser.Parse(in);
96   ASSERT_FALSE(r.IsSuccess());
97   EXPECT_EQ("1: extra parameters after SET command: EXTRA", r.Error());
98 }
99 
100 }  // namespace amberscript
101 }  // namespace amber
102