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