This source file includes following definitions.
- test_function
- my_asnprintf
- test_vasnprintf
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include "unistdio.h"
22
23 #include <locale.h>
24 #include <stdarg.h>
25 #include <stdint.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "macros.h"
30
31 static void
32 test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
33 {
34
35
36 {
37 static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski";
38 {
39 size_t length;
40 char *result =
41 my_asnprintf (NULL, &length, "%U %d", unicode_string, 33, 44, 55);
42 ASSERT (result != NULL);
43 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
44 || strcmp (result, "Rafal Maszkowski 33") == 0);
45 ASSERT (length == strlen (result));
46 free (result);
47 }
48 {
49 size_t length;
50 char *result =
51 my_asnprintf (NULL, &length, "%20U %d", unicode_string, 33, 44, 55);
52 ASSERT (result != NULL);
53 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
54 || strcmp (result, " Rafal Maszkowski 33") == 0);
55 ASSERT (length == strlen (result));
56 free (result);
57 }
58 {
59 size_t length;
60 char *result =
61 my_asnprintf (NULL, &length, "%-20U %d", unicode_string, 33, 44, 55);
62 ASSERT (result != NULL);
63 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
64 || strcmp (result, "Rafal Maszkowski 33") == 0);
65 ASSERT (length == strlen (result));
66 free (result);
67 }
68 {
69 size_t length;
70 char *result =
71 my_asnprintf (NULL, &length, "%020U %d", unicode_string, 33, 44, 55);
72 ASSERT (result != NULL);
73 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
74 || strcmp (result, " Rafal Maszkowski 33") == 0);
75 ASSERT (length == strlen (result));
76 free (result);
77 }
78 }
79
80 {
81 static const uint16_t unicode_string[] =
82 {
83 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w',
84 's', 'k', 'i', 0
85 };
86 {
87 size_t length;
88 char *result =
89 my_asnprintf (NULL, &length, "%lU %d", unicode_string, 33, 44, 55);
90 ASSERT (result != NULL);
91 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
92 || strcmp (result, "Rafal Maszkowski 33") == 0);
93 ASSERT (length == strlen (result));
94 free (result);
95 }
96 {
97 size_t length;
98 char *result =
99 my_asnprintf (NULL, &length, "%20lU %d", unicode_string, 33, 44, 55);
100 ASSERT (result != NULL);
101 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
102 || strcmp (result, " Rafal Maszkowski 33") == 0);
103 ASSERT (length == strlen (result));
104 free (result);
105 }
106 {
107 size_t length;
108 char *result =
109 my_asnprintf (NULL, &length, "%-20lU %d", unicode_string, 33, 44, 55);
110 ASSERT (result != NULL);
111 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
112 || strcmp (result, "Rafal Maszkowski 33") == 0);
113 ASSERT (length == strlen (result));
114 free (result);
115 }
116 {
117 size_t length;
118 char *result =
119 my_asnprintf (NULL, &length, "%020lU %d", unicode_string, 33, 44, 55);
120 ASSERT (result != NULL);
121 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
122 || strcmp (result, " Rafal Maszkowski 33") == 0);
123 ASSERT (length == strlen (result));
124 free (result);
125 }
126 }
127
128 {
129 static const uint32_t unicode_string[] =
130 {
131 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w',
132 's', 'k', 'i', 0
133 };
134 {
135 size_t length;
136 char *result =
137 my_asnprintf (NULL, &length, "%llU %d", unicode_string, 33, 44, 55);
138 ASSERT (result != NULL);
139 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
140 || strcmp (result, "Rafal Maszkowski 33") == 0);
141 ASSERT (length == strlen (result));
142 free (result);
143 }
144 {
145 size_t length;
146 char *result =
147 my_asnprintf (NULL, &length, "%20llU %d", unicode_string, 33, 44, 55);
148 ASSERT (result != NULL);
149 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
150 || strcmp (result, " Rafal Maszkowski 33") == 0);
151 ASSERT (length == strlen (result));
152 free (result);
153 }
154 {
155 size_t length;
156 char *result =
157 my_asnprintf (NULL, &length, "%-20llU %d", unicode_string, 33, 44, 55);
158 ASSERT (result != NULL);
159 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
160 || strcmp (result, "Rafal Maszkowski 33") == 0);
161 ASSERT (length == strlen (result));
162 free (result);
163 }
164 {
165 size_t length;
166 char *result =
167 my_asnprintf (NULL, &length, "%020llU %d", unicode_string, 33, 44, 55);
168 ASSERT (result != NULL);
169 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
170 || strcmp (result, " Rafal Maszkowski 33") == 0);
171 ASSERT (length == strlen (result));
172 free (result);
173 }
174 }
175
176
177
178 {
179 const char *locale_string = "\304rger";
180 {
181 size_t length;
182 char *result =
183 my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55);
184 ASSERT (result != NULL);
185 ASSERT (strcmp (result, "\304rger 33") == 0);
186 ASSERT (length == strlen (result));
187 free (result);
188 }
189 {
190 size_t length;
191 char *result =
192 my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55);
193 ASSERT (result != NULL);
194 ASSERT (strcmp (result, " \304rger 33") == 0);
195 ASSERT (length == strlen (result));
196 free (result);
197 }
198 {
199 size_t length;
200 char *result =
201 my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55);
202 ASSERT (result != NULL);
203 ASSERT (strcmp (result, "\304rger 33") == 0);
204 ASSERT (length == strlen (result));
205 free (result);
206 }
207 {
208 size_t length;
209 char *result =
210 my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55);
211 ASSERT (result != NULL);
212 ASSERT (strcmp (result, " \304rger 33") == 0);
213 ASSERT (length == strlen (result));
214 free (result);
215 }
216 }
217 }
218
219 static char *
220 my_asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
221 {
222 va_list args;
223 char *ret;
224
225 va_start (args, format);
226 ret = ulc_vasnprintf (resultbuf, lengthp, format, args);
227 va_end (args);
228 return ret;
229 }
230
231 static void
232 test_vasnprintf ()
233 {
234 test_function (my_asnprintf);
235 }
236
237 int
238 main (int argc, char *argv[])
239 {
240
241 if (setlocale (LC_ALL, "") == NULL)
242 return 1;
243
244 test_vasnprintf ();
245 return 0;
246 }