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 <wctype.h>
18 #include <wchar.h>
19 #include "functionalext.h"
20
21 #define TEST_BUFFER_SIZE 128
22
23 /**
24 * @tc.name : mbstowcs_0100
25 * @tc.desc : Convert a multibyte string to a wide-character string
26 * @tc.level : Level 0
27 */
mbstowcs_0100(void)28 void mbstowcs_0100(void)
29 {
30 const char *src = "mbstowcs_0100";
31 wchar_t dst[TEST_BUFFER_SIZE];
32 const wchar_t *wsrc = L"mbstowcs_0100";
33
34 memset(dst, 0x0, sizeof(wchar_t) * TEST_BUFFER_SIZE);
35 size_t ret = mbstowcs(dst, src, strlen(src));
36 EXPECT_EQ("mbstowcs_0100", ret, strlen(src));
37
38 if (ret > 0) {
39 int r = wmemcmp(dst, wsrc, ret);
40 EXPECT_EQ("mbstowcs_0100", r, CMPFLAG);
41 }
42 }
43
44 /**
45 * @tc.name : mbstowcs_0200
46 * @tc.desc : Provide exception parameter data, convert the string to a wide string
47 * @tc.level : Level 2
48 */
mbstowcs_0200(void)49 void mbstowcs_0200(void)
50 {
51 const char *src = "mbstowcs_0200";
52 wchar_t dst[TEST_BUFFER_SIZE];
53 memset(dst, 0x0, sizeof(wchar_t) * TEST_BUFFER_SIZE);
54
55 size_t ret = mbstowcs(dst, src, 0);
56 if (ret != CMPFLAG) {
57 EXPECT_EQ("mbstowcs_0200", ret, CMPFLAG);
58 }
59
60 ret = mbstowcs(NULL, src, strlen(src));
61 EXPECT_EQ("mbstowcs_0200", ret, strlen(src));
62 }
63
main(void)64 int main(void)
65 {
66 mbstowcs_0100();
67 mbstowcs_0200();
68 return t_status;
69 }
70