• 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 "src/descriptor_set_and_binding_parser.h"
16 
17 #include "gtest/gtest.h"
18 
19 namespace amber {
20 
21 using DescriptorSetAndBindingParserTest = testing::Test;
22 
TEST_F(DescriptorSetAndBindingParserTest,CommaAndBinding)23 TEST_F(DescriptorSetAndBindingParserTest, CommaAndBinding) {
24   DescriptorSetAndBindingParser parser;
25   Result r = parser.Parse(":1234");
26   ASSERT_TRUE(r.IsSuccess()) << r.Error();
27 
28   EXPECT_FALSE(parser.HasPipelineName());
29   EXPECT_EQ(0u, parser.GetDescriptorSet());
30   EXPECT_EQ(1234u, parser.GetBinding());
31 }
32 
TEST_F(DescriptorSetAndBindingParserTest,Binding)33 TEST_F(DescriptorSetAndBindingParserTest, Binding) {
34   DescriptorSetAndBindingParser parser;
35   Result r = parser.Parse("1234");
36   ASSERT_TRUE(r.IsSuccess()) << r.Error();
37 
38   EXPECT_EQ(0u, parser.GetDescriptorSet());
39   EXPECT_EQ(1234u, parser.GetBinding());
40 }
41 
TEST_F(DescriptorSetAndBindingParserTest,DescSetAndBinding)42 TEST_F(DescriptorSetAndBindingParserTest, DescSetAndBinding) {
43   DescriptorSetAndBindingParser parser;
44   Result r = parser.Parse("1234:5678");
45   ASSERT_TRUE(r.IsSuccess()) << r.Error();
46 
47   EXPECT_EQ(1234u, parser.GetDescriptorSet());
48   EXPECT_EQ(5678u, parser.GetBinding());
49 }
50 
TEST_F(DescriptorSetAndBindingParserTest,EmptyBufferId)51 TEST_F(DescriptorSetAndBindingParserTest, EmptyBufferId) {
52   DescriptorSetAndBindingParser parser;
53   Result r = parser.Parse("");
54   EXPECT_EQ("Invalid buffer id: ", r.Error());
55 }
56 
TEST_F(DescriptorSetAndBindingParserTest,InvalidCharacter)57 TEST_F(DescriptorSetAndBindingParserTest, InvalidCharacter) {
58   DescriptorSetAndBindingParser parser;
59   Result r = parser.Parse("abcd");
60   EXPECT_EQ("Invalid buffer id: abcd", r.Error());
61 }
62 
TEST_F(DescriptorSetAndBindingParserTest,InvalidCharacterBetweenTwoNumbers)63 TEST_F(DescriptorSetAndBindingParserTest, InvalidCharacterBetweenTwoNumbers) {
64   DescriptorSetAndBindingParser parser;
65   Result r = parser.Parse("1234a5678");
66   EXPECT_EQ("Invalid buffer id: 1234a5678", r.Error());
67 }
68 
TEST_F(DescriptorSetAndBindingParserTest,InvalidCharacterAfterComma)69 TEST_F(DescriptorSetAndBindingParserTest, InvalidCharacterAfterComma) {
70   DescriptorSetAndBindingParser parser;
71   Result r = parser.Parse("1234:a5678");
72   EXPECT_EQ(
73       "Binding for a buffer must be non-negative integer, but you gave: a5678",
74       r.Error());
75 }
76 
TEST_F(DescriptorSetAndBindingParserTest,NegativeDescSet)77 TEST_F(DescriptorSetAndBindingParserTest, NegativeDescSet) {
78   DescriptorSetAndBindingParser parser;
79   Result r = parser.Parse("-1234:5678");
80   EXPECT_EQ(
81       "Descriptor set and binding for a buffer must be non-negative integer, "
82       "but you gave: -1234",
83       r.Error());
84 }
85 
TEST_F(DescriptorSetAndBindingParserTest,NegativeBindingAfterComma)86 TEST_F(DescriptorSetAndBindingParserTest, NegativeBindingAfterComma) {
87   DescriptorSetAndBindingParser parser;
88   Result r = parser.Parse(":-1234");
89   EXPECT_EQ(
90       "Binding for a buffer must be non-negative integer, but you gave: -1234",
91       r.Error());
92 }
93 
TEST_F(DescriptorSetAndBindingParserTest,NegativeBinding)94 TEST_F(DescriptorSetAndBindingParserTest, NegativeBinding) {
95   DescriptorSetAndBindingParser parser;
96   Result r = parser.Parse("-1234");
97   EXPECT_EQ(
98       "Descriptor set and binding for a buffer must be non-negative integer, "
99       "but you gave: -1234",
100       r.Error());
101 }
102 
TEST_F(DescriptorSetAndBindingParserTest,DescSetAndNegativeBinding)103 TEST_F(DescriptorSetAndBindingParserTest, DescSetAndNegativeBinding) {
104   DescriptorSetAndBindingParser parser;
105   Result r = parser.Parse("1234:-5678");
106   EXPECT_EQ(
107       "Binding for a buffer must be non-negative integer, but you gave: -5678",
108       r.Error());
109 }
110 
TEST_F(DescriptorSetAndBindingParserTest,WithPipelineName)111 TEST_F(DescriptorSetAndBindingParserTest, WithPipelineName) {
112   DescriptorSetAndBindingParser parser;
113   Result r = parser.Parse("pipeline1:123:234");
114   ASSERT_TRUE(r.IsSuccess()) << r.Error();
115 
116   EXPECT_TRUE(parser.HasPipelineName());
117   EXPECT_EQ("pipeline1", parser.PipelineName());
118   EXPECT_EQ(123u, parser.GetDescriptorSet());
119   EXPECT_EQ(234u, parser.GetBinding());
120 }
121 
122 }  // namespace amber
123