• 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 "los_config.h"
34 #include "posix_test.h"
35 #include "kernel_test.h"
36 #include "log.h"
37 #include <ctype.h>
38 
39 #define RET_TRUE 1
40 #define RET_FALSE 0
41 
42 /* *
43  * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
44  * @param        : subsystem name is utils
45  * @param        : module name is utilsFile
46  * @param        : test suit name is CmsisTaskFuncTestSuite
47  */
48 LITE_TEST_SUIT(Posix, Posixctype, PosixCtypeFuncTestSuite);
49 
50 /* *
51  * @tc.setup     : setup for all testcases
52  * @return       : setup result, TRUE is success, FALSE is fail
53  */
PosixCtypeFuncTestSuiteSetUp(void)54 static BOOL PosixCtypeFuncTestSuiteSetUp(void)
55 {
56     return TRUE;
57 }
58 
59 /* *
60  * @tc.teardown  : teardown for all testcases
61  * @return       : teardown result, TRUE is success, FALSE is fail
62  */
PosixCtypeFuncTestSuiteTearDown(void)63 static BOOL PosixCtypeFuncTestSuiteTearDown(void)
64 {
65     printf("==== [ Ctype TEST ] ====\n\n");
66     return TRUE;
67 }
68 
69 /* *
70  * @tc.number TEST_CTYPE_ISALNUM_001
71  * @tc.name   ctype_isalnum test with not exist pid
72  * @tc.desc   [C- SOFTWARE -0200]
73  */
74 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum001, Function | MediumTest | Level1)
75 {
76     int src = 'A';
77     int ret = isalnum(src);
78     TEST_ASSERT_NOT_EQUAL(0, ret);
79     return 0;
80 }
81 
82 /* *
83  * @tc.number TEST_CTYPE_ISALNUM_002
84  * @tc.name   ctype_isalnum test with not exist pid
85  * @tc.desc   [C- SOFTWARE -0200]
86  */
87 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum002, Function | MediumTest | Level1)
88 {
89     int src = '1';
90     int ret = isalnum(src);
91     TEST_ASSERT_NOT_EQUAL(0, ret);
92     return 0;
93 }
94 
95 /* *
96  * @tc.number TEST_CTYPE_ISALNUM_003
97  * @tc.name   ctype_isalnum test with not exist pid
98  * @tc.desc   [C- SOFTWARE -0200]
99  */
100 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum003, Function | MediumTest | Level1)
101 {
102     int src = '@';
103     int ret = isalnum(src);
104     TEST_ASSERT_EQUAL_INT(0, ret);
105     return 0;
106 }
107 
108 /* *
109  * @tc.number TEST_CTYPE_ISALNUM_004
110  * @tc.name   ctype_isalnum test with not exist pid
111  * @tc.desc   [C- SOFTWARE -0200]
112  */
113 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum004, Function | MediumTest | Level1)
114 {
115     int src = ' ';
116     int ret = isalnum(src);
117     TEST_ASSERT_EQUAL_INT(0, ret);
118     return 0;
119 }
120 
121 /* *
122  * @tc.number TEST_CTYPE_ISALNUM_005
123  * @tc.name   ctype_isalnum test with not exist pid
124  * @tc.desc   [C- SOFTWARE -0200]
125  */
126 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum005, Function | MediumTest | Level1)
127 {
128     int src = '\f'; // 0x0c 14
129     int ret = isalnum(src);
130     TEST_ASSERT_EQUAL_INT(0, ret);
131     return 0;
132 }
133 
134 
135 /* *
136  * @tc.number TEST_CTYPE_ISASCII_001
137  * @tc.name   ctype_isascii test with not exist pid
138  * @tc.desc   [C- SOFTWARE -0200]
139  */
140 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii001, Function | MediumTest | Level1)
141 {
142     const int src = -1;
143     int ret = isascii(src);
144     TEST_ASSERT_EQUAL_INT(0, ret);
145     return 0;
146 }
147 
148 /* *
149  * @tc.number TEST_CTYPE_ISASCII_002
150  * @tc.name   ctype_isascii test with not exist pid
151  * @tc.desc   [C- SOFTWARE -0200]
152  */
153 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii002, Function | MediumTest | Level1)
154 {
155     const int src = 0;
156     int ret = isascii(src);
157     TEST_ASSERT_NOT_EQUAL(0, ret);
158     return 0;
159 }
160 
161 /* *
162  * @tc.number TEST_CTYPE_ISASCII_003
163  * @tc.name   ctype_isascii test with not exist pid
164  * @tc.desc   [C- SOFTWARE -0200]
165  */
166 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii003, Function | MediumTest | Level1)
167 {
168     const int src = 127;
169     int ret = isascii(src);
170     TEST_ASSERT_NOT_EQUAL(0, ret);
171     return 0;
172 }
173 
174 /* *
175  * @tc.number TEST_CTYPE_ISASCII_004
176  * @tc.name   ctype_isascii test with not exist pid
177  * @tc.desc   [C- SOFTWARE -0200]
178  */
179 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii004, Function | MediumTest | Level1)
180 {
181     const int src = 128;
182     int ret = isascii(src);
183     TEST_ASSERT_EQUAL_INT(0, ret);
184     return 0;
185 }
186 
187 /* *
188  * @tc.number TEST_CTYPE_ISASCII_005
189  * @tc.name   ctype_isascii test with not exist pid
190  * @tc.desc   [C- SOFTWARE -0200]
191  */
192 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii005, Function | MediumTest | Level1)
193 {
194     int src = '\f'; // 0x0c 14
195     int ret = isascii(src);
196     TEST_ASSERT_NOT_EQUAL(0, ret);
197     return 0;
198 }
199 
200 /* *
201  * @tc.number TEST_CTYPE_ISPRINT_001
202  * @tc.name   ctype_isprint test with not exist pid
203  * @tc.desc   [C- SOFTWARE -0200]
204  */
205 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint001, Function | MediumTest | Level1)
206 {
207     int src = 'A';
208     int ret = isprint(src);
209     TEST_ASSERT_NOT_EQUAL(0, ret);
210     return 0;
211 }
212 
213 /* *
214  * @tc.number TEST_CTYPE_ISPRINT_002
215  * @tc.name   ctype_isprint test with not exist pid
216  * @tc.desc   [C- SOFTWARE -0200]
217  */
218 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint002, Function | MediumTest | Level1)
219 {
220     int src = '1';
221     int ret = isprint(src);
222     TEST_ASSERT_NOT_EQUAL(0, ret);
223     return 0;
224 }
225 
226 /* *
227  * @tc.number TEST_CTYPE_ISPRINT_003
228  * @tc.name   ctype_isprint test with not exist pid
229  * @tc.desc   [C- SOFTWARE -0200]
230  */
231 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint003, Function | MediumTest | Level1)
232 {
233     int src = '@';
234     int ret = isprint(src);
235     TEST_ASSERT_NOT_EQUAL(0, ret);
236     return 0;
237 }
238 
239 /* *
240  * @tc.number TEST_CTYPE_ISPRINT_004
241  * @tc.name   ctype_isprint test with not exist pid
242  * @tc.desc   [C- SOFTWARE -0200]
243  */
244 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint004, Function | MediumTest | Level1)
245 {
246     int src = ' ';
247     int ret = isprint(src);
248     TEST_ASSERT_NOT_EQUAL(0, ret);
249     return 0;
250 }
251 
252 /* *
253  * @tc.number TEST_CTYPE_ISPRINT_005
254  * @tc.name   ctype_isprint test with not exist pid
255  * @tc.desc   [C- SOFTWARE -0200]
256  */
257 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint005, Function | MediumTest | Level1)
258 {
259     int src = '\f'; // 0x0c
260     int ret = isprint(src);
261     TEST_ASSERT_EQUAL_INT(0, ret);
262     return 0;
263 }
264 
265 
266 /* *
267  * @tc.number TEST_CTYPE_ISSPACE_001
268  * @tc.name   Ctype_isspace test with not exist pid
269  * @tc.desc   [C- SOFTWARE -0200]
270  */
271 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace001, Function | MediumTest | Level1)
272 {
273     int src = 'A';
274     int ret = isspace(src);
275     TEST_ASSERT_EQUAL_INT(0, ret);
276     return 0;
277 }
278 
279 /* *
280  * @tc.number TEST_CTYPE_ISSPACE_002
281  * @tc.name   Ctype_isspace test with not exist pid
282  * @tc.desc   [C- SOFTWARE -0200]
283  */
284 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace002, Function | MediumTest | Level1)
285 {
286     int src = '1';
287     int ret = isspace(src);
288     TEST_ASSERT_EQUAL_INT(0, ret);
289     return 0;
290 }
291 
292 /* *
293  * @tc.number TEST_CTYPE_ISSPACE_003
294  * @tc.name   Ctype_isspace test with not exist pid
295  * @tc.desc   [C- SOFTWARE -0200]
296  */
297 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace003, Function | MediumTest | Level1)
298 {
299     int src = '@';
300     int ret = isspace(src);
301     TEST_ASSERT_EQUAL_INT(0, ret);
302     return 0;
303 }
304 
305 /* *
306  * @tc.number TEST_CTYPE_ISSPACE_004
307  * @tc.name   Ctype_isspace test with not exist pid
308  * @tc.desc   [C- SOFTWARE -0200]
309  */
310 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace004, Function | MediumTest | Level1)
311 {
312     int src = ' ';
313     int ret = isspace(src);
314     TEST_ASSERT_NOT_EQUAL(0, ret);
315     return 0;
316 }
317 
318 /* *
319  * @tc.number TEST_CTYPE_ISSPACE_005
320  * @tc.name   Ctype_isspace test with not exist pid
321  * @tc.desc   [C- SOFTWARE -0200]
322  */
323 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace005, Function | MediumTest | Level1)
324 {
325     int src = '\t';
326     int ret = isspace(src);
327     TEST_ASSERT_NOT_EQUAL(0, ret);
328     return 0;
329 }
330 
331 
332 /* *
333  * @tc.number TEST_CTYPE_ISUPPER_001
334  * @tc.name   Ctype_isupper test with not exist pid
335  * @tc.desc   [C- SOFTWARE -0200]
336  */
337 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper001, Function | MediumTest | Level1)
338 {
339     int src = 'A';
340     int ret = isupper(src);
341     TEST_ASSERT_NOT_EQUAL(0, ret);
342     return 0;
343 }
344 
345 /* *
346  * @tc.number TEST_CTYPE_ISUPPER_002
347  * @tc.name   Ctype_isupper test with not exist pid
348  * @tc.desc   [C- SOFTWARE -0200]
349  */
350 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper002, Function | MediumTest | Level1)
351 {
352     int src = 'a';
353     int ret = isupper(src);
354     TEST_ASSERT_EQUAL_INT(0, ret);
355     return 0;
356 }
357 
358 /* *
359  * @tc.number TEST_CTYPE_ISUPPER_003
360  * @tc.name   Ctype_isupper test with not exist pid
361  * @tc.desc   [C- SOFTWARE -0200]
362  */
363 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper003, Function | MediumTest | Level1)
364 {
365     const int src = 0x45;
366     int ret = isupper(src);
367     TEST_ASSERT_NOT_EQUAL(0, ret);
368     return 0;
369 }
370 
371 /* *
372  * @tc.number TEST_CTYPE_ISUPPER_004
373  * @tc.name   Ctype_isupper test with not exist pid
374  * @tc.desc   [C- SOFTWARE -0200]
375  */
376 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper004, Function | MediumTest | Level1)
377 {
378     int src = ' ';
379     int ret = isupper(src);
380     TEST_ASSERT_EQUAL_INT(0, ret);
381     return 0;
382 }
383 
384 /* *
385  * @tc.number TEST_CTYPE_ISUPPER_005
386  * @tc.name   Ctype_isupper test with not exist pid
387  * @tc.desc   [C- SOFTWARE -0200]
388  */
389 LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper005, Function | MediumTest | Level1)
390 {
391     int src = '\t';
392     int ret = isupper(src);
393     TEST_ASSERT_EQUAL_INT(0, ret);
394     return 0;
395 }
396 
397 RUN_TEST_SUITE(PosixCtypeFuncTestSuite);
398 
PosixCtypeFuncTest()399 void PosixCtypeFuncTest()
400 {
401     LOG("begin PosixCtypeFuncTest....");
402     RUN_ONE_TESTCASE(testCtypeIsalnum001);
403     RUN_ONE_TESTCASE(testCtypeIsalnum002);
404     RUN_ONE_TESTCASE(testCtypeIsalnum003);
405     RUN_ONE_TESTCASE(testCtypeIsalnum004);
406     RUN_ONE_TESTCASE(testCtypeIsalnum005);
407     RUN_ONE_TESTCASE(testCtypeIsascii001);
408     RUN_ONE_TESTCASE(testCtypeIsascii002);
409     RUN_ONE_TESTCASE(testCtypeIsascii003);
410     RUN_ONE_TESTCASE(testCtypeIsascii004);
411     RUN_ONE_TESTCASE(testCtypeIsascii005);
412     RUN_ONE_TESTCASE(testCtypeIsprint001);
413     RUN_ONE_TESTCASE(testCtypeIsprint002);
414     RUN_ONE_TESTCASE(testCtypeIsprint003);
415     RUN_ONE_TESTCASE(testCtypeIsprint004);
416     RUN_ONE_TESTCASE(testCtypeIsprint005);
417     RUN_ONE_TESTCASE(testCtypeIsspace001);
418     RUN_ONE_TESTCASE(testCtypeIsspace002);
419     RUN_ONE_TESTCASE(testCtypeIsspace003);
420     RUN_ONE_TESTCASE(testCtypeIsspace004);
421     RUN_ONE_TESTCASE(testCtypeIsspace005);
422     RUN_ONE_TESTCASE(testCtypeIsupper001);
423     RUN_ONE_TESTCASE(testCtypeIsupper002);
424     RUN_ONE_TESTCASE(testCtypeIsupper003);
425     RUN_ONE_TESTCASE(testCtypeIsupper004);
426     RUN_ONE_TESTCASE(testCtypeIsupper005);
427 
428     return;
429 }