• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <wchar.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include "test.h"
20 
21 /**
22  * @tc.name      : wcspbrk_0100
23  * @tc.desc      : Test wcspbrk to get the first occurrence of the target character in the source string
24  * @tc.level     : Level 0
25  */
wcspbrk_0100(void)26 void wcspbrk_0100(void)
27 {
28     const wchar_t *s = L"hello, world!";
29     wchar_t *result = wcspbrk(s, L"-");
30     if (result) {
31         t_error("%s wcspbrk get are not null\n", __func__);
32     }
33 }
34 
35 /**
36  * @tc.name      : wcspbrk_0200
37  * @tc.desc      : Test the result of wcspbrk when the target character appears at the first position of the source
38  *                 character
39  * @tc.level     : Level 1
40  */
wcspbrk_0200(void)41 void wcspbrk_0200(void)
42 {
43     const wchar_t *s = L"hello, world!";
44     wchar_t *result = wcspbrk(s, L"abch");
45     if (wcscmp(result, s) != 0) {
46         t_error("%s wcspbrk get result is %lc are not %lc\n", __func__, result, s);
47     }
48 }
49 
50 /**
51  * @tc.name      : wcspbrk_0300
52  * @tc.desc      : Test the result of wcspbrk when the target character appears in the middle of the source character
53  * @tc.level     : Level 1
54  */
wcspbrk_0300(void)55 void wcspbrk_0300(void)
56 {
57     const wchar_t *s = L"hello, world!";
58     wchar_t *result = wcspbrk(s, L"l");
59     if (wcscmp(result, s + 2) != 0) {
60         t_error("%s wcspbrk get result is %lc are not %lc\n", __func__, result, s + 2);
61     }
62 }
63 
64 /**
65  * @tc.name      : wcspbrk_0400
66  * @tc.desc      : Test the result of wcspbrk when the target character is punctuation
67  * @tc.level     : Level 1
68  */
wcspbrk_0400(void)69 void wcspbrk_0400(void)
70 {
71     const wchar_t *s = L"hello, world!";
72     wchar_t *result = wcspbrk(s, L",. !");
73     if (wcscmp(result, s + 5) != 0) {
74         t_error("%s wcspbrk get result is %lc are not %lc\n", __func__, result, s + 5);
75     }
76 }
77 
main(int argc,char * argv[])78 int main(int argc, char *argv[])
79 {
80     wcspbrk_0100();
81     wcspbrk_0200();
82     wcspbrk_0300();
83     wcspbrk_0400();
84     return t_status;
85 }