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\305\202 Maszkowski 33") == 0);
44 ASSERT (length == strlen (result));
45 free (result);
46 }
47 {
48 size_t length;
49 char *result =
50 my_asnprintf (NULL, &length, "%20U %d", unicode_string, 33, 44, 55);
51 ASSERT (result != NULL);
52 ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0);
53 ASSERT (length == strlen (result));
54 free (result);
55 }
56 {
57 size_t length;
58 char *result =
59 my_asnprintf (NULL, &length, "%-20U %d", unicode_string, 33, 44, 55);
60 ASSERT (result != NULL);
61 ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0);
62 ASSERT (length == strlen (result));
63 free (result);
64 }
65 {
66 size_t length;
67 char *result =
68 my_asnprintf (NULL, &length, "%020U %d", unicode_string, 33, 44, 55);
69 ASSERT (result != NULL);
70 ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0);
71 ASSERT (length == strlen (result));
72 free (result);
73 }
74 }
75
76 {
77 static const uint16_t unicode_string[] =
78 {
79 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w',
80 's', 'k', 'i', 0
81 };
82 {
83 size_t length;
84 char *result =
85 my_asnprintf (NULL, &length, "%lU %d", unicode_string, 33, 44, 55);
86 ASSERT (result != NULL);
87 ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0);
88 ASSERT (length == strlen (result));
89 free (result);
90 }
91 {
92 size_t length;
93 char *result =
94 my_asnprintf (NULL, &length, "%20lU %d", unicode_string, 33, 44, 55);
95 ASSERT (result != NULL);
96 ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0);
97 ASSERT (length == strlen (result));
98 free (result);
99 }
100 {
101 size_t length;
102 char *result =
103 my_asnprintf (NULL, &length, "%-20lU %d", unicode_string, 33, 44, 55);
104 ASSERT (result != NULL);
105 ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0);
106 ASSERT (length == strlen (result));
107 free (result);
108 }
109 {
110 size_t length;
111 char *result =
112 my_asnprintf (NULL, &length, "%020lU %d", unicode_string, 33, 44, 55);
113 ASSERT (result != NULL);
114 ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0);
115 ASSERT (length == strlen (result));
116 free (result);
117 }
118 }
119
120 {
121 static const uint32_t unicode_string[] =
122 {
123 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w',
124 's', 'k', 'i', 0
125 };
126 {
127 size_t length;
128 char *result =
129 my_asnprintf (NULL, &length, "%llU %d", unicode_string, 33, 44, 55);
130 ASSERT (result != NULL);
131 ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0);
132 ASSERT (length == strlen (result));
133 free (result);
134 }
135 {
136 size_t length;
137 char *result =
138 my_asnprintf (NULL, &length, "%20llU %d", unicode_string, 33, 44, 55);
139 ASSERT (result != NULL);
140 ASSERT (strcmp (result, " Rafa\305\202 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\305\202 Maszkowski 33") == 0);
150 ASSERT (length == strlen (result));
151 free (result);
152 }
153 {
154 size_t length;
155 char *result =
156 my_asnprintf (NULL, &length, "%020llU %d", unicode_string, 33, 44, 55);
157 ASSERT (result != NULL);
158 ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0);
159 ASSERT (length == strlen (result));
160 free (result);
161 }
162 }
163
164
165
166 {
167 const char *locale_string = "\303\204rger";
168 {
169 size_t length;
170 char *result =
171 my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55);
172 ASSERT (result != NULL);
173 ASSERT (strcmp (result, "\303\204rger 33") == 0);
174 ASSERT (length == strlen (result));
175 free (result);
176 }
177 {
178 size_t length;
179 char *result =
180 my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55);
181 ASSERT (result != NULL);
182 ASSERT (strcmp (result, " \303\204rger 33") == 0);
183 ASSERT (length == strlen (result));
184 free (result);
185 }
186 {
187 size_t length;
188 char *result =
189 my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55);
190 ASSERT (result != NULL);
191 ASSERT (strcmp (result, "\303\204rger 33") == 0);
192 ASSERT (length == strlen (result));
193 free (result);
194 }
195 {
196 size_t length;
197 char *result =
198 my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55);
199 ASSERT (result != NULL);
200 ASSERT (strcmp (result, " \303\204rger 33") == 0);
201 ASSERT (length == strlen (result));
202 free (result);
203 }
204 }
205 }
206
207 static char *
208 my_asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
209 {
210 va_list args;
211 char *ret;
212
213 va_start (args, format);
214 ret = ulc_vasnprintf (resultbuf, lengthp, format, args);
215 va_end (args);
216 return ret;
217 }
218
219 static void
220 test_vasnprintf ()
221 {
222 test_function (my_asnprintf);
223 }
224
225 int
226 main (int argc, char *argv[])
227 {
228
229 if (setlocale (LC_ALL, "") == NULL)
230 return 1;
231
232 test_vasnprintf ();
233 return 0;
234 }