Mercurial > hg > octave-kai > gnulib-hg
annotate tests/test-fflush2.c @ 10944:f08a483da33c
Tests for module 'wcsnrtombs'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 22 Dec 2008 00:43:50 +0100 |
parents | 0be6f1ab456d |
children | 1b3e52ed017e |
rev | line source |
---|---|
9772
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of POSIX compatible fflush() function. |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
2 Copyright (C) 2008 Free Software Foundation, Inc. |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 (at your option) any later version. |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 #include <config.h> |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #include <stdio.h> |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include <stdlib.h> |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 /* This test can only be made to work on specific platforms. */ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #if defined _IO_ferror_unlocked || defined __sferror /* GNU libc, BeOS; FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 # define ASSERT(expr) \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 do \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 { \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 if (!(expr)) \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 { \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ |
9889
0be6f1ab456d
Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents:
9819
diff
changeset
|
31 fflush (stderr); \ |
9772
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 abort (); \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 } \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 } \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 while (0) |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 #else |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 # define ASSERT(expr) \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 do \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 { \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 if (!(expr)) \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 { \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 printf ("Skipping test: expected failure on this platform\n"); \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 exit (77); \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 } \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 } \ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 while (0) |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 #endif |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 int |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 main (int argc, char **argv) |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 { |
9818
fc76a5b22f64
Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
52 #if 0 |
fc76a5b22f64
Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
53 /* Check fflush after a backup ungetc() call. This is case 1 in terms of |
fc76a5b22f64
Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
54 <http://lists.gnu.org/archive/html/bug-gnulib/2008-03/msg00131.html>. |
fc76a5b22f64
Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
55 The Austin Group has not yet decided how this should behave. */ |
fc76a5b22f64
Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
56 #endif |
fc76a5b22f64
Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
57 #if 0 |
9819 | 58 /* Check fflush after a non-backup ungetc() call. This is case 2 in terms of |
9818
fc76a5b22f64
Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
59 <http://lists.gnu.org/archive/html/bug-gnulib/2008-03/msg00131.html>. |
fc76a5b22f64
Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
60 The Austin Group has not yet decided how this should behave. */ |
9772
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 /* Check that fflush after a non-backup ungetc() call discards the ungetc |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 buffer. This is mandated by POSIX |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 <http://www.opengroup.org/susv3/functions/ungetc.html>: |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 "The value of the file-position indicator for the stream after |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 reading or discarding all pushed-back bytes shall be the same |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 as it was before the bytes were pushed back." */ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 int c; |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 c = fgetc (stdin); |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 ASSERT (c == '#'); |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 c = fgetc (stdin); |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 ASSERT (c == '!'); |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 /* Here the file-position indicator must be 2. */ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 c = ungetc ('@', stdin); |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 ASSERT (c == '@'); |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 fflush (stdin); |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 /* Here the file-position indicator must be 2 again. */ |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 c = fgetc (stdin); |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 ASSERT (c == '/'); |
9818
fc76a5b22f64
Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
86 #endif |
9772
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 return 0; |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 } |