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, PosixCTypeTolowerTest);
47
48 /* *
49 * @tc.setup : setup for all testcases
50 * @return : setup result, TRUE is success, FALSE is fail
51 */
PosixCTypeTolowerTestSetUp(void)52 static BOOL PosixCTypeTolowerTestSetUp(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 */
PosixCTypeTolowerTestTearDown(void)61 static BOOL PosixCTypeTolowerTestTearDown(void)
62 {
63 LOG("+-------------------------------------------+\n");
64 return TRUE;
65 }
66
67 /* *
68 * @tc.number : TEST_CTYPE_TOLOWER_001
69 * @tc.name : Converts an uppercase letter specified by c to its lowercase equivalent
70 * @tc.desc : [C- SOFTWARE -0200]
71 */
72 LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower001, Function | MediumTest | Level1)
73 {
74 int a = 'a';
75 int ret = tolower(a);
76 if (ret == 'a') {
77 LOG("[DEMO] posix ctype test case 1:tolower(%c)==%c ok.\n", a, ret);
78 } else {
79 LOG("[DEMO] posix ctype test case 1:tolower(%c)!=%c fail.\n", a, ret);
80 }
81 ICUNIT_ASSERT_EQUAL(ret, 'a', ret);
82 return 0;
83 }
84
85 /* *
86 * @tc.number : TEST_CTYPE_TOLOWER_002
87 * @tc.name : Converts an uppercase letter specified by c to its lowercase equivalent
88 * @tc.desc : [C- SOFTWARE -0200]
89 */
90 LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower002, Function | MediumTest | Level1)
91 {
92 int a = 'A';
93 int ret = tolower(a);
94 if (ret == 'a') {
95 LOG("[DEMO] posix ctype test case 2:tolower(%c)==%c ok.\n", a, ret);
96 } else {
97 LOG("[DEMO] posix ctype test case 2:tolower(%c)!=%c fail.\n", a, ret);
98 }
99 ICUNIT_ASSERT_EQUAL(ret, 'a', ret);
100 return 0;
101 }
102
103 /* *
104 * @tc.number : TEST_CTYPE_TOLOWER_003
105 * @tc.name : Converts an uppercase letter to lowercase equivalent
106 * @tc.desc : [C- SOFTWARE -0200]
107 */
108 LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower003, Function | MediumTest | Level1)
109 {
110 int a = 'z';
111 int ret = tolower(a);
112 if (ret == 'z') {
113 LOG("[DEMO] posix ctype test case 3:tolower(%c)==%c ok.\n", a, ret);
114 } else {
115 LOG("[DEMO] posix ctype test case 3:tolower(%c)!=%c fail.\n", a, ret);
116 }
117 ICUNIT_ASSERT_EQUAL(ret, 'z', ret);
118 return 0;
119 }
120
121 /* *
122 * @tc.number : TEST_CTYPE_TOLOWER_004
123 * @tc.name : Converts an uppercase letter to its lowercase equivalent
124 * @tc.desc : [C- SOFTWARE -0200]
125 */
126 LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower004, Function | MediumTest | Level1)
127 {
128 int a = 'Z';
129 int ret = tolower(a);
130 if (ret == 'z') {
131 LOG("[DEMO] posix ctype test case 4:tolower(%c)==%c ok.\n", a, ret);
132 } else {
133 LOG("[DEMO] posix ctype test case 4:tolower(%c)!=%c fail.\n", a, ret);
134 }
135 ICUNIT_ASSERT_EQUAL(ret, 'z', ret);
136 return 0;
137 }
138
139 /* *
140 * @tc.number : TEST_CTYPE_TOLOWER_005
141 * @tc.name : Converts an uppercase letter to its lowercase equivalent
142 * @tc.desc : [C- SOFTWARE -0200]
143 */
144 LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower005, Function | MediumTest | Level1)
145 {
146 int a = '1';
147 int ret = tolower(a);
148 if (ret == '1') {
149 LOG("[DEMO] posix ctype test case 5(except):tolower(%c)==%c ok.\n", a, ret);
150 } else {
151 LOG("[DEMO] posix ctype test case 5(except):tolower(%c)!=%c fail.\n", a, ret);
152 }
153 ICUNIT_ASSERT_EQUAL(ret, '1', ret);
154 return 0;
155 }
156
PosixTolowerFuncTest()157 void PosixTolowerFuncTest()
158 {
159 LOG("begin PosixTolowerFuncTest....");
160 RUN_ONE_TESTCASE(testCTypeTolower001);
161 RUN_ONE_TESTCASE(testCTypeTolower002);
162 RUN_ONE_TESTCASE(testCTypeTolower003);
163 RUN_ONE_TESTCASE(testCTypeTolower004);
164 RUN_ONE_TESTCASE(testCTypeTolower005);
165
166 return;
167 }