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 "posix_test.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, PosixStdlibAtolTest);
48
49 /* *
50 * @tc.setup : setup for all testcases
51 * @return : setup result, TRUE is success, FALSE is fail
52 */
PosixStdlibAtolTestSetUp(void)53 static BOOL PosixStdlibAtolTestSetUp(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 */
PosixStdlibAtolTestTearDown(void)62 static BOOL PosixStdlibAtolTestTearDown(void)
63 {
64 LOG("+-------------------------------------------+\n");
65 return TRUE;
66 }
67
68 /* *
69 * @tc.number : TEST_STDLIB_ATOL_001
70 * @tc.name : convert string to long integer
71 * @tc.desc : [C- SOFTWARE -0200]
72 */
73 LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol001, Function | MediumTest | Level1)
74 {
75 const long value = atol("2147483647");
76 if (value == 2147483647) {
77 LOG("[DEMO] posix stdlib test case 1:atol(%ld) ok.\n", value);
78 } else {
79 LOG("[DEMO] posix stdlib test case 1:atol(%ld) fail.\n", value);
80 }
81 TEST_ASSERT_EQUAL_INT32(2147483647, value);
82 return 0;
83 }
84
85 /* *
86 * @tc.number : TEST_STDLIB_ATOL_002
87 * @tc.name : convert string to long integer
88 * @tc.desc : [C- SOFTWARE -0200]
89 */
90 LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol002, Function | MediumTest | Level1)
91 {
92 const long value = atol("-2147483648");
93 if (value == -2147483648) {
94 LOG("[DEMO] posix stdlib test case 2:atol(%ld) ok.\n", value);
95 } else {
96 LOG("[DEMO] posix stdlib test case 2:atol(%ld) fail.\n", value);
97 }
98 TEST_ASSERT_EQUAL_INT32(-2147483648, value);
99 return 0;
100 }
101
102 /* *
103 * @tc.number : TEST_STDLIB_ATOL_003
104 * @tc.name : convert string to long integer
105 * @tc.desc : [C- SOFTWARE -0200]
106 */
107 LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol003, Function | MediumTest | Level1)
108 {
109 const long value = atol("100");
110 if (value == 100) {
111 LOG("[DEMO] posix stdlib test case 3:atol(%ld) ok.\n", value);
112 } else {
113 LOG("[DEMO] posix stdlib test case 3:atol(%ld) fail.\n", value);
114 }
115 TEST_ASSERT_EQUAL_INT32(100, value);
116 return 0;
117 }
118
119 #if (LOSCFG_LIBC_MUSL == 1)
120 /* *
121 * @tc.number : TEST_STDLIB_ATOL_004
122 * @tc.name : convert string to long integer
123 * @tc.desc : [C- SOFTWARE -0200]
124 */
125 LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol004, Function | MediumTest | Level1)
126 {
127 const long value = atol("2147483648");
128 if (value != 2147483648) {
129 LOG("[DEMO] posix stdlib test case 4(except):atol(%ld) != 2147483648 ok.\n", value);
130 } else {
131 LOG("[DEMO] posix stdlib test case 4(except):atol(%ld) fail.\n", value);
132 }
133 TEST_ASSERT_EQUAL_INT32(-2147483648, value);
134 return 0;
135 }
136
137 /* *
138 * @tc.number : TEST_STDLIB_ATOL_005
139 * @tc.name : convert string to long integer
140 * @tc.desc : [C- SOFTWARE -0200]
141 */
142 LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol005, Function | MediumTest | Level1)
143 {
144 const long value = atol("-2147483649");
145 if (value == 2147483647) {
146 LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) != -2147483649 ok.\n", value);
147 } else {
148 LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) fail.\n", value);
149 }
150 TEST_ASSERT_EQUAL_INT32(2147483647, value);
151 return 0;
152 }
153 #endif
154
155 /* *
156 * @tc.number : TEST_STDLIB_ATOL_006
157 * @tc.name : convert string to long integer
158 * @tc.desc : [C- SOFTWARE -0200]
159 */
160 LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol006, Function | MediumTest | Level1)
161 {
162 const long value = atol("+100");
163 if (value == 100) {
164 LOG("[DEMO] posix stdlib test case 6:atol(%ld) == +100 ok.\n", value);
165 } else {
166 LOG("[DEMO] posix stdlib test case 6:atol(%ld) fail.\n", value);
167 }
168 TEST_ASSERT_EQUAL_INT32(100, value);
169 return 0;
170 }
171
172 /* *
173 * @tc.number : TEST_STDLIB_ATOL_007
174 * @tc.name : convert string to long integer
175 * @tc.desc : [C- SOFTWARE -0200]
176 */
177 LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol007, Function | MediumTest | Level1)
178 {
179 const long value = atol("-100");
180 if (value == -100) {
181 LOG("[DEMO] posix stdlib test case 7:atol(%ld) == -100 ok.\n", value);
182 } else {
183 LOG("[DEMO] posix stdlib test case 7:atoi(%ld) fail.\n", value);
184 }
185 TEST_ASSERT_EQUAL_INT32(-100, value);
186 return 0;
187 }
188
189 /* *
190 * @tc.number : TEST_STDLIB_ATOL_008
191 * @tc.name : convert string to long integer
192 * @tc.desc : [C- SOFTWARE -0200]
193 */
194 LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol008, Function | MediumTest | Level1)
195 {
196 long value = atol("+-100");
197 if (value == 0) {
198 LOG("[DEMO] posix stdlib test case 8(except):atol(%ld) == +-100 ok.\n", value);
199 } else {
200 LOG("[DEMO] posix stdlib test case 8(except):atol(%ld) fail.\n", value);
201 }
202 TEST_ASSERT_EQUAL_INT32(0, value);
203 return 0;
204 }
205
206 /* *
207 * @tc.number : TEST_STDLIB_ATOL_009
208 * @tc.name : convert string to long integer
209 * @tc.desc : [C- SOFTWARE -0200]
210 */
211 LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol009, Function | MediumTest | Level1)
212 {
213 long value = atol("12+-100");
214 if (value == 12) {
215 LOG("[DEMO] posix stdlib test case 9(except):atol(%ld) ok == 12+-100.\n", value);
216 } else {
217 LOG("[DEMO] posix stdlib test case 9(except):atol(%ld) fail.\n", value);
218 }
219 TEST_ASSERT_EQUAL_INT32(12, value);
220 return 0;
221 }
222
223 RUN_TEST_SUITE(PosixStdlibAtolTest);
224
PosixStdlibAtolFuncTest()225 void PosixStdlibAtolFuncTest()
226 {
227 LOG("begin PosixStdlibAtolFuncTest....");
228 RUN_ONE_TESTCASE(testStdlibAtol001);
229 RUN_ONE_TESTCASE(testStdlibAtol002);
230 RUN_ONE_TESTCASE(testStdlibAtol003);
231 #if (LOSCFG_LIBC_MUSL == 1)
232 RUN_ONE_TESTCASE(testStdlibAtol004);
233 RUN_ONE_TESTCASE(testStdlibAtol005);
234 #endif
235 RUN_ONE_TESTCASE(testStdlibAtol006);
236 RUN_ONE_TESTCASE(testStdlibAtol007);
237 RUN_ONE_TESTCASE(testStdlibAtol008);
238 RUN_ONE_TESTCASE(testStdlibAtol009);
239
240 return;
241 }