• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      : mbsnrtowcs_0100
26  * @tc.desc      : whether the function successfully converted the character
27  * @tc.level     : Level 0
28  */
mbsnrtowcs_0100(void)29 void mbsnrtowcs_0100(void)
30 {
31     const char *test = "musl test";
32 
33     wchar_t wc[ARRY_MAX];
34     memset(wc, 0, sizeof(wc));
35 
36     size_t result = mbsnrtowcs(wc, &test, 2, ARRY_MAX, NULL);
37     if (result != -1) {
38         EXPECT_EQ("mbsnrtowcs_0100", result, 2);
39         EXPECT_EQ("mbsnrtowcs_0100", wc[0], L'm');
40         EXPECT_EQ("mbsnrtowcs_0100", wc[1], L'u');
41     }
42 }
43 
44 /**
45  * @tc.name      : mbsnrtowcs_0200
46  * @tc.desc      : Pass in the return value of the abnormal length judgment function
47  * @tc.level     : Level 2
48  */
mbsnrtowcs_0200(void)49 void mbsnrtowcs_0200(void)
50 {
51     const char *test = "musl test";
52     wchar_t wc[ARRY_MAX];
53     memset(wc, 0, sizeof(wc));
54     size_t result = mbsnrtowcs(wc, &test, 11, ARRY_MAX, NULL);
55 
56     EXPECT_EQ("mbsnrtowcs_0200", result, 9);
57 }
58 
main(void)59 int main(void)
60 {
61     mbsnrtowcs_0100();
62     mbsnrtowcs_0200();
63 
64     return t_status;
65 }