• 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 "hctest.h"
34 #include "los_config.h"
35 #include "kernel_test.h"
36 #include <ctype.h>
37 #include <stdlib.h>
38 #include <string.h>
39 /* *
40  * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
41  * @param        : subsystem name is utils
42  * @param        : module name is utilsFile
43  * @param        : test suit name is CmsisTaskFuncTestSuite
44  */
45 LITE_TEST_SUIT(Posix, Posixtimer, PosixStringStrStrTest);
46 
47 /* *
48  * @tc.setup     : setup for all testcases
49  * @return       : setup result, TRUE is success, FALSE is fail
50  */
PosixStringStrStrTestSetUp(void)51 static BOOL PosixStringStrStrTestSetUp(void)
52 {
53     return TRUE;
54 }
55 
56 /* *
57  * @tc.teardown  : teardown for all testcases
58  * @return       : teardown result, TRUE is success, FALSE is fail
59  */
PosixStringStrStrTestTearDown(void)60 static BOOL PosixStringStrStrTestTearDown(void)
61 {
62     LOG("+-------------------------------------------+\n");
63     return TRUE;
64 }
65 
66 /* *
67  * @tc.number    : TEST_STRING_STRSTR_001
68  * @tc.name      : find the first occurrence of sub-string in a string
69  * @tc.desc      : [C- SOFTWARE -0200]
70  */
71 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr001, Function | MediumTest | Level1)
72 {
73     const char destS[] = "string this is string";
74     const char srcS[] = "string";
75 
76     char *ret = strstr(destS, srcS);
77     if (strcmp(ret, destS) == 0) {
78         LOG("[DEMO] posix string test case 1:strstr(%s) %s ok.\n", srcS, destS);
79     } else {
80         LOG("[DEMO] posix string test case 1:strstr(%s) %s fail.\n", srcS, destS);
81     }
82     TEST_ASSERT_EQUAL_STRING(ret, destS);
83 }
84 
85 /* *
86  * @tc.number    : TEST_STRING_STRSTR_002
87  * @tc.name      : find the first occurrence of sub-string in a string
88  * @tc.desc      : [C- SOFTWARE -0200]
89  */
90 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr002, Function | MediumTest | Level1)
91 {
92     const char destS[] = "string this is string";
93     const char srcS[] = "this is";
94 
95     char *ret = strstr(destS, srcS);
96     if (strcmp(ret, "this is string") == 0) {
97         LOG("[DEMO] posix string test case 2:strstr(%s) %s ok.\n", srcS, destS);
98     } else {
99         LOG("[DEMO] posix string test case 2:strstr(%s) %s fail.\n", srcS, destS);
100     }
101     TEST_ASSERT_EQUAL_STRING(ret, "this is string");
102 }
103 
104 /* *
105  * @tc.number    : TEST_STRING_STRSTR_003
106  * @tc.name      : find the first occurrence of sub-string in a string
107  * @tc.desc      : [C- SOFTWARE -0200]
108  */
109 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr003, Function | MediumTest | Level1)
110 {
111     const char dest[] = "hello world !";
112     const char srcT[] = "\0hello";
113 
114     char *ret = strstr(dest, srcT);
115     if (strcmp(ret, dest) == 0) {
116         LOG("[DEMO] posix string test case 3:strstr(%s) %s ok.\n", srcT, dest);
117     } else {
118         LOG("[DEMO] posix string test case 3:strstr(%s) %s fail.\n", srcT, dest);
119     }
120     TEST_ASSERT_EQUAL_STRING(ret, dest);
121 }
122 
123 /* *
124  * @tc.number    : TEST_STRING_STRSTR_004
125  * @tc.name      : find the first occurrence of sub-string in a string
126  * @tc.desc      : [C- SOFTWARE -0200]
127  */
128 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr004, Function | MediumTest | Level1)
129 {
130     const char dest[] = "hello world !";
131     const char src[] = "heAlo";
132 
133     char *ret = strstr(dest, src);
134     if (ret == NULL) {
135         LOG("[DEMO] posix string test case 4(except):strstr(%s) %s ok.\n", src, dest);
136     } else {
137         LOG("[DEMO] posix string test case 4(except):strstr(%s) %s fail.\n", src, dest);
138     }
139     TEST_ASSERT_NULL(ret);
140 }
141 
142 /* *
143  * @tc.number    : TEST_STRING_STRSTR_005
144  * @tc.name      : find the first occurrence of sub-string in a string
145  * @tc.desc      : [C- SOFTWARE -0200]
146  */
147 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr005, Function | MediumTest | Level1)
148 {
149     const char dest[] = "hello world !";
150     const char src[] = "hellm";
151 
152     char *ret = strstr(dest, src);
153     if (ret == NULL) {
154         LOG("[DEMO] posix string test case 5(except):strstr(%s) %s ok.\n", src, dest);
155     } else {
156         LOG("[DEMO] posix string test case 5(except):strstr(%s) %s fail.\n", src, dest);
157     }
158     TEST_ASSERT_NULL(ret);
159 }
160 
161 /* *
162  * @tc.number    : TEST_STRING_STRSTR_006
163  * @tc.name      : find the first occurrence of sub-string in a string
164  * @tc.desc      : [C- SOFTWARE -0200]
165  */
166 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr006, Function | MediumTest | Level1)
167 {
168     const char destS[] = "string this is string";
169     const char srcOne[] = "t"; // one byte
170 
171     char *ret = strstr(destS, srcOne);
172     if (strcmp(ret, "tring this is string") == 0) {
173         LOG("[DEMO] posix string test case 6:strstr(%s) %s ok.\n", srcOne, destS);
174     } else {
175         LOG("[DEMO] posix string test case 6:strstr(%s) %s fail.\n", srcOne, destS);
176     }
177     TEST_ASSERT_EQUAL_STRING(ret, "tring this is string");
178 }
179 
180 /* *
181  * @tc.number    : TEST_STRING_STRSTR_007
182  * @tc.name      : find the first occurrence of sub-string in a string
183  * @tc.desc      : [C- SOFTWARE -0200]
184  */
185 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr007, Function | MediumTest | Level1)
186 {
187     const char destS[] = "string this is string";
188     const char srcOne[] = "m"; // one byte
189 
190     char *ret = strstr(destS, srcOne);
191     if (ret == NULL) {
192         LOG("[DEMO] posix string test case 7(except):strstr(%s) %s ok.\n", srcOne, destS);
193     } else {
194         LOG("[DEMO] posix string test case 7(except):strstr(%s) %s fail.\n", srcOne, destS);
195     }
196     TEST_ASSERT_NULL(ret);
197 }
198 
199 /* *
200  * @tc.number    : TEST_STRING_STRSTR_008
201  * @tc.name      : find the first occurrence of sub-string in a string
202  * @tc.desc      : [C- SOFTWARE -0200]
203  */
204 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr008, Function | MediumTest | Level1)
205 {
206     const char destS[] = "string this is string";
207     const char srcTwo[] = "th"; // two byte
208 
209     char *ret = strstr(destS, srcTwo);
210     if (strcmp(ret, "this is string") == 0) {
211         LOG("[DEMO] posix string test case 8:strstr(%s) %s ok.\n", srcTwo, destS);
212     } else {
213         LOG("[DEMO] posix string test case 8:strstr(%s) %s fail.\n", srcTwo, destS);
214     }
215     TEST_ASSERT_EQUAL_STRING(ret, "this is string");
216 }
217 
218 /* *
219  * @tc.number    : TEST_STRING_STRSTR_009
220  * @tc.name      : find the first occurrence of sub-string in a string
221  * @tc.desc      : [C- SOFTWARE -0200]
222  */
223 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr009, Function | MediumTest | Level1)
224 {
225     const char destS[] = "string this is string";
226     const char srcTwo2[] = "tm"; // two byte
227 
228     char *ret = strstr(destS, srcTwo2);
229     if (ret == NULL) {
230         LOG("[DEMO] posix string test case 9(except):strstr(%s) %s ok.\n", srcTwo2, destS);
231     } else {
232         LOG("[DEMO] posix string test case 9(except):strstr(%s) %s fail.\n", srcTwo2, destS);
233     }
234     TEST_ASSERT_NULL(ret);
235 }
236 
237 /* *
238  * @tc.number    : TEST_STRING_STRSTR_010
239  * @tc.name      : find the first occurrence of sub-string in a string
240  * @tc.desc      : [C- SOFTWARE -0200]
241  */
242 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr010, Function | MediumTest | Level1)
243 {
244     const char destS[] = "string this is string";
245     const char srcThree[] = "thi"; // three byte
246 
247     char *ret = strstr(destS, srcThree);
248     if (strcmp(ret, "this is string") == 0) {
249         LOG("[DEMO] posix string test case 10:strstr(%s) %s ok.\n", srcThree, destS);
250     } else {
251         LOG("[DEMO] posix string test case 10:strstr(%s) %s fail.\n", srcThree, destS);
252     }
253     TEST_ASSERT_EQUAL_STRING(ret, "this is string");
254 }
255 
256 /* *
257  * @tc.number    : TEST_STRING_STRSTR_011
258  * @tc.name      : find the first occurrence of sub-string in a string
259  * @tc.desc      : [C- SOFTWARE -0200]
260  */
261 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr011, Function | MediumTest | Level1)
262 {
263     const char destS[] = "string this is string";
264     const char srcThree[] = "thm"; // three byte
265 
266     char *ret = strstr(destS, srcThree);
267     if (ret == NULL) {
268         LOG("[DEMO] posix string test case 11(except):strstr(%s) %s ok.\n", srcThree, destS);
269     } else {
270         LOG("[DEMO] posix string test case 11(except):strstr(%s) %s fail.\n", srcThree, destS);
271     }
272     TEST_ASSERT_NULL(ret);
273 }
274 
275 /* *
276  * @tc.number    : TEST_STRING_STRSTR_012
277  * @tc.name      : find the first occurrence of sub-string in a string
278  * @tc.desc      : [C- SOFTWARE -0200]
279  */
280 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr012, Function | MediumTest | Level1)
281 {
282     const char destS[] = "string this is string";
283     const char srcFour[] = "this"; // four byte
284 
285     char *ret = strstr(destS, srcFour);
286     if (strcmp(ret, "this is string") == 0) {
287         LOG("[DEMO] posix string test case 12:strstr(%s) %s ok.\n", srcFour, destS);
288     } else {
289         LOG("[DEMO] posix string test case 12:strstr(%s) %s fail.\n", srcFour, destS);
290     }
291     TEST_ASSERT_EQUAL_STRING(ret, "this is string");
292 }
293 
294 /* *
295  * @tc.number    : TEST_STRING_STRSTR_013
296  * @tc.name      : find the first occurrence of sub-string in a string
297  * @tc.desc      : [C- SOFTWARE -0200]
298  */
299 LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr013, Function | MediumTest | Level1)
300 {
301     const char destS[] = "string this is string";
302     const char srcFour[] = "thim"; // four byte
303 
304     char *ret = strstr(destS, srcFour);
305     if (ret == NULL) {
306         LOG("[DEMO] posix string test case 13(except):strstr(%s) %s ok.\n", srcFour, destS);
307     } else {
308         LOG("[DEMO] posix string test case 13(except):strstr(%s) %s fail.\n", srcFour, destS);
309     }
310     TEST_ASSERT_NULL(ret);
311 }
312 
313 RUN_TEST_SUITE(PosixStringStrStrTest);