X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-freadahead.c;h=3f34a42167de5d516da2f6f9442ccb02b790d74e;hb=880d107;hp=9bc5d737665129f97039c1bfc4a409bb0fc88ca4;hpb=5bca97aedcd1e07c1bd80c242239b83c7df9194d;p=gnulib.git
diff --git a/tests/test-freadahead.c b/tests/test-freadahead.c
index 9bc5d7376..3f34a4216 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-2010 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. */
@@ -21,20 +20,10 @@
#include "freadahead.h"
-#include
#include
#include
-#define ASSERT(expr) \
- do \
- { \
- if (!(expr)) \
- { \
- fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
- abort (); \
- } \
- } \
- while (0)
+#include "macros.h"
int
main (int argc, char **argv)
@@ -51,12 +40,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;