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 /**
20 * @tc.name : __flbf_0100
21 * @tc.desc : Line buffer test
22 * @tc.level : Level 0
23 */
__flbf_0100(void)24 void __flbf_0100(void)
25 {
26 char buf[BUFSIZ];
27
28 FILE *fp = fopen("/proc/version", "r");
29 EXPECT_PTRNE("__flbf_0100", fp, NULL);
30
31 int ret = setvbuf(fp, buf, _IOLBF, sizeof buf);
32 EXPECT_EQ("__flbf_0100", ret, 0);
33
34 int result = __flbf(fp);
35 EXPECT_TRUE("__flbf_0100", result);
36 fclose(fp);
37 }
38
39 /**
40 * @tc.name : __flbf_0200
41 * @tc.desc : Full buffer test
42 * @tc.level : Level 2
43 */
__flbf_0200(void)44 void __flbf_0200(void)
45 {
46 char buf[BUFSIZ];
47
48 FILE *fp = fopen("/proc/version", "r");
49 EXPECT_PTRNE("__flbf_0200", fp, NULL);
50
51 int ret = setvbuf(fp, buf, _IOFBF, sizeof buf);
52 EXPECT_EQ("__flbf_0200", ret, 0);
53
54 int result = __flbf(fp);
55 EXPECT_FALSE("__flbf_0200", result);
56 fclose(fp);
57 }
58
59 /**
60 * @tc.name : __flbf_0300
61 * @tc.desc : Unbuffered test
62 * @tc.level : Level 2
63 */
__flbf_0300(void)64 void __flbf_0300(void)
65 {
66 char buf[BUFSIZ];
67
68 FILE *fp = fopen("/proc/version", "r");
69 EXPECT_PTRNE("__flbf_0300", fp, NULL);
70
71 int ret = setvbuf(fp, buf, _IONBF, sizeof buf);
72 EXPECT_EQ("__flbf_0300", ret, 0);
73
74 int result = __flbf(fp);
75 EXPECT_FALSE("__flbf_0300", result);
76 fclose(fp);
77 }
78
main(int argc, char *argv[])79 int main(int argc, char *argv[])
80 {
81 __flbf_0100();
82 __flbf_0200();
83 __flbf_0300();
84 return t_status;
85 }