1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*===================================================================== |
6 | ** |
7 | ** Source: test1.c |
8 | ** |
9 | ** Purpose: Tests the PAL implementation of the feof function. |
10 | ** Open a file, and read some characters. Check that |
11 | ** feof states that it hasn't gone by the EOF. Then |
12 | ** read enough characters to go beyond the EOF, and check |
13 | ** that feof states this is so. |
14 | ** |
15 | ** Depends: |
16 | ** fopen |
17 | ** fread |
18 | ** |
19 | ** |
20 | ** |
21 | **===================================================================*/ |
22 | |
23 | /* The file 'testfile' should exist with 15 characters in it. If not, |
24 | something has been lost ... |
25 | */ |
26 | |
27 | #include <palsuite.h> |
28 | |
29 | int __cdecl main(int argc, char **argv) |
30 | { |
31 | const char filename[] = "testfile" ; |
32 | char buffer[128]; |
33 | FILE * fp = NULL; |
34 | int result; |
35 | |
36 | if (PAL_Initialize(argc, argv)) |
37 | { |
38 | return FAIL; |
39 | } |
40 | |
41 | |
42 | /* Open a file in READ mode */ |
43 | |
44 | if((fp = fopen(filename, "r" )) == NULL) |
45 | { |
46 | Fail("Unable to open a file for reading. Is the file " |
47 | "in the directory? It should be." ); |
48 | } |
49 | |
50 | /* Read 10 characters from the file. The file has 15 |
51 | characters in it. |
52 | */ |
53 | |
54 | if((result = fread(buffer,1,10,fp)) == 0) |
55 | { |
56 | Fail("ERROR: Zero characters read from the file. It should have " |
57 | "read 10 character in it." ); |
58 | } |
59 | |
60 | if(feof(fp)) |
61 | { |
62 | Fail("ERROR: feof returned a value greater than 0. No read " |
63 | "operation has gone beyond the EOF yet, and feof should " |
64 | "return 0 still." ); |
65 | } |
66 | |
67 | /* Read 10 characters from the file. The file has 15 |
68 | characters in it. The file pointer should have no passed |
69 | the end of file. |
70 | */ |
71 | |
72 | if((result = fread(buffer,1,10,fp)) == 0) |
73 | { |
74 | Fail("ERROR: Zero characters read from the file. It should have " |
75 | "read 5 character in it." ); |
76 | } |
77 | |
78 | if(feof(fp) == 0) |
79 | { |
80 | Fail("ERROR: feof returned 0. The file pointer has gone beyond " |
81 | "the EOF and this function should return positive now." ); |
82 | } |
83 | |
84 | PAL_Terminate(); |
85 | return PASS; |
86 | } |
87 | |
88 | |
89 | |