This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21
22
23 #define _GL_NO_LARGE_FILES
24 #include "fwriting.h"
25
26 #include <stdio.h>
27
28 #include "macros.h"
29
30 #define TESTFILE "t-fwriting.tmp"
31
32 int
33 main ()
34 {
35 FILE *fp;
36
37
38 fp = fopen (TESTFILE, "w");
39 if (fp == NULL)
40 goto skip;
41 ASSERT (fwriting (fp));
42 if (fwrite ("foobarsh", 1, 8, fp) < 8)
43 goto skip;
44 ASSERT (fwriting (fp));
45 if (fclose (fp))
46 goto skip;
47
48
49 fp = fopen (TESTFILE, "r");
50 if (fp == NULL)
51 goto skip;
52 ASSERT (!fwriting (fp));
53 if (fgetc (fp) != 'f')
54 goto skip;
55 ASSERT (!fwriting (fp));
56 if (fseek (fp, 2, SEEK_CUR))
57 goto skip;
58 ASSERT (!fwriting (fp));
59 if (fgetc (fp) != 'b')
60 goto skip;
61 ASSERT (!fwriting (fp));
62 fflush (fp);
63 ASSERT (!fwriting (fp));
64 if (fgetc (fp) != 'a')
65 goto skip;
66 ASSERT (!fwriting (fp));
67 if (fseek (fp, 0, SEEK_END))
68 goto skip;
69 ASSERT (!fwriting (fp));
70 if (fclose (fp))
71 goto skip;
72
73
74
75
76
77
78
79 fp = fopen (TESTFILE, "r+");
80 if (fp == NULL)
81 goto skip;
82 ASSERT (!fwriting (fp));
83 if (fgetc (fp) != 'f')
84 goto skip;
85 ASSERT (!fwriting (fp));
86 if (fseek (fp, 2, SEEK_CUR))
87 goto skip;
88 ASSERT (!fwriting (fp));
89 if (fgetc (fp) != 'b')
90 goto skip;
91 ASSERT (!fwriting (fp));
92
93
94 if (fseek (fp, 0, SEEK_CUR) != 0)
95 goto skip;
96 ASSERT (!fwriting (fp));
97 if (fputc ('x', fp) != 'x')
98 goto skip;
99 ASSERT (fwriting (fp));
100 if (fseek (fp, 0, SEEK_END))
101 goto skip;
102
103
104
105 if (fclose (fp))
106 goto skip;
107
108
109
110
111
112
113
114 fp = fopen (TESTFILE, "r+");
115 if (fp == NULL)
116 goto skip;
117 ASSERT (!fwriting (fp));
118 if (fgetc (fp) != 'f')
119 goto skip;
120 ASSERT (!fwriting (fp));
121 if (fseek (fp, 2, SEEK_CUR))
122 goto skip;
123 ASSERT (!fwriting (fp));
124 if (fgetc (fp) != 'b')
125 goto skip;
126 ASSERT (!fwriting (fp));
127 fflush (fp);
128 ASSERT (!fwriting (fp));
129 if (fgetc (fp) != 'x')
130 goto skip;
131 ASSERT (!fwriting (fp));
132
133
134 if (fseek (fp, 0, SEEK_CUR) != 0)
135 goto skip;
136 ASSERT (!fwriting (fp));
137 if (fputc ('z', fp) != 'z')
138 goto skip;
139 ASSERT (fwriting (fp));
140 if (fseek (fp, 0, SEEK_END))
141 goto skip;
142
143
144
145 if (fclose (fp))
146 goto skip;
147
148
149 fp = fopen (TESTFILE, "a");
150 if (fp == NULL)
151 goto skip;
152 ASSERT (fwriting (fp));
153 if (fwrite ("bla", 1, 3, fp) < 3)
154 goto skip;
155 ASSERT (fwriting (fp));
156 if (fclose (fp))
157 goto skip;
158
159 return 0;
160
161 skip:
162 fprintf (stderr, "Skipping test: file operations failed.\n");
163 return 77;
164 }