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 <fcntl.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <wchar.h>
20 #include "functionalext.h"
21
22 const int32_t PUTC_RET = 112;
23 const int32_t CREAT_MODE = 666;
24
25 /**
26 * @tc.name : putwc_0100
27 * @tc.desc : Verify putwc process success
28 * @tc.level : Level 0
29 */
putwc_0100(void)30 void putwc_0100(void)
31 {
32 int32_t ret = creat("putwc_0100.txt", CREAT_MODE);
33 if (ret < 0) {
34 EXPECT_MT("putwc_0100", ret, 0);
35 return;
36 }
37 FILE *fptr = fopen("putwc_0100.txt", "w");
38 EXPECT_PTRNE("putwc_0100", fptr, NULL);
39 wchar_t wc = L'p';
40 ret = putwc(wc, fptr);
41 EXPECT_EQ("putwc_0100", ret, PUTC_RET);
42 ret = fclose(fptr);
43 EXPECT_EQ("putwc_0100", ret, 0);
44 remove("putwc_0100.txt");
45 }
46
47 /**
48 * @tc.name : putwc_0200
49 * @tc.desc : Verify fputc process failed.
50 * @tc.level : level 2.
51 */
putwc_0200(void)52 void putwc_0200(void)
53 {
54 int32_t ret = creat("putwc_0200.txt", CREAT_MODE);
55 if (ret < 0) {
56 EXPECT_MT("putwc_0200", ret, 0);
57 return;
58 }
59 FILE *fptr = fopen("putwc_0200.txt", "r");
60 EXPECT_PTRNE("putwc_0200", fptr, NULL);
61 wchar_t wc = L'p';
62 ret = putwc(wc, fptr);
63 EXPECT_EQ("putwc_0200", ret, WEOF);
64 ret = fclose(fptr);
65 EXPECT_EQ("putwc_0200", ret, 0);
66 remove("putwc_0200.txt");
67 }
68
main(void)69 int main(void)
70 {
71 putwc_0100();
72 putwc_0200();
73 return t_status;
74 }
75