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 <stdlib.h>
17 #include <wchar.h>
18
19 #include "test.h"
20
21 #define BUF_SIZE (40)
22
23 /**
24 * @tc.name : wcstombs_0100
25 * @tc.desc : convert a wide-character string to a multibyte string
26 * @tc.level : Level 0
27 */
wcstombs_0100(void)28 void wcstombs_0100(void)
29 {
30 char buf[BUF_SIZE] = {0};
31 wchar_t src[] = L"Hello";
32
33 size_t result = wcstombs(buf, src, BUF_SIZE);
34 if (result < 0) {
35 t_error("%s failed: wcstombs. result = %zu\n", __func__, result);
36 }
37 }
38
39 /**
40 * @tc.name : wcstombs_0200
41 * @tc.desc : convert a wide-character string to a multibyte string with zero size
42 * @tc.level : Level 1
43 */
wcstombs_0200(void)44 void wcstombs_0200(void)
45 {
46 char buf[BUF_SIZE] = {0};
47 wchar_t src[] = L"Hello";
48
49 size_t result = wcstombs(buf, src, 0);
50 if (result != 0) {
51 t_error("%s failed: wcstombs. result = %zu\n", __func__, result);
52 }
53 }
54
55 /**
56 * @tc.name : wcstombs_0300
57 * @tc.desc : convert a wide-character string to NULL
58 * @tc.level : Level 2
59 */
wcstombs_0300(void)60 void wcstombs_0300(void)
61 {
62 wchar_t src[] = L"Hello";
63
64 size_t result = wcstombs(NULL, src, 0);
65 if (result != wcslen(src)) {
66 t_error("%s failed: wcstombs. result = %zu\n", __func__, result);
67 }
68 }
69
main(int argc,char * argv[])70 int main(int argc, char *argv[])
71 {
72 wcstombs_0100();
73 wcstombs_0200();
74 wcstombs_0300();
75
76 return t_status;
77 }
78