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 <stdlib.h>
18 #include "functionalext.h"
19
20 const int32_t INIT_LEN = 0;
21
22 /**
23 * @tc.name : fflush_0100
24 * @tc.desc : Verify fflush process success and return 0.
25 * @tc.level : level 0
26 */
fflush_0100(void)27 void fflush_0100(void)
28 {
29 int32_t ret = fflush(NULL);
30 EXPECT_EQ("fflush_0100", ret, INIT_LEN);
31 }
32
33 /**
34 * @tc.name : fflush_0200
35 * @tc.desc : Verify fflush and stdout process success and return 0.
36 * @tc.level : level 0
37 */
fflush_0200(void)38 void fflush_0200(void)
39 {
40 char array[] = "this is fflush test!";
41 int32_t ret = fprintf(stdout, "%s", array);
42 EXPECT_MT("fflush_0200", ret, 0);
43 ret = fflush(NULL);
44 EXPECT_EQ("fflush_0200", ret, INIT_LEN);
45 }
46
47 /**
48 * @tc.name : fflush_0300
49 * @tc.desc : Verify fflush and stderr process success and return 0.
50 * @tc.level : level 0
51 */
fflush_0300(void)52 void fflush_0300(void)
53 {
54 char array[] = "this is fflush error!";
55 int32_t ret = fprintf(stderr, "%s", array);
56 EXPECT_MT("fflush_0300", ret, 0);
57 ret = fflush(NULL);
58 EXPECT_EQ("fflush_0300", ret, INIT_LEN);
59 }
60
61 /**
62 * @tc.name : fflush_0400
63 * @tc.desc : Verify fflush and fopen("w") and fclose process success and return 0.
64 * @tc.level : level 0
65 */
fflush_0400(void)66 void fflush_0400(void)
67 {
68 FILE *fptr = fopen("/data/tempory_testff.txt", "w");
69 int32_t ret = 0;
70 if (fptr != NULL) {
71 fputs("fopen is success", fptr);
72 ret = fflush(fptr);
73 fclose(fptr);
74 }
75 EXPECT_EQ("fflush_0400", ret, INIT_LEN);
76 }
77
78 /**
79 * @tc.name : fflush_0500
80 * @tc.desc : Verify fflush and fopen("r") and fclose process success and return 0.
81 * @tc.level : level 0
82 */
fflush_0500(void)83 void fflush_0500(void)
84 {
85 FILE *fptr = fopen("/data/tempory_testff.txt", "r");
86 int32_t ret = 0;
87 if (fptr != NULL) {
88 ret = fflush(fptr);
89 fclose(fptr);
90 }
91 EXPECT_EQ("fflush_0500", ret, INIT_LEN);
92 remove("/data/tempory_testff.txt");
93 }
94
main(void)95 int main(void)
96 {
97 fflush_0100();
98 fflush_0200();
99 fflush_0300();
100 fflush_0400();
101 fflush_0500();
102 return t_status;
103 }
104