1 /*
2 * Copyright (c) 2025 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 <stdlib.h>
17 #include "functionalext.h"
18
19 #define VALUE_0 2
20 #define VALUE_A 12
21 #define VALUE_Z 63
22 #define VALUE 64
23 #define VALUE_0123 1327298
24 #define VALUE_ABCD 3990348
25 #define VALUE_ZZZZZ 1073741823
26
27 /**
28 * @tc.name : a64l_0100
29 * @tc.desc : Verify normal character
30 * @tc.level : Level 0
31 */
a64l_0100(void)32 void a64l_0100(void)
33 {
34 long result1 = a64l("0");
35 long result2 = a64l("A");
36 long result3 = a64l("z");
37 long result4 = a64l("./");
38 EXPECT_EQ("a64l_0100", result1, VALUE_0); // expect result is 2
39 EXPECT_EQ("a64l_0100", result2, VALUE_A); // expect result is 12
40 EXPECT_EQ("a64l_0100", result3, VALUE_Z); // expect result is 63
41 EXPECT_EQ("a64l_0100", result4, VALUE); // expect result is 64
42 }
43
44 /**
45 * @tc.name : a64l_0200
46 * @tc.desc : Verify multi character
47 * @tc.level : Level 0
48 */
a64l_0200(void)49 void a64l_0200(void)
50 {
51 long result1 = a64l("0123");
52 long result2 = a64l("ABCD");
53 EXPECT_EQ("a64l_0200", result1, VALUE_0123); // (2 | (3 << 6) | (4 << 12) | (5 << 18))
54 EXPECT_EQ("a64l_0200", result2, VALUE_ABCD); // (12 | (13 << 6) | (14 << 12) | (15 << 18)
55 }
56
57 /**
58 * @tc.name : a64l_0300
59 * @tc.desc : Verify illegal character
60 * @tc.level : Level 0
61 */
a64l_0300(void)62 void a64l_0300(void)
63 {
64 long result1 = a64l("A@B");
65 long result2 = a64l("0#");
66 EXPECT_EQ("a64l_0300", result1, VALUE_A); // expect result is 12
67 EXPECT_EQ("a64l_0300", result2, VALUE_0); // expect result is 2
68 }
69
70 /**
71 * @tc.name : a64l_0400
72 * @tc.desc : Verify empty characters
73 * @tc.level : Level 0
74 */
a64l_0400(void)75 void a64l_0400(void)
76 {
77 long result = a64l("");
78 EXPECT_EQ("a64l_0400", result, 0);
79 }
80
81 /**
82 * @tc.name : a64l_0500
83 * @tc.desc : Verify the maximum length
84 * @tc.level : Level 0
85 */
a64l_0500(void)86 void a64l_0500(void)
87 {
88 long result1 = a64l("zzzzzz");
89 long result2 = a64l("zzzzz");
90 EXPECT_EQ("a64l_0500", result1, -1); // (63 | (63 << 6) | (63 << 12) | (63 << 18) | (63 << 24) | (63 << 30))
91 EXPECT_EQ("a64l_0500", result2, VALUE_ZZZZZ); // (63 | (63 << 6) | (63 << 12) | (63 << 18) | (63 << 24))
92 }
93
main(int argc,char * argv[])94 int main(int argc, char *argv[])
95 {
96 a64l_0100();
97 a64l_0200();
98 a64l_0300();
99 a64l_0400();
100 a64l_0500();
101 return t_status;
102 }