• 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 <stdio.h>
17 #include <string.h>
18 #include <stdlib.h>
19 #include <locale.h>
20 #include <wchar.h>
21 #include "test.h"
22 
23 /**
24  * @tc.name      : wctomb_0100
25  * @tc.desc      : Test the wctomb method to copy wide characters into a string
26  * @tc.level     : Level 0
27  */
wctomb_0100(void)28 void wctomb_0100(void)
29 {
30     char byte[256] = {0};
31     int result = wctomb(byte, L'h');
32     if (result != 1) {
33         t_error("%s wctomb get result is %d are not want 1\n", __func__, result);
34     }
35 }
36 
37 /**
38  * @tc.name      : wctomb_0200
39  * @tc.desc      : Test the result of wctomb when the incoming wide character is the terminator
40  * @tc.level     : Level 1
41  */
wctomb_0200(void)42 void wctomb_0200(void)
43 {
44     char byte[256] = {0};
45     int result = wctomb(byte, L'\0');
46     if (result != 1) {
47         t_error("%s wctomb get result is %d are not want 1\n", __func__, result);
48     }
49 }
50 
51 /**
52  * @tc.name      : wctomb_0300
53  * @tc.desc      : wctomb result when test string is NULL
54  * @tc.level     : Level 2
55  */
wctomb_0300(void)56 void wctomb_0300(void)
57 {
58     int result = wctomb(NULL, L'h');
59     if (result != 0) {
60         t_error("%s wctomb get result is %d are not want 0\n", __func__, result);
61     }
62 }
63 
64 /**
65  * @tc.name      : wctomb_0400
66  * @tc.desc      : wctomb result when test string is NULL and wide character is terminator
67  * @tc.level     : Level 2
68  */
wctomb_0400(void)69 void wctomb_0400(void)
70 {
71     int result = wctomb(NULL, L'\0');
72     if (result != 0) {
73         t_error("%s wctomb get result is %d are not want 0\n", __func__, result);
74     }
75 }
76 
main(int argc,char * argv[])77 int main(int argc, char *argv[])
78 {
79     wctomb_0100();
80     wctomb_0200();
81     wctomb_0300();
82     wctomb_0400();
83     return t_status;
84 }