annotate tests/test-vasnprintf-posix.c @ 8804:6ce313658b4d

Work around an incorrect implementation of the 0 flag on most platforms.
author Bruno Haible <bruno@clisp.org>
date Sun, 06 May 2007 23:02:10 +0000
parents 6c1d98929550
children 4c705f82cd20
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of POSIX compatible vasnprintf() and asnprintf() functions.
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2007 Free Software Foundation, Inc.
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 any later version.
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #ifdef HAVE_CONFIG_H
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 # include <config.h>
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #endif
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include "vasnprintf.h"
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <stdarg.h>
8354
81b3f885ff9d Include <stddef.h>, for ptrdiff_t.
Bruno Haible <bruno@clisp.org>
parents: 8344
diff changeset
27 #include <stddef.h>
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
28 #include <stdio.h>
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include <stdint.h>
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #include <stdlib.h>
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #include <string.h>
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
33 #define ASSERT(expr) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
34 do \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
35 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
36 if (!(expr)) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
37 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
38 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
39 abort (); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
40 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
41 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
42 while (0)
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43
8543
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
44 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
45 #ifdef __DECC
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
46 static double
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
47 NaN ()
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
48 {
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
49 static double zero = 0.0;
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
50 return zero / zero;
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
51 }
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
52 #else
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
53 # define NaN() (0.0 / 0.0)
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
54 #endif
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
55
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 static void
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 char buf[8];
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 int size;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 /* Test return value convention. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 for (size = 0; size <= 8; size++)
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 size_t length = size;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 char *result = my_asnprintf (NULL, &length, "%d", 12345);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 ASSERT (strcmp (result, "12345") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 ASSERT (length == 5);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 for (size = 0; size <= 8; size++)
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 char *result;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 memcpy (buf, "DEADBEEF", 8);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 length = size;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 result = my_asnprintf (buf, &length, "%d", 12345);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 ASSERT (strcmp (result, "12345") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 ASSERT (length == 5);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 if (size < 6)
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 ASSERT (result != buf);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 if (result != buf)
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 /* Test support of size specifiers as in C99. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 my_asnprintf (NULL, &length, "%ju %d", (uintmax_t) 12345671, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 ASSERT (strcmp (result, "12345671 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 my_asnprintf (NULL, &length, "%zu %d", (size_t) 12345672, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 ASSERT (strcmp (result, "12345672 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 my_asnprintf (NULL, &length, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 ASSERT (strcmp (result, "12345673 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 my_asnprintf (NULL, &length, "%Lg %d", (long double) 1.5, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 ASSERT (strcmp (result, "1.5 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 output of floating-point numbers. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 { /* A positive number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 my_asnprintf (NULL, &length, "%a %d", 3.1416015625, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 ASSERT (strcmp (result, "0x1.922p+1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 || strcmp (result, "0x3.244p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 || strcmp (result, "0x6.488p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 || strcmp (result, "0xc.91p-2 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 { /* A negative number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 my_asnprintf (NULL, &length, "%A %d", -3.1416015625, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 || strcmp (result, "-0X3.244P+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 || strcmp (result, "-0X6.488P-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 || strcmp (result, "-0XC.91P-2 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 { /* Positive zero. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 my_asnprintf (NULL, &length, "%a %d", 0.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 ASSERT (strcmp (result, "0x0p+0 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 { /* Negative zero. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 my_asnprintf (NULL, &length, "%a %d", -0.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 { /* Positive infinity. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 my_asnprintf (NULL, &length, "%a %d", 1.0 / 0.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 ASSERT (strcmp (result, "inf 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 { /* Negative infinity. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 my_asnprintf (NULL, &length, "%a %d", -1.0 / 0.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 ASSERT (strcmp (result, "-inf 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 { /* NaN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
204 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205 char *result =
8543
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
206 my_asnprintf (NULL, &length, "%a %d", NaN (), 33, 44, 55);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208 ASSERT (strcmp (result, "nan 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
213 { /* Rounding near the decimal point. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
214 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216 my_asnprintf (NULL, &length, "%.0a %d", 1.5, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218 ASSERT (strcmp (result, "0x2p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 || strcmp (result, "0x3p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 || strcmp (result, "0x6p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 || strcmp (result, "0xcp-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
223 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
224 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
225
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 { /* Rounding with precision 0. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229 my_asnprintf (NULL, &length, "%.0a %d", 1.51, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231 ASSERT (strcmp (result, "0x2p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 || strcmp (result, "0x3p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233 || strcmp (result, "0x6p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234 || strcmp (result, "0xcp-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
235 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
239 { /* Rounding with precision 1. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 my_asnprintf (NULL, &length, "%.1a %d", 1.51, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 ASSERT (strcmp (result, "0x1.8p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245 || strcmp (result, "0x3.0p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246 || strcmp (result, "0x6.1p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247 || strcmp (result, "0xc.1p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 { /* Rounding with precision 2. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
253 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 my_asnprintf (NULL, &length, "%.2a %d", 1.51, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 ASSERT (strcmp (result, "0x1.83p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 || strcmp (result, "0x3.05p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 || strcmp (result, "0x6.0ap-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 || strcmp (result, "0xc.14p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265 { /* Rounding with precision 3. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 my_asnprintf (NULL, &length, "%.3a %d", 1.51, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270 ASSERT (strcmp (result, "0x1.829p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 || strcmp (result, "0x3.052p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272 || strcmp (result, "0x6.0a4p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 || strcmp (result, "0xc.148p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278 { /* Rounding can turn a ...FFF into a ...000. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 my_asnprintf (NULL, &length, "%.3a %d", 1.49999, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 ASSERT (strcmp (result, "0x1.800p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 || strcmp (result, "0x3.000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 || strcmp (result, "0x6.000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 || strcmp (result, "0xc.000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
291 { /* Rounding can turn a ...FFF into a ...000.
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
292 This shows a MacOS X 10.3.9 (Darwin 7.9) bug. */
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
293 size_t length;
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
294 char *result =
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
295 my_asnprintf (NULL, &length, "%.1a %d", 1.999, 33, 44, 55);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
296 ASSERT (result != NULL);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
297 ASSERT (strcmp (result, "0x1.0p+1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
298 || strcmp (result, "0x2.0p+0 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
299 || strcmp (result, "0x4.0p-1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
300 || strcmp (result, "0x8.0p-2 33") == 0);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
301 ASSERT (length == strlen (result));
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
302 free (result);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
303 }
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
304
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305 { /* Width. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 my_asnprintf (NULL, &length, "%10a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 || strcmp (result, " 0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 || strcmp (result, " 0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 || strcmp (result, " 0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
318 { /* Small precision. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
319 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
320 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
321 my_asnprintf (NULL, &length, "%.10a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324 || strcmp (result, "0x3.8000000000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
325 || strcmp (result, "0x7.0000000000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
326 || strcmp (result, "0xe.0000000000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
327 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
328 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
329 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
330
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
331 { /* Large precision. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
334 my_asnprintf (NULL, &length, "%.50a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
335 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
336 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
337 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
338 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
339 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
340 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
341 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
344 { /* FLAG_LEFT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
345 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
346 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
347 my_asnprintf (NULL, &length, "%-10a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
348 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 || strcmp (result, "0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
351 || strcmp (result, "0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352 || strcmp (result, "0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
354 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
356
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
357 { /* FLAG_SHOWSIGN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
359 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
360 my_asnprintf (NULL, &length, "%+a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
363 || strcmp (result, "+0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364 || strcmp (result, "+0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365 || strcmp (result, "+0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
369
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
370 { /* FLAG_SPACE. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
371 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
372 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
373 my_asnprintf (NULL, &length, "% a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
374 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
375 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
376 || strcmp (result, " 0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377 || strcmp (result, " 0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 || strcmp (result, " 0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
379 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
380 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
382
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
383 { /* FLAG_ALT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
384 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
385 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
386 my_asnprintf (NULL, &length, "%#a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
387 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
388 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
389 || strcmp (result, "0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390 || strcmp (result, "0x7.p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 || strcmp (result, "0xe.p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
392 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
393 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
394 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
395
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
396 { /* FLAG_ALT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
397 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
398 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
399 my_asnprintf (NULL, &length, "%#a %d", 1.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
400 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
401 ASSERT (strcmp (result, "0x1.p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
402 || strcmp (result, "0x2.p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
403 || strcmp (result, "0x4.p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
404 || strcmp (result, "0x8.p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
407 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
408
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
409 { /* FLAG_ZERO with finite number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
410 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
411 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
412 my_asnprintf (NULL, &length, "%010a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
413 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
414 ASSERT (strcmp (result, "0x001.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
415 || strcmp (result, "0x003.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
416 || strcmp (result, "0x00007p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
417 || strcmp (result, "0x0000ep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
418 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
420 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
421
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
422 { /* FLAG_ZERO with infinite number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
423 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
424 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
425 my_asnprintf (NULL, &length, "%010a %d", 1.0 / 0.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
426 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
427 /* "0000000inf 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
428 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
429 ASSERT (strcmp (result, " inf 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
430 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
431 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
432 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
433
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
434 { /* FLAG_ZERO with NaN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
435 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
436 char *result =
8543
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8354
diff changeset
437 my_asnprintf (NULL, &length, "%010a %d", NaN (), 33, 44, 55);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
438 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
439 /* "0000000nan 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
440 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
441 ASSERT (strcmp (result, " nan 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
443 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
444 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
445
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
446 { /* A positive number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
447 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
448 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
449 my_asnprintf (NULL, &length, "%La %d", 3.1416015625L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
450 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
451 ASSERT (strcmp (result, "0x1.922p+1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
452 || strcmp (result, "0x3.244p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
453 || strcmp (result, "0x6.488p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
454 || strcmp (result, "0xc.91p-2 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
455 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
456 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
457 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
458
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
459 { /* A negative number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
460 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
461 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
462 my_asnprintf (NULL, &length, "%LA %d", -3.1416015625L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
463 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
464 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
465 || strcmp (result, "-0X3.244P+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
466 || strcmp (result, "-0X6.488P-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
467 || strcmp (result, "-0XC.91P-2 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
468 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
469 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
470 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
471
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
472 { /* Positive zero. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
473 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
474 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
475 my_asnprintf (NULL, &length, "%La %d", 0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
476 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
477 ASSERT (strcmp (result, "0x0p+0 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
478 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
479 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
480 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
481
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
482 { /* Negative zero. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
483 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
484 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
485 my_asnprintf (NULL, &length, "%La %d", -0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
486 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
487 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
488 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
489 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
490 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
491
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
492 { /* Positive infinity. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
493 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
494 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
495 my_asnprintf (NULL, &length, "%La %d", 1.0L / 0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
496 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
497 ASSERT (strcmp (result, "inf 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
498 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
499 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
500 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
501
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
502 { /* Negative infinity. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
503 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
504 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
505 my_asnprintf (NULL, &length, "%La %d", -1.0L / 0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
506 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
507 ASSERT (strcmp (result, "-inf 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
508 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
509 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
510 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
511
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
512 { /* NaN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
513 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
514 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
515 my_asnprintf (NULL, &length, "%La %d", 0.0L / 0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
516 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
517 ASSERT (strcmp (result, "nan 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
518 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
519 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
520 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
521
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
522 { /* Rounding near the decimal point. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
523 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
524 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
525 my_asnprintf (NULL, &length, "%.0La %d", 1.5L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
526 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
527 ASSERT (strcmp (result, "0x2p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
528 || strcmp (result, "0x3p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
529 || strcmp (result, "0x6p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
530 || strcmp (result, "0xcp-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
531 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
532 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
533 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
534
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
535 { /* Rounding with precision 0. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
536 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
537 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
538 my_asnprintf (NULL, &length, "%.0La %d", 1.51L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
539 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
540 ASSERT (strcmp (result, "0x2p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
541 || strcmp (result, "0x3p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
542 || strcmp (result, "0x6p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
543 || strcmp (result, "0xcp-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
544 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
545 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
546 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
547
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
548 { /* Rounding with precision 1. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
549 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
550 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
551 my_asnprintf (NULL, &length, "%.1La %d", 1.51L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
552 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
553 ASSERT (strcmp (result, "0x1.8p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
554 || strcmp (result, "0x3.0p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
555 || strcmp (result, "0x6.1p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
556 || strcmp (result, "0xc.1p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
557 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
558 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
559 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
560
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
561 { /* Rounding with precision 2. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
562 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
563 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
564 my_asnprintf (NULL, &length, "%.2La %d", 1.51L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
565 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
566 ASSERT (strcmp (result, "0x1.83p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
567 || strcmp (result, "0x3.05p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
568 || strcmp (result, "0x6.0ap-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
569 || strcmp (result, "0xc.14p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
570 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
571 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
572 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
573
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
574 { /* Rounding with precision 3. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
575 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
576 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
577 my_asnprintf (NULL, &length, "%.3La %d", 1.51L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
578 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
579 ASSERT (strcmp (result, "0x1.829p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
580 || strcmp (result, "0x3.052p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
581 || strcmp (result, "0x6.0a4p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
582 || strcmp (result, "0xc.148p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
583 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
584 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
585 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
586
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
587 { /* Rounding can turn a ...FFF into a ...000. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
588 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
589 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
590 my_asnprintf (NULL, &length, "%.3La %d", 1.49999L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
591 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
592 ASSERT (strcmp (result, "0x1.800p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
593 || strcmp (result, "0x3.000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
594 || strcmp (result, "0x6.000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
595 || strcmp (result, "0xc.000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
596 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
597 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
598 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
599
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
600 { /* Rounding can turn a ...FFF into a ...000.
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
601 This shows a MacOS X 10.3.9 (Darwin 7.9) bug and a
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
602 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
603 size_t length;
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
604 char *result =
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
605 my_asnprintf (NULL, &length, "%.1La %d", 1.999L, 33, 44, 55);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
606 ASSERT (result != NULL);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
607 ASSERT (strcmp (result, "0x1.0p+1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
608 || strcmp (result, "0x2.0p+0 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
609 || strcmp (result, "0x4.0p-1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
610 || strcmp (result, "0x8.0p-2 33") == 0);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
611 ASSERT (length == strlen (result));
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
612 free (result);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
613 }
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
614
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
615 { /* Width. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
616 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
617 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
618 my_asnprintf (NULL, &length, "%10La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
619 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
620 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
621 || strcmp (result, " 0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
622 || strcmp (result, " 0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
623 || strcmp (result, " 0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
624 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
625 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
626 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
627
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
628 { /* Small precision. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
629 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
630 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
631 my_asnprintf (NULL, &length, "%.10La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
632 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
633 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
634 || strcmp (result, "0x3.8000000000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
635 || strcmp (result, "0x7.0000000000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
636 || strcmp (result, "0xe.0000000000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
637 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
638 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
639 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
640
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
641 { /* Large precision. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
642 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
643 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
644 my_asnprintf (NULL, &length, "%.50La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
645 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
646 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
647 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
648 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
649 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
650 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
651 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
652 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
653
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
654 { /* FLAG_LEFT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
655 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
656 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
657 my_asnprintf (NULL, &length, "%-10La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
658 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
659 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
660 || strcmp (result, "0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
661 || strcmp (result, "0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
662 || strcmp (result, "0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
663 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
664 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
665 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
666
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
667 { /* FLAG_SHOWSIGN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
668 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
669 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
670 my_asnprintf (NULL, &length, "%+La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
671 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
672 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
673 || strcmp (result, "+0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
674 || strcmp (result, "+0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
675 || strcmp (result, "+0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
676 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
677 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
678 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
679
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
680 { /* FLAG_SPACE. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
681 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
682 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
683 my_asnprintf (NULL, &length, "% La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
684 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
685 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
686 || strcmp (result, " 0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
687 || strcmp (result, " 0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
688 || strcmp (result, " 0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
689 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
690 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
691 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
692
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
693 { /* FLAG_ALT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
694 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
695 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
696 my_asnprintf (NULL, &length, "%#La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
697 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
698 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
699 || strcmp (result, "0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
700 || strcmp (result, "0x7.p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
701 || strcmp (result, "0xe.p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
702 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
703 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
704 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
705
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
706 { /* FLAG_ALT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
707 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
708 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
709 my_asnprintf (NULL, &length, "%#La %d", 1.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
710 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
711 ASSERT (strcmp (result, "0x1.p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
712 || strcmp (result, "0x2.p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
713 || strcmp (result, "0x4.p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
714 || strcmp (result, "0x8.p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
715 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
716 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
717 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
718
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
719 { /* FLAG_ZERO with finite number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
720 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
721 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
722 my_asnprintf (NULL, &length, "%010La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
723 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
724 ASSERT (strcmp (result, "0x001.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
725 || strcmp (result, "0x003.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
726 || strcmp (result, "0x00007p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
727 || strcmp (result, "0x0000ep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
728 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
729 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
730 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
731
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
732 { /* FLAG_ZERO with infinite number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
733 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
734 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
735 my_asnprintf (NULL, &length, "%010La %d", 1.0L / 0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
736 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
737 /* "0000000inf 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
738 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
739 ASSERT (strcmp (result, " inf 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
740 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
741 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
742 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
743
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
744 { /* FLAG_ZERO with NaN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
745 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
746 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
747 my_asnprintf (NULL, &length, "%010La %d", 0.0L / 0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
748 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
749 /* "0000000nan 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
750 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
751 ASSERT (strcmp (result, " nan 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
752 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
753 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
754 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
755
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
756 /* Test the support of the %f format directive. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
757
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
758 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
759 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
760 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
761 my_asnprintf (NULL, &length, "%f %d", 12.75, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
762 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
763 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
764 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
765 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
766 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
767
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
768 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
769 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
770 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
771 my_asnprintf (NULL, &length, "%f %d", 1234567.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
772 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
773 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
774 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
775 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
776 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
777
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
778 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
779 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
780 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
781 my_asnprintf (NULL, &length, "%f %d", -0.03125, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
782 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
783 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
784 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
785 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
786 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
787
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
788 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
789 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
790 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
791 my_asnprintf (NULL, &length, "%f %d", 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
792 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
793 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
794 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
795 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
796 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
797
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
798 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
799 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
800 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
801 my_asnprintf (NULL, &length, "%f %d", -0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
802 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
803 ASSERT (strcmp (result, "-0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
804 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
805 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
806 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
807
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
808 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
809 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
810 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
811 my_asnprintf (NULL, &length, "%f %d", 1.0 / 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
812 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
813 ASSERT (strcmp (result, "inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
814 || strcmp (result, "infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
815 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
816 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
817 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
818
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
819 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
820 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
821 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
822 my_asnprintf (NULL, &length, "%f %d", -1.0 / 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
823 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
824 ASSERT (strcmp (result, "-inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
825 || strcmp (result, "-infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
826 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
827 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
828 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
829
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
830 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
831 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
832 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
833 my_asnprintf (NULL, &length, "%f %d", NaN (), 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
834 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
835 ASSERT (strcmp (result, "nan 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
836 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
837 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
838 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
839
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
840 { /* Width. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
841 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
842 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
843 my_asnprintf (NULL, &length, "%10f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
844 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
845 ASSERT (strcmp (result, " 1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
846 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
847 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
848 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
849
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
850 { /* FLAG_LEFT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
851 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
852 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
853 my_asnprintf (NULL, &length, "%-10f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
854 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
855 ASSERT (strcmp (result, "1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
856 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
857 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
858 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
859
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
860 { /* FLAG_SHOWSIGN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
861 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
862 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
863 my_asnprintf (NULL, &length, "%+f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
864 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
865 ASSERT (strcmp (result, "+1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
866 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
867 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
868 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
869
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
870 { /* FLAG_SPACE. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
871 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
872 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
873 my_asnprintf (NULL, &length, "% f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
874 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
875 ASSERT (strcmp (result, " 1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
876 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
877 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
878 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
879
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
880 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
881 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
882 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
883 my_asnprintf (NULL, &length, "%#f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
884 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
885 ASSERT (strcmp (result, "1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
886 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
887 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
888 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
889
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
890 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
891 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
892 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
893 my_asnprintf (NULL, &length, "%#.f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
894 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
895 ASSERT (strcmp (result, "2. 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
896 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
897 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
898 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
899
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
900 { /* FLAG_ZERO with finite number. */
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
901 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
902 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
903 my_asnprintf (NULL, &length, "%015f %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
904 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
905 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
906 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
907 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
908 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
909
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
910 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
911 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
912 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
913 my_asnprintf (NULL, &length, "%015f %d", -1.0 / 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
914 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
915 ASSERT (strcmp (result, " -inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
916 || strcmp (result, " -infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
917 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
918 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
919 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
920
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
921 { /* FLAG_ZERO with NaN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
922 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
923 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
924 my_asnprintf (NULL, &length, "%015f %d", NaN (), 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
925 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
926 ASSERT (strcmp (result, " nan 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
927 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
928 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
929 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
930
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
931 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
932 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
933 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
934 my_asnprintf (NULL, &length, "%.f %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
935 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
936 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
937 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
938 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
939 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
940
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
941 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
942 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
943 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
944 my_asnprintf (NULL, &length, "%Lf %d", 12.75L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
945 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
946 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
947 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
948 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
949 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
950
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
951 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
952 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
953 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
954 my_asnprintf (NULL, &length, "%Lf %d", 1234567.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
955 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
956 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
957 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
958 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
959 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
960
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
961 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
962 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
963 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
964 my_asnprintf (NULL, &length, "%Lf %d", -0.03125L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
965 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
966 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
967 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
968 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
969 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
970
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
971 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
972 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
973 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
974 my_asnprintf (NULL, &length, "%Lf %d", 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
975 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
976 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
977 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
978 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
979 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
980
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
981 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
982 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
983 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
984 my_asnprintf (NULL, &length, "%Lf %d", -0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
985 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
986 ASSERT (strcmp (result, "-0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
987 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
988 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
989 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
990
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
991 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
992 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
993 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
994 my_asnprintf (NULL, &length, "%Lf %d", 1.0L / 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
995 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
996 ASSERT (strcmp (result, "inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
997 || strcmp (result, "infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
998 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
999 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1000 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1001
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1002 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1003 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1004 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1005 my_asnprintf (NULL, &length, "%Lf %d", -1.0L / 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1006 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1007 ASSERT (strcmp (result, "-inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1008 || strcmp (result, "-infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1009 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1010 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1011 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1012
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1013 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1014 static long double zero = 0.0L;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1015 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1016 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1017 my_asnprintf (NULL, &length, "%Lf %d", zero / zero, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1018 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1019 ASSERT (strcmp (result, "nan 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1020 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1021 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1022 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1023
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1024 { /* Width. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1025 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1026 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1027 my_asnprintf (NULL, &length, "%10Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1028 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1029 ASSERT (strcmp (result, " 1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1030 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1031 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1032 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1033
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1034 { /* FLAG_LEFT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1035 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1036 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1037 my_asnprintf (NULL, &length, "%-10Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1038 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1039 ASSERT (strcmp (result, "1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1040 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1041 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1042 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1043
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1044 { /* FLAG_SHOWSIGN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1045 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1046 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1047 my_asnprintf (NULL, &length, "%+Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1048 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1049 ASSERT (strcmp (result, "+1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1050 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1051 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1052 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1053
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1054 { /* FLAG_SPACE. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1055 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1056 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1057 my_asnprintf (NULL, &length, "% Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1058 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1059 ASSERT (strcmp (result, " 1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1060 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1061 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1062 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1063
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1064 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1065 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1066 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1067 my_asnprintf (NULL, &length, "%#Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1068 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1069 ASSERT (strcmp (result, "1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1070 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1071 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1072 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1073
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1074 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1075 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1076 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1077 my_asnprintf (NULL, &length, "%#.Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1078 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1079 ASSERT (strcmp (result, "2. 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1080 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1081 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1082 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1083
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1084 { /* FLAG_ZERO with finite number. */
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1085 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1086 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1087 my_asnprintf (NULL, &length, "%015Lf %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1088 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1089 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1090 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1091 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1092 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1093
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1094 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1095 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1096 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1097 my_asnprintf (NULL, &length, "%015Lf %d", -1.0L / 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1098 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1099 ASSERT (strcmp (result, " -inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1100 || strcmp (result, " -infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1101 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1102 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1103 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1104
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1105 { /* FLAG_ZERO with NaN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1106 static long double zero = 0.0L;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1107 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1108 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1109 my_asnprintf (NULL, &length, "%015Lf %d", zero / zero, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1110 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1111 ASSERT (strcmp (result, " nan 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1112 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1113 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1114 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1115
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1116 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1117 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1118 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1119 my_asnprintf (NULL, &length, "%.Lf %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1120 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1121 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1122 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1123 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1124 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1125
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1126 /* Test the support of the %F format directive. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1127
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1128 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1129 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1130 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1131 my_asnprintf (NULL, &length, "%F %d", 12.75, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1132 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1133 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1134 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1135 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1136 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1137
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1138 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1139 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1140 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1141 my_asnprintf (NULL, &length, "%F %d", 1234567.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1142 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1143 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1144 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1145 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1146 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1147
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1148 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1149 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1150 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1151 my_asnprintf (NULL, &length, "%F %d", -0.03125, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1152 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1153 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1154 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1155 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1156 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1157
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1158 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1159 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1160 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1161 my_asnprintf (NULL, &length, "%F %d", 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1162 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1163 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1164 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1165 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1166 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1167
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1168 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1169 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1170 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1171 my_asnprintf (NULL, &length, "%F %d", -0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1172 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1173 ASSERT (strcmp (result, "-0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1174 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1175 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1176 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1177
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1178 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1179 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1180 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1181 my_asnprintf (NULL, &length, "%F %d", 1.0 / 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1182 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1183 ASSERT (strcmp (result, "INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1184 || strcmp (result, "INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1185 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1186 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1187 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1188
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1189 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1190 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1191 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1192 my_asnprintf (NULL, &length, "%F %d", -1.0 / 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1193 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1194 ASSERT (strcmp (result, "-INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1195 || strcmp (result, "-INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1196 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1197 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1198 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1199
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1200 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1201 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1202 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1203 my_asnprintf (NULL, &length, "%F %d", NaN (), 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1204 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1205 ASSERT (strcmp (result, "NAN 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1206 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1207 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1208 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1209
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1210 { /* FLAG_ZERO. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1211 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1212 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1213 my_asnprintf (NULL, &length, "%015F %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1214 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1215 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1216 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1217 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1218 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1219
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1220 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1221 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1222 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1223 my_asnprintf (NULL, &length, "%015F %d", -1.0 / 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1224 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1225 ASSERT (strcmp (result, " -INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1226 || strcmp (result, " -INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1227 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1228 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1229 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1230
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1231 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1232 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1233 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1234 my_asnprintf (NULL, &length, "%.F %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1235 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1236 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1237 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1238 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1239 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1240
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1241 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1242 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1243 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1244 my_asnprintf (NULL, &length, "%LF %d", 12.75L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1245 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1246 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1247 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1248 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1249 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1250
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1251 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1252 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1253 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1254 my_asnprintf (NULL, &length, "%LF %d", 1234567.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1255 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1256 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1257 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1258 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1259 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1260
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1261 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1262 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1263 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1264 my_asnprintf (NULL, &length, "%LF %d", -0.03125L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1265 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1266 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1267 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1268 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1269 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1270
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1271 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1272 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1273 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1274 my_asnprintf (NULL, &length, "%LF %d", 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1275 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1276 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1277 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1278 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1279 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1280
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1281 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1282 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1283 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1284 my_asnprintf (NULL, &length, "%LF %d", -0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1285 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1286 ASSERT (strcmp (result, "-0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1287 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1288 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1289 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1290
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1291 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1292 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1293 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1294 my_asnprintf (NULL, &length, "%LF %d", 1.0L / 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1295 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1296 ASSERT (strcmp (result, "INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1297 || strcmp (result, "INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1298 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1299 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1300 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1301
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1302 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1303 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1304 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1305 my_asnprintf (NULL, &length, "%LF %d", -1.0L / 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1306 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1307 ASSERT (strcmp (result, "-INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1308 || strcmp (result, "-INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1309 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1310 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1311 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1312
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1313 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1314 static long double zero = 0.0L;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1315 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1316 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1317 my_asnprintf (NULL, &length, "%LF %d", zero / zero, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1318 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1319 ASSERT (strcmp (result, "NAN 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1320 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1321 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1322 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1323
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1324 { /* FLAG_ZERO. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1325 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1326 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1327 my_asnprintf (NULL, &length, "%015LF %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1328 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1329 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1330 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1331 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1332 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1333
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1334 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1335 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1336 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1337 my_asnprintf (NULL, &length, "%015LF %d", -1.0L / 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1338 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1339 ASSERT (strcmp (result, " -INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1340 || strcmp (result, " -INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1341 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1342 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1343 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1344
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1345 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1346 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1347 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1348 my_asnprintf (NULL, &length, "%.LF %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1349 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1350 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1351 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1352 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1353 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1354
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1355 /* Test the support of the %n format directive. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1356
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1357 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1358 int count = -1;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1359 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1360 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1361 my_asnprintf (NULL, &length, "%d %n", 123, &count, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1362 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1363 ASSERT (strcmp (result, "123 ") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1364 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1365 ASSERT (count == 4);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1366 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1367 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1368
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1369 /* Test the support of the POSIX/XSI format strings with positions. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1370
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1371 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1372 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1373 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1374 my_asnprintf (NULL, &length, "%2$d %1$d", 33, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1375 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1376 ASSERT (strcmp (result, "55 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1377 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1378 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1379 }
8803
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1380
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1381 /* Test the support of the grouping flag. */
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1382
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1383 {
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1384 size_t length;
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1385 char *result =
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1386 my_asnprintf (NULL, &length, "%'d %d", 1234567, 99);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1387 ASSERT (result != NULL);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1388 ASSERT (result[strlen (result) - 1] == '9');
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1389 ASSERT (length == strlen (result));
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1390 free (result);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
1391 }
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1392 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1393
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1394 static char *
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1395 my_asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1396 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1397 va_list args;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1398 char *ret;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1399
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1400 va_start (args, format);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1401 ret = vasnprintf (resultbuf, lengthp, format, args);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1402 va_end (args);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1403 return ret;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1404 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1405
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1406 static void
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1407 test_vasnprintf ()
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1408 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1409 test_function (my_asnprintf);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1410 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1411
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1412 static void
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1413 test_asnprintf ()
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1414 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1415 test_function (asnprintf);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1416 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1417
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1418 int
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1419 main (int argc, char *argv[])
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1420 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1421 test_vasnprintf ();
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1422 test_asnprintf ();
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1423 return 0;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1424 }