1 /**
2 * Copyright (c) 2021-2024 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 ark::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 // NOLINTNEXTLINE(readability-magic-numbers)
29 str[4] = 255;
30 Charset<unsigned char> cs2 {&(str[0])};
31 EXPECT_TRUE(cs1('t'));
32 EXPECT_FALSE(cs1('q'));
33 EXPECT_TRUE(cs2('2'));
34 EXPECT_FALSE(cs2('1'));
35 EXPECT_TRUE(cs2(255));
36
37 Charset cs3 = cs1 + cs2;
38 EXPECT_TRUE(cs3('t'));
39 EXPECT_FALSE(cs3('p'));
40 EXPECT_TRUE(cs3('2'));
41 EXPECT_TRUE(cs3('1'));
42 EXPECT_TRUE(cs3(255));
43
44 Charset cs4 = cs1 - cs2;
45 EXPECT_FALSE(cs4('t'));
46 EXPECT_FALSE(cs4('p'));
47 EXPECT_FALSE(cs4('2'));
48 EXPECT_TRUE(cs4('1'));
49 EXPECT_FALSE(cs4(255));
50
51 Charset cs5 = !cs1;
52 EXPECT_FALSE(cs5('t'));
53 EXPECT_TRUE(cs5('p'));
54 EXPECT_TRUE(cs5('2'));
55 EXPECT_FALSE(cs5('1'));
56 EXPECT_TRUE(cs5(255));
57 }
58 } // namespace ark::parser::test