Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/unistdio/test-ulc-vasnprintf2.c @ 14730:f0a9a2cd267c
fclose: preserve fflush errors
Caught by gcc -Werror=unused-but-set-variable.
* lib/fclose.c (rpl_fclose): Don't lose fflush errors.
Reported by Jim Meyering.
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Wed, 11 May 2011 11:35:06 -0600 |
parents | 97fc9a21a8fb |
children | 8250f2777afc |
rev | line source |
---|---|
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of ulc_vasnprintf() function in an ISO-8859-1 locale. |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
12559
diff
changeset
|
2 Copyright (C) 2007-2011 Free Software Foundation, Inc. |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9030
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9030
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9030
diff
changeset
|
7 (at your option) any later version. |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9030
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #include <config.h> |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include "unistdio.h" |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include <locale.h> |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #include <stdarg.h> |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #include <stdint.h> |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 #include <stdlib.h> |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 #include <string.h> |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
29 #include "macros.h" |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 static void |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 /* Test the support of the 'U' conversion specifier for Unicode strings. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
41 my_asnprintf (NULL, &length, "%U %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
44 || strcmp (result, "Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 { /* Width. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
51 my_asnprintf (NULL, &length, "%20U %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
54 || strcmp (result, " Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 { /* FLAG_LEFT. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
61 my_asnprintf (NULL, &length, "%-20U %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
64 || strcmp (result, "Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 { /* FLAG_ZERO: no effect. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
71 my_asnprintf (NULL, &length, "%020U %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
74 || strcmp (result, " Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 static const uint16_t unicode_string[] = /* Rafał Maszkowski */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
83 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
84 's', 'k', 'i', 0 |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 }; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
89 my_asnprintf (NULL, &length, "%lU %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
92 || strcmp (result, "Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
93 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 { /* Width. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
99 my_asnprintf (NULL, &length, "%20lU %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
102 || strcmp (result, " Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 { /* FLAG_LEFT. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
109 my_asnprintf (NULL, &length, "%-20lU %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
111 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
112 || strcmp (result, "Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
113 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
114 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
115 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
116 { /* FLAG_ZERO: no effect. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
119 my_asnprintf (NULL, &length, "%020lU %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
120 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
121 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
122 || strcmp (result, " Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
123 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
124 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
125 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
127 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
128 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
129 static const uint32_t unicode_string[] = /* Rafał Maszkowski */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
130 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
131 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
132 's', 'k', 'i', 0 |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
133 }; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
134 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
135 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
136 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
137 my_asnprintf (NULL, &length, "%llU %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
138 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
139 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
140 || strcmp (result, "Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
141 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
142 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
143 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
144 { /* Width. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
145 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
146 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
147 my_asnprintf (NULL, &length, "%20llU %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
148 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
149 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
150 || strcmp (result, " Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
151 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 { /* FLAG_LEFT. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
157 my_asnprintf (NULL, &length, "%-20llU %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
160 || strcmp (result, "Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
161 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
162 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
163 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
164 { /* FLAG_ZERO: no effect. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
165 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
166 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
167 my_asnprintf (NULL, &length, "%020llU %d", unicode_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
168 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
169 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
170 || strcmp (result, " Rafal Maszkowski 33") == 0); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
171 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
172 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
173 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
174 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
175 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
176 /* Test the support of the 's' conversion specifier for strings. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
177 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
178 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
179 const char *locale_string = "\304rger"; /* Ärger */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
180 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
181 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
182 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
183 my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
184 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
185 ASSERT (strcmp (result, "\304rger 33") == 0); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
186 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
187 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
188 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
189 { /* Width. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
190 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
191 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
192 my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
193 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
194 ASSERT (strcmp (result, " \304rger 33") == 0); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
195 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
196 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
197 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
198 { /* FLAG_LEFT. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
199 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
200 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
201 my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
202 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
203 ASSERT (strcmp (result, "\304rger 33") == 0); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
204 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
205 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
206 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
207 { /* FLAG_ZERO: no effect. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
208 size_t length; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
209 char *result = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
210 my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); |
9030
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
211 ASSERT (result != NULL); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
212 ASSERT (strcmp (result, " \304rger 33") == 0); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
213 ASSERT (length == strlen (result)); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
214 free (result); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
215 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
216 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
217 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
218 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
219 static char * |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
220 my_asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
221 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
222 va_list args; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
223 char *ret; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
224 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
225 va_start (args, format); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
226 ret = ulc_vasnprintf (resultbuf, lengthp, format, args); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
227 va_end (args); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
228 return ret; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
229 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
230 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
231 static void |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
232 test_vasnprintf () |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
233 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
234 test_function (my_asnprintf); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
235 } |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
236 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
237 int |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
238 main (int argc, char *argv[]) |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
239 { |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
240 /* configure should already have checked that the locale is supported. */ |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
241 if (setlocale (LC_ALL, "") == NULL) |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
242 return 1; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
243 |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
244 test_vasnprintf (); |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
245 return 0; |
870029929d86
Formatted output functions for Unicode strings.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
246 } |