1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdio.h>
17 #include <string.h>
18 #include <wchar.h>
19 #include "test.h"
20
21 /**
22 * @tc.name : wcsrchr_0100
23 * @tc.desc : Test wcsrchr to get the position of the last occurrence of the target wide character in the wide
24 * string
25 * @tc.level : Level 0
26 */
wcsrchr_0100(void)27 void wcsrchr_0100(void)
28 {
29 wchar_t *ch = L"hello, world";
30 wchar_t *result = wcsrchr(ch, L'h');
31 if (wcscmp(result, ch) != 0) {
32 t_error("%s wcsrchr get result is %s are not want 'hello, world'\n", __func__, result);
33 }
34 }
35
36 /**
37 * @tc.name : wcsrchr_0200
38 * @tc.desc : wcsrchr returns result when testing multiple occurrences of target character in wide string
39 * @tc.level : Level 1
40 */
wcsrchr_0200(void)41 void wcsrchr_0200(void)
42 {
43 wchar_t *ch = L"hello, world";
44 wchar_t *result = wcsrchr(ch, L'l');
45 if (wcscmp(result, ch + 10) != 0) {
46 t_error("%s wcsrchr get result is %s are not want 'ld'\n", __func__, result);
47 }
48 }
49
50 /**
51 * @tc.name : wcsrchr_0300
52 * @tc.desc : The test wide string does not contain the target wide character is the wcsrchr result
53 * @tc.level : Level 1
54 */
wcsrchr_0300(void)55 void wcsrchr_0300(void)
56 {
57 wchar_t *ch = L"hello, world";
58 wchar_t *result = wcsrchr(ch, L'a');
59 if (result) {
60 t_error("%s wcsrchr get result is %s are not want ''\n", __func__, result);
61 }
62 }
63
main(int argc,char * argv[])64 int main(int argc, char *argv[])
65 {
66 wcsrchr_0100();
67 wcsrchr_0200();
68 wcsrchr_0300();
69 return t_status;
70 }