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 <locale.h>
19 #include <wchar.h>
20 #include "test.h"
21
22 /**
23 * @tc.name : wctob_0100
24 * @tc.desc : Call the wctob function to convert wide characters to single bytes
25 * @tc.level : Level 0
26 */
wctob_0100(void)27 void wctob_0100(void)
28 {
29 wchar_t c = L'A';
30 int result = wctob(c);
31 if (result != 'A') {
32 t_error("%s wctob get result is %c are not 'A'", __func__, result);
33 }
34 }
35
36 /**
37 * @tc.name : wctob_0200
38 * @tc.desc : characters over 0x80
39 * @tc.level : Level 1
40 */
wctob_0200(void)41 void wctob_0200(void)
42 {
43 wchar_t c = L'\u00df';
44 int result = wctob(c);
45 if (result != EOF) {
46 t_error("%s wctob get result is %d are not -1", __func__, result);
47 }
48 }
49
50 /**
51 * @tc.name : wctob_0300
52 * @tc.desc : Wide characters exceed 0xff00
53 * @tc.level : Level 1
54 */
wctob_0300(void)55 void wctob_0300(void)
56 {
57 wchar_t c = L'\uff02';
58 int result = wctob(c);
59 if (result != EOF) {
60 t_error("%s wctob get result is %c are not EOF", __func__, result);
61 }
62 }
63
main(int argc,char * argv[])64 int main(int argc, char *argv[])
65 {
66 setlocale(LC_ALL, "en_US.utf8");
67
68 wctob_0100();
69 wctob_0200();
70 wctob_0300();
71 return t_status;
72 }