X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-freadahead.c;h=2cf1d73a91bb6b796eecbe04170df8c3a9d185ad;hb=cecd5115b408a0c0d04af38206d897a627bded76;hp=d4b098a45b21eeac43337ae8881fdc997f1762f5;hpb=57fdfd3f8ec62b105c53bcdf6f127c35c7fe7391;p=gnulib.git diff --git a/tests/test-freadahead.c b/tests/test-freadahead.c index d4b098a45..2cf1d73a9 100644 --- a/tests/test-freadahead.c +++ b/tests/test-freadahead.c @@ -1,5 +1,5 @@ /* Test of freadahead() function. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007-2012 Free Software Foundation, Inc. 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 @@ -20,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) @@ -50,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;