X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=tests%2Ftest-freadahead.c;h=c216231aa42fe9933df5ecd642eccf9c517065f0;hb=dcfa509347541cf4a44f7e5be5fc74398d8a8199;hp=9bc5d737665129f97039c1bfc4a409bb0fc88ca4;hpb=5bca97aedcd1e07c1bd80c242239b83c7df9194d;p=gnulib.git
diff --git a/tests/test-freadahead.c b/tests/test-freadahead.c
index 9bc5d7376..c216231aa 100644
--- a/tests/test-freadahead.c
+++ b/tests/test-freadahead.c
@@ -1,10 +1,10 @@
/* Test of freadahead() function.
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007-2008 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -12,8 +12,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program. If not, see . */
/* Written by Bruno Haible , 2007. */
@@ -26,14 +25,15 @@
#include
#define ASSERT(expr) \
- do \
- { \
- if (!(expr)) \
- { \
+ do \
+ { \
+ if (!(expr)) \
+ { \
fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
- abort (); \
- } \
- } \
+ fflush (stderr); \
+ abort (); \
+ } \
+ } \
while (0)
int
@@ -51,12 +51,33 @@ main (int argc, char **argv)
else
{
if (lseek (0, 0, SEEK_CUR) == nbytes)
- /* An unbuffered stdio, such as BeOS or on uClibc compiled without
- __STDIO_BUFFERS. */
- ASSERT (freadahead (stdin) == 0);
+ /* An unbuffered stdio, such as BeOS or on uClibc compiled without
+ __STDIO_BUFFERS. */
+ ASSERT (freadahead (stdin) == 0);
else
- /* Normal buffered stdio. */
- ASSERT (freadahead (stdin) != 0);
+ {
+ /* Normal buffered stdio. */
+ size_t buffered;
+ int c, c2;
+
+ ASSERT (freadahead (stdin) != 0);
+ buffered = freadahead (stdin);
+
+ c = fgetc (stdin);
+ ASSERT (freadahead (stdin) == buffered - 1);
+ ungetc (c, stdin);
+ ASSERT (freadahead (stdin) == buffered);
+ c2 = fgetc (stdin);
+ ASSERT (c2 == c);
+ ASSERT (freadahead (stdin) == buffered - 1);
+
+ c = '@';
+ ungetc (c, stdin);
+ ASSERT (freadahead (stdin) == buffered);
+ c2 = fgetc (stdin);
+ ASSERT (c2 == c);
+ ASSERT (freadahead (stdin) == buffered - 1);
+ }
}
return 0;