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 : wcpncpy_0100
23 * @tc.desc : Test the wcpncpy method to copy a wide string in bits
24 * @tc.level : Level 0
25 */
wcpncpy_0100(void)26 void wcpncpy_0100(void)
27 {
28 wchar_t src[] = L"Source string";
29 wchar_t dst[18];
30 size_t src_len = 13;
31 wchar_t *result = wcpncpy(dst, src, src_len + 1);
32 if (wcscmp(result, dst + src_len) != 0) {
33 t_error("%s wcpncpy get result is %ls are not want %ls\n", __func__, result, dst + src_len);
34 }
35 if (wcscmp(src, dst) != 0) {
36 t_error("%s wcpncpy get dst is %ls are not want %ls\n", __func__, dst, src);
37 }
38 }
39
40 /**
41 * @tc.name : wcpncpy_0200
42 * @tc.desc : Test the result of the wcpncpy method when the incoming length is less than the copied wide string
43 * @tc.level : Level 1
44 */
wcpncpy_0200(void)45 void wcpncpy_0200(void)
46 {
47 wchar_t src[] = L"Source string";
48 wchar_t dst[18];
49 size_t src_len = 13;
50 wchar_t *result = wcpncpy(dst, src, 2);
51 if (wcscmp(result, dst + 2) != 0) {
52 t_error("%s wcpncpy get result is %ls are not want %ls\n", __func__, result, dst + 2);
53 }
54 if (wcscmp(dst, L"So") != 0) {
55 t_error("%s wcpncpy get dst is %ls are not want %ls\n", __func__, dst, src);
56 }
57 }
58
59 /**
60 * @tc.name : wcpncpy_0300
61 * @tc.desc : Test the result of the wcpncpy method when the incoming length is greater than the copied wide string
62 * @tc.level : Level 1
63 */
wcpncpy_0300(void)64 void wcpncpy_0300(void)
65 {
66 wchar_t src[] = L"Source string";
67 wchar_t dst[18];
68 size_t src_len = 13;
69 wchar_t *result = wcpncpy(dst, src, 17);
70 if (wcscmp(result, dst + src_len) != 0) {
71 t_error("%s wcpncpy get result is %ls are not want %ls\n", __func__, result, dst + src_len);
72 }
73 if (wcscmp(src, dst) != 0) {
74 t_error("%s wcpncpy get dst is %ls are not want %ls\n", __func__, dst, src);
75 }
76 }
77
main(int argc,char * argv[])78 int main(int argc, char *argv[])
79 {
80 wcpncpy_0100();
81 wcpncpy_0200();
82 wcpncpy_0300();
83 return t_status;
84 }