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
20 #include "functionalext.h"
21
22 #define ARRY_MAX 128
23
24 /**
25 * @tc.name : mblen_0100
26 * @tc.desc : whether the function successfully converted the character
27 * @tc.level : Level 0
28 */
mbtowc_0100(void)29 void mbtowc_0100(void)
30 {
31 const char *test = "musl";
32 wchar_t wc[ARRY_MAX];
33 size_t result = 0;
34 result = mbtowc(wc, test, 1);
35
36 EXPECT_EQ("mbtowc_0100", result, 1);
37 EXPECT_EQ("mbtowc_0100", wc[0], L'm');
38 }
39
40 /**
41 * @tc.name : mbtowc_0200
42 * @tc.desc : Pass in the return value of the abnormal length judgment function
43 * @tc.level : Level 2
44 */
mbtowc_0200(void)45 void mbtowc_0200(void)
46 {
47 const char *test = "musl";
48 wchar_t wc[ARRY_MAX];
49 size_t result = 0;
50 result = mbtowc(wc, test, 0);
51 EXPECT_EQ("mbtowc_0200", result, -1);
52 EXPECT_EQ("mbtowc_0200", errno, EILSEQ);
53
54 result = mbtowc(wc, NULL, 0);
55 EXPECT_EQ("mbtowc_0200", result, 0);
56 EXPECT_EQ("mbtowc_0200", errno, EILSEQ);
57
58 result = mbtowc(NULL, test, 1);
59 EXPECT_EQ("mbtowc_0200", result, 1);
60 EXPECT_EQ("mbtowc_0200", errno, EILSEQ);
61 }
62
main(void)63 int main(void)
64 {
65 mbtowc_0100();
66 mbtowc_0200();
67
68 return t_status;
69 }