• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "ohos_types.h"
33 #include "hctest.h"
34 #include "los_config.h"
35 #include "kernel_test.h"
36 #include "ctype.h"
37 #include "stdlib.h"
38 #include "string.h"
39 #include "log.h"
40 
41 /* *
42  * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
43  * @param        : subsystem name is utils
44  * @param        : module name is utilsFile
45  * @param        : test suit name is CmsisTaskFuncTestSuite
46  */
47 LITE_TEST_SUIT(Posix, Posixtimer, PosixStdlibAtoiTest);
48 
49 /* *
50  * @tc.setup     : setup for all testcases
51  * @return       : setup result, TRUE is success, FALSE is fail
52  */
PosixStdlibAtoiTestSetUp(void)53 static BOOL PosixStdlibAtoiTestSetUp(void)
54 {
55     return TRUE;
56 }
57 
58 /* *
59  * @tc.teardown  : teardown for all testcases
60  * @return       : teardown result, TRUE is success, FALSE is fail
61  */
PosixStdlibAtoiTestTearDown(void)62 static BOOL PosixStdlibAtoiTestTearDown(void)
63 {
64     LOG("+-------------------------------------------+\n");
65     return TRUE;
66 }
67 
68 /* *
69  * @tc.number    : TEST_STDLIB_ATOI_001
70  * @tc.name      : convert string to integer
71  * @tc.desc      : [C- SOFTWARE -0200]
72  */
73 LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi001, Function | MediumTest | Level1)
74 {
75     int value = atoi("2147483647");
76     if (value == 2147483647) {
77         LOG("[DEMO] posix stdlib test case 1:atoi(%d) ok.\n", value);
78     } else {
79         LOG("[DEMO] posix stdlib test case 1:atoi(%d) fail.\n", value);
80     }
81     TEST_ASSERT_EQUAL_INT(2147483647, value);
82 }
83 
84 /* *
85  * @tc.number    : TEST_STDLIB_ATOI_002
86  * @tc.name      : convert string to integer
87  * @tc.desc      : [C- SOFTWARE -0200]
88  */
89 LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi002, Function | MediumTest | Level1)
90 {
91     int value = atoi("-2147483648");
92     if (value == -2147483648) {
93         LOG("[DEMO] posix stdlib test case 2:atoi(%d) ok.\n", value);
94     } else {
95         LOG("[DEMO] posix stdlib test case 2:atoi(%d) fail.\n", value);
96     }
97     TEST_ASSERT_EQUAL_INT(-2147483648, value);
98 }
99 
100 /* *
101  * @tc.number    : TEST_STDLIB_ATOI_003
102  * @tc.name      : convert string to integer
103  * @tc.desc      : [C- SOFTWARE -0200]
104  */
105 LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi003, Function | MediumTest | Level1)
106 {
107     int value = atoi("100");
108     if (value == 100) {
109         LOG("[DEMO] posix stdlib test case 3:atoi(%d) ok.\n", value);
110     } else {
111         LOG("[DEMO] posix stdlib test case 3:atoi(%d) fail.\n", value);
112     }
113     TEST_ASSERT_EQUAL_INT(100, value);
114 }
115 
116 /* *
117  * @tc.number    : TEST_STDLIB_ATOI_004
118  * @tc.name      : convert string to integer
119  * @tc.desc      : [C- SOFTWARE -0200]
120  */
121 LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi004, Function | MediumTest | Level1)
122 {
123     int value = atoi("2147483648");
124     if (value == -2147483648) {
125         LOG("[DEMO] posix stdlib test case 4(except):atoi(%d) != 2147483648 ok.\n", value);
126     } else {
127         LOG("[DEMO] posix stdlib test case 4(except):atoi(%d) fail.\n", value);
128     }
129     TEST_ASSERT_EQUAL_INT(-2147483648, value);
130 }
131 
132 /* *
133  * @tc.number    : TEST_STDLIB_ATOI_005
134  * @tc.name      : convert string to integer
135  * @tc.desc      : [C- SOFTWARE -0200]
136  */
137 LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi005, Function | MediumTest | Level1)
138 {
139     int value = atoi("-2147483649");
140     if (value == 2147483647) {
141         LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) != -2147483649 ok.\n", value);
142     } else {
143         LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) fail.\n", value);
144     }
145     TEST_ASSERT_EQUAL_INT(2147483647, value);
146 }
147 
148 /* *
149  * @tc.number    : TEST_STDLIB_ATOI_006
150  * @tc.name      : convert string to integer
151  * @tc.desc      : [C- SOFTWARE -0200]
152  */
153 LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi006, Function | MediumTest | Level1)
154 {
155     int value = atoi("+100");
156     if (value == 100) {
157         LOG("[DEMO] posix stdlib test case 6:atoi(%d) == +100 ok.\n", value);
158     } else {
159         LOG("[DEMO] posix stdlib test case 6:atoi(%d) fail.\n", value);
160     }
161     TEST_ASSERT_EQUAL_INT(100, value);
162 }
163 
164 /* *
165  * @tc.number    : TEST_STDLIB_ATOI_007
166  * @tc.name      : convert string to integer
167  * @tc.desc      : [C- SOFTWARE -0200]
168  */
169 LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi007, Function | MediumTest | Level1)
170 {
171     int value = atoi("-100");
172     if (value == -100) {
173         LOG("[DEMO] posix stdlib test case 7:atoi(%d) == -100 ok.\n", value);
174     } else {
175         LOG("[DEMO] posix stdlib test case 7:atoi(%d) fail.\n", value);
176     }
177     TEST_ASSERT_EQUAL_INT(-100, value);
178 }
179 
180 /* *
181  * @tc.number    : TEST_STDLIB_ATOI_008
182  * @tc.name      : convert string to integer
183  * @tc.desc      : [C- SOFTWARE -0200]
184  */
185 LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi008, Function | MediumTest | Level1)
186 {
187     int value = atoi("+-100");
188     if (value == 0) {
189         LOG("[DEMO] posix stdlib test case 8(except):atoi(%d) ==  +-100 ok.\n", value);
190     } else {
191         LOG("[DEMO] posix stdlib test case 8(except):atoi(%d) fail.\n", value);
192     }
193     TEST_ASSERT_EQUAL_INT(0, value);
194 }
195 
196 /* *
197  * @tc.number    : TEST_STDLIB_ATOI_009
198  * @tc.name      : convert string to integer
199  * @tc.desc      : [C- SOFTWARE -0200]
200  */
201 LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi009, Function | MediumTest | Level1)
202 {
203     int value = atoi("12+-100");
204     if (value == 12) {
205         LOG("[DEMO] posix stdlib test case 9(except):atoi(%d) ok == 12+-100.\n", value);
206     } else {
207         LOG("[DEMO] posix stdlib test case 9(except):atoi(%d) fail.\n", value);
208     }
209     TEST_ASSERT_EQUAL_INT(12, value);
210 }
211 
212 /* *
213  * @tc.number    : TEST_STDLIB_ATOI_010
214  * @tc.name      : convert string to integer
215  * @tc.desc      : [C- SOFTWARE -0200]
216  */
217 LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi010, Function | MediumTest | Level1)
218 {
219     int value = atoi("21474836470");
220     if (value == -10) {
221         LOG("[DEMO] posix stdlib test case 10(except):atoi(%d) ok == 21474836470.\n", value);
222     } else {
223         LOG("[DEMO] posix stdlib test case 10(except):atoi(%d) fail.\n", value);
224     }
225     TEST_ASSERT_EQUAL_INT(-10, value);
226 }
227 
228 RUN_TEST_SUITE(PosixStdlibAtoiTest);
229 
PosixStdlibAtoiFuncTest()230 void PosixStdlibAtoiFuncTest()
231 {
232     LOG("begin PosixStdlibAtoiFuncTest....");
233     RUN_ONE_TESTCASE(testStdlibAtoi001);
234     RUN_ONE_TESTCASE(testStdlibAtoi002);
235     RUN_ONE_TESTCASE(testStdlibAtoi003);
236     RUN_ONE_TESTCASE(testStdlibAtoi004);
237     RUN_ONE_TESTCASE(testStdlibAtoi005);
238     RUN_ONE_TESTCASE(testStdlibAtoi006);
239     RUN_ONE_TESTCASE(testStdlibAtoi007);
240     RUN_ONE_TESTCASE(testStdlibAtoi008);
241     RUN_ONE_TESTCASE(testStdlibAtoi009);
242     RUN_ONE_TESTCASE(testStdlibAtoi010);
243 
244     return;
245 }