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_ext.h>
17 #include "functionalext.h"
18
19 const char *path = "/data/fpending.txt";
20
21 /**
22 * @tc.name : __fpending_0100
23 * @tc.desc : The parameter is valid, f is the file opened in w mode, there is data in the buffer,
24 * get the number of bytes in the current buffer.
25 * @tc.level : Level 0
26 */
__fpending_0100(void)27 void __fpending_0100(void)
28 {
29 char *str = "This is a test";
30 FILE *fp = fopen(path, "w");
31 EXPECT_PTRNE("__fpending_0100", fp, NULL);
32
33 fputs(str, fp);
34 size_t ret = __fpending(fp);
35 EXPECT_TRUE("__fpending_0100", ret > 0);
36 EXPECT_EQ("__fpending_0100", ret, strlen(str));
37
38 fclose(fp);
39 remove(path);
40 }
41
42 /**
43 * @tc.name : __fpending_0200
44 * @tc.desc : The parameter is valid, f is the file opened in w mode, there is no data in the buffer,
45 * et the number of bytes in the current buffer.
46 * @tc.level : Level 1
47 */
__fpending_0200(void)48 void __fpending_0200(void)
49 {
50 char *str = "This is a test";
51 FILE *fp = fopen(path, "w");
52 EXPECT_PTRNE("__fpending_0200", fp, NULL);
53
54 fputs(str, fp);
55 fflush(fp);
56 size_t ret = __fpending(fp);
57 EXPECT_EQ("__fpending_0200", ret, 0);
58
59 fclose(fp);
60 remove(path);
61 }
62
63 /**
64 * @tc.name : __fpending_0300
65 * @tc.desc : The parameter is valid, f is the file opened in r mode, and the number of bytes in
66 * the current buffer cannot be obtained.
67 * @tc.level : Level 2
68 */
__fpending_0300(void)69 void __fpending_0300(void)
70 {
71 char *str = "This is a test";
72 FILE *fp = fopen(path, "w");
73 EXPECT_PTRNE("__fpending_0300", fp, NULL);
74
75 fputs(str, fp);
76 fclose(fp);
77
78 FILE *ffp = fopen(path, "r");
79 size_t ret = __fpending(ffp);
80 EXPECT_EQ("__fpending_0300", ret, 0);
81
82 fclose(ffp);
83 remove(path);
84 }
85
main(int argc,char * argv[])86 int main(int argc, char *argv[])
87 {
88 __fpending_0100();
89 __fpending_0200();
90 __fpending_0300();
91 return t_status;
92 }