• 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 <ctype.h>
18 #include "functionalext.h"
19 
20 long long int result = 123456789012345;
21 int resultA = 123456;
22 int resultC = -123456;
23 int resultD = 1234567890;
24 int resultE = 1234;
25 int successfully = 0;
26 int resultG = 12;
27 
28 /**
29  * @tc.name      : atoll_0100
30  * @tc.desc      : Verify that the string can be converted to an integer (parameter is 123456789012345)
31  * @tc.level     : Level 0
32  */
atoll_0100(void)33 void atoll_0100(void)
34 {
35     long long int num;
36     char str[] = "123456789012345";
37     num = atoll(str);
38     EXPECT_EQ("atoll_0100", num, result);
39 }
40 
41 /**
42  * @tc.name      : atoll_0200
43  * @tc.desc      : Verify that the string can be converted to an integer (parameter is 000123456)
44  * @tc.level     : Level 0
45  */
atoll_0200(void)46 void atoll_0200(void)
47 {
48     long long int num;
49     char str[] = "000123456";
50     num = atoll(str);
51     EXPECT_EQ("atoll_0200", num, resultA);
52 }
53 
54 /**
55  * @tc.name      : atoll_0300
56  * @tc.desc      : Verify that the string can be converted to an integer (parameter is  123456)
57  * @tc.level     : Level 1
58  */
atoll_0300(void)59 void atoll_0300(void)
60 {
61     long long int num;
62     char str[] = " 123456";
63     num = atoll(str);
64     EXPECT_EQ("atoll_0300", num, resultA);
65 }
66 
67 /**
68  * @tc.name      : atoll_0400
69  * @tc.desc      : Verify that the string can be converted to an integer (parameter is 123 456)
70  * @tc.level     : Level 1
71  */
atoll_0400(void)72 void atoll_0400(void)
73 {
74     long long int num;
75     char str[] = "123 456";
76     num = atoll(str);
77     EXPECT_EQ("atoll_0400", num, 123);
78 }
79 
80 /**
81  * @tc.name      : atoll_0500
82  * @tc.desc      : Verify that the string can be converted to an integer (parameter is -123456)
83  * @tc.level     : Level 1
84  */
atoll_0500(void)85 void atoll_0500(void)
86 {
87     long long int num;
88     char str[] = "-123456";
89     num = atoll(str);
90     EXPECT_EQ("atoll_0500", num, resultC);
91 }
92 
93 /**
94  * @tc.name      : atoll_0600
95  * @tc.desc      : Verify that the string can be converted to an integer (parameter is 1234567890-56)
96  * @tc.level     : Level 1
97  */
atoll_0600(void)98 void atoll_0600(void)
99 {
100     long long int num;
101     char str[] = "1234567890-56";
102     num = atoll(str);
103     EXPECT_EQ("atoll_0600", num, resultD);
104 }
105 
106 /**
107  * @tc.name      : atoll_0700
108  * @tc.desc      : Verify that the string can be converted to an integer (parameter is +123456)
109  * @tc.level     : Level 1
110  */
atoll_0700(void)111 void atoll_0700(void)
112 {
113     long long int num;
114     char str[] = "+123456";
115     num = atoll(str);
116     EXPECT_EQ("atoll_0700", num, resultA);
117 }
118 
119 /**
120  * @tc.name      : atoll_0800
121  * @tc.desc      : Verify that the string can be converted to an integer (parameter is 1234+56)
122  * @tc.level     : Level 1
123  */
atoll_0800(void)124 void atoll_0800(void)
125 {
126     long long int num;
127     char str[] = "1234+56";
128     num = atoll(str);
129     EXPECT_EQ("atoll_0800", num, resultE);
130 }
131 
132 /**
133  * @tc.name      : atoll_0900
134  * @tc.desc      : Verify that cannot convert string to integer (parameter is a123456)
135  * @tc.level     : Level 2
136  */
atoll_0900(void)137 void atoll_0900(void)
138 {
139     long long int num;
140     char str[] = "a123456";
141     num = atoll(str);
142     EXPECT_EQ("atoll_0900", num, successfully);
143 }
144 
145 /**
146  * @tc.name      : atoll_1000
147  * @tc.desc      : Verify that cannot convert string to integer (parameter is 12b3456789012345)
148  * @tc.level     : Level 2
149  */
atoll_1000(void)150 void atoll_1000(void)
151 {
152     long long int num;
153     char str[] = "12b3456789012345";
154     num = atoll(str);
155     EXPECT_EQ("atoll_1000", num, resultG);
156 }
157 
158 /**
159  * @tc.name      : atoll_1100
160  * @tc.desc      : Verify that cannot convert string to integer (parameter is NULL)
161  * @tc.level     : Level 2
162  */
atoll_1100(void)163 void atoll_1100(void)
164 {
165     long long int num;
166     char str[] = "NULL";
167     num = atoll(str);
168     EXPECT_EQ("atoll_1100", num, successfully);
169 }
170 
171 /**
172  * @tc.name      : atoll_1200
173  * @tc.desc      : Verify that cannot convert string to integer (parameter is “”)
174  * @tc.level     : Level 2
175  */
atoll_1200(void)176 void atoll_1200(void)
177 {
178     long long int num;
179     char str[] = "";
180     num = atoll(str);
181     EXPECT_EQ("atoll_1200", num, successfully);
182 }
183 
main(int argc,char * argv[])184 int main(int argc, char *argv[])
185 {
186     atoll_0100();
187     atoll_0200();
188     atoll_0300();
189     atoll_0400();
190     atoll_0500();
191     atoll_0600();
192     atoll_0700();
193     atoll_0800();
194     atoll_0900();
195     atoll_1000();
196     atoll_1100();
197     atoll_1200();
198 
199     return t_status;
200 }