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 <stdlib.h>
19 #include <signal.h>
20 #include <wchar.h>
21 #include "test.h"
22
deal_aberrant(int code)23 void deal_aberrant(int code)
24 {
25 if (code != SIGSEGV) {
26 t_error("wcsdup_0200 code is %d are not SIGSEGV", __func__, code);
27 }
28 exit(t_status);
29 }
30
31 /**
32 * @tc.name : wcsdup_0100
33 * @tc.desc : Call wcsdup to get a newly allocated wide string
34 * @tc.level : Level 0
35 */
wcsdup_0100(void)36 void wcsdup_0100(void)
37 {
38 wchar_t *src = L"hello";
39 wchar_t *result = wcsdup(src);
40 if (wcscmp(src, result) != 0) {
41 t_error("%s wcscmp get result is %ls are not want %ls\n", __func__, result, src);
42 }
43 }
44
45 /**
46 * @tc.name : wcsdup_0200
47 * @tc.desc : Test the wcsdup result when the incoming null
48 * @tc.level : Level 2
49 */
wcsdup_0200(void)50 void wcsdup_0200(void)
51 {
52 signal(SIGSEGV, deal_aberrant);
53 wchar_t *result = wcsdup(NULL);
54 }
55
main(int argc, char *argv[])56 int main(int argc, char *argv[])
57 {
58 wcsdup_0100();
59 wcsdup_0200();
60 return t_status;
61 }