Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/test-fwritable.c @ 16201:8250f2777afc
maint: update all copyright year number ranges
Run "make update-copyright".
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sun, 01 Jan 2012 10:04:58 +0100 |
parents | 97fc9a21a8fb |
children | e542fd46ad6f |
rev | line source |
---|---|
8690 | 1 /* Test of fwritable() function. |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
2 Copyright (C) 2007-2012 Free Software Foundation, Inc. |
8690 | 3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
8690 | 5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
7 (at your option) any later version. |
8690 | 8 |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8690 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ | |
18 | |
19 #include <config.h> | |
20 | |
12724 | 21 /* None of the files accessed by this test are large, so disable the |
22 fseek link warning if we are not using the gnulib fseek module. */ | |
23 #define _GL_NO_LARGE_FILES | |
8690 | 24 #include "fwritable.h" |
25 | |
8754 | 26 #include <stdio.h> |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
27 |
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
28 #include "macros.h" |
8690 | 29 |
30 #define TESTFILE "t-fwritable.tmp" | |
31 | |
32 int | |
33 main () | |
34 { | |
35 FILE *fp; | |
36 | |
37 /* Create a file with some contents. */ | |
38 fp = fopen (TESTFILE, "w"); | |
39 if (fp == NULL) | |
40 goto skip; | |
41 ASSERT (fwritable (fp)); | |
42 if (fwrite ("foobarsh", 1, 8, fp) < 8) | |
43 goto skip; | |
44 ASSERT (fwritable (fp)); | |
45 if (fclose (fp)) | |
46 goto skip; | |
47 | |
48 /* Open it in read-only mode. */ | |
49 fp = fopen (TESTFILE, "r"); | |
50 if (fp == NULL) | |
51 goto skip; | |
52 ASSERT (!fwritable (fp)); | |
53 if (fgetc (fp) != 'f') | |
54 goto skip; | |
55 ASSERT (!fwritable (fp)); | |
56 if (fseek (fp, 2, SEEK_CUR)) | |
57 goto skip; | |
58 ASSERT (!fwritable (fp)); | |
59 if (fgetc (fp) != 'b') | |
60 goto skip; | |
61 ASSERT (!fwritable (fp)); | |
62 fflush (fp); | |
63 ASSERT (!fwritable (fp)); | |
64 if (fgetc (fp) != 'a') | |
65 goto skip; | |
66 ASSERT (!fwritable (fp)); | |
67 if (fseek (fp, 0, SEEK_END)) | |
68 goto skip; | |
69 ASSERT (!fwritable (fp)); | |
70 if (fclose (fp)) | |
71 goto skip; | |
72 | |
73 /* Open it in read-write mode. */ | |
74 fp = fopen (TESTFILE, "r+"); | |
75 if (fp == NULL) | |
76 goto skip; | |
77 ASSERT (fwritable (fp)); | |
78 if (fgetc (fp) != 'f') | |
79 goto skip; | |
80 ASSERT (fwritable (fp)); | |
81 if (fseek (fp, 2, SEEK_CUR)) | |
82 goto skip; | |
83 ASSERT (fwritable (fp)); | |
84 if (fgetc (fp) != 'b') | |
85 goto skip; | |
86 ASSERT (fwritable (fp)); | |
87 fflush (fp); | |
88 ASSERT (fwritable (fp)); | |
89 if (fgetc (fp) != 'a') | |
90 goto skip; | |
91 ASSERT (fwritable (fp)); | |
92 if (fputc ('z', fp) != 'z') | |
93 goto skip; | |
94 ASSERT (fwritable (fp)); | |
95 if (fseek (fp, 0, SEEK_END)) | |
96 goto skip; | |
97 ASSERT (fwritable (fp)); | |
98 if (fclose (fp)) | |
99 goto skip; | |
100 | |
101 /* Open it in append mode. */ | |
102 fp = fopen (TESTFILE, "a"); | |
103 if (fp == NULL) | |
104 goto skip; | |
105 ASSERT (fwritable (fp)); | |
106 if (fwrite ("bla", 1, 3, fp) < 3) | |
107 goto skip; | |
108 ASSERT (fwritable (fp)); | |
109 if (fclose (fp)) | |
110 goto skip; | |
111 | |
112 return 0; | |
113 | |
114 skip: | |
115 fprintf (stderr, "Skipping test: file operations failed.\n"); | |
116 return 77; | |
117 } |