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_ext.h>
18 #include "functionalext.h"
19
20 const int32_t INIT_LEN = 0;
21
22 /**
23 * @tc.name : flushlbf_0100
24 * @tc.desc : Verify that flushing the line buffer was successful.
25 * @tc.level : Level 0
26 */
flushlbf_0100(void)27 void flushlbf_0100(void)
28 {
29 char buffer[1024] = {0};
30 char array[] = "This is a test!";
31 const char *path = "/data/test.txt";
32
33 FILE *fd = fopen(path, "w+");
34 EXPECT_PTRNE("flushlbf_0100", fd, NULL);
35
36 fprintf(fd, "%s", array);
37 FILE *fp = freopen("/data/test.txt", "r", stdin);
38 EXPECT_PTRNE("flushlbf_0100", fp, NULL);
39
40 fseek(fp, 0, SEEK_SET);
41 int32_t rsize = fread(buffer, 1, 10, fd);
42 EXPECT_EQ("flushlbf_0100", rsize, INIT_LEN);
43
44 _flushlbf();
45
46 fseek(fp, 0, SEEK_SET);
47 fread(buffer, 1, 20, fp);
48 EXPECT_STREQ("flushlbf_0100", buffer, array);
49
50 fclose(stdin);
51 fclose(fd);
52 fclose(fp);
53 remove(path);
54 }
55
main(int argc, char *argv[])56 int main(int argc, char *argv[])
57 {
58 flushlbf_0100();
59 return t_status;
60 }
61