Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/test-fseek.c @ 9872:8724fb6c1548
Make test-fseeko.c failures meaningful.
* tests/test-fseeko.c: Print line number on failure.
* tests/test-fseek.c: Likewise.
Reported by Nelson H. F. Beebe.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Fri, 04 Apr 2008 06:58:46 -0600 |
parents | 77504e34a17d |
children | 0be6f1ab456d |
rev | line source |
---|---|
8886 | 1 /* Test of fseek() function. |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
2 Copyright (C) 2007, 2008 Free Software Foundation, Inc. |
8886 | 3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8886
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
8886 | 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:
8886
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:
8886
diff
changeset
|
7 (at your option) any later version. |
8886 | 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:
8886
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8886 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include <stdio.h> | |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
22 #include <stdlib.h> |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
23 |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
24 #define ASSERT(expr) \ |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
25 do \ |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
26 { \ |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
27 if (!(expr)) \ |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
28 { \ |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
29 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
30 abort (); \ |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
31 } \ |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
32 } \ |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
33 while (0) |
8886 | 34 |
35 int | |
36 main (int argc, char **argv) | |
37 { | |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
38 /* Assume stdin is non-empty, seekable, and starts with '#!/bin/sh' |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
39 iff argc > 1. */ |
8886 | 40 int expected = argc > 1 ? 0 : -1; |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
41 ASSERT (fseek (stdin, 0, SEEK_CUR) == expected); |
9526 | 42 if (argc > 1) |
43 { | |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
44 /* Test that fseek discards previously read ungetc data. */ |
9528 | 45 int ch = fgetc (stdin); |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
46 ASSERT (ch == '#'); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
47 ASSERT (ungetc (ch, stdin) == ch); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
48 ASSERT (fseek (stdin, 2, SEEK_SET) == 0); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
49 /* Test that fseek discards random ungetc data. */ |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
50 ch = fgetc (stdin); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
51 ASSERT (ch == '/'); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
52 ASSERT (ungetc (ch ^ 0xff, stdin) == (ch ^ 0xff)); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
53 ASSERT (fseek (stdin, 0, SEEK_END) == 0); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
54 ASSERT (fgetc (stdin) == EOF); |
9528 | 55 /* Test that fseek resets end-of-file marker. */ |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
56 ASSERT (feof (stdin)); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
57 ASSERT (fseek (stdin, 0, SEEK_END) == 0); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
58 ASSERT (!feof (stdin)); |
9526 | 59 } |
60 return 0; | |
8886 | 61 } |