• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 <stdlib.h>
17 #include "functionalext.h"
18 
19 typedef void (*TEST_FUN)();
20 const int32_t ZERO = 0;
21 const int32_t NUMBER = 123456;
22 const int32_t NUM = 123;
23 const int32_t NUMB = 1234;
24 const int32_t NU = 12;
25 const int32_t BURDENNUM = -2147483648;
26 
27 /**
28  * @tc.name      : atoi_0100
29  * @tc.desc      : Verify that there are and only numbers (starting with non-zero digits) strings are
30  *                 converted to integers
31  * @tc.level     : Level 0
32  */
atoi_0100(void)33 void atoi_0100(void)
34 {
35     char str[] = "123456";
36     int32_t fptr = atoi(str);
37     EXPECT_EQ("atoi_0100", fptr, NUMBER);
38 }
39 
40 /**
41  * @tc.name      : atoi_0200
42  * @tc.desc      : Verify that there are and only numbers (starting with a 0) string is converted to an integer
43  * @tc.level     : Level 0
44  */
atoi_0200(void)45 void atoi_0200(void)
46 {
47     char str[] = "000123456";
48     int32_t fptr = atoi(str);
49     EXPECT_EQ("atoi_0200", fptr, NUMBER);
50 }
51 
52 /**
53  * @tc.name      : atoi_0300
54  * @tc.desc      : Verify that spaces are at the beginning of the string string is converted to an integer
55  * @tc.level     : Level 1
56  */
atoi_0300(void)57 void atoi_0300(void)
58 {
59     char str[] = " 123456";
60     int32_t fptr = atoi(str);
61     EXPECT_EQ("atoi_0300", fptr, NUMBER);
62 }
63 
64 /**
65  * @tc.name      : atoi_0400
66  * @tc.desc      : Verify that spaces are in the middle of the string and convert the string to an integer
67  * @tc.level     : Level 1
68  */
atoi_0400(void)69 void atoi_0400(void)
70 {
71     char str[] = "123  456";
72     int32_t fptr = atoi(str);
73     EXPECT_EQ("atoi_0400", fptr, NUM);
74 }
75 
76 /**
77  * @tc.name      : atoi_0500
78  * @tc.desc      : Verify that string conversion to integer (- at the beginning of the number)
79  * @tc.level     : Level 1
80  */
atoi_0500(void)81 void atoi_0500(void)
82 {
83     char str[] = "-123456";
84     int32_t fptr = atoi(str);
85     EXPECT_EQ("atoi_0500", fptr, -NUMBER);
86 }
87 
88 /**
89  * @tc.name      : atoi_0600
90  * @tc.desc      : Verify that string conversion to integer (- in the middle of the number)
91  * @tc.level     : Level 1
92  */
atoi_0600(void)93 void atoi_0600(void)
94 {
95     char str[] = "1234-56";
96     int32_t fptr = atoi(str);
97     EXPECT_EQ("atoi_0600", fptr, NUMB);
98 }
99 
100 /**
101  * @tc.name      : atoi_0700
102  * @tc.desc      : Verify that string conversion to integer (+ at the beginning of the number)
103  * @tc.level     : Level 1
104  */
atoi_0700(void)105 void atoi_0700(void)
106 {
107     char str[] = "+123456";
108     int32_t fptr = atoi(str);
109     EXPECT_EQ("atoi_0700", fptr, NUMBER);
110 }
111 
112 /**
113  * @tc.name      : atoi_0800
114  * @tc.desc      : Verify that string conversion to integer (+ in the middle of the number)
115  * @tc.level     : Level 1
116  */
atoi_0800(void)117 void atoi_0800(void)
118 {
119     char str[] = "1234+56";
120     int32_t fptr = atoi(str);
121     EXPECT_EQ("atoi_0800", fptr, NUMB);
122 }
123 
124 /**
125  * @tc.name      : atoi_0900
126  * @tc.desc      : Verify that string conversion to integer (English characters are at the beginning)
127  * @tc.level     : Level 2
128  */
atoi_0900(void)129 void atoi_0900(void)
130 {
131     char str[] = "a123456";
132     int32_t fptr = atoi(str);
133     EXPECT_EQ("atoi_0900", fptr, ZERO);
134 }
135 
136 /**
137  * @tc.name      : atoi_1000
138  * @tc.desc      : Verify that string conversion to integer (English characters are in the middle)
139  * @tc.level     : Level 2
140  */
atoi_1000(void)141 void atoi_1000(void)
142 {
143     char str[] = "12b3456";
144     int32_t fptr = atoi(str);
145     EXPECT_EQ("atoi_1000", fptr, NU);
146 }
147 
148 /**
149  * @tc.name      : atoi_1100
150  * @tc.desc      : Verify that string conversion to integer (parameter invalid NULL)
151  * @tc.level     : Level 2
152  */
atoi_1100(void)153 void atoi_1100(void)
154 {
155     char str[] = "NULL";
156     int32_t fptr = atoi(str);
157     EXPECT_EQ("atoi_1100", fptr, ZERO);
158 }
159 
160 /**
161  * @tc.name      : atoi_1200
162  * @tc.desc      : Verify that string conversion to integer (parameter invalid "")
163  * @tc.level     : Level 2
164  */
atoi_1200(void)165 void atoi_1200(void)
166 {
167     char str[] = "";
168     int32_t fptr = atoi(str);
169     EXPECT_EQ("atoi_1200", fptr, ZERO);
170 }
171 
172 /**
173  * @tc.name      : atoi_1300
174  * @tc.desc      : Verify that string conversion to integer (parameter exceeds max value)
175  * @tc.level     : Level 2
176  */
atoi_1300(void)177 void atoi_1300(void)
178 {
179     char str[] = "2147483648";
180     int32_t fptr = atoi(str);
181     EXPECT_EQ("atoi_1300", fptr, BURDENNUM);
182 }
183 
184 /**
185  * @tc.name      : atoi_1400
186  * @tc.desc      : erify that string conversion to integer (parameter less than minimum value)
187  * @tc.level     : Level 2
188  */
atoi_1400(void)189 void atoi_1400(void)
190 {
191     char str[] = "-2147483648";
192     int32_t fptr = atoi(str);
193     EXPECT_EQ("atoi_1400", fptr, BURDENNUM);
194 }
195 
196 TEST_FUN G_Fun_Array[] = {
197     atoi_0100,
198     atoi_0200,
199     atoi_0300,
200     atoi_0400,
201     atoi_0500,
202     atoi_0600,
203     atoi_0700,
204     atoi_0800,
205     atoi_0900,
206     atoi_1000,
207     atoi_1100,
208     atoi_1200,
209     atoi_1300,
210     atoi_1400,
211 };
212 
main(int argc,char * argv[])213 int main(int argc, char *argv[])
214 {
215     int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
216     for (int pos = 0; pos < num; ++pos) {
217         G_Fun_Array[pos]();
218     }
219 
220     return t_status;
221 }