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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 int
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 main (int argc, char **argv)
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
ca6c212b4ed8 Beef up fseek tests.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
42 if (argc > 1)
ca6c212b4ed8 Beef up fseek tests.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
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
77504e34a17d Another fseek test.
Eric Blake <ebb9@byu.net>
parents: 9526
diff changeset
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
77504e34a17d Another fseek test.
Eric Blake <ebb9@byu.net>
parents: 9526
diff changeset
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
ca6c212b4ed8 Beef up fseek tests.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
59 }
ca6c212b4ed8 Beef up fseek tests.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
60 return 0;
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 }