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/freading.txt";
20
21 /**
22 * @tc.name : __freading_0100
23 * @tc.desc : The parameter is valid, the file is opened in read-only mode, and the file stream can
24 * be judged to be read-only.
25 * @tc.level : Level 0
26 */
__freading_0100(void)27 void __freading_0100(void)
28 {
29 char *str = "This is a test";
30 FILE *fp = fopen(path, "w");
31 fputs(str, fp);
32 fclose(fp);
33 FILE *ffp = fopen(path, "r");
34 size_t ret = __freading(ffp);
35 EXPECT_NE("__freading_0100", ret, 0);
36 fclose(ffp);
37 remove(path);
38 }
39
40 /**
41 * @tc.name : __freading_0200
42 * @tc.desc : The parameter is valid, the file has just been read, and it is judged that the file
43 * stream has been read.
44 * @tc.level : Level 0
45 */
__freading_0200(void)46 void __freading_0200(void)
47 {
48 char *str = "This is a test";
49 FILE *fp = fopen(path, "w");
50 fputs(str, fp);
51 fclose(fp);
52 FILE *ffp = fopen(path, "r");
53 char buf[100];
54 fgets(buf, 100, ffp);
55 size_t ret = __freading(ffp);
56 EXPECT_NE("__freading_0200", ret, 0);
57 fclose(ffp);
58 remove(path);
59 }
60
61 /**
62 * @tc.name : __freading_0300
63 * @tc.desc : The parameter is valid, the file has just been written, and it is judged that the file stream
64 * has not been read.
65 * @tc.level : Level 2
66 */
__freading_0300(void)67 void __freading_0300(void)
68 {
69 char *str = "This is a test";
70 FILE *fp = fopen(path, "w");
71 fputs(str, fp);
72 size_t ret = __freading(fp);
73 EXPECT_EQ("__freading_0300", ret, 0);
74 fclose(fp);
75 remove(path);
76 }
77
main(int argc,char * argv[])78 int main(int argc, char *argv[])
79 {
80 __freading_0100();
81 __freading_0200();
82 __freading_0300();
83 return t_status;
84 }