Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/test-vsprintf-posix.c @ 9889:0be6f1ab456d
Flush the standard error stream before aborting.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 11 Apr 2008 16:31:39 +0200 |
parents | 21157f1c35b7 |
children | 849e7305914c |
rev | line source |
---|---|
8372
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of POSIX compatible vsprintf() function. |
9858
21157f1c35b7
Avoid some warnings from "gcc -Wshadow".
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
2 Copyright (C) 2007-2008 Free Software Foundation, Inc. |
8372
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8919
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
8372
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8919
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8919
diff
changeset
|
7 (at your option) any later version. |
8372
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8919
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8372
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
8891
633babea5f62
Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents:
8834
diff
changeset
|
19 #include <config.h> |
8372
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include <stdio.h> |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
8919
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
23 #include <float.h> |
8372
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #include <stdarg.h> |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #include <stddef.h> |
8754 | 26 #include <stdio.h> |
8372
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 #include <stdint.h> |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 #include <stdlib.h> |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 #include <string.h> |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 |
8834 | 31 #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) |
8754 | 32 #define ASSERT(expr) \ |
33 do \ | |
34 { \ | |
35 if (!(expr)) \ | |
36 { \ | |
37 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ | |
9889
0be6f1ab456d
Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents:
9858
diff
changeset
|
38 fflush (stderr); \ |
8754 | 39 abort (); \ |
40 } \ | |
41 } \ | |
42 while (0) | |
8372
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 |
9858
21157f1c35b7
Avoid some warnings from "gcc -Wshadow".
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
44 #include "test-sprintf-posix.h" |
21157f1c35b7
Avoid some warnings from "gcc -Wshadow".
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
45 |
8372
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 static int |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 my_sprintf (char *str, const char *format, ...) |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 { |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 va_list args; |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 int ret; |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 va_start (args, format); |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 ret = vsprintf (str, format, args); |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 va_end (args); |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 return ret; |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 } |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 int |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 main (int argc, char *argv[]) |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 { |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 test_function (my_sprintf); |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 return 0; |
94c5f157e65c
Tests for module 'vsprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 } |