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, PosixCTypeIsxdigitTest);
47
48 /* *
49 * @tc.setup : setup for all testcases
50 * @return : setup result, TRUE is success, FALSE is fail
51 */
PosixCTypeIsxdigitTestSetUp(void)52 static BOOL PosixCTypeIsxdigitTestSetUp(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 */
PosixCTypeIsxdigitTestTearDown(void)61 static BOOL PosixCTypeIsxdigitTestTearDown(void)
62 {
63 LOG("+-------------------------------------------+\n");
64 return TRUE;
65 }
66
67 /* *
68 * @tc.number : TEST_CTYPE_ISXDIGIT_001
69 * @tc.name : Checks whether a parameter is a hexadecimal digit
70 * @tc.desc : [C- SOFTWARE -0200]
71 */
72 LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit001, Function | MediumTest | Level1)
73 {
74 int a = '0';
75 int ret = isxdigit(a);
76 if (ret != 0) {
77 LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
78 } else {
79 LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
80 }
81 TEST_ASSERT_NOT_EQUAL(0, ret);
82 return 0;
83 }
84
85 /* *
86 * @tc.number : TEST_CTYPE_ISXDIGIT_002
87 * @tc.name : Checks whether a parameter is a hexadecimal digit
88 * @tc.desc : [C- SOFTWARE -0200]
89 */
90 LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit002, Function | MediumTest | Level1)
91 {
92 int a = '5';
93 int ret = isxdigit(a);
94 if (ret != 0) {
95 LOG("[DEMO] posix ctype test case 2:isxdigit(%c) ok.\n", a);
96 } else {
97 LOG("[DEMO] posix ctype test case 2:isxdigit(%c) fail.\n", a);
98 }
99 TEST_ASSERT_NOT_EQUAL(0, ret);
100 return 0;
101 }
102
103 /* *
104 * @tc.number : TEST_CTYPE_ISXDIGIT_003
105 * @tc.name : Checks whether a parameter is a hexadecimal digit
106 * @tc.desc : [C- SOFTWARE -0200]
107 */
108 LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit003, Function | MediumTest | Level1)
109 {
110 int a = '9';
111 int ret = isxdigit(a);
112 if (ret != 0) {
113 LOG("[DEMO] posix ctype test case 3:isxdigit(%c) ok.\n", a);
114 } else {
115 LOG("[DEMO] posix ctype test case 3:isxdigit(%c) fail.\n", a);
116 }
117 TEST_ASSERT_NOT_EQUAL(0, ret);
118 return 0;
119 }
120
121 /* *
122 * @tc.number : TEST_CTYPE_ISXDIGIT_004
123 * @tc.name : Checks whether a parameter is a hexadecimal digit
124 * @tc.desc : [C- SOFTWARE -0200]
125 */
126 LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit004, Function | MediumTest | Level1)
127 {
128 int a = 'a';
129 int ret = isxdigit(a);
130 if (ret != 0) {
131 LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
132 } else {
133 LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
134 }
135 TEST_ASSERT_NOT_EQUAL(0, ret);
136 return 0;
137 }
138
139 /* *
140 * @tc.number : TEST_CTYPE_ISXDIGIT_005
141 * @tc.name : Checks whether a parameter is a hexadecimal digit
142 * @tc.desc : [C- SOFTWARE -0200]
143 */
144 LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit005, Function | MediumTest | Level1)
145 {
146 int a = 'f';
147 int ret = isxdigit(a);
148 if (ret != 0) {
149 LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
150 } else {
151 LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
152 }
153 TEST_ASSERT_NOT_EQUAL(0, ret);
154 return 0;
155 }
156
157 /* *
158 * @tc.number : TEST_CTYPE_ISXDIGIT_006
159 * @tc.name : Checks whether a parameter is a hexadecimal digit
160 * @tc.desc : [C- SOFTWARE -0200]
161 */
162 LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit006, Function | MediumTest | Level1)
163 {
164 int a = 'A';
165 int ret = isxdigit(a);
166 if (ret != 0) {
167 LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
168 } else {
169 LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
170 }
171 TEST_ASSERT_NOT_EQUAL(0, ret);
172 return 0;
173 }
174
175 /* *
176 * @tc.number : TEST_CTYPE_ISXDIGIT_007
177 * @tc.name : Checks whether a parameter is a hexadecimal digit
178 * @tc.desc : [C- SOFTWARE -0200]
179 */
180 LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit007, Function | MediumTest | Level1)
181 {
182 int a = 'F';
183 int ret = isxdigit(a);
184 if (ret != 0) {
185 LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
186 } else {
187 LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
188 }
189 TEST_ASSERT_NOT_EQUAL(0, ret);
190 return 0;
191 }
192
193 /* *
194 * @tc.number : TEST_CTYPE_ISXDIGIT_008
195 * @tc.name : Checks whether a parameter is a hexadecimal digit
196 * @tc.desc : [C- SOFTWARE -0200]
197 */
198 LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit008, Function | MediumTest | Level1)
199 {
200 int a = 'F' + 1;
201 int ret = isxdigit(a);
202 if (ret == 0) {
203 LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) ok.\n", a);
204 } else {
205 LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) fail.\n", a);
206 }
207 TEST_ASSERT_EQUAL_INT(0, ret);
208 return 0;
209 }
210
211 /* *
212 * @tc.number : TEST_CTYPE_ISXDIGIT_009
213 * @tc.name : Checks whether a parameter is a hexadecimal digit
214 * @tc.desc : [C- SOFTWARE -0200]
215 */
216 LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit009, Function | MediumTest | Level1)
217 {
218 int a = '0' - 1;
219 int ret = isxdigit(a);
220 if (ret == 0) {
221 LOG("[DEMO] posix ctype test case 4(except):isxdigit(%c) ok.\n", a);
222 } else {
223 LOG("[DEMO] posix ctype test case 4(except):isxdigit(%c) fail.\n", a);
224 }
225 TEST_ASSERT_EQUAL_INT(0, ret);
226 return 0;
227 }
228
229 /* *
230 * @tc.number : TEST_CTYPE_ISXDIGIT_010
231 * @tc.name : Checks whether a parameter is a hexadecimal digit
232 * @tc.desc : [C- SOFTWARE -0200]
233 */
234 LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit010, Function | MediumTest | Level1)
235 {
236 int a = '9' + 1;
237 int ret = isxdigit(a);
238 if (ret == 0) {
239 LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) ok.\n", a);
240 } else {
241 LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) fail.\n", a);
242 }
243 TEST_ASSERT_EQUAL_INT(0, ret);
244 return 0;
245 }
246
247 RUN_TEST_SUITE(PosixCTypeIsxdigitTest);
248
PosixIsxdigitFuncTest()249 void PosixIsxdigitFuncTest()
250 {
251 LOG("begin PosixIsxdigitFuncTest....");
252 RUN_ONE_TESTCASE(testCTypeIsxdigit001);
253 RUN_ONE_TESTCASE(testCTypeIsxdigit002);
254 RUN_ONE_TESTCASE(testCTypeIsxdigit003);
255 RUN_ONE_TESTCASE(testCTypeIsxdigit004);
256 RUN_ONE_TESTCASE(testCTypeIsxdigit005);
257 RUN_ONE_TESTCASE(testCTypeIsxdigit006);
258 RUN_ONE_TESTCASE(testCTypeIsxdigit007);
259 RUN_ONE_TESTCASE(testCTypeIsxdigit008);
260 RUN_ONE_TESTCASE(testCTypeIsxdigit009);
261 RUN_ONE_TESTCASE(testCTypeIsxdigit010);
262
263 return;
264 }