annotate tests/test-freadseek.c @ 40223:84a15f7137a7

Fix another test failure introduced by the same commit.
author Bruno Haible <bruno@clisp.org>
date Sun, 10 Mar 2019 13:08:25 +0100
parents b06060465f09
children 5d9b82ca550a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9739
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of freadseek() function.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2007-2019 Free Software Foundation, Inc.
9739
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
9739
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2008. */
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "freadseek.h"
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stdio.h>
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdlib.h>
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <string.h>
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <unistd.h>
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
28 #include "macros.h"
9739
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 int
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 main (int argc, char **argv)
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 {
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 static const char stdin_contents[] =
40223
84a15f7137a7 Fix another test failure introduced by the same commit.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
34 "#!/bin/sh\n\n${CHECKER} ./test-freadseek${EXEEXT} 5 19 6 7 18 9 19 < \"$srcdir/test-freadseek.sh\" || exit 1\ncat \"$srcdir/test-freadseek.sh\" | ${CHECKER} ./test-freadseek${EXEEXT} 5 19 6 7 18 9 19 || exit 1\nexit 0\n";
9739
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 int nbytes1 = atoi (argv[1]);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 int nbytes2 = atoi (argv[2]);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 int nbytes3 = atoi (argv[3]);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 int nbytes4 = atoi (argv[4]);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 int nbytes5 = atoi (argv[5]);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 int nbytes6 = atoi (argv[6]);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 int nbytes7 = atoi (argv[7]);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 void *buf1 = malloc (nbytes1);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 void *buf3 = malloc (nbytes3);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 void *buf5 = malloc (nbytes5);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 void *buf7 = malloc (nbytes7);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 /* A private variable to keep track of the position. */
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 size_t position = 0;
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 ASSERT (fread (buf1, 1, nbytes1, stdin) == nbytes1);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 ASSERT (memcmp (buf1, stdin_contents + position, nbytes1) == 0);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 position += nbytes1;
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 /* Test normal behaviour. */
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 ASSERT (freadseek (stdin, nbytes2) == 0);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 position += nbytes2;
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 ASSERT (fread (buf3, 1, nbytes3, stdin) == nbytes3);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 ASSERT (memcmp (buf3, stdin_contents + position, nbytes3) == 0);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 position += nbytes3;
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 /* Test behaviour after normal ungetc. */
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 ungetc (fgetc (stdin), stdin);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 ASSERT (freadseek (stdin, nbytes4) == 0);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 position += nbytes4;
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 ASSERT (fread (buf5, 1, nbytes5, stdin) == nbytes5);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 ASSERT (memcmp (buf5, stdin_contents + position, nbytes5) == 0);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 position += nbytes5;
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 /* Test behaviour after arbitrary ungetc. */
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 fgetc (stdin);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 ungetc ('@', stdin);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 ASSERT (freadseek (stdin, nbytes6) == 0);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 position += nbytes6;
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 ASSERT (fread (buf7, 1, nbytes7, stdin) == nbytes7);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 ASSERT (memcmp (buf7, stdin_contents + position, nbytes7) == 0);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 position += nbytes7;
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 /* Test move to end of file. */
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 ASSERT (freadseek (stdin, strlen (stdin_contents) - position) == 0);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 ASSERT (fgetc (stdin) == EOF);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 ASSERT (!ferror (stdin));
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84
11237
2bd541cd96ac Disable two tests on FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
85 #if !defined __MINT__ /* FreeMiNT has problems seeking past end of file */
9739
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 /* Test move beyond end of file. */
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 ASSERT (freadseek (stdin, 1000000) == 0);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 ASSERT (fgetc (stdin) == EOF);
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 ASSERT (!ferror (stdin));
11237
2bd541cd96ac Disable two tests on FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
90 #endif
9739
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 return 0;
8b28ae918b51 Tests for module 'freadseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 }