Mercurial > gnulib
annotate tests/test-freadseek.c @ 18626:12df2165ec1c
version-etc: new year
* build-aux/gendocs.sh (version):
* doc/gendocs_template:
* doc/gendocs_template_min:
* doc/gnulib.texi:
* lib/version-etc.c (COPYRIGHT_YEAR):
Update copyright dates by hand in templates and the like.
* all files: Run 'make update-copyright'.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sun, 01 Jan 2017 02:59:23 +0000 |
parents | 31b2239ca59c |
children | 9759915b2aca |
rev | line source |
---|---|
9739 | 1 /* Test of freadseek() function. |
18626 | 2 Copyright (C) 2007-2017 Free Software Foundation, Inc. |
9739 | 3 |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
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 | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2008. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include "freadseek.h" | |
22 | |
23 #include <stdio.h> | |
24 #include <stdlib.h> | |
25 #include <string.h> | |
26 #include <unistd.h> | |
27 | |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
28 #include "macros.h" |
9739 | 29 |
30 int | |
31 main (int argc, char **argv) | |
32 { | |
33 static const char stdin_contents[] = | |
34 "#!/bin/sh\n\n./test-freadseek${EXEEXT} 5 19 6 7 18 9 19 < \"$srcdir/test-freadseek.sh\" || exit 1\ncat \"$srcdir/test-freadseek.sh\" | ./test-freadseek${EXEEXT} 5 19 6 7 18 9 19 || exit 1\nexit 0\n"; | |
35 int nbytes1 = atoi (argv[1]); | |
36 int nbytes2 = atoi (argv[2]); | |
37 int nbytes3 = atoi (argv[3]); | |
38 int nbytes4 = atoi (argv[4]); | |
39 int nbytes5 = atoi (argv[5]); | |
40 int nbytes6 = atoi (argv[6]); | |
41 int nbytes7 = atoi (argv[7]); | |
42 void *buf1 = malloc (nbytes1); | |
43 void *buf3 = malloc (nbytes3); | |
44 void *buf5 = malloc (nbytes5); | |
45 void *buf7 = malloc (nbytes7); | |
46 /* A private variable to keep track of the position. */ | |
47 size_t position = 0; | |
48 | |
49 ASSERT (fread (buf1, 1, nbytes1, stdin) == nbytes1); | |
50 ASSERT (memcmp (buf1, stdin_contents + position, nbytes1) == 0); | |
51 position += nbytes1; | |
52 | |
53 /* Test normal behaviour. */ | |
54 ASSERT (freadseek (stdin, nbytes2) == 0); | |
55 position += nbytes2; | |
56 | |
57 ASSERT (fread (buf3, 1, nbytes3, stdin) == nbytes3); | |
58 ASSERT (memcmp (buf3, stdin_contents + position, nbytes3) == 0); | |
59 position += nbytes3; | |
60 | |
61 /* Test behaviour after normal ungetc. */ | |
62 ungetc (fgetc (stdin), stdin); | |
63 ASSERT (freadseek (stdin, nbytes4) == 0); | |
64 position += nbytes4; | |
65 | |
66 ASSERT (fread (buf5, 1, nbytes5, stdin) == nbytes5); | |
67 ASSERT (memcmp (buf5, stdin_contents + position, nbytes5) == 0); | |
68 position += nbytes5; | |
69 | |
70 /* Test behaviour after arbitrary ungetc. */ | |
71 fgetc (stdin); | |
72 ungetc ('@', stdin); | |
73 ASSERT (freadseek (stdin, nbytes6) == 0); | |
74 position += nbytes6; | |
75 | |
76 ASSERT (fread (buf7, 1, nbytes7, stdin) == nbytes7); | |
77 ASSERT (memcmp (buf7, stdin_contents + position, nbytes7) == 0); | |
78 position += nbytes7; | |
79 | |
80 /* Test move to end of file. */ | |
81 ASSERT (freadseek (stdin, strlen (stdin_contents) - position) == 0); | |
82 ASSERT (fgetc (stdin) == EOF); | |
83 ASSERT (!ferror (stdin)); | |
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 | 86 /* Test move beyond end of file. */ |
87 ASSERT (freadseek (stdin, 1000000) == 0); | |
88 ASSERT (fgetc (stdin) == EOF); | |
89 ASSERT (!ferror (stdin)); | |
11237
2bd541cd96ac
Disable two tests on FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
90 #endif |
9739 | 91 |
92 return 0; | |
93 } |