• 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 <ctype.h>
33 #include "ohos_types.h"
34 #include "posix_test.h"
35 #include "los_config.h"
36 #include "kernel_test.h"
37 #include "log.h"
38 
39 
40 /**
41  * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
42  * @param        : subsystem name is utils
43  * @param        : module name is utilsFile
44  * @param        : test suit name is CmsisTaskFuncTestSuite
45  */
46 LITE_TEST_SUIT(Posix, Posixtimer, PosixCTypeIsdigitTest);
47 
48 /**
49  * @tc.setup     : setup for all testcases
50  * @return       : setup result, TRUE is success, FALSE is fail
51  */
PosixCTypeIsdigitTestSetUp(void)52 static BOOL PosixCTypeIsdigitTestSetUp(void)
53 {
54     return TRUE;
55 }
56 
57 /**
58  * @tc.teardown  : teardown for all testcases
59  * @return       : teardown result, TRUE is success, FALSE is fail
60  */
PosixCTypeIsdigitTestTearDown(void)61 static BOOL PosixCTypeIsdigitTestTearDown(void)
62 {
63     LOG("+-------------------------------------------+\n");
64     return TRUE;
65 }
66 
67 /**
68  * @tc.number    : TEST_CTYPE_ISDIGIT_001
69  * @tc.name      : Checks whether a parameter is a decimal digit (0-9)
70  * @tc.desc      : [C- SOFTWARE -0200]
71  */
72 LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit001, Function | MediumTest | Level1)
73 {
74     int a = '0';
75     int ret = isdigit(a);
76     if (ret != 0) {
77         LOG("[DEMO] posix ctype test case 1:isdigit(%c) ok.\n", a);
78     }
79     else {
80         LOG("[DEMO] posix ctype test case 1:isdigit(%c) fail.\n", a);
81     }
82     TEST_ASSERT_NOT_EQUAL(0, ret);
83     return 0;
84 }
85 
86 /**
87  * @tc.number    : TEST_CTYPE_ISDIGIT_002
88  * @tc.name      : Checks whether a parameter is a decimal digit (0-9)
89  * @tc.desc      : [C- SOFTWARE -0200]
90  */
91 LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit002, Function | MediumTest | Level1)
92 {
93     int a = '5';
94     int ret = isdigit(a);
95     if (ret != 0) {
96         LOG("[DEMO] posix ctype test case 2:isdigit(%c) ok.\n", a);
97     }
98     else {
99         LOG("[DEMO] posix ctype test case 2:isdigit(%c) fail.\n", a);
100     }
101     TEST_ASSERT_NOT_EQUAL(0, ret);
102     return 0;
103 }
104 
105 /**
106  * @tc.number    : TEST_CTYPE_ISDIGIT_003
107  * @tc.name      : Checks whether a parameter is a decimal digit (0-9)
108  * @tc.desc      : [C- SOFTWARE -0200]
109  */
110 LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit003, Function | MediumTest | Level1)
111 {
112     int a = '9';
113     int ret = isdigit(a);
114     if (ret != 0) {
115         LOG("[DEMO] posix ctype test case 3:isdigit(%c) ok.\n", a);
116     }
117     else {
118         LOG("[DEMO] posix ctype test case 3:isdigit(%c) fail.\n", a);
119     }
120     TEST_ASSERT_NOT_EQUAL(0, ret);
121     return 0;
122 }
123 
124 /**
125  * @tc.number    : TEST_CTYPE_ISDIGIT_004
126  * @tc.name      : Checks whether a parameter is a decimal digit (0-9)
127  * @tc.desc      : [C- SOFTWARE -0200]
128  */
129 LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit004, Function | MediumTest | Level1)
130 {
131     int a = '0' - 1;
132     int ret = isdigit(a);
133     if (ret == 0) {
134         LOG("[DEMO] posix ctype test case 4(except):isdigit(%c) ok.\n", a);
135     }
136     else {
137         LOG("[DEMO] posix ctype test case 4(except):isdigit(%c) fail.\n", a);
138     }
139     TEST_ASSERT_EQUAL_INT(0, ret);
140     return 0;
141 }
142 
143 /**
144  * @tc.number    : TEST_CTYPE_ISDIGIT_005
145  * @tc.name      : Checks whether a parameter is a decimal digit (0-9)
146  * @tc.desc      : [C- SOFTWARE -0200]
147  */
148 LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit005, Function | MediumTest | Level1)
149 {
150     int a = '9' + 1;
151     int ret = isdigit(a);
152     if (ret == 0) {
153         LOG("[DEMO] posix ctype test case 5(except):isdigit(%c) ok.\n", a);
154     }
155     else {
156         LOG("[DEMO] posix ctype test case 5(except):isdigit(%c) fail.\n", a);
157     }
158     TEST_ASSERT_EQUAL_INT(0, ret);
159     return 0;
160 }
161 
162 RUN_TEST_SUITE(PosixCTypeIsdigitTest);
163 
164 
PosixIsdigitFuncTest()165 void PosixIsdigitFuncTest()
166 {
167     LOG("begin PosixIsdigitFuncTest....");
168     RUN_ONE_TESTCASE(testCTypeIsdigit001);
169     RUN_ONE_TESTCASE(testCTypeIsdigit002);
170     RUN_ONE_TESTCASE(testCTypeIsdigit003);
171     RUN_ONE_TESTCASE(testCTypeIsdigit004);
172     RUN_ONE_TESTCASE(testCTypeIsdigit005);
173 
174     return;
175 }
176 
177