• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
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 implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <vector>
17 
18 #include <gtest/gtest.h>
19 
20 #include "util/parser/charset.h"
21 
22 namespace panda::parser::test {
TEST(VerifierParserTest,Charset)23 TEST(VerifierParserTest, Charset)
24 {
25     std::vector<unsigned char> str {'s', 't', 'r', '1', '\0', '\0'};
26     charset<unsigned char> cs1 {&(str[0])};
27     str[3] = '2';
28     str[4] = 255;
29     charset<unsigned char> cs2 {&(str[0])};
30     EXPECT_TRUE(cs1('t'));
31     EXPECT_FALSE(cs1('q'));
32     EXPECT_TRUE(cs2('2'));
33     EXPECT_FALSE(cs2('1'));
34     EXPECT_TRUE(cs2(255));
35 
36     charset cs3 = cs1 + cs2;
37     EXPECT_TRUE(cs3('t'));
38     EXPECT_FALSE(cs3('p'));
39     EXPECT_TRUE(cs3('2'));
40     EXPECT_TRUE(cs3('1'));
41     EXPECT_TRUE(cs3(255));
42 
43     charset cs4 = cs1 - cs2;
44     EXPECT_FALSE(cs4('t'));
45     EXPECT_FALSE(cs4('p'));
46     EXPECT_FALSE(cs4('2'));
47     EXPECT_TRUE(cs4('1'));
48     EXPECT_FALSE(cs4(255));
49 
50     charset cs5 = !cs1;
51     EXPECT_FALSE(cs5('t'));
52     EXPECT_TRUE(cs5('p'));
53     EXPECT_TRUE(cs5('2'));
54     EXPECT_FALSE(cs5('1'));
55     EXPECT_TRUE(cs5(255));
56 }
57 }  // namespace panda::parser::test