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 <signal.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <wchar.h>
20 #include "test.h"
21
22 #define BUFF_SIZE (40)
23
handler(int sig)24 void handler(int sig)
25 {
26 exit(t_status);
27 }
28
29 /**
30 * @tc.name : wcscpy_0100
31 * @tc.desc : Copies the C wide string pointed by wcs into the array pointed by des
32 * @tc.level : Level 0
33 */
wcscpy_0100(void)34 void wcscpy_0100(void)
35 {
36 wchar_t wcs[] = L"wcscpy test";
37 wchar_t des[BUFF_SIZE];
38 wcscpy(des, wcs);
39 if (wcscmp(wcs, des)) {
40 t_error("%s wcscpy failed", __func__);
41 }
42 }
43
44 /**
45 * @tc.name : wcscpy_0200
46 * @tc.desc : Copy when wcs is an empty string
47 * @tc.level : Level 1
48 */
wcscpy_0200(void)49 void wcscpy_0200(void)
50 {
51 wchar_t wcs[] = L"";
52 wchar_t des[] = L"wcscpy test";
53 wcscpy(des, wcs);
54 if (wcscmp(wcs, des)) {
55 t_error("%s des is not equal to wcs", __func__);
56 }
57 }
58
59 /**
60 * @tc.name : wcscpy_0300
61 * @tc.desc : des is empty, the program is abnormal
62 * @tc.level : Level 2
63 */
wcscpy_0300(void)64 void wcscpy_0300(void)
65 {
66 signal(SIGSEGV, handler);
67
68 wchar_t wcs[] = L"wcscpy test";
69 wcscpy(NULL, wcs);
70 }
71
main(int argc,char * argv[])72 int main(int argc, char *argv[])
73 {
74 wcscpy_0100();
75 wcscpy_0200();
76 wcscpy_0300();
77 return t_status;
78 }