blob: 4a598f22dce06cd2b5f041b5f5e8b51ba1f1c84a [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ***************************************************************************/
22
23/*
24 * The purpose of this test is to minimally exercise libcurl's internal
25 * curl_m*printf formatting capabilities and handling of some data types.
26 */
27
28#include "test.h"
29
30#ifdef HAVE_LIMITS_H
31#include <limits.h>
32#endif
33
34#ifdef HAVE_LOCALE_H
35# include <locale.h> /* for setlocale() */
36#endif
37
38#include "memdebug.h"
39
40#if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
41# define MPRNT_SUFFIX_CURL_OFF_T LL
42#else
43# define MPRNT_SUFFIX_CURL_OFF_T L
44#endif
45
46
47#ifdef CURL_ISOCPP
48# define MPRNT_OFF_T_C_HELPER2(Val,Suffix) Val ## Suffix
49#else
50# define MPRNT_OFF_T_C_HELPER2(Val,Suffix) Val/**/Suffix
51#endif
52#define MPRNT_OFF_T_C_HELPER1(Val,Suffix) MPRNT_OFF_T_C_HELPER2(Val,Suffix)
53#define MPRNT_OFF_T_C(Val) MPRNT_OFF_T_C_HELPER1(Val,MPRNT_SUFFIX_CURL_OFF_T)
54
55
56#define BUFSZ 256
57#define USHORT_TESTS_ARRSZ 1 + 100
58#define SSHORT_TESTS_ARRSZ 1 + 100
59#define UINT_TESTS_ARRSZ 1 + 100
60#define SINT_TESTS_ARRSZ 1 + 100
61#define ULONG_TESTS_ARRSZ 1 + 100
62#define SLONG_TESTS_ARRSZ 1 + 100
63#define COFFT_TESTS_ARRSZ 1 + 100
64
65
66struct unsshort_st {
67 unsigned short num; /* unsigned short */
68 const char *expected; /* expected string */
69 char result[BUFSZ]; /* result string */
70};
71
72
73struct sigshort_st {
74 short num; /* signed short */
75 const char *expected; /* expected string */
76 char result[BUFSZ]; /* result string */
77};
78
79
80struct unsint_st {
81 unsigned int num; /* unsigned int */
82 const char *expected; /* expected string */
83 char result[BUFSZ]; /* result string */
84};
85
86
87struct sigint_st {
88 int num; /* signed int */
89 const char *expected; /* expected string */
90 char result[BUFSZ]; /* result string */
91};
92
93
94struct unslong_st {
95 unsigned long num; /* unsigned long */
96 const char *expected; /* expected string */
97 char result[BUFSZ]; /* result string */
98};
99
100
101struct siglong_st {
102 long num; /* signed long */
103 const char *expected; /* expected string */
104 char result[BUFSZ]; /* result string */
105};
106
107
108struct curloff_st {
109 curl_off_t num; /* curl_off_t */
110 const char *expected; /* expected string */
111 char result[BUFSZ]; /* result string */
112};
113
114
115static struct unsshort_st us_test[USHORT_TESTS_ARRSZ];
116static struct sigshort_st ss_test[SSHORT_TESTS_ARRSZ];
117static struct unsint_st ui_test[UINT_TESTS_ARRSZ];
118static struct sigint_st si_test[SINT_TESTS_ARRSZ];
119static struct unslong_st ul_test[ULONG_TESTS_ARRSZ];
120static struct siglong_st sl_test[SLONG_TESTS_ARRSZ];
121static struct curloff_st co_test[COFFT_TESTS_ARRSZ];
122
123
124static int test_unsigned_short_formatting(void)
125{
126 int i, j;
127 int num_ushort_tests;
128 int failed = 0;
129
130#if (SIZEOF_SHORT == 1)
131
132 i=1; us_test[i].num = 0xFFU; us_test[i].expected = "256";
133 i++; us_test[i].num = 0xF0U; us_test[i].expected = "240";
134 i++; us_test[i].num = 0x0FU; us_test[i].expected = "15";
135
136 i++; us_test[i].num = 0xE0U; us_test[i].expected = "224";
137 i++; us_test[i].num = 0x0EU; us_test[i].expected = "14";
138
139 i++; us_test[i].num = 0xC0U; us_test[i].expected = "192";
140 i++; us_test[i].num = 0x0CU; us_test[i].expected = "12";
141
142 i++; us_test[i].num = 0x01U; us_test[i].expected = "1";
143 i++; us_test[i].num = 0x00U; us_test[i].expected = "0";
144
145 num_ushort_tests = i;
146
147#elif (SIZEOF_SHORT == 2)
148
149 i=1; us_test[i].num = 0xFFFFU; us_test[i].expected = "65535";
150 i++; us_test[i].num = 0xFF00U; us_test[i].expected = "65280";
151 i++; us_test[i].num = 0x00FFU; us_test[i].expected = "255";
152
153 i++; us_test[i].num = 0xF000U; us_test[i].expected = "61440";
154 i++; us_test[i].num = 0x0F00U; us_test[i].expected = "3840";
155 i++; us_test[i].num = 0x00F0U; us_test[i].expected = "240";
156 i++; us_test[i].num = 0x000FU; us_test[i].expected = "15";
157
158 i++; us_test[i].num = 0xC000U; us_test[i].expected = "49152";
159 i++; us_test[i].num = 0x0C00U; us_test[i].expected = "3072";
160 i++; us_test[i].num = 0x00C0U; us_test[i].expected = "192";
161 i++; us_test[i].num = 0x000CU; us_test[i].expected = "12";
162
163 i++; us_test[i].num = 0x0001U; us_test[i].expected = "1";
164 i++; us_test[i].num = 0x0000U; us_test[i].expected = "0";
165
166 num_ushort_tests = i;
167
168#elif (SIZEOF_SHORT == 4)
169
170 i=1; us_test[i].num = 0xFFFFFFFFU; us_test[i].expected = "4294967295";
171 i++; us_test[i].num = 0xFFFF0000U; us_test[i].expected = "4294901760";
172 i++; us_test[i].num = 0x0000FFFFU; us_test[i].expected = "65535";
173
174 i++; us_test[i].num = 0xFF000000U; us_test[i].expected = "4278190080";
175 i++; us_test[i].num = 0x00FF0000U; us_test[i].expected = "16711680";
176 i++; us_test[i].num = 0x0000FF00U; us_test[i].expected = "65280";
177 i++; us_test[i].num = 0x000000FFU; us_test[i].expected = "255";
178
179 i++; us_test[i].num = 0xF0000000U; us_test[i].expected = "4026531840";
180 i++; us_test[i].num = 0x0F000000U; us_test[i].expected = "251658240";
181 i++; us_test[i].num = 0x00F00000U; us_test[i].expected = "15728640";
182 i++; us_test[i].num = 0x000F0000U; us_test[i].expected = "983040";
183 i++; us_test[i].num = 0x0000F000U; us_test[i].expected = "61440";
184 i++; us_test[i].num = 0x00000F00U; us_test[i].expected = "3840";
185 i++; us_test[i].num = 0x000000F0U; us_test[i].expected = "240";
186 i++; us_test[i].num = 0x0000000FU; us_test[i].expected = "15";
187
188 i++; us_test[i].num = 0xC0000000U; us_test[i].expected = "3221225472";
189 i++; us_test[i].num = 0x0C000000U; us_test[i].expected = "201326592";
190 i++; us_test[i].num = 0x00C00000U; us_test[i].expected = "12582912";
191 i++; us_test[i].num = 0x000C0000U; us_test[i].expected = "786432";
192 i++; us_test[i].num = 0x0000C000U; us_test[i].expected = "49152";
193 i++; us_test[i].num = 0x00000C00U; us_test[i].expected = "3072";
194 i++; us_test[i].num = 0x000000C0U; us_test[i].expected = "192";
195 i++; us_test[i].num = 0x0000000CU; us_test[i].expected = "12";
196
197 i++; us_test[i].num = 0x00000001U; us_test[i].expected = "1";
198 i++; us_test[i].num = 0x00000000U; us_test[i].expected = "0";
199
200 num_ushort_tests = i;
201
202#endif
203
204 for(i=1; i<=num_ushort_tests; i++) {
205
206 for(j=0; j<BUFSZ; j++)
207 us_test[i].result[j] = 'X';
208 us_test[i].result[BUFSZ-1] = '\0';
209
210 (void)curl_msprintf(us_test[i].result, "%hu", us_test[i].num);
211
212 if(memcmp(us_test[i].result,
213 us_test[i].expected,
214 strlen(us_test[i].expected))) {
215 printf("unsigned short test #%.2d: Failed (Expected: %s Got: %s)\n",
216 i, us_test[i].expected, us_test[i].result);
217 failed++;
218 }
219
220 }
221
222 if(!failed)
223 printf("All curl_mprintf() unsigned short tests OK!\n");
224 else
225 printf("Some curl_mprintf() unsigned short tests Failed!\n");
226
227 return failed;
228}
229
230
231static int test_signed_short_formatting(void)
232{
233 int i, j;
234 int num_sshort_tests;
235 int failed = 0;
236
237#if (SIZEOF_SHORT == 1)
238
239 i=1; ss_test[i].num = 0x7F; ss_test[i].expected = "127";
240
241 i++; ss_test[i].num = 0x70; ss_test[i].expected = "112";
242 i++; ss_test[i].num = 0x07; ss_test[i].expected = "7";
243
244 i++; ss_test[i].num = 0x50; ss_test[i].expected = "80";
245 i++; ss_test[i].num = 0x05; ss_test[i].expected = "5";
246
247 i++; ss_test[i].num = 0x01; ss_test[i].expected = "1";
248 i++; ss_test[i].num = 0x00; ss_test[i].expected = "0";
249
250 i++; ss_test[i].num = -0x7F -1; ss_test[i].expected = "-128";
251
252 i++; ss_test[i].num = -0x70 -1; ss_test[i].expected = "-113";
253 i++; ss_test[i].num = -0x07 -1; ss_test[i].expected = "-8";
254
255 i++; ss_test[i].num = -0x50 -1; ss_test[i].expected = "-81";
256 i++; ss_test[i].num = -0x05 -1; ss_test[i].expected = "-6";
257
258 i++; ss_test[i].num = 0x00 -1; ss_test[i].expected = "-1";
259
260 num_sshort_tests = i;
261
262#elif (SIZEOF_SHORT == 2)
263
264 i=1; ss_test[i].num = 0x7FFF; ss_test[i].expected = "32767";
265 i++; ss_test[i].num = 0x7FFE; ss_test[i].expected = "32766";
266 i++; ss_test[i].num = 0x7FFD; ss_test[i].expected = "32765";
267 i++; ss_test[i].num = 0x7F00; ss_test[i].expected = "32512";
268 i++; ss_test[i].num = 0x07F0; ss_test[i].expected = "2032";
269 i++; ss_test[i].num = 0x007F; ss_test[i].expected = "127";
270
271 i++; ss_test[i].num = 0x7000; ss_test[i].expected = "28672";
272 i++; ss_test[i].num = 0x0700; ss_test[i].expected = "1792";
273 i++; ss_test[i].num = 0x0070; ss_test[i].expected = "112";
274 i++; ss_test[i].num = 0x0007; ss_test[i].expected = "7";
275
276 i++; ss_test[i].num = 0x5000; ss_test[i].expected = "20480";
277 i++; ss_test[i].num = 0x0500; ss_test[i].expected = "1280";
278 i++; ss_test[i].num = 0x0050; ss_test[i].expected = "80";
279 i++; ss_test[i].num = 0x0005; ss_test[i].expected = "5";
280
281 i++; ss_test[i].num = 0x0001; ss_test[i].expected = "1";
282 i++; ss_test[i].num = 0x0000; ss_test[i].expected = "0";
283
284 i++; ss_test[i].num = -0x7FFF -1; ss_test[i].expected = "-32768";
285 i++; ss_test[i].num = -0x7FFE -1; ss_test[i].expected = "-32767";
286 i++; ss_test[i].num = -0x7FFD -1; ss_test[i].expected = "-32766";
287 i++; ss_test[i].num = -0x7F00 -1; ss_test[i].expected = "-32513";
288 i++; ss_test[i].num = -0x07F0 -1; ss_test[i].expected = "-2033";
289 i++; ss_test[i].num = -0x007F -1; ss_test[i].expected = "-128";
290
291 i++; ss_test[i].num = -0x7000 -1; ss_test[i].expected = "-28673";
292 i++; ss_test[i].num = -0x0700 -1; ss_test[i].expected = "-1793";
293 i++; ss_test[i].num = -0x0070 -1; ss_test[i].expected = "-113";
294 i++; ss_test[i].num = -0x0007 -1; ss_test[i].expected = "-8";
295
296 i++; ss_test[i].num = -0x5000 -1; ss_test[i].expected = "-20481";
297 i++; ss_test[i].num = -0x0500 -1; ss_test[i].expected = "-1281";
298 i++; ss_test[i].num = -0x0050 -1; ss_test[i].expected = "-81";
299 i++; ss_test[i].num = -0x0005 -1; ss_test[i].expected = "-6";
300
301 i++; ss_test[i].num = 0x0000 -1; ss_test[i].expected = "-1";
302
303 num_sshort_tests = i;
304
305#elif (SIZEOF_SHORT == 4)
306
307 i=1; ss_test[i].num = 0x7FFFFFFF; ss_test[i].expected = "2147483647";
308 i++; ss_test[i].num = 0x7FFFFFFE; ss_test[i].expected = "2147483646";
309 i++; ss_test[i].num = 0x7FFFFFFD; ss_test[i].expected = "2147483645";
310 i++; ss_test[i].num = 0x7FFF0000; ss_test[i].expected = "2147418112";
311 i++; ss_test[i].num = 0x00007FFF; ss_test[i].expected = "32767";
312
313 i++; ss_test[i].num = 0x7F000000; ss_test[i].expected = "2130706432";
314 i++; ss_test[i].num = 0x007F0000; ss_test[i].expected = "8323072";
315 i++; ss_test[i].num = 0x00007F00; ss_test[i].expected = "32512";
316 i++; ss_test[i].num = 0x0000007F; ss_test[i].expected = "127";
317
318 i++; ss_test[i].num = 0x70000000; ss_test[i].expected = "1879048192";
319 i++; ss_test[i].num = 0x07000000; ss_test[i].expected = "117440512";
320 i++; ss_test[i].num = 0x00700000; ss_test[i].expected = "7340032";
321 i++; ss_test[i].num = 0x00070000; ss_test[i].expected = "458752";
322 i++; ss_test[i].num = 0x00007000; ss_test[i].expected = "28672";
323 i++; ss_test[i].num = 0x00000700; ss_test[i].expected = "1792";
324 i++; ss_test[i].num = 0x00000070; ss_test[i].expected = "112";
325 i++; ss_test[i].num = 0x00000007; ss_test[i].expected = "7";
326
327 i++; ss_test[i].num = 0x50000000; ss_test[i].expected = "1342177280";
328 i++; ss_test[i].num = 0x05000000; ss_test[i].expected = "83886080";
329 i++; ss_test[i].num = 0x00500000; ss_test[i].expected = "5242880";
330 i++; ss_test[i].num = 0x00050000; ss_test[i].expected = "327680";
331 i++; ss_test[i].num = 0x00005000; ss_test[i].expected = "20480";
332 i++; ss_test[i].num = 0x00000500; ss_test[i].expected = "1280";
333 i++; ss_test[i].num = 0x00000050; ss_test[i].expected = "80";
334 i++; ss_test[i].num = 0x00000005; ss_test[i].expected = "5";
335
336 i++; ss_test[i].num = 0x00000001; ss_test[i].expected = "1";
337 i++; ss_test[i].num = 0x00000000; ss_test[i].expected = "0";
338
339 i++; ss_test[i].num = -0x7FFFFFFF -1; ss_test[i].expected = "-2147483648";
340 i++; ss_test[i].num = -0x7FFFFFFE -1; ss_test[i].expected = "-2147483647";
341 i++; ss_test[i].num = -0x7FFFFFFD -1; ss_test[i].expected = "-2147483646";
342 i++; ss_test[i].num = -0x7FFF0000 -1; ss_test[i].expected = "-2147418113";
343 i++; ss_test[i].num = -0x00007FFF -1; ss_test[i].expected = "-32768";
344
345 i++; ss_test[i].num = -0x7F000000 -1; ss_test[i].expected = "-2130706433";
346 i++; ss_test[i].num = -0x007F0000 -1; ss_test[i].expected = "-8323073";
347 i++; ss_test[i].num = -0x00007F00 -1; ss_test[i].expected = "-32513";
348 i++; ss_test[i].num = -0x0000007F -1; ss_test[i].expected = "-128";
349
350 i++; ss_test[i].num = -0x70000000 -1; ss_test[i].expected = "-1879048193";
351 i++; ss_test[i].num = -0x07000000 -1; ss_test[i].expected = "-117440513";
352 i++; ss_test[i].num = -0x00700000 -1; ss_test[i].expected = "-7340033";
353 i++; ss_test[i].num = -0x00070000 -1; ss_test[i].expected = "-458753";
354 i++; ss_test[i].num = -0x00007000 -1; ss_test[i].expected = "-28673";
355 i++; ss_test[i].num = -0x00000700 -1; ss_test[i].expected = "-1793";
356 i++; ss_test[i].num = -0x00000070 -1; ss_test[i].expected = "-113";
357 i++; ss_test[i].num = -0x00000007 -1; ss_test[i].expected = "-8";
358
359 i++; ss_test[i].num = -0x50000000 -1; ss_test[i].expected = "-1342177281";
360 i++; ss_test[i].num = -0x05000000 -1; ss_test[i].expected = "-83886081";
361 i++; ss_test[i].num = -0x00500000 -1; ss_test[i].expected = "-5242881";
362 i++; ss_test[i].num = -0x00050000 -1; ss_test[i].expected = "-327681";
363 i++; ss_test[i].num = -0x00005000 -1; ss_test[i].expected = "-20481";
364 i++; ss_test[i].num = -0x00000500 -1; ss_test[i].expected = "-1281";
365 i++; ss_test[i].num = -0x00000050 -1; ss_test[i].expected = "-81";
366 i++; ss_test[i].num = -0x00000005 -1; ss_test[i].expected = "-6";
367
368 i++; ss_test[i].num = 0x00000000 -1; ss_test[i].expected = "-1";
369
370 num_sshort_tests = i;
371
372#endif
373
374 for(i=1; i<=num_sshort_tests; i++) {
375
376 for(j=0; j<BUFSZ; j++)
377 ss_test[i].result[j] = 'X';
378 ss_test[i].result[BUFSZ-1] = '\0';
379
380 (void)curl_msprintf(ss_test[i].result, "%hd", ss_test[i].num);
381
382 if(memcmp(ss_test[i].result,
383 ss_test[i].expected,
384 strlen(ss_test[i].expected))) {
385 printf("signed short test #%.2d: Failed (Expected: %s Got: %s)\n",
386 i, ss_test[i].expected, ss_test[i].result);
387 failed++;
388 }
389
390 }
391
392 if(!failed)
393 printf("All curl_mprintf() signed short tests OK!\n");
394 else
395 printf("Some curl_mprintf() signed short tests Failed!\n");
396
397 return failed;
398}
399
400
401static int test_unsigned_int_formatting(void)
402{
403 int i, j;
404 int num_uint_tests;
405 int failed = 0;
406
407#if (SIZEOF_INT == 2)
408
409 i=1; ui_test[i].num = 0xFFFFU; ui_test[i].expected = "65535";
410 i++; ui_test[i].num = 0xFF00U; ui_test[i].expected = "65280";
411 i++; ui_test[i].num = 0x00FFU; ui_test[i].expected = "255";
412
413 i++; ui_test[i].num = 0xF000U; ui_test[i].expected = "61440";
414 i++; ui_test[i].num = 0x0F00U; ui_test[i].expected = "3840";
415 i++; ui_test[i].num = 0x00F0U; ui_test[i].expected = "240";
416 i++; ui_test[i].num = 0x000FU; ui_test[i].expected = "15";
417
418 i++; ui_test[i].num = 0xC000U; ui_test[i].expected = "49152";
419 i++; ui_test[i].num = 0x0C00U; ui_test[i].expected = "3072";
420 i++; ui_test[i].num = 0x00C0U; ui_test[i].expected = "192";
421 i++; ui_test[i].num = 0x000CU; ui_test[i].expected = "12";
422
423 i++; ui_test[i].num = 0x0001U; ui_test[i].expected = "1";
424 i++; ui_test[i].num = 0x0000U; ui_test[i].expected = "0";
425
426 num_uint_tests = i;
427
428#elif (SIZEOF_INT == 4)
429
430 i=1; ui_test[i].num = 0xFFFFFFFFU; ui_test[i].expected = "4294967295";
431 i++; ui_test[i].num = 0xFFFF0000U; ui_test[i].expected = "4294901760";
432 i++; ui_test[i].num = 0x0000FFFFU; ui_test[i].expected = "65535";
433
434 i++; ui_test[i].num = 0xFF000000U; ui_test[i].expected = "4278190080";
435 i++; ui_test[i].num = 0x00FF0000U; ui_test[i].expected = "16711680";
436 i++; ui_test[i].num = 0x0000FF00U; ui_test[i].expected = "65280";
437 i++; ui_test[i].num = 0x000000FFU; ui_test[i].expected = "255";
438
439 i++; ui_test[i].num = 0xF0000000U; ui_test[i].expected = "4026531840";
440 i++; ui_test[i].num = 0x0F000000U; ui_test[i].expected = "251658240";
441 i++; ui_test[i].num = 0x00F00000U; ui_test[i].expected = "15728640";
442 i++; ui_test[i].num = 0x000F0000U; ui_test[i].expected = "983040";
443 i++; ui_test[i].num = 0x0000F000U; ui_test[i].expected = "61440";
444 i++; ui_test[i].num = 0x00000F00U; ui_test[i].expected = "3840";
445 i++; ui_test[i].num = 0x000000F0U; ui_test[i].expected = "240";
446 i++; ui_test[i].num = 0x0000000FU; ui_test[i].expected = "15";
447
448 i++; ui_test[i].num = 0xC0000000U; ui_test[i].expected = "3221225472";
449 i++; ui_test[i].num = 0x0C000000U; ui_test[i].expected = "201326592";
450 i++; ui_test[i].num = 0x00C00000U; ui_test[i].expected = "12582912";
451 i++; ui_test[i].num = 0x000C0000U; ui_test[i].expected = "786432";
452 i++; ui_test[i].num = 0x0000C000U; ui_test[i].expected = "49152";
453 i++; ui_test[i].num = 0x00000C00U; ui_test[i].expected = "3072";
454 i++; ui_test[i].num = 0x000000C0U; ui_test[i].expected = "192";
455 i++; ui_test[i].num = 0x0000000CU; ui_test[i].expected = "12";
456
457 i++; ui_test[i].num = 0x00000001U; ui_test[i].expected = "1";
458 i++; ui_test[i].num = 0x00000000U; ui_test[i].expected = "0";
459
460 num_uint_tests = i;
461
462#elif (SIZEOF_INT == 8)
463
464 /* !checksrc! disable LONGLINE all */
465 i=1; ui_test[i].num = 0xFFFFFFFFFFFFFFFFU; ui_test[i].expected = "18446744073709551615";
466 i++; ui_test[i].num = 0xFFFFFFFF00000000U; ui_test[i].expected = "18446744069414584320";
467 i++; ui_test[i].num = 0x00000000FFFFFFFFU; ui_test[i].expected = "4294967295";
468
469 i++; ui_test[i].num = 0xFFFF000000000000U; ui_test[i].expected = "18446462598732840960";
470 i++; ui_test[i].num = 0x0000FFFF00000000U; ui_test[i].expected = "281470681743360";
471 i++; ui_test[i].num = 0x00000000FFFF0000U; ui_test[i].expected = "4294901760";
472 i++; ui_test[i].num = 0x000000000000FFFFU; ui_test[i].expected = "65535";
473
474 i++; ui_test[i].num = 0xFF00000000000000U; ui_test[i].expected = "18374686479671623680";
475 i++; ui_test[i].num = 0x00FF000000000000U; ui_test[i].expected = "71776119061217280";
476 i++; ui_test[i].num = 0x0000FF0000000000U; ui_test[i].expected = "280375465082880";
477 i++; ui_test[i].num = 0x000000FF00000000U; ui_test[i].expected = "1095216660480";
478 i++; ui_test[i].num = 0x00000000FF000000U; ui_test[i].expected = "4278190080";
479 i++; ui_test[i].num = 0x0000000000FF0000U; ui_test[i].expected = "16711680";
480 i++; ui_test[i].num = 0x000000000000FF00U; ui_test[i].expected = "65280";
481 i++; ui_test[i].num = 0x00000000000000FFU; ui_test[i].expected = "255";
482
483 i++; ui_test[i].num = 0xF000000000000000U; ui_test[i].expected = "17293822569102704640";
484 i++; ui_test[i].num = 0x0F00000000000000U; ui_test[i].expected = "1080863910568919040";
485 i++; ui_test[i].num = 0x00F0000000000000U; ui_test[i].expected = "67553994410557440";
486 i++; ui_test[i].num = 0x000F000000000000U; ui_test[i].expected = "4222124650659840";
487 i++; ui_test[i].num = 0x0000F00000000000U; ui_test[i].expected = "263882790666240";
488 i++; ui_test[i].num = 0x00000F0000000000U; ui_test[i].expected = "16492674416640";
489 i++; ui_test[i].num = 0x000000F000000000U; ui_test[i].expected = "1030792151040";
490 i++; ui_test[i].num = 0x0000000F00000000U; ui_test[i].expected = "64424509440";
491 i++; ui_test[i].num = 0x00000000F0000000U; ui_test[i].expected = "4026531840";
492 i++; ui_test[i].num = 0x000000000F000000U; ui_test[i].expected = "251658240";
493 i++; ui_test[i].num = 0x0000000000F00000U; ui_test[i].expected = "15728640";
494 i++; ui_test[i].num = 0x00000000000F0000U; ui_test[i].expected = "983040";
495 i++; ui_test[i].num = 0x000000000000F000U; ui_test[i].expected = "61440";
496 i++; ui_test[i].num = 0x0000000000000F00U; ui_test[i].expected = "3840";
497 i++; ui_test[i].num = 0x00000000000000F0U; ui_test[i].expected = "240";
498 i++; ui_test[i].num = 0x000000000000000FU; ui_test[i].expected = "15";
499
500 i++; ui_test[i].num = 0xC000000000000000U; ui_test[i].expected = "13835058055282163712";
501 i++; ui_test[i].num = 0x0C00000000000000U; ui_test[i].expected = "864691128455135232";
502 i++; ui_test[i].num = 0x00C0000000000000U; ui_test[i].expected = "54043195528445952";
503 i++; ui_test[i].num = 0x000C000000000000U; ui_test[i].expected = "3377699720527872";
504 i++; ui_test[i].num = 0x0000C00000000000U; ui_test[i].expected = "211106232532992";
505 i++; ui_test[i].num = 0x00000C0000000000U; ui_test[i].expected = "13194139533312";
506 i++; ui_test[i].num = 0x000000C000000000U; ui_test[i].expected = "824633720832";
507 i++; ui_test[i].num = 0x0000000C00000000U; ui_test[i].expected = "51539607552";
508 i++; ui_test[i].num = 0x00000000C0000000U; ui_test[i].expected = "3221225472";
509 i++; ui_test[i].num = 0x000000000C000000U; ui_test[i].expected = "201326592";
510 i++; ui_test[i].num = 0x0000000000C00000U; ui_test[i].expected = "12582912";
511 i++; ui_test[i].num = 0x00000000000C0000U; ui_test[i].expected = "786432";
512 i++; ui_test[i].num = 0x000000000000C000U; ui_test[i].expected = "49152";
513 i++; ui_test[i].num = 0x0000000000000C00U; ui_test[i].expected = "3072";
514 i++; ui_test[i].num = 0x00000000000000C0U; ui_test[i].expected = "192";
515 i++; ui_test[i].num = 0x000000000000000CU; ui_test[i].expected = "12";
516
517 i++; ui_test[i].num = 0x00000001U; ui_test[i].expected = "1";
518 i++; ui_test[i].num = 0x00000000U; ui_test[i].expected = "0";
519
520 num_uint_tests = i;
521
522#endif
523
524 for(i=1; i<=num_uint_tests; i++) {
525
526 for(j=0; j<BUFSZ; j++)
527 ui_test[i].result[j] = 'X';
528 ui_test[i].result[BUFSZ-1] = '\0';
529
530 (void)curl_msprintf(ui_test[i].result, "%u", ui_test[i].num);
531
532 if(memcmp(ui_test[i].result,
533 ui_test[i].expected,
534 strlen(ui_test[i].expected))) {
535 printf("unsigned int test #%.2d: Failed (Expected: %s Got: %s)\n",
536 i, ui_test[i].expected, ui_test[i].result);
537 failed++;
538 }
539
540 }
541
542 if(!failed)
543 printf("All curl_mprintf() unsigned int tests OK!\n");
544 else
545 printf("Some curl_mprintf() unsigned int tests Failed!\n");
546
547 return failed;
548}
549
550
551static int test_signed_int_formatting(void)
552{
553 int i, j;
554 int num_sint_tests;
555 int failed = 0;
556
557#if (SIZEOF_INT == 2)
558
559 i=1; si_test[i].num = 0x7FFF; si_test[i].expected = "32767";
560 i++; si_test[i].num = 0x7FFE; si_test[i].expected = "32766";
561 i++; si_test[i].num = 0x7FFD; si_test[i].expected = "32765";
562 i++; si_test[i].num = 0x7F00; si_test[i].expected = "32512";
563 i++; si_test[i].num = 0x07F0; si_test[i].expected = "2032";
564 i++; si_test[i].num = 0x007F; si_test[i].expected = "127";
565
566 i++; si_test[i].num = 0x7000; si_test[i].expected = "28672";
567 i++; si_test[i].num = 0x0700; si_test[i].expected = "1792";
568 i++; si_test[i].num = 0x0070; si_test[i].expected = "112";
569 i++; si_test[i].num = 0x0007; si_test[i].expected = "7";
570
571 i++; si_test[i].num = 0x5000; si_test[i].expected = "20480";
572 i++; si_test[i].num = 0x0500; si_test[i].expected = "1280";
573 i++; si_test[i].num = 0x0050; si_test[i].expected = "80";
574 i++; si_test[i].num = 0x0005; si_test[i].expected = "5";
575
576 i++; si_test[i].num = 0x0001; si_test[i].expected = "1";
577 i++; si_test[i].num = 0x0000; si_test[i].expected = "0";
578
579 i++; si_test[i].num = -0x7FFF -1; si_test[i].expected = "-32768";
580 i++; si_test[i].num = -0x7FFE -1; si_test[i].expected = "-32767";
581 i++; si_test[i].num = -0x7FFD -1; si_test[i].expected = "-32766";
582 i++; si_test[i].num = -0x7F00 -1; si_test[i].expected = "-32513";
583 i++; si_test[i].num = -0x07F0 -1; si_test[i].expected = "-2033";
584 i++; si_test[i].num = -0x007F -1; si_test[i].expected = "-128";
585
586 i++; si_test[i].num = -0x7000 -1; si_test[i].expected = "-28673";
587 i++; si_test[i].num = -0x0700 -1; si_test[i].expected = "-1793";
588 i++; si_test[i].num = -0x0070 -1; si_test[i].expected = "-113";
589 i++; si_test[i].num = -0x0007 -1; si_test[i].expected = "-8";
590
591 i++; si_test[i].num = -0x5000 -1; si_test[i].expected = "-20481";
592 i++; si_test[i].num = -0x0500 -1; si_test[i].expected = "-1281";
593 i++; si_test[i].num = -0x0050 -1; si_test[i].expected = "-81";
594 i++; si_test[i].num = -0x0005 -1; si_test[i].expected = "-6";
595
596 i++; si_test[i].num = 0x0000 -1; si_test[i].expected = "-1";
597
598 num_sint_tests = i;
599
600#elif (SIZEOF_INT == 4)
601
602 i=1; si_test[i].num = 0x7FFFFFFF; si_test[i].expected = "2147483647";
603 i++; si_test[i].num = 0x7FFFFFFE; si_test[i].expected = "2147483646";
604 i++; si_test[i].num = 0x7FFFFFFD; si_test[i].expected = "2147483645";
605 i++; si_test[i].num = 0x7FFF0000; si_test[i].expected = "2147418112";
606 i++; si_test[i].num = 0x00007FFF; si_test[i].expected = "32767";
607
608 i++; si_test[i].num = 0x7F000000; si_test[i].expected = "2130706432";
609 i++; si_test[i].num = 0x007F0000; si_test[i].expected = "8323072";
610 i++; si_test[i].num = 0x00007F00; si_test[i].expected = "32512";
611 i++; si_test[i].num = 0x0000007F; si_test[i].expected = "127";
612
613 i++; si_test[i].num = 0x70000000; si_test[i].expected = "1879048192";
614 i++; si_test[i].num = 0x07000000; si_test[i].expected = "117440512";
615 i++; si_test[i].num = 0x00700000; si_test[i].expected = "7340032";
616 i++; si_test[i].num = 0x00070000; si_test[i].expected = "458752";
617 i++; si_test[i].num = 0x00007000; si_test[i].expected = "28672";
618 i++; si_test[i].num = 0x00000700; si_test[i].expected = "1792";
619 i++; si_test[i].num = 0x00000070; si_test[i].expected = "112";
620 i++; si_test[i].num = 0x00000007; si_test[i].expected = "7";
621
622 i++; si_test[i].num = 0x50000000; si_test[i].expected = "1342177280";
623 i++; si_test[i].num = 0x05000000; si_test[i].expected = "83886080";
624 i++; si_test[i].num = 0x00500000; si_test[i].expected = "5242880";
625 i++; si_test[i].num = 0x00050000; si_test[i].expected = "327680";
626 i++; si_test[i].num = 0x00005000; si_test[i].expected = "20480";
627 i++; si_test[i].num = 0x00000500; si_test[i].expected = "1280";
628 i++; si_test[i].num = 0x00000050; si_test[i].expected = "80";
629 i++; si_test[i].num = 0x00000005; si_test[i].expected = "5";
630
631 i++; si_test[i].num = 0x00000001; si_test[i].expected = "1";
632 i++; si_test[i].num = 0x00000000; si_test[i].expected = "0";
633
634 i++; si_test[i].num = -0x7FFFFFFF -1; si_test[i].expected = "-2147483648";
635 i++; si_test[i].num = -0x7FFFFFFE -1; si_test[i].expected = "-2147483647";
636 i++; si_test[i].num = -0x7FFFFFFD -1; si_test[i].expected = "-2147483646";
637 i++; si_test[i].num = -0x7FFF0000 -1; si_test[i].expected = "-2147418113";
638 i++; si_test[i].num = -0x00007FFF -1; si_test[i].expected = "-32768";
639
640 i++; si_test[i].num = -0x7F000000 -1; si_test[i].expected = "-2130706433";
641 i++; si_test[i].num = -0x007F0000 -1; si_test[i].expected = "-8323073";
642 i++; si_test[i].num = -0x00007F00 -1; si_test[i].expected = "-32513";
643 i++; si_test[i].num = -0x0000007F -1; si_test[i].expected = "-128";
644
645 i++; si_test[i].num = -0x70000000 -1; si_test[i].expected = "-1879048193";
646 i++; si_test[i].num = -0x07000000 -1; si_test[i].expected = "-117440513";
647 i++; si_test[i].num = -0x00700000 -1; si_test[i].expected = "-7340033";
648 i++; si_test[i].num = -0x00070000 -1; si_test[i].expected = "-458753";
649 i++; si_test[i].num = -0x00007000 -1; si_test[i].expected = "-28673";
650 i++; si_test[i].num = -0x00000700 -1; si_test[i].expected = "-1793";
651 i++; si_test[i].num = -0x00000070 -1; si_test[i].expected = "-113";
652 i++; si_test[i].num = -0x00000007 -1; si_test[i].expected = "-8";
653
654 i++; si_test[i].num = -0x50000000 -1; si_test[i].expected = "-1342177281";
655 i++; si_test[i].num = -0x05000000 -1; si_test[i].expected = "-83886081";
656 i++; si_test[i].num = -0x00500000 -1; si_test[i].expected = "-5242881";
657 i++; si_test[i].num = -0x00050000 -1; si_test[i].expected = "-327681";
658 i++; si_test[i].num = -0x00005000 -1; si_test[i].expected = "-20481";
659 i++; si_test[i].num = -0x00000500 -1; si_test[i].expected = "-1281";
660 i++; si_test[i].num = -0x00000050 -1; si_test[i].expected = "-81";
661 i++; si_test[i].num = -0x00000005 -1; si_test[i].expected = "-6";
662
663 i++; si_test[i].num = 0x00000000 -1; si_test[i].expected = "-1";
664
665 num_sint_tests = i;
666
667#elif (SIZEOF_INT == 8)
668
669 i=1; si_test[i].num = 0x7FFFFFFFFFFFFFFF; si_test[i].expected = "9223372036854775807";
670 i++; si_test[i].num = 0x7FFFFFFFFFFFFFFE; si_test[i].expected = "9223372036854775806";
671 i++; si_test[i].num = 0x7FFFFFFFFFFFFFFD; si_test[i].expected = "9223372036854775805";
672 i++; si_test[i].num = 0x7FFFFFFF00000000; si_test[i].expected = "9223372032559808512";
673 i++; si_test[i].num = 0x000000007FFFFFFF; si_test[i].expected = "2147483647";
674
675 i++; si_test[i].num = 0x7FFF000000000000; si_test[i].expected = "9223090561878065152";
676 i++; si_test[i].num = 0x00007FFF00000000; si_test[i].expected = "140733193388032";
677 i++; si_test[i].num = 0x000000007FFF0000; si_test[i].expected = "2147418112";
678 i++; si_test[i].num = 0x0000000000007FFF; si_test[i].expected = "32767";
679
680 i++; si_test[i].num = 0x7F00000000000000; si_test[i].expected = "9151314442816847872";
681 i++; si_test[i].num = 0x007F000000000000; si_test[i].expected = "35747322042253312";
682 i++; si_test[i].num = 0x00007F0000000000; si_test[i].expected = "139637976727552";
683 i++; si_test[i].num = 0x0000007F00000000; si_test[i].expected = "545460846592";
684 i++; si_test[i].num = 0x000000007F000000; si_test[i].expected = "2130706432";
685 i++; si_test[i].num = 0x00000000007F0000; si_test[i].expected = "8323072";
686 i++; si_test[i].num = 0x0000000000007F00; si_test[i].expected = "32512";
687 i++; si_test[i].num = 0x000000000000007F; si_test[i].expected = "127";
688
689 i++; si_test[i].num = 0x7000000000000000; si_test[i].expected = "8070450532247928832";
690 i++; si_test[i].num = 0x0700000000000000; si_test[i].expected = "504403158265495552";
691 i++; si_test[i].num = 0x0070000000000000; si_test[i].expected = "31525197391593472";
692 i++; si_test[i].num = 0x0007000000000000; si_test[i].expected = "1970324836974592";
693 i++; si_test[i].num = 0x0000700000000000; si_test[i].expected = "123145302310912";
694 i++; si_test[i].num = 0x0000070000000000; si_test[i].expected = "7696581394432";
695 i++; si_test[i].num = 0x0000007000000000; si_test[i].expected = "481036337152";
696 i++; si_test[i].num = 0x0000000700000000; si_test[i].expected = "30064771072";
697 i++; si_test[i].num = 0x0000000070000000; si_test[i].expected = "1879048192";
698 i++; si_test[i].num = 0x0000000007000000; si_test[i].expected = "117440512";
699 i++; si_test[i].num = 0x0000000000700000; si_test[i].expected = "7340032";
700 i++; si_test[i].num = 0x0000000000070000; si_test[i].expected = "458752";
701 i++; si_test[i].num = 0x0000000000007000; si_test[i].expected = "28672";
702 i++; si_test[i].num = 0x0000000000000700; si_test[i].expected = "1792";
703 i++; si_test[i].num = 0x0000000000000070; si_test[i].expected = "112";
704 i++; si_test[i].num = 0x0000000000000007; si_test[i].expected = "7";
705
706 i++; si_test[i].num = 0x0000000000000001; si_test[i].expected = "1";
707 i++; si_test[i].num = 0x0000000000000000; si_test[i].expected = "0";
708
709 i++; si_test[i].num = -0x7FFFFFFFFFFFFFFF -1; si_test[i].expected = "-9223372036854775808";
710 i++; si_test[i].num = -0x7FFFFFFFFFFFFFFE -1; si_test[i].expected = "-9223372036854775807";
711 i++; si_test[i].num = -0x7FFFFFFFFFFFFFFD -1; si_test[i].expected = "-9223372036854775806";
712 i++; si_test[i].num = -0x7FFFFFFF00000000 -1; si_test[i].expected = "-9223372032559808513";
713 i++; si_test[i].num = -0x000000007FFFFFFF -1; si_test[i].expected = "-2147483648";
714
715 i++; si_test[i].num = -0x7FFF000000000000 -1; si_test[i].expected = "-9223090561878065153";
716 i++; si_test[i].num = -0x00007FFF00000000 -1; si_test[i].expected = "-140733193388033";
717 i++; si_test[i].num = -0x000000007FFF0000 -1; si_test[i].expected = "-2147418113";
718 i++; si_test[i].num = -0x0000000000007FFF -1; si_test[i].expected = "-32768";
719
720 i++; si_test[i].num = -0x7F00000000000000 -1; si_test[i].expected = "-9151314442816847873";
721 i++; si_test[i].num = -0x007F000000000000 -1; si_test[i].expected = "-35747322042253313";
722 i++; si_test[i].num = -0x00007F0000000000 -1; si_test[i].expected = "-139637976727553";
723 i++; si_test[i].num = -0x0000007F00000000 -1; si_test[i].expected = "-545460846593";
724 i++; si_test[i].num = -0x000000007F000000 -1; si_test[i].expected = "-2130706433";
725 i++; si_test[i].num = -0x00000000007F0000 -1; si_test[i].expected = "-8323073";
726 i++; si_test[i].num = -0x0000000000007F00 -1; si_test[i].expected = "-32513";
727 i++; si_test[i].num = -0x000000000000007F -1; si_test[i].expected = "-128";
728
729 i++; si_test[i].num = -0x7000000000000000 -1; si_test[i].expected = "-8070450532247928833";
730 i++; si_test[i].num = -0x0700000000000000 -1; si_test[i].expected = "-504403158265495553";
731 i++; si_test[i].num = -0x0070000000000000 -1; si_test[i].expected = "-31525197391593473";
732 i++; si_test[i].num = -0x0007000000000000 -1; si_test[i].expected = "-1970324836974593";
733 i++; si_test[i].num = -0x0000700000000000 -1; si_test[i].expected = "-123145302310913";
734 i++; si_test[i].num = -0x0000070000000000 -1; si_test[i].expected = "-7696581394433";
735 i++; si_test[i].num = -0x0000007000000000 -1; si_test[i].expected = "-481036337153";
736 i++; si_test[i].num = -0x0000000700000000 -1; si_test[i].expected = "-30064771073";
737 i++; si_test[i].num = -0x0000000070000000 -1; si_test[i].expected = "-1879048193";
738 i++; si_test[i].num = -0x0000000007000000 -1; si_test[i].expected = "-117440513";
739 i++; si_test[i].num = -0x0000000000700000 -1; si_test[i].expected = "-7340033";
740 i++; si_test[i].num = -0x0000000000070000 -1; si_test[i].expected = "-458753";
741 i++; si_test[i].num = -0x0000000000007000 -1; si_test[i].expected = "-28673";
742 i++; si_test[i].num = -0x0000000000000700 -1; si_test[i].expected = "-1793";
743 i++; si_test[i].num = -0x0000000000000070 -1; si_test[i].expected = "-113";
744 i++; si_test[i].num = -0x0000000000000007 -1; si_test[i].expected = "-8";
745
746 i++; si_test[i].num = 0x0000000000000000 -1; si_test[i].expected = "-1";
747
748 num_sint_tests = i;
749
750#endif
751
752 for(i=1; i<=num_sint_tests; i++) {
753
754 for(j=0; j<BUFSZ; j++)
755 si_test[i].result[j] = 'X';
756 si_test[i].result[BUFSZ-1] = '\0';
757
758 (void)curl_msprintf(si_test[i].result, "%d", si_test[i].num);
759
760 if(memcmp(si_test[i].result,
761 si_test[i].expected,
762 strlen(si_test[i].expected))) {
763 printf("signed int test #%.2d: Failed (Expected: %s Got: %s)\n",
764 i, si_test[i].expected, si_test[i].result);
765 failed++;
766 }
767
768 }
769
770 if(!failed)
771 printf("All curl_mprintf() signed int tests OK!\n");
772 else
773 printf("Some curl_mprintf() signed int tests Failed!\n");
774
775 return failed;
776}
777
778
779static int test_unsigned_long_formatting(void)
780{
781 int i, j;
782 int num_ulong_tests;
783 int failed = 0;
784
785#if (CURL_SIZEOF_LONG == 2)
786
787 i=1; ul_test[i].num = 0xFFFFUL; ul_test[i].expected = "65535";
788 i++; ul_test[i].num = 0xFF00UL; ul_test[i].expected = "65280";
789 i++; ul_test[i].num = 0x00FFUL; ul_test[i].expected = "255";
790
791 i++; ul_test[i].num = 0xF000UL; ul_test[i].expected = "61440";
792 i++; ul_test[i].num = 0x0F00UL; ul_test[i].expected = "3840";
793 i++; ul_test[i].num = 0x00F0UL; ul_test[i].expected = "240";
794 i++; ul_test[i].num = 0x000FUL; ul_test[i].expected = "15";
795
796 i++; ul_test[i].num = 0xC000UL; ul_test[i].expected = "49152";
797 i++; ul_test[i].num = 0x0C00UL; ul_test[i].expected = "3072";
798 i++; ul_test[i].num = 0x00C0UL; ul_test[i].expected = "192";
799 i++; ul_test[i].num = 0x000CUL; ul_test[i].expected = "12";
800
801 i++; ul_test[i].num = 0x0001UL; ul_test[i].expected = "1";
802 i++; ul_test[i].num = 0x0000UL; ul_test[i].expected = "0";
803
804 num_ulong_tests = i;
805
806#elif (CURL_SIZEOF_LONG == 4)
807
808 i=1; ul_test[i].num = 0xFFFFFFFFUL; ul_test[i].expected = "4294967295";
809 i++; ul_test[i].num = 0xFFFF0000UL; ul_test[i].expected = "4294901760";
810 i++; ul_test[i].num = 0x0000FFFFUL; ul_test[i].expected = "65535";
811
812 i++; ul_test[i].num = 0xFF000000UL; ul_test[i].expected = "4278190080";
813 i++; ul_test[i].num = 0x00FF0000UL; ul_test[i].expected = "16711680";
814 i++; ul_test[i].num = 0x0000FF00UL; ul_test[i].expected = "65280";
815 i++; ul_test[i].num = 0x000000FFUL; ul_test[i].expected = "255";
816
817 i++; ul_test[i].num = 0xF0000000UL; ul_test[i].expected = "4026531840";
818 i++; ul_test[i].num = 0x0F000000UL; ul_test[i].expected = "251658240";
819 i++; ul_test[i].num = 0x00F00000UL; ul_test[i].expected = "15728640";
820 i++; ul_test[i].num = 0x000F0000UL; ul_test[i].expected = "983040";
821 i++; ul_test[i].num = 0x0000F000UL; ul_test[i].expected = "61440";
822 i++; ul_test[i].num = 0x00000F00UL; ul_test[i].expected = "3840";
823 i++; ul_test[i].num = 0x000000F0UL; ul_test[i].expected = "240";
824 i++; ul_test[i].num = 0x0000000FUL; ul_test[i].expected = "15";
825
826 i++; ul_test[i].num = 0xC0000000UL; ul_test[i].expected = "3221225472";
827 i++; ul_test[i].num = 0x0C000000UL; ul_test[i].expected = "201326592";
828 i++; ul_test[i].num = 0x00C00000UL; ul_test[i].expected = "12582912";
829 i++; ul_test[i].num = 0x000C0000UL; ul_test[i].expected = "786432";
830 i++; ul_test[i].num = 0x0000C000UL; ul_test[i].expected = "49152";
831 i++; ul_test[i].num = 0x00000C00UL; ul_test[i].expected = "3072";
832 i++; ul_test[i].num = 0x000000C0UL; ul_test[i].expected = "192";
833 i++; ul_test[i].num = 0x0000000CUL; ul_test[i].expected = "12";
834
835 i++; ul_test[i].num = 0x00000001UL; ul_test[i].expected = "1";
836 i++; ul_test[i].num = 0x00000000UL; ul_test[i].expected = "0";
837
838 num_ulong_tests = i;
839
840#elif (CURL_SIZEOF_LONG == 8)
841
842 i=1; ul_test[i].num = 0xFFFFFFFFFFFFFFFFUL; ul_test[i].expected = "18446744073709551615";
843 i++; ul_test[i].num = 0xFFFFFFFF00000000UL; ul_test[i].expected = "18446744069414584320";
844 i++; ul_test[i].num = 0x00000000FFFFFFFFUL; ul_test[i].expected = "4294967295";
845
846 i++; ul_test[i].num = 0xFFFF000000000000UL; ul_test[i].expected = "18446462598732840960";
847 i++; ul_test[i].num = 0x0000FFFF00000000UL; ul_test[i].expected = "281470681743360";
848 i++; ul_test[i].num = 0x00000000FFFF0000UL; ul_test[i].expected = "4294901760";
849 i++; ul_test[i].num = 0x000000000000FFFFUL; ul_test[i].expected = "65535";
850
851 i++; ul_test[i].num = 0xFF00000000000000UL; ul_test[i].expected = "18374686479671623680";
852 i++; ul_test[i].num = 0x00FF000000000000UL; ul_test[i].expected = "71776119061217280";
853 i++; ul_test[i].num = 0x0000FF0000000000UL; ul_test[i].expected = "280375465082880";
854 i++; ul_test[i].num = 0x000000FF00000000UL; ul_test[i].expected = "1095216660480";
855 i++; ul_test[i].num = 0x00000000FF000000UL; ul_test[i].expected = "4278190080";
856 i++; ul_test[i].num = 0x0000000000FF0000UL; ul_test[i].expected = "16711680";
857 i++; ul_test[i].num = 0x000000000000FF00UL; ul_test[i].expected = "65280";
858 i++; ul_test[i].num = 0x00000000000000FFUL; ul_test[i].expected = "255";
859
860 i++; ul_test[i].num = 0xF000000000000000UL; ul_test[i].expected = "17293822569102704640";
861 i++; ul_test[i].num = 0x0F00000000000000UL; ul_test[i].expected = "1080863910568919040";
862 i++; ul_test[i].num = 0x00F0000000000000UL; ul_test[i].expected = "67553994410557440";
863 i++; ul_test[i].num = 0x000F000000000000UL; ul_test[i].expected = "4222124650659840";
864 i++; ul_test[i].num = 0x0000F00000000000UL; ul_test[i].expected = "263882790666240";
865 i++; ul_test[i].num = 0x00000F0000000000UL; ul_test[i].expected = "16492674416640";
866 i++; ul_test[i].num = 0x000000F000000000UL; ul_test[i].expected = "1030792151040";
867 i++; ul_test[i].num = 0x0000000F00000000UL; ul_test[i].expected = "64424509440";
868 i++; ul_test[i].num = 0x00000000F0000000UL; ul_test[i].expected = "4026531840";
869 i++; ul_test[i].num = 0x000000000F000000UL; ul_test[i].expected = "251658240";
870 i++; ul_test[i].num = 0x0000000000F00000UL; ul_test[i].expected = "15728640";
871 i++; ul_test[i].num = 0x00000000000F0000UL; ul_test[i].expected = "983040";
872 i++; ul_test[i].num = 0x000000000000F000UL; ul_test[i].expected = "61440";
873 i++; ul_test[i].num = 0x0000000000000F00UL; ul_test[i].expected = "3840";
874 i++; ul_test[i].num = 0x00000000000000F0UL; ul_test[i].expected = "240";
875 i++; ul_test[i].num = 0x000000000000000FUL; ul_test[i].expected = "15";
876
877 i++; ul_test[i].num = 0xC000000000000000UL; ul_test[i].expected = "13835058055282163712";
878 i++; ul_test[i].num = 0x0C00000000000000UL; ul_test[i].expected = "864691128455135232";
879 i++; ul_test[i].num = 0x00C0000000000000UL; ul_test[i].expected = "54043195528445952";
880 i++; ul_test[i].num = 0x000C000000000000UL; ul_test[i].expected = "3377699720527872";
881 i++; ul_test[i].num = 0x0000C00000000000UL; ul_test[i].expected = "211106232532992";
882 i++; ul_test[i].num = 0x00000C0000000000UL; ul_test[i].expected = "13194139533312";
883 i++; ul_test[i].num = 0x000000C000000000UL; ul_test[i].expected = "824633720832";
884 i++; ul_test[i].num = 0x0000000C00000000UL; ul_test[i].expected = "51539607552";
885 i++; ul_test[i].num = 0x00000000C0000000UL; ul_test[i].expected = "3221225472";
886 i++; ul_test[i].num = 0x000000000C000000UL; ul_test[i].expected = "201326592";
887 i++; ul_test[i].num = 0x0000000000C00000UL; ul_test[i].expected = "12582912";
888 i++; ul_test[i].num = 0x00000000000C0000UL; ul_test[i].expected = "786432";
889 i++; ul_test[i].num = 0x000000000000C000UL; ul_test[i].expected = "49152";
890 i++; ul_test[i].num = 0x0000000000000C00UL; ul_test[i].expected = "3072";
891 i++; ul_test[i].num = 0x00000000000000C0UL; ul_test[i].expected = "192";
892 i++; ul_test[i].num = 0x000000000000000CUL; ul_test[i].expected = "12";
893
894 i++; ul_test[i].num = 0x00000001UL; ul_test[i].expected = "1";
895 i++; ul_test[i].num = 0x00000000UL; ul_test[i].expected = "0";
896
897 num_ulong_tests = i;
898
899#endif
900
901 for(i=1; i<=num_ulong_tests; i++) {
902
903 for(j=0; j<BUFSZ; j++)
904 ul_test[i].result[j] = 'X';
905 ul_test[i].result[BUFSZ-1] = '\0';
906
907 (void)curl_msprintf(ul_test[i].result, "%lu", ul_test[i].num);
908
909 if(memcmp(ul_test[i].result,
910 ul_test[i].expected,
911 strlen(ul_test[i].expected))) {
912 printf("unsigned long test #%.2d: Failed (Expected: %s Got: %s)\n",
913 i, ul_test[i].expected, ul_test[i].result);
914 failed++;
915 }
916
917 }
918
919 if(!failed)
920 printf("All curl_mprintf() unsigned long tests OK!\n");
921 else
922 printf("Some curl_mprintf() unsigned long tests Failed!\n");
923
924 return failed;
925}
926
927
928static int test_signed_long_formatting(void)
929{
930 int i, j;
931 int num_slong_tests;
932 int failed = 0;
933
934#if (CURL_SIZEOF_LONG == 2)
935
936 i=1; sl_test[i].num = 0x7FFFL; sl_test[i].expected = "32767";
937 i++; sl_test[i].num = 0x7FFEL; sl_test[i].expected = "32766";
938 i++; sl_test[i].num = 0x7FFDL; sl_test[i].expected = "32765";
939 i++; sl_test[i].num = 0x7F00L; sl_test[i].expected = "32512";
940 i++; sl_test[i].num = 0x07F0L; sl_test[i].expected = "2032";
941 i++; sl_test[i].num = 0x007FL; sl_test[i].expected = "127";
942
943 i++; sl_test[i].num = 0x7000L; sl_test[i].expected = "28672";
944 i++; sl_test[i].num = 0x0700L; sl_test[i].expected = "1792";
945 i++; sl_test[i].num = 0x0070L; sl_test[i].expected = "112";
946 i++; sl_test[i].num = 0x0007L; sl_test[i].expected = "7";
947
948 i++; sl_test[i].num = 0x5000L; sl_test[i].expected = "20480";
949 i++; sl_test[i].num = 0x0500L; sl_test[i].expected = "1280";
950 i++; sl_test[i].num = 0x0050L; sl_test[i].expected = "80";
951 i++; sl_test[i].num = 0x0005L; sl_test[i].expected = "5";
952
953 i++; sl_test[i].num = 0x0001L; sl_test[i].expected = "1";
954 i++; sl_test[i].num = 0x0000L; sl_test[i].expected = "0";
955
956 i++; sl_test[i].num = -0x7FFFL -1L; sl_test[i].expected = "-32768";
957 i++; sl_test[i].num = -0x7FFEL -1L; sl_test[i].expected = "-32767";
958 i++; sl_test[i].num = -0x7FFDL -1L; sl_test[i].expected = "-32766";
959 i++; sl_test[i].num = -0x7F00L -1L; sl_test[i].expected = "-32513";
960 i++; sl_test[i].num = -0x07F0L -1L; sl_test[i].expected = "-2033";
961 i++; sl_test[i].num = -0x007FL -1L; sl_test[i].expected = "-128";
962
963 i++; sl_test[i].num = -0x7000L -1L; sl_test[i].expected = "-28673";
964 i++; sl_test[i].num = -0x0700L -1L; sl_test[i].expected = "-1793";
965 i++; sl_test[i].num = -0x0070L -1L; sl_test[i].expected = "-113";
966 i++; sl_test[i].num = -0x0007L -1L; sl_test[i].expected = "-8";
967
968 i++; sl_test[i].num = -0x5000L -1L; sl_test[i].expected = "-20481";
969 i++; sl_test[i].num = -0x0500L -1L; sl_test[i].expected = "-1281";
970 i++; sl_test[i].num = -0x0050L -1L; sl_test[i].expected = "-81";
971 i++; sl_test[i].num = -0x0005L -1L; sl_test[i].expected = "-6";
972
973 i++; sl_test[i].num = 0x0000L -1L; sl_test[i].expected = "-1";
974
975 num_slong_tests = i;
976
977#elif (CURL_SIZEOF_LONG == 4)
978
979 i=1; sl_test[i].num = 0x7FFFFFFFL; sl_test[i].expected = "2147483647";
980 i++; sl_test[i].num = 0x7FFFFFFEL; sl_test[i].expected = "2147483646";
981 i++; sl_test[i].num = 0x7FFFFFFDL; sl_test[i].expected = "2147483645";
982 i++; sl_test[i].num = 0x7FFF0000L; sl_test[i].expected = "2147418112";
983 i++; sl_test[i].num = 0x00007FFFL; sl_test[i].expected = "32767";
984
985 i++; sl_test[i].num = 0x7F000000L; sl_test[i].expected = "2130706432";
986 i++; sl_test[i].num = 0x007F0000L; sl_test[i].expected = "8323072";
987 i++; sl_test[i].num = 0x00007F00L; sl_test[i].expected = "32512";
988 i++; sl_test[i].num = 0x0000007FL; sl_test[i].expected = "127";
989
990 i++; sl_test[i].num = 0x70000000L; sl_test[i].expected = "1879048192";
991 i++; sl_test[i].num = 0x07000000L; sl_test[i].expected = "117440512";
992 i++; sl_test[i].num = 0x00700000L; sl_test[i].expected = "7340032";
993 i++; sl_test[i].num = 0x00070000L; sl_test[i].expected = "458752";
994 i++; sl_test[i].num = 0x00007000L; sl_test[i].expected = "28672";
995 i++; sl_test[i].num = 0x00000700L; sl_test[i].expected = "1792";
996 i++; sl_test[i].num = 0x00000070L; sl_test[i].expected = "112";
997 i++; sl_test[i].num = 0x00000007L; sl_test[i].expected = "7";
998
999 i++; sl_test[i].num = 0x50000000L; sl_test[i].expected = "1342177280";
1000 i++; sl_test[i].num = 0x05000000L; sl_test[i].expected = "83886080";
1001 i++; sl_test[i].num = 0x00500000L; sl_test[i].expected = "5242880";
1002 i++; sl_test[i].num = 0x00050000L; sl_test[i].expected = "327680";
1003 i++; sl_test[i].num = 0x00005000L; sl_test[i].expected = "20480";
1004 i++; sl_test[i].num = 0x00000500L; sl_test[i].expected = "1280";
1005 i++; sl_test[i].num = 0x00000050L; sl_test[i].expected = "80";
1006 i++; sl_test[i].num = 0x00000005L; sl_test[i].expected = "5";
1007
1008 i++; sl_test[i].num = 0x00000001L; sl_test[i].expected = "1";
1009 i++; sl_test[i].num = 0x00000000L; sl_test[i].expected = "0";
1010
1011 i++; sl_test[i].num = -0x7FFFFFFFL -1L; sl_test[i].expected = "-2147483648";
1012 i++; sl_test[i].num = -0x7FFFFFFEL -1L; sl_test[i].expected = "-2147483647";
1013 i++; sl_test[i].num = -0x7FFFFFFDL -1L; sl_test[i].expected = "-2147483646";
1014 i++; sl_test[i].num = -0x7FFF0000L -1L; sl_test[i].expected = "-2147418113";
1015 i++; sl_test[i].num = -0x00007FFFL -1L; sl_test[i].expected = "-32768";
1016
1017 i++; sl_test[i].num = -0x7F000000L -1L; sl_test[i].expected = "-2130706433";
1018 i++; sl_test[i].num = -0x007F0000L -1L; sl_test[i].expected = "-8323073";
1019 i++; sl_test[i].num = -0x00007F00L -1L; sl_test[i].expected = "-32513";
1020 i++; sl_test[i].num = -0x0000007FL -1L; sl_test[i].expected = "-128";
1021
1022 i++; sl_test[i].num = -0x70000000L -1L; sl_test[i].expected = "-1879048193";
1023 i++; sl_test[i].num = -0x07000000L -1L; sl_test[i].expected = "-117440513";
1024 i++; sl_test[i].num = -0x00700000L -1L; sl_test[i].expected = "-7340033";
1025 i++; sl_test[i].num = -0x00070000L -1L; sl_test[i].expected = "-458753";
1026 i++; sl_test[i].num = -0x00007000L -1L; sl_test[i].expected = "-28673";
1027 i++; sl_test[i].num = -0x00000700L -1L; sl_test[i].expected = "-1793";
1028 i++; sl_test[i].num = -0x00000070L -1L; sl_test[i].expected = "-113";
1029 i++; sl_test[i].num = -0x00000007L -1L; sl_test[i].expected = "-8";
1030
1031 i++; sl_test[i].num = -0x50000000L -1L; sl_test[i].expected = "-1342177281";
1032 i++; sl_test[i].num = -0x05000000L -1L; sl_test[i].expected = "-83886081";
1033 i++; sl_test[i].num = -0x00500000L -1L; sl_test[i].expected = "-5242881";
1034 i++; sl_test[i].num = -0x00050000L -1L; sl_test[i].expected = "-327681";
1035 i++; sl_test[i].num = -0x00005000L -1L; sl_test[i].expected = "-20481";
1036 i++; sl_test[i].num = -0x00000500L -1L; sl_test[i].expected = "-1281";
1037 i++; sl_test[i].num = -0x00000050L -1L; sl_test[i].expected = "-81";
1038 i++; sl_test[i].num = -0x00000005L -1L; sl_test[i].expected = "-6";
1039
1040 i++; sl_test[i].num = 0x00000000L -1L; sl_test[i].expected = "-1";
1041
1042 num_slong_tests = i;
1043
1044#elif (CURL_SIZEOF_LONG == 8)
1045
1046 i=1; sl_test[i].num = 0x7FFFFFFFFFFFFFFFL; sl_test[i].expected = "9223372036854775807";
1047 i++; sl_test[i].num = 0x7FFFFFFFFFFFFFFEL; sl_test[i].expected = "9223372036854775806";
1048 i++; sl_test[i].num = 0x7FFFFFFFFFFFFFFDL; sl_test[i].expected = "9223372036854775805";
1049 i++; sl_test[i].num = 0x7FFFFFFF00000000L; sl_test[i].expected = "9223372032559808512";
1050 i++; sl_test[i].num = 0x000000007FFFFFFFL; sl_test[i].expected = "2147483647";
1051
1052 i++; sl_test[i].num = 0x7FFF000000000000L; sl_test[i].expected = "9223090561878065152";
1053 i++; sl_test[i].num = 0x00007FFF00000000L; sl_test[i].expected = "140733193388032";
1054 i++; sl_test[i].num = 0x000000007FFF0000L; sl_test[i].expected = "2147418112";
1055 i++; sl_test[i].num = 0x0000000000007FFFL; sl_test[i].expected = "32767";
1056
1057 i++; sl_test[i].num = 0x7F00000000000000L; sl_test[i].expected = "9151314442816847872";
1058 i++; sl_test[i].num = 0x007F000000000000L; sl_test[i].expected = "35747322042253312";
1059 i++; sl_test[i].num = 0x00007F0000000000L; sl_test[i].expected = "139637976727552";
1060 i++; sl_test[i].num = 0x0000007F00000000L; sl_test[i].expected = "545460846592";
1061 i++; sl_test[i].num = 0x000000007F000000L; sl_test[i].expected = "2130706432";
1062 i++; sl_test[i].num = 0x00000000007F0000L; sl_test[i].expected = "8323072";
1063 i++; sl_test[i].num = 0x0000000000007F00L; sl_test[i].expected = "32512";
1064 i++; sl_test[i].num = 0x000000000000007FL; sl_test[i].expected = "127";
1065
1066 i++; sl_test[i].num = 0x7000000000000000L; sl_test[i].expected = "8070450532247928832";
1067 i++; sl_test[i].num = 0x0700000000000000L; sl_test[i].expected = "504403158265495552";
1068 i++; sl_test[i].num = 0x0070000000000000L; sl_test[i].expected = "31525197391593472";
1069 i++; sl_test[i].num = 0x0007000000000000L; sl_test[i].expected = "1970324836974592";
1070 i++; sl_test[i].num = 0x0000700000000000L; sl_test[i].expected = "123145302310912";
1071 i++; sl_test[i].num = 0x0000070000000000L; sl_test[i].expected = "7696581394432";
1072 i++; sl_test[i].num = 0x0000007000000000L; sl_test[i].expected = "481036337152";
1073 i++; sl_test[i].num = 0x0000000700000000L; sl_test[i].expected = "30064771072";
1074 i++; sl_test[i].num = 0x0000000070000000L; sl_test[i].expected = "1879048192";
1075 i++; sl_test[i].num = 0x0000000007000000L; sl_test[i].expected = "117440512";
1076 i++; sl_test[i].num = 0x0000000000700000L; sl_test[i].expected = "7340032";
1077 i++; sl_test[i].num = 0x0000000000070000L; sl_test[i].expected = "458752";
1078 i++; sl_test[i].num = 0x0000000000007000L; sl_test[i].expected = "28672";
1079 i++; sl_test[i].num = 0x0000000000000700L; sl_test[i].expected = "1792";
1080 i++; sl_test[i].num = 0x0000000000000070L; sl_test[i].expected = "112";
1081 i++; sl_test[i].num = 0x0000000000000007L; sl_test[i].expected = "7";
1082
1083 i++; sl_test[i].num = 0x0000000000000001L; sl_test[i].expected = "1";
1084 i++; sl_test[i].num = 0x0000000000000000L; sl_test[i].expected = "0";
1085
1086 i++; sl_test[i].num = -0x7FFFFFFFFFFFFFFFL -1L; sl_test[i].expected = "-9223372036854775808";
1087 i++; sl_test[i].num = -0x7FFFFFFFFFFFFFFEL -1L; sl_test[i].expected = "-9223372036854775807";
1088 i++; sl_test[i].num = -0x7FFFFFFFFFFFFFFDL -1L; sl_test[i].expected = "-9223372036854775806";
1089 i++; sl_test[i].num = -0x7FFFFFFF00000000L -1L; sl_test[i].expected = "-9223372032559808513";
1090 i++; sl_test[i].num = -0x000000007FFFFFFFL -1L; sl_test[i].expected = "-2147483648";
1091
1092 i++; sl_test[i].num = -0x7FFF000000000000L -1L; sl_test[i].expected = "-9223090561878065153";
1093 i++; sl_test[i].num = -0x00007FFF00000000L -1L; sl_test[i].expected = "-140733193388033";
1094 i++; sl_test[i].num = -0x000000007FFF0000L -1L; sl_test[i].expected = "-2147418113";
1095 i++; sl_test[i].num = -0x0000000000007FFFL -1L; sl_test[i].expected = "-32768";
1096
1097 i++; sl_test[i].num = -0x7F00000000000000L -1L; sl_test[i].expected = "-9151314442816847873";
1098 i++; sl_test[i].num = -0x007F000000000000L -1L; sl_test[i].expected = "-35747322042253313";
1099 i++; sl_test[i].num = -0x00007F0000000000L -1L; sl_test[i].expected = "-139637976727553";
1100 i++; sl_test[i].num = -0x0000007F00000000L -1L; sl_test[i].expected = "-545460846593";
1101 i++; sl_test[i].num = -0x000000007F000000L -1L; sl_test[i].expected = "-2130706433";
1102 i++; sl_test[i].num = -0x00000000007F0000L -1L; sl_test[i].expected = "-8323073";
1103 i++; sl_test[i].num = -0x0000000000007F00L -1L; sl_test[i].expected = "-32513";
1104 i++; sl_test[i].num = -0x000000000000007FL -1L; sl_test[i].expected = "-128";
1105
1106 i++; sl_test[i].num = -0x7000000000000000L -1L; sl_test[i].expected = "-8070450532247928833";
1107 i++; sl_test[i].num = -0x0700000000000000L -1L; sl_test[i].expected = "-504403158265495553";
1108 i++; sl_test[i].num = -0x0070000000000000L -1L; sl_test[i].expected = "-31525197391593473";
1109 i++; sl_test[i].num = -0x0007000000000000L -1L; sl_test[i].expected = "-1970324836974593";
1110 i++; sl_test[i].num = -0x0000700000000000L -1L; sl_test[i].expected = "-123145302310913";
1111 i++; sl_test[i].num = -0x0000070000000000L -1L; sl_test[i].expected = "-7696581394433";
1112 i++; sl_test[i].num = -0x0000007000000000L -1L; sl_test[i].expected = "-481036337153";
1113 i++; sl_test[i].num = -0x0000000700000000L -1L; sl_test[i].expected = "-30064771073";
1114 i++; sl_test[i].num = -0x0000000070000000L -1L; sl_test[i].expected = "-1879048193";
1115 i++; sl_test[i].num = -0x0000000007000000L -1L; sl_test[i].expected = "-117440513";
1116 i++; sl_test[i].num = -0x0000000000700000L -1L; sl_test[i].expected = "-7340033";
1117 i++; sl_test[i].num = -0x0000000000070000L -1L; sl_test[i].expected = "-458753";
1118 i++; sl_test[i].num = -0x0000000000007000L -1L; sl_test[i].expected = "-28673";
1119 i++; sl_test[i].num = -0x0000000000000700L -1L; sl_test[i].expected = "-1793";
1120 i++; sl_test[i].num = -0x0000000000000070L -1L; sl_test[i].expected = "-113";
1121 i++; sl_test[i].num = -0x0000000000000007L -1L; sl_test[i].expected = "-8";
1122
1123 i++; sl_test[i].num = 0x0000000000000000L -1L; sl_test[i].expected = "-1";
1124
1125 num_slong_tests = i;
1126
1127#endif
1128
1129 for(i=1; i<=num_slong_tests; i++) {
1130
1131 for(j=0; j<BUFSZ; j++)
1132 sl_test[i].result[j] = 'X';
1133 sl_test[i].result[BUFSZ-1] = '\0';
1134
1135 (void)curl_msprintf(sl_test[i].result, "%ld", sl_test[i].num);
1136
1137 if(memcmp(sl_test[i].result,
1138 sl_test[i].expected,
1139 strlen(sl_test[i].expected))) {
1140 printf("signed long test #%.2d: Failed (Expected: %s Got: %s)\n",
1141 i, sl_test[i].expected, sl_test[i].result);
1142 failed++;
1143 }
1144
1145 }
1146
1147 if(!failed)
1148 printf("All curl_mprintf() signed long tests OK!\n");
1149 else
1150 printf("Some curl_mprintf() signed long tests Failed!\n");
1151
1152 return failed;
1153}
1154
1155
1156static int test_curl_off_t_formatting(void)
1157{
1158 int i, j;
1159 int num_cofft_tests;
1160 int failed = 0;
1161
1162#if (CURL_SIZEOF_CURL_OFF_T == 2)
1163
1164 i=1; co_test[i].num = MPRNT_OFF_T_C(0x7FFF); co_test[i].expected = "32767";
1165 i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFE); co_test[i].expected = "32766";
1166 i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFD); co_test[i].expected = "32765";
1167 i++; co_test[i].num = MPRNT_OFF_T_C(0x7F00); co_test[i].expected = "32512";
1168 i++; co_test[i].num = MPRNT_OFF_T_C(0x07F0); co_test[i].expected = "2032";
1169 i++; co_test[i].num = MPRNT_OFF_T_C(0x007F); co_test[i].expected = "127";
1170
1171 i++; co_test[i].num = MPRNT_OFF_T_C(0x7000); co_test[i].expected = "28672";
1172 i++; co_test[i].num = MPRNT_OFF_T_C(0x0700); co_test[i].expected = "1792";
1173 i++; co_test[i].num = MPRNT_OFF_T_C(0x0070); co_test[i].expected = "112";
1174 i++; co_test[i].num = MPRNT_OFF_T_C(0x0007); co_test[i].expected = "7";
1175
1176 i++; co_test[i].num = MPRNT_OFF_T_C(0x5000); co_test[i].expected = "20480";
1177 i++; co_test[i].num = MPRNT_OFF_T_C(0x0500); co_test[i].expected = "1280";
1178 i++; co_test[i].num = MPRNT_OFF_T_C(0x0050); co_test[i].expected = "80";
1179 i++; co_test[i].num = MPRNT_OFF_T_C(0x0005); co_test[i].expected = "5";
1180
1181 i++; co_test[i].num = MPRNT_OFF_T_C(0x0001); co_test[i].expected = "1";
1182 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000); co_test[i].expected = "0";
1183
1184 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32768";
1185 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFE) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32767";
1186 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFD) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32766";
1187 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7F00) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32513";
1188 i++; co_test[i].num = -MPRNT_OFF_T_C(0x07F0) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2033";
1189 i++; co_test[i].num = -MPRNT_OFF_T_C(0x007F) -MPRNT_OFF_T_C(1); co_test[i].expected = "-128";
1190
1191 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-28673";
1192 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0700) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1793";
1193 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0070) -MPRNT_OFF_T_C(1); co_test[i].expected = "-113";
1194 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0007) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8";
1195
1196 i++; co_test[i].num = -MPRNT_OFF_T_C(0x5000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-20481";
1197 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0500) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1281";
1198 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0050) -MPRNT_OFF_T_C(1); co_test[i].expected = "-81";
1199 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0005) -MPRNT_OFF_T_C(1); co_test[i].expected = "-6";
1200
1201 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1";
1202
1203 num_cofft_tests = i;
1204
1205#elif (CURL_SIZEOF_CURL_OFF_T == 4)
1206
1207 i=1; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFF); co_test[i].expected = "2147483647";
1208 i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFE); co_test[i].expected = "2147483646";
1209 i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFD); co_test[i].expected = "2147483645";
1210 i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFF0000); co_test[i].expected = "2147418112";
1211 i++; co_test[i].num = MPRNT_OFF_T_C(0x00007FFF); co_test[i].expected = "32767";
1212
1213 i++; co_test[i].num = MPRNT_OFF_T_C(0x7F000000); co_test[i].expected = "2130706432";
1214 i++; co_test[i].num = MPRNT_OFF_T_C(0x007F0000); co_test[i].expected = "8323072";
1215 i++; co_test[i].num = MPRNT_OFF_T_C(0x00007F00); co_test[i].expected = "32512";
1216 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000007F); co_test[i].expected = "127";
1217
1218 i++; co_test[i].num = MPRNT_OFF_T_C(0x70000000); co_test[i].expected = "1879048192";
1219 i++; co_test[i].num = MPRNT_OFF_T_C(0x07000000); co_test[i].expected = "117440512";
1220 i++; co_test[i].num = MPRNT_OFF_T_C(0x00700000); co_test[i].expected = "7340032";
1221 i++; co_test[i].num = MPRNT_OFF_T_C(0x00070000); co_test[i].expected = "458752";
1222 i++; co_test[i].num = MPRNT_OFF_T_C(0x00007000); co_test[i].expected = "28672";
1223 i++; co_test[i].num = MPRNT_OFF_T_C(0x00000700); co_test[i].expected = "1792";
1224 i++; co_test[i].num = MPRNT_OFF_T_C(0x00000070); co_test[i].expected = "112";
1225 i++; co_test[i].num = MPRNT_OFF_T_C(0x00000007); co_test[i].expected = "7";
1226
1227 i++; co_test[i].num = MPRNT_OFF_T_C(0x50000000); co_test[i].expected = "1342177280";
1228 i++; co_test[i].num = MPRNT_OFF_T_C(0x05000000); co_test[i].expected = "83886080";
1229 i++; co_test[i].num = MPRNT_OFF_T_C(0x00500000); co_test[i].expected = "5242880";
1230 i++; co_test[i].num = MPRNT_OFF_T_C(0x00050000); co_test[i].expected = "327680";
1231 i++; co_test[i].num = MPRNT_OFF_T_C(0x00005000); co_test[i].expected = "20480";
1232 i++; co_test[i].num = MPRNT_OFF_T_C(0x00000500); co_test[i].expected = "1280";
1233 i++; co_test[i].num = MPRNT_OFF_T_C(0x00000050); co_test[i].expected = "80";
1234 i++; co_test[i].num = MPRNT_OFF_T_C(0x00000005); co_test[i].expected = "5";
1235
1236 i++; co_test[i].num = MPRNT_OFF_T_C(0x00000001); co_test[i].expected = "1";
1237 i++; co_test[i].num = MPRNT_OFF_T_C(0x00000000); co_test[i].expected = "0";
1238
1239 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147483648";
1240 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFE) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147483647";
1241 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFD) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147483646";
1242 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFF0000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147418113";
1243 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00007FFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32768";
1244
1245 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7F000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2130706433";
1246 i++; co_test[i].num = -MPRNT_OFF_T_C(0x007F0000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8323073";
1247 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00007F00) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32513";
1248 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000007F) -MPRNT_OFF_T_C(1); co_test[i].expected = "-128";
1249
1250 i++; co_test[i].num = -MPRNT_OFF_T_C(0x70000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1879048193";
1251 i++; co_test[i].num = -MPRNT_OFF_T_C(0x07000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-117440513";
1252 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00700000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-7340033";
1253 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00070000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-458753";
1254 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00007000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-28673";
1255 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000700) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1793";
1256 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000070) -MPRNT_OFF_T_C(1); co_test[i].expected = "-113";
1257 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000007) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8";
1258
1259 i++; co_test[i].num = -MPRNT_OFF_T_C(0x50000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1342177281";
1260 i++; co_test[i].num = -MPRNT_OFF_T_C(0x05000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-83886081";
1261 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00500000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-5242881";
1262 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00050000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-327681";
1263 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00005000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-20481";
1264 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000500) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1281";
1265 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000050) -MPRNT_OFF_T_C(1); co_test[i].expected = "-81";
1266 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000005) -MPRNT_OFF_T_C(1); co_test[i].expected = "-6";
1267
1268 i++; co_test[i].num = MPRNT_OFF_T_C(0x00000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1";
1269
1270 num_cofft_tests = i;
1271
1272#elif (CURL_SIZEOF_CURL_OFF_T == 8)
1273
1274 i=1; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFF); co_test[i].expected = "9223372036854775807";
1275 i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFE); co_test[i].expected = "9223372036854775806";
1276 i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFD); co_test[i].expected = "9223372036854775805";
1277 i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFF00000000); co_test[i].expected = "9223372032559808512";
1278 i++; co_test[i].num = MPRNT_OFF_T_C(0x000000007FFFFFFF); co_test[i].expected = "2147483647";
1279
1280 i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFF000000000000); co_test[i].expected = "9223090561878065152";
1281 i++; co_test[i].num = MPRNT_OFF_T_C(0x00007FFF00000000); co_test[i].expected = "140733193388032";
1282 i++; co_test[i].num = MPRNT_OFF_T_C(0x000000007FFF0000); co_test[i].expected = "2147418112";
1283 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000007FFF); co_test[i].expected = "32767";
1284
1285 i++; co_test[i].num = MPRNT_OFF_T_C(0x7F00000000000000); co_test[i].expected = "9151314442816847872";
1286 i++; co_test[i].num = MPRNT_OFF_T_C(0x007F000000000000); co_test[i].expected = "35747322042253312";
1287 i++; co_test[i].num = MPRNT_OFF_T_C(0x00007F0000000000); co_test[i].expected = "139637976727552";
1288 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000007F00000000); co_test[i].expected = "545460846592";
1289 i++; co_test[i].num = MPRNT_OFF_T_C(0x000000007F000000); co_test[i].expected = "2130706432";
1290 i++; co_test[i].num = MPRNT_OFF_T_C(0x00000000007F0000); co_test[i].expected = "8323072";
1291 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000007F00); co_test[i].expected = "32512";
1292 i++; co_test[i].num = MPRNT_OFF_T_C(0x000000000000007F); co_test[i].expected = "127";
1293
1294 i++; co_test[i].num = MPRNT_OFF_T_C(0x7000000000000000); co_test[i].expected = "8070450532247928832";
1295 i++; co_test[i].num = MPRNT_OFF_T_C(0x0700000000000000); co_test[i].expected = "504403158265495552";
1296 i++; co_test[i].num = MPRNT_OFF_T_C(0x0070000000000000); co_test[i].expected = "31525197391593472";
1297 i++; co_test[i].num = MPRNT_OFF_T_C(0x0007000000000000); co_test[i].expected = "1970324836974592";
1298 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000700000000000); co_test[i].expected = "123145302310912";
1299 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000070000000000); co_test[i].expected = "7696581394432";
1300 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000007000000000); co_test[i].expected = "481036337152";
1301 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000700000000); co_test[i].expected = "30064771072";
1302 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000070000000); co_test[i].expected = "1879048192";
1303 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000007000000); co_test[i].expected = "117440512";
1304 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000700000); co_test[i].expected = "7340032";
1305 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000070000); co_test[i].expected = "458752";
1306 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000007000); co_test[i].expected = "28672";
1307 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000000700); co_test[i].expected = "1792";
1308 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000000070); co_test[i].expected = "112";
1309 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000000007); co_test[i].expected = "7";
1310
1311 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000000001); co_test[i].expected = "1";
1312 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000000000); co_test[i].expected = "0";
1313
1314 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9223372036854775808";
1315 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFE) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9223372036854775807";
1316 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFD) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9223372036854775806";
1317 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFF00000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9223372032559808513";
1318 i++; co_test[i].num = -MPRNT_OFF_T_C(0x000000007FFFFFFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147483648";
1319
1320 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFF000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9223090561878065153";
1321 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00007FFF00000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-140733193388033";
1322 i++; co_test[i].num = -MPRNT_OFF_T_C(0x000000007FFF0000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147418113";
1323 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000007FFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32768";
1324
1325 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7F00000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9151314442816847873";
1326 i++; co_test[i].num = -MPRNT_OFF_T_C(0x007F000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-35747322042253313";
1327 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00007F0000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-139637976727553";
1328 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000007F00000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-545460846593";
1329 i++; co_test[i].num = -MPRNT_OFF_T_C(0x000000007F000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2130706433";
1330 i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000000007F0000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8323073";
1331 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000007F00) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32513";
1332 i++; co_test[i].num = -MPRNT_OFF_T_C(0x000000000000007F) -MPRNT_OFF_T_C(1); co_test[i].expected = "-128";
1333
1334 i++; co_test[i].num = -MPRNT_OFF_T_C(0x7000000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8070450532247928833";
1335 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0700000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-504403158265495553";
1336 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0070000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-31525197391593473";
1337 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0007000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1970324836974593";
1338 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000700000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-123145302310913";
1339 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000070000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-7696581394433";
1340 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000007000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-481036337153";
1341 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000700000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-30064771073";
1342 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000070000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1879048193";
1343 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000007000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-117440513";
1344 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000700000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-7340033";
1345 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000070000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-458753";
1346 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000007000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-28673";
1347 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000000700) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1793";
1348 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000000070) -MPRNT_OFF_T_C(1); co_test[i].expected = "-113";
1349 i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000000007) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8";
1350
1351 i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1";
1352
1353 num_cofft_tests = i;
1354
1355#endif
1356
1357 for(i=1; i<=num_cofft_tests; i++) {
1358
1359 for(j=0; j<BUFSZ; j++)
1360 co_test[i].result[j] = 'X';
1361 co_test[i].result[BUFSZ-1] = '\0';
1362
1363 (void)curl_msprintf(co_test[i].result, "%" CURL_FORMAT_CURL_OFF_T,
1364 co_test[i].num);
1365
1366 if(memcmp(co_test[i].result,
1367 co_test[i].expected,
1368 strlen(co_test[i].expected))) {
1369 printf("curl_off_t test #%.2d: Failed (Expected: %s Got: %s)\n",
1370 i, co_test[i].expected, co_test[i].result);
1371 failed++;
1372 }
1373
1374 }
1375
1376 if(!failed)
1377 printf("All curl_mprintf() curl_off_t tests OK!\n");
1378 else
1379 printf("Some curl_mprintf() curl_off_t tests Failed!\n");
1380
1381 return failed;
1382}
1383
1384static int _string_check(int linenumber, char *buf, const char *buf2)
1385{
1386 if(strcmp(buf, buf2)) {
1387 /* they shouldn't differ */
1388 printf("sprintf line %d failed:\nwe '%s'\nsystem: '%s'\n",
1389 linenumber, buf, buf2);
1390 return 1;
1391 }
1392 return 0;
1393}
1394#define string_check(x,y) _string_check(__LINE__, x, y)
1395
1396static int _strlen_check(int linenumber, char *buf, size_t len)
1397{
1398 size_t buflen = strlen(buf);
1399 if(len != buflen) {
1400 /* they shouldn't differ */
1401 printf("sprintf strlen:%d failed:\nwe '%d'\nsystem: '%d'\n",
1402 linenumber, buflen, len);
1403 return 1;
1404 }
1405 return 0;
1406}
1407
1408#define strlen_check(x,y) _strlen_check(__LINE__, x, y)
1409
1410/*
1411 * The output strings in this test need to have been verified with a system
1412 * sprintf() before used here.
1413 */
1414static int test_string_formatting(void)
1415{
1416 int errors = 0;
1417 char buf[256];
1418 curl_msnprintf(buf, sizeof(buf), "%0*d%s", 2, 9, "foo");
1419 errors += string_check(buf, "09foo");
1420
1421 curl_msnprintf(buf, sizeof(buf), "%*.*s", 5, 2, "foo");
1422 errors += string_check(buf, " fo");
1423
1424 curl_msnprintf(buf, sizeof(buf), "%*.*s", 2, 5, "foo");
1425 errors += string_check(buf, "foo");
1426
1427 curl_msnprintf(buf, sizeof(buf), "%*.*s", 0, 10, "foo");
1428 errors += string_check(buf, "foo");
1429
1430 curl_msnprintf(buf, sizeof(buf), "%-10s", "foo");
1431 errors += string_check(buf, "foo ");
1432
1433 curl_msnprintf(buf, sizeof(buf), "%10s", "foo");
1434 errors += string_check(buf, " foo");
1435
1436 curl_msnprintf(buf, sizeof(buf), "%*.*s", -10, -10, "foo");
1437 errors += string_check(buf, "foo ");
1438
1439 if(!errors)
1440 printf("All curl_mprintf() strings tests OK!\n");
1441 else
1442 printf("Some curl_mprintf() string tests Failed!\n");
1443
1444 return errors;
1445}
1446
1447static int test_weird_arguments(void)
1448{
1449 int errors = 0;
1450 char buf[256];
1451 int rc;
1452
1453 /* MAX_PARAMETERS is 128, try exact 128! */
1454 rc = curl_msnprintf(buf, sizeof(buf),
1455 "%d%d%d%d%d%d%d%d%d%d" /* 10 */
1456 "%d%d%d%d%d%d%d%d%d%d" /* 10 1 */
1457 "%d%d%d%d%d%d%d%d%d%d" /* 10 2 */
1458 "%d%d%d%d%d%d%d%d%d%d" /* 10 3 */
1459 "%d%d%d%d%d%d%d%d%d%d" /* 10 4 */
1460 "%d%d%d%d%d%d%d%d%d%d" /* 10 5 */
1461 "%d%d%d%d%d%d%d%d%d%d" /* 10 6 */
1462 "%d%d%d%d%d%d%d%d%d%d" /* 10 7 */
1463 "%d%d%d%d%d%d%d%d%d%d" /* 10 8 */
1464 "%d%d%d%d%d%d%d%d%d%d" /* 10 9 */
1465 "%d%d%d%d%d%d%d%d%d%d" /* 10 10 */
1466 "%d%d%d%d%d%d%d%d%d%d" /* 10 11 */
1467 "%d%d%d%d%d%d%d%d" /* 8 */
1468 ,
1469 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 */
1470 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 1 */
1471 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 2 */
1472 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 3 */
1473 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 4 */
1474 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 5 */
1475 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 6 */
1476 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 7 */
1477 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 8 */
1478 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 9 */
1479 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 10 */
1480 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 11 */
1481 0, 1, 2, 3, 4, 5, 6, 7); /* 8 */
1482
1483 if(rc != 128) {
1484 printf("curl_mprintf() returned %d and not 128!\n", rc);
1485 errors++;
1486 }
1487
1488 errors += string_check(buf,
1489 "0123456789" /* 10 */
1490 "0123456789" /* 10 1 */
1491 "0123456789" /* 10 2 */
1492 "0123456789" /* 10 3 */
1493 "0123456789" /* 10 4 */
1494 "0123456789" /* 10 5 */
1495 "0123456789" /* 10 6 */
1496 "0123456789" /* 10 7 */
1497 "0123456789" /* 10 8 */
1498 "0123456789" /* 10 9 */
1499 "0123456789" /* 10 10*/
1500 "0123456789" /* 10 11 */
1501 "01234567" /* 8 */
1502 );
1503
1504 /* MAX_PARAMETERS is 128, try more! */
1505 buf[0] = 0;
1506 rc = curl_msnprintf(buf, sizeof(buf),
1507 "%d%d%d%d%d%d%d%d%d%d" /* 10 */
1508 "%d%d%d%d%d%d%d%d%d%d" /* 10 1 */
1509 "%d%d%d%d%d%d%d%d%d%d" /* 10 2 */
1510 "%d%d%d%d%d%d%d%d%d%d" /* 10 3 */
1511 "%d%d%d%d%d%d%d%d%d%d" /* 10 4 */
1512 "%d%d%d%d%d%d%d%d%d%d" /* 10 5 */
1513 "%d%d%d%d%d%d%d%d%d%d" /* 10 6 */
1514 "%d%d%d%d%d%d%d%d%d%d" /* 10 7 */
1515 "%d%d%d%d%d%d%d%d%d%d" /* 10 8 */
1516 "%d%d%d%d%d%d%d%d%d%d" /* 10 9 */
1517 "%d%d%d%d%d%d%d%d%d%d" /* 10 10 */
1518 "%d%d%d%d%d%d%d%d%d%d" /* 10 11 */
1519 "%d%d%d%d%d%d%d%d%d" /* 9 */
1520 ,
1521 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 */
1522 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 1 */
1523 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 2 */
1524 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 3 */
1525 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 4 */
1526 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 5 */
1527 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 6 */
1528 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 7 */
1529 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 8 */
1530 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 9 */
1531 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 10 */
1532 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 11 */
1533 0, 1, 2, 3, 4, 5, 6, 7, 8); /* 9 */
1534
1535 if(rc != -1) {
1536 printf("curl_mprintf() returned %d and not -1!\n", rc);
1537 errors++;
1538 }
1539
1540 errors += string_check(buf, "");
1541
1542 if(errors)
1543 printf("Some curl_mprintf() weird arguments tests failed!\n");
1544
1545 return errors;
1546}
1547
1548/* DBL_MAX value from Linux */
1549#define MAXIMIZE -1.7976931348623157081452E+308
1550
1551static int test_float_formatting(void)
1552{
1553 int errors = 0;
1554 char buf[512]; /* larger than max float size */
1555 curl_msnprintf(buf, sizeof(buf), "%f", 9.0);
1556 errors += string_check(buf, "9.000000");
1557
1558 curl_msnprintf(buf, sizeof(buf), "%.1f", 9.1);
1559 errors += string_check(buf, "9.1");
1560
1561 curl_msnprintf(buf, sizeof(buf), "%.2f", 9.1);
1562 errors += string_check(buf, "9.10");
1563
1564 curl_msnprintf(buf, sizeof(buf), "%.0f", 9.1);
1565 errors += string_check(buf, "9");
1566
1567 curl_msnprintf(buf, sizeof(buf), "%0f", 9.1);
1568 errors += string_check(buf, "9.100000");
1569
1570 curl_msnprintf(buf, sizeof(buf), "%10f", 9.1);
1571 errors += string_check(buf, " 9.100000");
1572
1573 curl_msnprintf(buf, sizeof(buf), "%10.3f", 9.1);
1574 errors += string_check(buf, " 9.100");
1575
1576 curl_msnprintf(buf, sizeof(buf), "%-10.3f", 9.1);
1577 errors += string_check(buf, "9.100 ");
1578
1579 curl_msnprintf(buf, sizeof(buf), "%-10.3f", 9.123456);
1580 errors += string_check(buf, "9.123 ");
1581
1582 curl_msnprintf(buf, sizeof(buf), "%.-2f", 9.1);
1583 errors += string_check(buf, "9.100000");
1584
1585 curl_msnprintf(buf, sizeof(buf), "%*f", 10, 9.1);
1586 errors += string_check(buf, " 9.100000");
1587
1588 curl_msnprintf(buf, sizeof(buf), "%*f", 3, 9.1);
1589 errors += string_check(buf, "9.100000");
1590
1591 curl_msnprintf(buf, sizeof(buf), "%*f", 6, 9.2987654);
1592 errors += string_check(buf, "9.298765");
1593
1594 curl_msnprintf(buf, sizeof(buf), "%*f", 6, 9.298765);
1595 errors += string_check(buf, "9.298765");
1596
1597 curl_msnprintf(buf, sizeof(buf), "%*f", 6, 9.29876);
1598 errors += string_check(buf, "9.298760");
1599
1600 curl_msnprintf(buf, sizeof(buf), "%.*f", 6, 9.2987654);
1601 errors += string_check(buf, "9.298765");
1602 curl_msnprintf(buf, sizeof(buf), "%.*f", 5, 9.2987654);
1603 errors += string_check(buf, "9.29877");
1604 curl_msnprintf(buf, sizeof(buf), "%.*f", 4, 9.2987654);
1605 errors += string_check(buf, "9.2988");
1606 curl_msnprintf(buf, sizeof(buf), "%.*f", 3, 9.2987654);
1607 errors += string_check(buf, "9.299");
1608 curl_msnprintf(buf, sizeof(buf), "%.*f", 2, 9.2987654);
1609 errors += string_check(buf, "9.30");
1610 curl_msnprintf(buf, sizeof(buf), "%.*f", 1, 9.2987654);
1611 errors += string_check(buf, "9.3");
1612 curl_msnprintf(buf, sizeof(buf), "%.*f", 0, 9.2987654);
1613 errors += string_check(buf, "9");
1614
1615 /* very large precisions easily turn into system specific outputs so we only
1616 check the output buffer length here as we know the internal limit */
1617
1618 curl_msnprintf(buf, sizeof(buf), "%.*f", (1<<30), 9.2987654);
1619 errors += strlen_check(buf, 325);
1620
1621 curl_msnprintf(buf, sizeof(buf), "%10000.10000f", 9.2987654);
1622 errors += strlen_check(buf, 325);
1623
1624 curl_msnprintf(buf, sizeof(buf), "%240.10000f",
1625 123456789123456789123456789.2987654);
1626 errors += strlen_check(buf, 325);
1627
1628 /* check negative when used signed */
1629 curl_msnprintf(buf, sizeof(buf), "%*f", INT_MIN, 9.1);
1630 errors += string_check(buf, "9.100000");
1631
1632 /* curl_msnprintf() limits a single float output to 325 bytes maximum
1633 width */
1634 curl_msnprintf(buf, sizeof(buf), "%*f", (1<<30), 9.1);
1635 errors += string_check(buf, " 9.100000");
1636 curl_msnprintf(buf, sizeof(buf), "%100000f", 9.1);
1637 errors += string_check(buf, " 9.100000");
1638
1639 curl_msnprintf(buf, sizeof(buf), "%f", MAXIMIZE);
1640 errors += strlen_check(buf, 317);
1641
1642 curl_msnprintf(buf, 2, "%f", MAXIMIZE);
1643 errors += strlen_check(buf, 1);
1644 curl_msnprintf(buf, 3, "%f", MAXIMIZE);
1645 errors += strlen_check(buf, 2);
1646 curl_msnprintf(buf, 4, "%f", MAXIMIZE);
1647 errors += strlen_check(buf, 3);
1648 curl_msnprintf(buf, 5, "%f", MAXIMIZE);
1649 errors += strlen_check(buf, 4);
1650 curl_msnprintf(buf, 6, "%f", MAXIMIZE);
1651 errors += strlen_check(buf, 5);
1652
1653 if(!errors)
1654 printf("All float strings tests OK!\n");
1655 else
1656 printf("test_float_formatting Failed!\n");
1657
1658 return errors;
1659}
1660/* !checksrc! enable LONGLINE */
1661
1662int test(char *URL)
1663{
1664 int errors = 0;
1665 (void)URL; /* not used */
1666
1667#ifdef HAVE_SETLOCALE
1668 /*
1669 * The test makes assumptions about the numeric locale (specifically,
1670 * RADIXCHAR) so set it to a known working (and portable) one.
1671 */
1672 setlocale(LC_NUMERIC, "C");
1673#endif
1674
1675 errors += test_weird_arguments();
1676
1677 errors += test_unsigned_short_formatting();
1678
1679 errors += test_signed_short_formatting();
1680
1681 errors += test_unsigned_int_formatting();
1682
1683 errors += test_signed_int_formatting();
1684
1685 errors += test_unsigned_long_formatting();
1686
1687 errors += test_signed_long_formatting();
1688
1689 errors += test_curl_off_t_formatting();
1690
1691 errors += test_string_formatting();
1692
1693 errors += test_float_formatting();
1694
1695 if(errors)
1696 return TEST_ERR_MAJOR_BAD;
1697 else
1698 return 0;
1699}