maint: update copyright
[gnulib.git] / tests / test-freadahead.c
index d4b098a..f50c54e 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of freadahead() function.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007-2014 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
 
 #include "freadahead.h"
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 
-#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;