master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 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 ***************************************************************************/
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 */
30#include "first.h"
32#ifdef HAVE_LOCALE_H
33# include <locale.h> /* for setlocale() */
34#endif
36#ifdef CURL_HAVE_DIAG
37#pragma GCC diagnostic push
38#pragma GCC diagnostic ignored "-Wformat"
39#pragma GCC diagnostic ignored "-Wformat-extra-args"
40#if !defined(__clang__) && __GNUC__ >= 7
41#pragma GCC diagnostic ignored "-Wformat-overflow"
42#endif
43#if defined(__clang__) && \
44 (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1))
45#pragma clang diagnostic ignored "-Wformat-non-iso"
46#endif
47#endif
49#ifdef __clang__
50#pragma clang diagnostic push
51#pragma clang diagnostic ignored "-Wformat-nonliteral"
52#endif
53#ifdef CURL_HAVE_DIAG
54#pragma GCC diagnostic push
55#pragma GCC diagnostic ignored "-Wformat-nonliteral"
56#endif
58#define BUFSZ 256
60struct unsshort_st {
61 unsigned short num; /* unsigned short */
62 const char *expected; /* expected string */
63 char result[BUFSZ]; /* result string */
64};
66struct sigshort_st {
67 short num; /* signed short */
68 const char *expected; /* expected string */
69 char result[BUFSZ]; /* result string */
70};
72struct unsint_st {
73 unsigned int num; /* unsigned int */
74 const char *expected; /* expected string */
75 char result[BUFSZ]; /* result string */
76};
78struct sigint_st {
79 int num; /* signed int */
80 const char *expected; /* expected string */
81 char result[BUFSZ]; /* result string */
82};
84struct unslong_st {
85 unsigned long num; /* unsigned long */
86 const char *expected; /* expected string */
87 char result[BUFSZ]; /* result string */
88};
90struct siglong_st {
91 long num; /* signed long */
92 const char *expected; /* expected string */
93 char result[BUFSZ]; /* result string */
94};
96struct curloff_st {
97 curl_off_t num; /* curl_off_t */
98 const char *expected; /* expected string */
99 char result[BUFSZ]; /* result string */
100};
102static int string_check_low(int linenumber, char *buf, const char *buf2)
103{
104 if(strcmp(buf, buf2)) {
105 /* they should not differ */
106 curl_mprintf("sprintf line %d failed:\nwe '%s'\nsystem: '%s'\n",
107 linenumber, buf, buf2);
108 return 1;
109 }
110 return 0;
111}
112#define string_check(x, y) string_check_low(__LINE__, x, y)
114static int strlen_check_low(int linenumber, char *buf, size_t len)
115{
116 size_t buflen = strlen(buf);
117 if(len != buflen) {
118 /* they should not differ */
119 curl_mprintf("sprintf strlen:%d failed:\nwe '%zu'\nsystem: '%zu'\n",
120 linenumber, buflen, len);
121 return 1;
122 }
123 return 0;
124}
125#define strlen_check(x, y) strlen_check_low(__LINE__, x, y)
127static struct unsshort_st us_test[1 + 100];
128static struct sigshort_st ss_test[1 + 100];
129static struct unsint_st ui_test[1 + 100];
130static struct sigint_st si_test[1 + 100];
131static struct unslong_st ul_test[1 + 100];
132static struct siglong_st sl_test[1 + 100];
133static struct curloff_st co_test[1 + 100];
135static int test_unsigned_short_formatting(void)
136{
137 int i, j;
138 int num_ushort_tests = 0;
139 int failed = 0;
141 i = 1; us_test[i].num = 0xFFFFU; us_test[i].expected = "65535";
142 i++; us_test[i].num = 0xFF00U; us_test[i].expected = "65280";
143 i++; us_test[i].num = 0x00FFU; us_test[i].expected = "255";
145 i++; us_test[i].num = 0xF000U; us_test[i].expected = "61440";
146 i++; us_test[i].num = 0x0F00U; us_test[i].expected = "3840";
147 i++; us_test[i].num = 0x00F0U; us_test[i].expected = "240";
148 i++; us_test[i].num = 0x000FU; us_test[i].expected = "15";
150 i++; us_test[i].num = 0xC000U; us_test[i].expected = "49152";
151 i++; us_test[i].num = 0x0C00U; us_test[i].expected = "3072";
152 i++; us_test[i].num = 0x00C0U; us_test[i].expected = "192";
153 i++; us_test[i].num = 0x000CU; us_test[i].expected = "12";
155 i++; us_test[i].num = 0x0001U; us_test[i].expected = "1";
156 i++; us_test[i].num = 0x0000U; us_test[i].expected = "0";
158 num_ushort_tests = i;
160 for(i = 1; i <= num_ushort_tests; i++) {
162 for(j = 0; j < BUFSZ; j++)
163 us_test[i].result[j] = 'X';
164 us_test[i].result[BUFSZ - 1] = '\0';
166 (void)curl_msprintf(us_test[i].result, "%hu", us_test[i].num);
168 if(memcmp(us_test[i].result,
169 us_test[i].expected,
170 strlen(us_test[i].expected))) {
171 curl_mprintf("unsigned short test #%.2d: Failed "
172 "(Expected: %s Got: %s)\n",
173 i, us_test[i].expected, us_test[i].result);
174 failed++;
175 }
176 }
178 if(!failed)
179 curl_mprintf("All curl_mprintf() unsigned short tests OK!\n");
180 else
181 curl_mprintf("Some curl_mprintf() unsigned short tests Failed!\n");
183 return failed;
184}
186static int test_signed_short_formatting(void)
187{
188 int i, j;
189 int num_sshort_tests = 0;
190 int failed = 0;
192 i = 1; ss_test[i].num = 0x7FFF; ss_test[i].expected = "32767";
193 i++; ss_test[i].num = 0x7FFE; ss_test[i].expected = "32766";
194 i++; ss_test[i].num = 0x7FFD; ss_test[i].expected = "32765";
195 i++; ss_test[i].num = 0x7F00; ss_test[i].expected = "32512";
196 i++; ss_test[i].num = 0x07F0; ss_test[i].expected = "2032";
197 i++; ss_test[i].num = 0x007F; ss_test[i].expected = "127";
199 i++; ss_test[i].num = 0x7000; ss_test[i].expected = "28672";
200 i++; ss_test[i].num = 0x0700; ss_test[i].expected = "1792";
201 i++; ss_test[i].num = 0x0070; ss_test[i].expected = "112";
202 i++; ss_test[i].num = 0x0007; ss_test[i].expected = "7";
204 i++; ss_test[i].num = 0x5000; ss_test[i].expected = "20480";
205 i++; ss_test[i].num = 0x0500; ss_test[i].expected = "1280";
206 i++; ss_test[i].num = 0x0050; ss_test[i].expected = "80";
207 i++; ss_test[i].num = 0x0005; ss_test[i].expected = "5";
209 i++; ss_test[i].num = 0x0001; ss_test[i].expected = "1";
210 i++; ss_test[i].num = 0x0000; ss_test[i].expected = "0";
212 i++; ss_test[i].num = -0x7FFF -1; ss_test[i].expected = "-32768";
213 i++; ss_test[i].num = -0x7FFE -1; ss_test[i].expected = "-32767";
214 i++; ss_test[i].num = -0x7FFD -1; ss_test[i].expected = "-32766";
215 i++; ss_test[i].num = -0x7F00 -1; ss_test[i].expected = "-32513";
216 i++; ss_test[i].num = -0x07F0 -1; ss_test[i].expected = "-2033";
217 i++; ss_test[i].num = -0x007F -1; ss_test[i].expected = "-128";
219 i++; ss_test[i].num = -0x7000 -1; ss_test[i].expected = "-28673";
220 i++; ss_test[i].num = -0x0700 -1; ss_test[i].expected = "-1793";
221 i++; ss_test[i].num = -0x0070 -1; ss_test[i].expected = "-113";
222 i++; ss_test[i].num = -0x0007 -1; ss_test[i].expected = "-8";
224 i++; ss_test[i].num = -0x5000 -1; ss_test[i].expected = "-20481";
225 i++; ss_test[i].num = -0x0500 -1; ss_test[i].expected = "-1281";
226 i++; ss_test[i].num = -0x0050 -1; ss_test[i].expected = "-81";
227 i++; ss_test[i].num = -0x0005 -1; ss_test[i].expected = "-6";
229 i++; ss_test[i].num = 0x0000 -1; ss_test[i].expected = "-1";
231 num_sshort_tests = i;
233 for(i = 1; i <= num_sshort_tests; i++) {
235 for(j = 0; j < BUFSZ; j++)
236 ss_test[i].result[j] = 'X';
237 ss_test[i].result[BUFSZ - 1] = '\0';
239 (void)curl_msprintf(ss_test[i].result, "%hd", ss_test[i].num);
241 if(memcmp(ss_test[i].result,
242 ss_test[i].expected,
243 strlen(ss_test[i].expected))) {
244 curl_mprintf("signed short test #%.2d: Failed (Expected: %s Got: %s)\n",
245 i, ss_test[i].expected, ss_test[i].result);
246 failed++;
247 }
248 }
250 if(!failed)
251 curl_mprintf("All curl_mprintf() signed short tests OK!\n");
252 else
253 curl_mprintf("Some curl_mprintf() signed short tests Failed!\n");
255 return failed;
256}
258static int test_unsigned_int_formatting(void)
259{
260 int i, j;
261 int num_uint_tests = 0;
262 int failed = 0;
263 char buf[128];
265 i = 1; ui_test[i].num = 0xFFFFFFFFU; ui_test[i].expected = "4294967295";
266 i++; ui_test[i].num = 0xFFFF0000U; ui_test[i].expected = "4294901760";
267 i++; ui_test[i].num = 0x0000FFFFU; ui_test[i].expected = "65535";
269 i++; ui_test[i].num = 0xFF000000U; ui_test[i].expected = "4278190080";
270 i++; ui_test[i].num = 0x00FF0000U; ui_test[i].expected = "16711680";
271 i++; ui_test[i].num = 0x0000FF00U; ui_test[i].expected = "65280";
272 i++; ui_test[i].num = 0x000000FFU; ui_test[i].expected = "255";
274 i++; ui_test[i].num = 0xF0000000U; ui_test[i].expected = "4026531840";
275 i++; ui_test[i].num = 0x0F000000U; ui_test[i].expected = "251658240";
276 i++; ui_test[i].num = 0x00F00000U; ui_test[i].expected = "15728640";
277 i++; ui_test[i].num = 0x000F0000U; ui_test[i].expected = "983040";
278 i++; ui_test[i].num = 0x0000F000U; ui_test[i].expected = "61440";
279 i++; ui_test[i].num = 0x00000F00U; ui_test[i].expected = "3840";
280 i++; ui_test[i].num = 0x000000F0U; ui_test[i].expected = "240";
281 i++; ui_test[i].num = 0x0000000FU; ui_test[i].expected = "15";
283 i++; ui_test[i].num = 0xC0000000U; ui_test[i].expected = "3221225472";
284 i++; ui_test[i].num = 0x0C000000U; ui_test[i].expected = "201326592";
285 i++; ui_test[i].num = 0x00C00000U; ui_test[i].expected = "12582912";
286 i++; ui_test[i].num = 0x000C0000U; ui_test[i].expected = "786432";
287 i++; ui_test[i].num = 0x0000C000U; ui_test[i].expected = "49152";
288 i++; ui_test[i].num = 0x00000C00U; ui_test[i].expected = "3072";
289 i++; ui_test[i].num = 0x000000C0U; ui_test[i].expected = "192";
290 i++; ui_test[i].num = 0x0000000CU; ui_test[i].expected = "12";
292 i++; ui_test[i].num = 0x00000001U; ui_test[i].expected = "1";
293 i++; ui_test[i].num = 0x00000000U; ui_test[i].expected = "0";
295 num_uint_tests = i;
297 for(i = 1; i <= num_uint_tests; i++) {
299 for(j = 0; j < BUFSZ; j++)
300 ui_test[i].result[j] = 'X';
301 ui_test[i].result[BUFSZ - 1] = '\0';
303 (void)curl_msprintf(ui_test[i].result, "%u", ui_test[i].num);
305 if(memcmp(ui_test[i].result,
306 ui_test[i].expected,
307 strlen(ui_test[i].expected))) {
308 curl_mprintf("unsigned int test #%.2d: Failed (Expected: %s Got: %s)\n",
309 i, ui_test[i].expected, ui_test[i].result);
310 failed++;
311 }
312 }
314 curl_msnprintf(buf, sizeof(buf), "%+u", 1234);
315 failed += string_check(buf, "+1234");
317 if(!failed)
318 curl_mprintf("All curl_mprintf() unsigned int tests OK!\n");
319 else
320 curl_mprintf("Some curl_mprintf() unsigned int tests Failed!\n");
322 return failed;
323}
325static int test_signed_int_formatting(void)
326{
327 int i, j;
328 int num_sint_tests = 0;
329 int failed = 0;
331 i = 1; si_test[i].num = 0x7FFFFFFF; si_test[i].expected = "2147483647";
332 i++; si_test[i].num = 0x7FFFFFFE; si_test[i].expected = "2147483646";
333 i++; si_test[i].num = 0x7FFFFFFD; si_test[i].expected = "2147483645";
334 i++; si_test[i].num = 0x7FFF0000; si_test[i].expected = "2147418112";
335 i++; si_test[i].num = 0x00007FFF; si_test[i].expected = "32767";
337 i++; si_test[i].num = 0x7F000000; si_test[i].expected = "2130706432";
338 i++; si_test[i].num = 0x007F0000; si_test[i].expected = "8323072";
339 i++; si_test[i].num = 0x00007F00; si_test[i].expected = "32512";
340 i++; si_test[i].num = 0x0000007F; si_test[i].expected = "127";
342 i++; si_test[i].num = 0x70000000; si_test[i].expected = "1879048192";
343 i++; si_test[i].num = 0x07000000; si_test[i].expected = "117440512";
344 i++; si_test[i].num = 0x00700000; si_test[i].expected = "7340032";
345 i++; si_test[i].num = 0x00070000; si_test[i].expected = "458752";
346 i++; si_test[i].num = 0x00007000; si_test[i].expected = "28672";
347 i++; si_test[i].num = 0x00000700; si_test[i].expected = "1792";
348 i++; si_test[i].num = 0x00000070; si_test[i].expected = "112";
349 i++; si_test[i].num = 0x00000007; si_test[i].expected = "7";
351 i++; si_test[i].num = 0x50000000; si_test[i].expected = "1342177280";
352 i++; si_test[i].num = 0x05000000; si_test[i].expected = "83886080";
353 i++; si_test[i].num = 0x00500000; si_test[i].expected = "5242880";
354 i++; si_test[i].num = 0x00050000; si_test[i].expected = "327680";
355 i++; si_test[i].num = 0x00005000; si_test[i].expected = "20480";
356 i++; si_test[i].num = 0x00000500; si_test[i].expected = "1280";
357 i++; si_test[i].num = 0x00000050; si_test[i].expected = "80";
358 i++; si_test[i].num = 0x00000005; si_test[i].expected = "5";
360 i++; si_test[i].num = 0x00000001; si_test[i].expected = "1";
361 i++; si_test[i].num = 0x00000000; si_test[i].expected = "0";
363 i++; si_test[i].num = -0x7FFFFFFF -1; si_test[i].expected = "-2147483648";
364 i++; si_test[i].num = -0x7FFFFFFE -1; si_test[i].expected = "-2147483647";
365 i++; si_test[i].num = -0x7FFFFFFD -1; si_test[i].expected = "-2147483646";
366 i++; si_test[i].num = -0x7FFF0000 -1; si_test[i].expected = "-2147418113";
367 i++; si_test[i].num = -0x00007FFF -1; si_test[i].expected = "-32768";
369 i++; si_test[i].num = -0x7F000000 -1; si_test[i].expected = "-2130706433";
370 i++; si_test[i].num = -0x007F0000 -1; si_test[i].expected = "-8323073";
371 i++; si_test[i].num = -0x00007F00 -1; si_test[i].expected = "-32513";
372 i++; si_test[i].num = -0x0000007F -1; si_test[i].expected = "-128";
374 i++; si_test[i].num = -0x70000000 -1; si_test[i].expected = "-1879048193";
375 i++; si_test[i].num = -0x07000000 -1; si_test[i].expected = "-117440513";
376 i++; si_test[i].num = -0x00700000 -1; si_test[i].expected = "-7340033";
377 i++; si_test[i].num = -0x00070000 -1; si_test[i].expected = "-458753";
378 i++; si_test[i].num = -0x00007000 -1; si_test[i].expected = "-28673";
379 i++; si_test[i].num = -0x00000700 -1; si_test[i].expected = "-1793";
380 i++; si_test[i].num = -0x00000070 -1; si_test[i].expected = "-113";
381 i++; si_test[i].num = -0x00000007 -1; si_test[i].expected = "-8";
383 i++; si_test[i].num = -0x50000000 -1; si_test[i].expected = "-1342177281";
384 i++; si_test[i].num = -0x05000000 -1; si_test[i].expected = "-83886081";
385 i++; si_test[i].num = -0x00500000 -1; si_test[i].expected = "-5242881";
386 i++; si_test[i].num = -0x00050000 -1; si_test[i].expected = "-327681";
387 i++; si_test[i].num = -0x00005000 -1; si_test[i].expected = "-20481";
388 i++; si_test[i].num = -0x00000500 -1; si_test[i].expected = "-1281";
389 i++; si_test[i].num = -0x00000050 -1; si_test[i].expected = "-81";
390 i++; si_test[i].num = -0x00000005 -1; si_test[i].expected = "-6";
392 i++; si_test[i].num = 0x00000000 -1; si_test[i].expected = "-1";
394 num_sint_tests = i;
396 for(i = 1; i <= num_sint_tests; i++) {
398 for(j = 0; j < BUFSZ; j++)
399 si_test[i].result[j] = 'X';
400 si_test[i].result[BUFSZ - 1] = '\0';
402 (void)curl_msprintf(si_test[i].result, "%d", si_test[i].num);
404 if(memcmp(si_test[i].result,
405 si_test[i].expected,
406 strlen(si_test[i].expected))) {
407 curl_mprintf("signed int test #%.2d: Failed (Expected: %s Got: %s)\n",
408 i, si_test[i].expected, si_test[i].result);
409 failed++;
410 }
411 }
413 if(!failed)
414 curl_mprintf("All curl_mprintf() signed int tests OK!\n");
415 else
416 curl_mprintf("Some curl_mprintf() signed int tests Failed!\n");
418 return failed;
419}
421static int test_unsigned_long_formatting(void)
422{
423 int i, j;
424 int num_ulong_tests = 0;
425 int failed = 0;
427#if SIZEOF_LONG == 4
429 i = 1; ul_test[i].num = 0xFFFFFFFFUL; ul_test[i].expected = "4294967295";
430 i++; ul_test[i].num = 0xFFFF0000UL; ul_test[i].expected = "4294901760";
431 i++; ul_test[i].num = 0x0000FFFFUL; ul_test[i].expected = "65535";
433 i++; ul_test[i].num = 0xFF000000UL; ul_test[i].expected = "4278190080";
434 i++; ul_test[i].num = 0x00FF0000UL; ul_test[i].expected = "16711680";
435 i++; ul_test[i].num = 0x0000FF00UL; ul_test[i].expected = "65280";
436 i++; ul_test[i].num = 0x000000FFUL; ul_test[i].expected = "255";
438 i++; ul_test[i].num = 0xF0000000UL; ul_test[i].expected = "4026531840";
439 i++; ul_test[i].num = 0x0F000000UL; ul_test[i].expected = "251658240";
440 i++; ul_test[i].num = 0x00F00000UL; ul_test[i].expected = "15728640";
441 i++; ul_test[i].num = 0x000F0000UL; ul_test[i].expected = "983040";
442 i++; ul_test[i].num = 0x0000F000UL; ul_test[i].expected = "61440";
443 i++; ul_test[i].num = 0x00000F00UL; ul_test[i].expected = "3840";
444 i++; ul_test[i].num = 0x000000F0UL; ul_test[i].expected = "240";
445 i++; ul_test[i].num = 0x0000000FUL; ul_test[i].expected = "15";
447 i++; ul_test[i].num = 0xC0000000UL; ul_test[i].expected = "3221225472";
448 i++; ul_test[i].num = 0x0C000000UL; ul_test[i].expected = "201326592";
449 i++; ul_test[i].num = 0x00C00000UL; ul_test[i].expected = "12582912";
450 i++; ul_test[i].num = 0x000C0000UL; ul_test[i].expected = "786432";
451 i++; ul_test[i].num = 0x0000C000UL; ul_test[i].expected = "49152";
452 i++; ul_test[i].num = 0x00000C00UL; ul_test[i].expected = "3072";
453 i++; ul_test[i].num = 0x000000C0UL; ul_test[i].expected = "192";
454 i++; ul_test[i].num = 0x0000000CUL; ul_test[i].expected = "12";
456 i++; ul_test[i].num = 0x00000001UL; ul_test[i].expected = "1";
457 i++; ul_test[i].num = 0x00000000UL; ul_test[i].expected = "0";
459 num_ulong_tests = i;
461#elif SIZEOF_LONG == 8
462 /* !checksrc! disable LONGLINE all */
463 i = 1; ul_test[i].num = 0xFFFFFFFFFFFFFFFFUL; ul_test[i].expected = "18446744073709551615";
464 i++; ul_test[i].num = 0xFFFFFFFF00000000UL; ul_test[i].expected = "18446744069414584320";
465 i++; ul_test[i].num = 0x00000000FFFFFFFFUL; ul_test[i].expected = "4294967295";
467 i++; ul_test[i].num = 0xFFFF000000000000UL; ul_test[i].expected = "18446462598732840960";
468 i++; ul_test[i].num = 0x0000FFFF00000000UL; ul_test[i].expected = "281470681743360";
469 i++; ul_test[i].num = 0x00000000FFFF0000UL; ul_test[i].expected = "4294901760";
470 i++; ul_test[i].num = 0x000000000000FFFFUL; ul_test[i].expected = "65535";
472 i++; ul_test[i].num = 0xFF00000000000000UL; ul_test[i].expected = "18374686479671623680";
473 i++; ul_test[i].num = 0x00FF000000000000UL; ul_test[i].expected = "71776119061217280";
474 i++; ul_test[i].num = 0x0000FF0000000000UL; ul_test[i].expected = "280375465082880";
475 i++; ul_test[i].num = 0x000000FF00000000UL; ul_test[i].expected = "1095216660480";
476 i++; ul_test[i].num = 0x00000000FF000000UL; ul_test[i].expected = "4278190080";
477 i++; ul_test[i].num = 0x0000000000FF0000UL; ul_test[i].expected = "16711680";
478 i++; ul_test[i].num = 0x000000000000FF00UL; ul_test[i].expected = "65280";
479 i++; ul_test[i].num = 0x00000000000000FFUL; ul_test[i].expected = "255";
481 i++; ul_test[i].num = 0xF000000000000000UL; ul_test[i].expected = "17293822569102704640";
482 i++; ul_test[i].num = 0x0F00000000000000UL; ul_test[i].expected = "1080863910568919040";
483 i++; ul_test[i].num = 0x00F0000000000000UL; ul_test[i].expected = "67553994410557440";
484 i++; ul_test[i].num = 0x000F000000000000UL; ul_test[i].expected = "4222124650659840";
485 i++; ul_test[i].num = 0x0000F00000000000UL; ul_test[i].expected = "263882790666240";
486 i++; ul_test[i].num = 0x00000F0000000000UL; ul_test[i].expected = "16492674416640";
487 i++; ul_test[i].num = 0x000000F000000000UL; ul_test[i].expected = "1030792151040";
488 i++; ul_test[i].num = 0x0000000F00000000UL; ul_test[i].expected = "64424509440";
489 i++; ul_test[i].num = 0x00000000F0000000UL; ul_test[i].expected = "4026531840";
490 i++; ul_test[i].num = 0x000000000F000000UL; ul_test[i].expected = "251658240";
491 i++; ul_test[i].num = 0x0000000000F00000UL; ul_test[i].expected = "15728640";
492 i++; ul_test[i].num = 0x00000000000F0000UL; ul_test[i].expected = "983040";
493 i++; ul_test[i].num = 0x000000000000F000UL; ul_test[i].expected = "61440";
494 i++; ul_test[i].num = 0x0000000000000F00UL; ul_test[i].expected = "3840";
495 i++; ul_test[i].num = 0x00000000000000F0UL; ul_test[i].expected = "240";
496 i++; ul_test[i].num = 0x000000000000000FUL; ul_test[i].expected = "15";
498 i++; ul_test[i].num = 0xC000000000000000UL; ul_test[i].expected = "13835058055282163712";
499 i++; ul_test[i].num = 0x0C00000000000000UL; ul_test[i].expected = "864691128455135232";
500 i++; ul_test[i].num = 0x00C0000000000000UL; ul_test[i].expected = "54043195528445952";
501 i++; ul_test[i].num = 0x000C000000000000UL; ul_test[i].expected = "3377699720527872";
502 i++; ul_test[i].num = 0x0000C00000000000UL; ul_test[i].expected = "211106232532992";
503 i++; ul_test[i].num = 0x00000C0000000000UL; ul_test[i].expected = "13194139533312";
504 i++; ul_test[i].num = 0x000000C000000000UL; ul_test[i].expected = "824633720832";
505 i++; ul_test[i].num = 0x0000000C00000000UL; ul_test[i].expected = "51539607552";
506 i++; ul_test[i].num = 0x00000000C0000000UL; ul_test[i].expected = "3221225472";
507 i++; ul_test[i].num = 0x000000000C000000UL; ul_test[i].expected = "201326592";
508 i++; ul_test[i].num = 0x0000000000C00000UL; ul_test[i].expected = "12582912";
509 i++; ul_test[i].num = 0x00000000000C0000UL; ul_test[i].expected = "786432";
510 i++; ul_test[i].num = 0x000000000000C000UL; ul_test[i].expected = "49152";
511 i++; ul_test[i].num = 0x0000000000000C00UL; ul_test[i].expected = "3072";
512 i++; ul_test[i].num = 0x00000000000000C0UL; ul_test[i].expected = "192";
513 i++; ul_test[i].num = 0x000000000000000CUL; ul_test[i].expected = "12";
515 i++; ul_test[i].num = 0x00000001UL; ul_test[i].expected = "1";
516 i++; ul_test[i].num = 0x00000000UL; ul_test[i].expected = "0";
518 num_ulong_tests = i;
520#endif
522 for(i = 1; i <= num_ulong_tests; i++) {
524 for(j = 0; j < BUFSZ; j++)
525 ul_test[i].result[j] = 'X';
526 ul_test[i].result[BUFSZ - 1] = '\0';
528 (void)curl_msprintf(ul_test[i].result, "%lu", ul_test[i].num);
530 if(memcmp(ul_test[i].result,
531 ul_test[i].expected,
532 strlen(ul_test[i].expected))) {
533 curl_mprintf("unsigned long test #%.2d: Failed (Expected: %s Got: %s)\n",
534 i, ul_test[i].expected, ul_test[i].result);
535 failed++;
536 }
537 }
539 if(!failed)
540 curl_mprintf("All curl_mprintf() unsigned long tests OK!\n");
541 else
542 curl_mprintf("Some curl_mprintf() unsigned long tests Failed!\n");
544 return failed;
545}
547static int test_signed_long_formatting(void)
548{
549 int i, j;
550 int num_slong_tests = 0;
551 int failed = 0;
553#if SIZEOF_LONG == 4
555 i = 1; sl_test[i].num = 0x7FFFFFFFL; sl_test[i].expected = "2147483647";
556 i++; sl_test[i].num = 0x7FFFFFFEL; sl_test[i].expected = "2147483646";
557 i++; sl_test[i].num = 0x7FFFFFFDL; sl_test[i].expected = "2147483645";
558 i++; sl_test[i].num = 0x7FFF0000L; sl_test[i].expected = "2147418112";
559 i++; sl_test[i].num = 0x00007FFFL; sl_test[i].expected = "32767";
561 i++; sl_test[i].num = 0x7F000000L; sl_test[i].expected = "2130706432";
562 i++; sl_test[i].num = 0x007F0000L; sl_test[i].expected = "8323072";
563 i++; sl_test[i].num = 0x00007F00L; sl_test[i].expected = "32512";
564 i++; sl_test[i].num = 0x0000007FL; sl_test[i].expected = "127";
566 i++; sl_test[i].num = 0x70000000L; sl_test[i].expected = "1879048192";
567 i++; sl_test[i].num = 0x07000000L; sl_test[i].expected = "117440512";
568 i++; sl_test[i].num = 0x00700000L; sl_test[i].expected = "7340032";
569 i++; sl_test[i].num = 0x00070000L; sl_test[i].expected = "458752";
570 i++; sl_test[i].num = 0x00007000L; sl_test[i].expected = "28672";
571 i++; sl_test[i].num = 0x00000700L; sl_test[i].expected = "1792";
572 i++; sl_test[i].num = 0x00000070L; sl_test[i].expected = "112";
573 i++; sl_test[i].num = 0x00000007L; sl_test[i].expected = "7";
575 i++; sl_test[i].num = 0x50000000L; sl_test[i].expected = "1342177280";
576 i++; sl_test[i].num = 0x05000000L; sl_test[i].expected = "83886080";
577 i++; sl_test[i].num = 0x00500000L; sl_test[i].expected = "5242880";
578 i++; sl_test[i].num = 0x00050000L; sl_test[i].expected = "327680";
579 i++; sl_test[i].num = 0x00005000L; sl_test[i].expected = "20480";
580 i++; sl_test[i].num = 0x00000500L; sl_test[i].expected = "1280";
581 i++; sl_test[i].num = 0x00000050L; sl_test[i].expected = "80";
582 i++; sl_test[i].num = 0x00000005L; sl_test[i].expected = "5";
584 i++; sl_test[i].num = 0x00000001L; sl_test[i].expected = "1";
585 i++; sl_test[i].num = 0x00000000L; sl_test[i].expected = "0";
587 i++; sl_test[i].num = -0x7FFFFFFFL -1L; sl_test[i].expected = "-2147483648";
588 i++; sl_test[i].num = -0x7FFFFFFEL -1L; sl_test[i].expected = "-2147483647";
589 i++; sl_test[i].num = -0x7FFFFFFDL -1L; sl_test[i].expected = "-2147483646";
590 i++; sl_test[i].num = -0x7FFF0000L -1L; sl_test[i].expected = "-2147418113";
591 i++; sl_test[i].num = -0x00007FFFL -1L; sl_test[i].expected = "-32768";
593 i++; sl_test[i].num = -0x7F000000L -1L; sl_test[i].expected = "-2130706433";
594 i++; sl_test[i].num = -0x007F0000L -1L; sl_test[i].expected = "-8323073";
595 i++; sl_test[i].num = -0x00007F00L -1L; sl_test[i].expected = "-32513";
596 i++; sl_test[i].num = -0x0000007FL -1L; sl_test[i].expected = "-128";
598 i++; sl_test[i].num = -0x70000000L -1L; sl_test[i].expected = "-1879048193";
599 i++; sl_test[i].num = -0x07000000L -1L; sl_test[i].expected = "-117440513";
600 i++; sl_test[i].num = -0x00700000L -1L; sl_test[i].expected = "-7340033";
601 i++; sl_test[i].num = -0x00070000L -1L; sl_test[i].expected = "-458753";
602 i++; sl_test[i].num = -0x00007000L -1L; sl_test[i].expected = "-28673";
603 i++; sl_test[i].num = -0x00000700L -1L; sl_test[i].expected = "-1793";
604 i++; sl_test[i].num = -0x00000070L -1L; sl_test[i].expected = "-113";
605 i++; sl_test[i].num = -0x00000007L -1L; sl_test[i].expected = "-8";
607 i++; sl_test[i].num = -0x50000000L -1L; sl_test[i].expected = "-1342177281";
608 i++; sl_test[i].num = -0x05000000L -1L; sl_test[i].expected = "-83886081";
609 i++; sl_test[i].num = -0x00500000L -1L; sl_test[i].expected = "-5242881";
610 i++; sl_test[i].num = -0x00050000L -1L; sl_test[i].expected = "-327681";
611 i++; sl_test[i].num = -0x00005000L -1L; sl_test[i].expected = "-20481";
612 i++; sl_test[i].num = -0x00000500L -1L; sl_test[i].expected = "-1281";
613 i++; sl_test[i].num = -0x00000050L -1L; sl_test[i].expected = "-81";
614 i++; sl_test[i].num = -0x00000005L -1L; sl_test[i].expected = "-6";
616 i++; sl_test[i].num = 0x00000000L -1L; sl_test[i].expected = "-1";
618 num_slong_tests = i;
620#elif SIZEOF_LONG == 8
622 i = 1; sl_test[i].num = 0x7FFFFFFFFFFFFFFFL; sl_test[i].expected = "9223372036854775807";
623 i++; sl_test[i].num = 0x7FFFFFFFFFFFFFFEL; sl_test[i].expected = "9223372036854775806";
624 i++; sl_test[i].num = 0x7FFFFFFFFFFFFFFDL; sl_test[i].expected = "9223372036854775805";
625 i++; sl_test[i].num = 0x7FFFFFFF00000000L; sl_test[i].expected = "9223372032559808512";
626 i++; sl_test[i].num = 0x000000007FFFFFFFL; sl_test[i].expected = "2147483647";
628 i++; sl_test[i].num = 0x7FFF000000000000L; sl_test[i].expected = "9223090561878065152";
629 i++; sl_test[i].num = 0x00007FFF00000000L; sl_test[i].expected = "140733193388032";
630 i++; sl_test[i].num = 0x000000007FFF0000L; sl_test[i].expected = "2147418112";
631 i++; sl_test[i].num = 0x0000000000007FFFL; sl_test[i].expected = "32767";
633 i++; sl_test[i].num = 0x7F00000000000000L; sl_test[i].expected = "9151314442816847872";
634 i++; sl_test[i].num = 0x007F000000000000L; sl_test[i].expected = "35747322042253312";
635 i++; sl_test[i].num = 0x00007F0000000000L; sl_test[i].expected = "139637976727552";
636 i++; sl_test[i].num = 0x0000007F00000000L; sl_test[i].expected = "545460846592";
637 i++; sl_test[i].num = 0x000000007F000000L; sl_test[i].expected = "2130706432";
638 i++; sl_test[i].num = 0x00000000007F0000L; sl_test[i].expected = "8323072";
639 i++; sl_test[i].num = 0x0000000000007F00L; sl_test[i].expected = "32512";
640 i++; sl_test[i].num = 0x000000000000007FL; sl_test[i].expected = "127";
642 i++; sl_test[i].num = 0x7000000000000000L; sl_test[i].expected = "8070450532247928832";
643 i++; sl_test[i].num = 0x0700000000000000L; sl_test[i].expected = "504403158265495552";
644 i++; sl_test[i].num = 0x0070000000000000L; sl_test[i].expected = "31525197391593472";
645 i++; sl_test[i].num = 0x0007000000000000L; sl_test[i].expected = "1970324836974592";
646 i++; sl_test[i].num = 0x0000700000000000L; sl_test[i].expected = "123145302310912";
647 i++; sl_test[i].num = 0x0000070000000000L; sl_test[i].expected = "7696581394432";
648 i++; sl_test[i].num = 0x0000007000000000L; sl_test[i].expected = "481036337152";
649 i++; sl_test[i].num = 0x0000000700000000L; sl_test[i].expected = "30064771072";
650 i++; sl_test[i].num = 0x0000000070000000L; sl_test[i].expected = "1879048192";
651 i++; sl_test[i].num = 0x0000000007000000L; sl_test[i].expected = "117440512";
652 i++; sl_test[i].num = 0x0000000000700000L; sl_test[i].expected = "7340032";
653 i++; sl_test[i].num = 0x0000000000070000L; sl_test[i].expected = "458752";
654 i++; sl_test[i].num = 0x0000000000007000L; sl_test[i].expected = "28672";
655 i++; sl_test[i].num = 0x0000000000000700L; sl_test[i].expected = "1792";
656 i++; sl_test[i].num = 0x0000000000000070L; sl_test[i].expected = "112";
657 i++; sl_test[i].num = 0x0000000000000007L; sl_test[i].expected = "7";
659 i++; sl_test[i].num = 0x0000000000000001L; sl_test[i].expected = "1";
660 i++; sl_test[i].num = 0x0000000000000000L; sl_test[i].expected = "0";
662 i++; sl_test[i].num = -0x7FFFFFFFFFFFFFFFL -1L; sl_test[i].expected = "-9223372036854775808";
663 i++; sl_test[i].num = -0x7FFFFFFFFFFFFFFEL -1L; sl_test[i].expected = "-9223372036854775807";
664 i++; sl_test[i].num = -0x7FFFFFFFFFFFFFFDL -1L; sl_test[i].expected = "-9223372036854775806";
665 i++; sl_test[i].num = -0x7FFFFFFF00000000L -1L; sl_test[i].expected = "-9223372032559808513";
666 i++; sl_test[i].num = -0x000000007FFFFFFFL -1L; sl_test[i].expected = "-2147483648";
668 i++; sl_test[i].num = -0x7FFF000000000000L -1L; sl_test[i].expected = "-9223090561878065153";
669 i++; sl_test[i].num = -0x00007FFF00000000L -1L; sl_test[i].expected = "-140733193388033";
670 i++; sl_test[i].num = -0x000000007FFF0000L -1L; sl_test[i].expected = "-2147418113";
671 i++; sl_test[i].num = -0x0000000000007FFFL -1L; sl_test[i].expected = "-32768";
673 i++; sl_test[i].num = -0x7F00000000000000L -1L; sl_test[i].expected = "-9151314442816847873";
674 i++; sl_test[i].num = -0x007F000000000000L -1L; sl_test[i].expected = "-35747322042253313";
675 i++; sl_test[i].num = -0x00007F0000000000L -1L; sl_test[i].expected = "-139637976727553";
676 i++; sl_test[i].num = -0x0000007F00000000L -1L; sl_test[i].expected = "-545460846593";
677 i++; sl_test[i].num = -0x000000007F000000L -1L; sl_test[i].expected = "-2130706433";
678 i++; sl_test[i].num = -0x00000000007F0000L -1L; sl_test[i].expected = "-8323073";
679 i++; sl_test[i].num = -0x0000000000007F00L -1L; sl_test[i].expected = "-32513";
680 i++; sl_test[i].num = -0x000000000000007FL -1L; sl_test[i].expected = "-128";
682 i++; sl_test[i].num = -0x7000000000000000L -1L; sl_test[i].expected = "-8070450532247928833";
683 i++; sl_test[i].num = -0x0700000000000000L -1L; sl_test[i].expected = "-504403158265495553";
684 i++; sl_test[i].num = -0x0070000000000000L -1L; sl_test[i].expected = "-31525197391593473";
685 i++; sl_test[i].num = -0x0007000000000000L -1L; sl_test[i].expected = "-1970324836974593";
686 i++; sl_test[i].num = -0x0000700000000000L -1L; sl_test[i].expected = "-123145302310913";
687 i++; sl_test[i].num = -0x0000070000000000L -1L; sl_test[i].expected = "-7696581394433";
688 i++; sl_test[i].num = -0x0000007000000000L -1L; sl_test[i].expected = "-481036337153";
689 i++; sl_test[i].num = -0x0000000700000000L -1L; sl_test[i].expected = "-30064771073";
690 i++; sl_test[i].num = -0x0000000070000000L -1L; sl_test[i].expected = "-1879048193";
691 i++; sl_test[i].num = -0x0000000007000000L -1L; sl_test[i].expected = "-117440513";
692 i++; sl_test[i].num = -0x0000000000700000L -1L; sl_test[i].expected = "-7340033";
693 i++; sl_test[i].num = -0x0000000000070000L -1L; sl_test[i].expected = "-458753";
694 i++; sl_test[i].num = -0x0000000000007000L -1L; sl_test[i].expected = "-28673";
695 i++; sl_test[i].num = -0x0000000000000700L -1L; sl_test[i].expected = "-1793";
696 i++; sl_test[i].num = -0x0000000000000070L -1L; sl_test[i].expected = "-113";
697 i++; sl_test[i].num = -0x0000000000000007L -1L; sl_test[i].expected = "-8";
699 i++; sl_test[i].num = 0x0000000000000000L -1L; sl_test[i].expected = "-1";
701 num_slong_tests = i;
703#endif
705 for(i = 1; i <= num_slong_tests; i++) {
707 for(j = 0; j < BUFSZ; j++)
708 sl_test[i].result[j] = 'X';
709 sl_test[i].result[BUFSZ - 1] = '\0';
711 (void)curl_msprintf(sl_test[i].result, "%ld", sl_test[i].num);
713 if(memcmp(sl_test[i].result,
714 sl_test[i].expected,
715 strlen(sl_test[i].expected))) {
716 curl_mprintf("signed long test #%.2d: Failed (Expected: %s Got: %s)\n",
717 i, sl_test[i].expected, sl_test[i].result);
718 failed++;
719 }
720 }
722 if(!failed)
723 curl_mprintf("All curl_mprintf() signed long tests OK!\n");
724 else
725 curl_mprintf("Some curl_mprintf() signed long tests Failed!\n");
727 return failed;
728}
730static int test_curl_off_t_formatting(void)
731{
732 int i, j;
733 int num_cofft_tests = 0;
734 int failed = 0;
736 i = 1; co_test[i].num = 0x7FFFFFFFFFFFFFFFLL; co_test[i].expected = "9223372036854775807";
737 i++; co_test[i].num = 0x7FFFFFFFFFFFFFFE; co_test[i].expected = "9223372036854775806";
738 i++; co_test[i].num = 0x7FFFFFFFFFFFFFFD; co_test[i].expected = "9223372036854775805";
739 i++; co_test[i].num = 0x7FFFFFFF00000000; co_test[i].expected = "9223372032559808512";
740 i++; co_test[i].num = 0x000000007FFFFFFF; co_test[i].expected = "2147483647";
742 i++; co_test[i].num = 0x7FFF000000000000; co_test[i].expected = "9223090561878065152";
743 i++; co_test[i].num = 0x00007FFF00000000; co_test[i].expected = "140733193388032";
744 i++; co_test[i].num = 0x000000007FFF0000; co_test[i].expected = "2147418112";
745 i++; co_test[i].num = 0x0000000000007FFF; co_test[i].expected = "32767";
747 i++; co_test[i].num = 0x7F00000000000000; co_test[i].expected = "9151314442816847872";
748 i++; co_test[i].num = 0x007F000000000000; co_test[i].expected = "35747322042253312";
749 i++; co_test[i].num = 0x00007F0000000000; co_test[i].expected = "139637976727552";
750 i++; co_test[i].num = 0x0000007F00000000; co_test[i].expected = "545460846592";
751 i++; co_test[i].num = 0x000000007F000000; co_test[i].expected = "2130706432";
752 i++; co_test[i].num = 0x00000000007F0000; co_test[i].expected = "8323072";
753 i++; co_test[i].num = 0x0000000000007F00; co_test[i].expected = "32512";
754 i++; co_test[i].num = 0x000000000000007F; co_test[i].expected = "127";
756 i++; co_test[i].num = 0x7000000000000000; co_test[i].expected = "8070450532247928832";
757 i++; co_test[i].num = 0x0700000000000000; co_test[i].expected = "504403158265495552";
758 i++; co_test[i].num = 0x0070000000000000; co_test[i].expected = "31525197391593472";
759 i++; co_test[i].num = 0x0007000000000000; co_test[i].expected = "1970324836974592";
760 i++; co_test[i].num = 0x0000700000000000; co_test[i].expected = "123145302310912";
761 i++; co_test[i].num = 0x0000070000000000; co_test[i].expected = "7696581394432";
762 i++; co_test[i].num = 0x0000007000000000; co_test[i].expected = "481036337152";
763 i++; co_test[i].num = 0x0000000700000000; co_test[i].expected = "30064771072";
764 i++; co_test[i].num = 0x0000000070000000; co_test[i].expected = "1879048192";
765 i++; co_test[i].num = 0x0000000007000000; co_test[i].expected = "117440512";
766 i++; co_test[i].num = 0x0000000000700000; co_test[i].expected = "7340032";
767 i++; co_test[i].num = 0x0000000000070000; co_test[i].expected = "458752";
768 i++; co_test[i].num = 0x0000000000007000; co_test[i].expected = "28672";
769 i++; co_test[i].num = 0x0000000000000700; co_test[i].expected = "1792";
770 i++; co_test[i].num = 0x0000000000000070; co_test[i].expected = "112";
771 i++; co_test[i].num = 0x0000000000000007; co_test[i].expected = "7";
773 i++; co_test[i].num = 0x0000000000000001; co_test[i].expected = "1";
774 i++; co_test[i].num = 0x0000000000000000; co_test[i].expected = "0";
776 i++; co_test[i].num = -0x7FFFFFFFFFFFFFFFLL - 1; co_test[i].expected = "-9223372036854775808";
777 i++; co_test[i].num = -0x7FFFFFFFFFFFFFFE -1; co_test[i].expected = "-9223372036854775807";
778 i++; co_test[i].num = -0x7FFFFFFFFFFFFFFD -1; co_test[i].expected = "-9223372036854775806";
779 i++; co_test[i].num = -0x7FFFFFFF00000000 -1; co_test[i].expected = "-9223372032559808513";
780 i++; co_test[i].num = -0x000000007FFFFFFF -1; co_test[i].expected = "-2147483648";
782 i++; co_test[i].num = -0x7FFF000000000000 -1; co_test[i].expected = "-9223090561878065153";
783 i++; co_test[i].num = -0x00007FFF00000000 -1; co_test[i].expected = "-140733193388033";
784 i++; co_test[i].num = -0x000000007FFF0000 -1; co_test[i].expected = "-2147418113";
785 i++; co_test[i].num = -0x0000000000007FFF -1; co_test[i].expected = "-32768";
787 i++; co_test[i].num = -0x7F00000000000000 -1; co_test[i].expected = "-9151314442816847873";
788 i++; co_test[i].num = -0x007F000000000000 -1; co_test[i].expected = "-35747322042253313";
789 i++; co_test[i].num = -0x00007F0000000000 -1; co_test[i].expected = "-139637976727553";
790 i++; co_test[i].num = -0x0000007F00000000 -1; co_test[i].expected = "-545460846593";
791 i++; co_test[i].num = -0x000000007F000000 -1; co_test[i].expected = "-2130706433";
792 i++; co_test[i].num = -0x00000000007F0000 -1; co_test[i].expected = "-8323073";
793 i++; co_test[i].num = -0x0000000000007F00 -1; co_test[i].expected = "-32513";
794 i++; co_test[i].num = -0x000000000000007F -1; co_test[i].expected = "-128";
796 i++; co_test[i].num = -0x7000000000000000 -1; co_test[i].expected = "-8070450532247928833";
797 i++; co_test[i].num = -0x0700000000000000 -1; co_test[i].expected = "-504403158265495553";
798 i++; co_test[i].num = -0x0070000000000000 -1; co_test[i].expected = "-31525197391593473";
799 i++; co_test[i].num = -0x0007000000000000 -1; co_test[i].expected = "-1970324836974593";
800 i++; co_test[i].num = -0x0000700000000000 -1; co_test[i].expected = "-123145302310913";
801 i++; co_test[i].num = -0x0000070000000000 -1; co_test[i].expected = "-7696581394433";
802 i++; co_test[i].num = -0x0000007000000000 -1; co_test[i].expected = "-481036337153";
803 i++; co_test[i].num = -0x0000000700000000 -1; co_test[i].expected = "-30064771073";
804 i++; co_test[i].num = -0x0000000070000000 -1; co_test[i].expected = "-1879048193";
805 i++; co_test[i].num = -0x0000000007000000 -1; co_test[i].expected = "-117440513";
806 i++; co_test[i].num = -0x0000000000700000 -1; co_test[i].expected = "-7340033";
807 i++; co_test[i].num = -0x0000000000070000 -1; co_test[i].expected = "-458753";
808 i++; co_test[i].num = -0x0000000000007000 -1; co_test[i].expected = "-28673";
809 i++; co_test[i].num = -0x0000000000000700 -1; co_test[i].expected = "-1793";
810 i++; co_test[i].num = -0x0000000000000070 -1; co_test[i].expected = "-113";
811 i++; co_test[i].num = -0x0000000000000007 -1; co_test[i].expected = "-8";
813 i++; co_test[i].num = 0x0000000000000000 -1; co_test[i].expected = "-1";
814/* !checksrc! enable LONGLINE */
816 num_cofft_tests = i;
818 for(i = 1; i <= num_cofft_tests; i++) {
820 for(j = 0; j < BUFSZ; j++)
821 co_test[i].result[j] = 'X';
822 co_test[i].result[BUFSZ - 1] = '\0';
824 (void)curl_msprintf(co_test[i].result, "%" CURL_FORMAT_CURL_OFF_T,
825 co_test[i].num);
827 if(memcmp(co_test[i].result,
828 co_test[i].expected,
829 strlen(co_test[i].expected))) {
830 curl_mprintf("curl_off_t test #%.2d: Failed (Expected: %s Got: %s)\n",
831 i, co_test[i].expected, co_test[i].result);
832 failed++;
833 }
834 }
836 if(!failed)
837 curl_mprintf("All curl_mprintf() curl_off_t tests OK!\n");
838 else
839 curl_mprintf("Some curl_mprintf() curl_off_t tests Failed!\n");
841 return failed;
842}
844/*
845 * The output strings in this test need to have been verified with a system
846 * sprintf() before used here.
847 */
848static int test_string_formatting(void)
849{
850 int errors = 0;
851 char buf[256];
852 curl_msnprintf(buf, sizeof(buf), "%0*d%s", 2, 9, "foo");
853 errors += string_check(buf, "09foo");
855 curl_msnprintf(buf, sizeof(buf), "%*.*s", 5, 2, "foo");
856 errors += string_check(buf, " fo"); /* spellchecker:disable-line */
858 curl_msnprintf(buf, sizeof(buf), "%*.*s", 2, 5, "foo");
859 errors += string_check(buf, "foo");
861 curl_msnprintf(buf, sizeof(buf), "%*.*s", 0, 10, "foo");
862 errors += string_check(buf, "foo");
864 curl_msnprintf(buf, sizeof(buf), "%-10s", "foo");
865 errors += string_check(buf, "foo ");
867 curl_msnprintf(buf, sizeof(buf), "%10s", "foo");
868 errors += string_check(buf, " foo");
870 curl_msnprintf(buf, sizeof(buf), "%*.*s", -10, -10, "foo");
871 errors += string_check(buf, "foo ");
873 if(!errors)
874 curl_mprintf("All curl_mprintf() strings tests OK!\n");
875 else
876 curl_mprintf("Some curl_mprintf() string tests Failed!\n");
878 return errors;
879}
881static int test_pos_arguments(void)
882{
883 int errors = 0;
884 char buf[256];
886 curl_msnprintf(buf, sizeof(buf), "%3$d %2$d %1$d", 500, 501, 502);
887 errors += string_check(buf, "502 501 500");
889 curl_msnprintf(buf, sizeof(buf), "%3$d %1$d %2$d", 500, 501, 502);
890 errors += string_check(buf, "502 500 501");
892 /* this is in invalid sequence but the output does not match
893 what glibc does */
894 curl_msnprintf(buf, sizeof(buf), "%3$d %d %2$d", 500, 501, 502);
895 errors += string_check(buf, "");
897 return errors;
898}
900static int test_width_precision(void)
901{
902 /* 325 is max precision (and width) for a double */
903 char larger[1024];
904#define SPACE60 " "
905#define SPACE300 SPACE60 SPACE60 SPACE60 SPACE60 SPACE60
906#define OK325 SPACE300 " 0"
908 int rc;
909 int errors = 0;
910 rc = curl_msnprintf(larger, sizeof(larger), "%325.325f", 0.1);
911 if(rc != 325)
912 errors++;
913 errors += string_check(larger, OK325);
915 rc = curl_msnprintf(larger, sizeof(larger), "%326.326f", 0.1);
916 if(rc != 325)
917 errors++;
918 errors += string_check(larger, OK325);
920 rc = curl_msnprintf(larger, sizeof(larger), "%1000.1000f", 0.1);
921 if(rc != 325)
922 errors++;
923 errors += string_check(larger, OK325);
925 rc = curl_msnprintf(larger, sizeof(larger), "%324.324f", 0.1);
926 if(rc != 324)
927 errors++;
928 rc = curl_msnprintf(larger, sizeof(larger), "%324.0f", 0.1);
929 if(rc != 324)
930 errors++;
931 rc = curl_msnprintf(larger, sizeof(larger), "%0.324f", 0.1);
932 if(rc != 325)
933 errors++;
935 return errors;
936}
938static int test_weird_arguments(void)
939{
940 int errors = 0;
941 char buf[256];
942 int rc;
944 /* verify %% */
945 (void)curl_msnprintf(buf, sizeof(buf), "%-20d%% right? %%", 500);
946 errors += string_check(buf, "500 % right? %");
948 /* 100 x % */
949 (void)curl_msnprintf(buf, sizeof(buf), "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
950 "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
951 "%%%%%%%%%%%%%%%%%%%%%%");
952 /* 50 x % */
953 errors += string_check(buf, "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
954 "%%%%%%%%%%%%%%%");
956 (void)curl_msnprintf(buf, sizeof(buf), "%2 AA %d %K", 500, 501, 502);
957 errors += string_check(buf, "%2 AA 500 %K");
959 (void)curl_msnprintf(buf, sizeof(buf), "%2 %d %K", 500, 501, 502);
960 errors += string_check(buf, "%2 500 %K");
962 /* MAX_PARAMETERS is 128, try exact 128! */
963 rc = curl_msnprintf(buf, sizeof(buf),
964 "%d%d%d%d%d%d%d%d%d%d" /* 10 */
965 "%d%d%d%d%d%d%d%d%d%d" /* 10 1 */
966 "%d%d%d%d%d%d%d%d%d%d" /* 10 2 */
967 "%d%d%d%d%d%d%d%d%d%d" /* 10 3 */
968 "%d%d%d%d%d%d%d%d%d%d" /* 10 4 */
969 "%d%d%d%d%d%d%d%d%d%d" /* 10 5 */
970 "%d%d%d%d%d%d%d%d%d%d" /* 10 6 */
971 "%d%d%d%d%d%d%d%d%d%d" /* 10 7 */
972 "%d%d%d%d%d%d%d%d%d%d" /* 10 8 */
973 "%d%d%d%d%d%d%d%d%d%d" /* 10 9 */
974 "%d%d%d%d%d%d%d%d%d%d" /* 10 10 */
975 "%d%d%d%d%d%d%d%d%d%d" /* 10 11 */
976 "%d%d%d%d%d%d%d%d" /* 8 */
977 ,
978 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 */
979 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 1 */
980 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 2 */
981 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 3 */
982 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 4 */
983 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 5 */
984 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 6 */
985 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 7 */
986 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 8 */
987 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 9 */
988 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 10 */
989 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 11 */
990 0, 1, 2, 3, 4, 5, 6, 7); /* 8 */
992 if(rc != 128) {
993 curl_mprintf("curl_mprintf() returned %d and not 128!\n", rc);
994 errors++;
995 }
997 errors += string_check(buf,
998 "0123456789" /* 10 */
999 "0123456789" /* 10 1 */
1000 "0123456789" /* 10 2 */
1001 "0123456789" /* 10 3 */
1002 "0123456789" /* 10 4 */
1003 "0123456789" /* 10 5 */
1004 "0123456789" /* 10 6 */
1005 "0123456789" /* 10 7 */
1006 "0123456789" /* 10 8 */
1007 "0123456789" /* 10 9 */
1008 "0123456789" /* 10 10 */
1009 "0123456789" /* 10 11 */
1010 "01234567" /* 8 */
1011 );
1013 /* MAX_PARAMETERS is 128, try more! */
1014 buf[0] = 0;
1015 rc = curl_msnprintf(buf, sizeof(buf),
1016 "%d%d%d%d%d%d%d%d%d%d" /* 10 */
1017 "%d%d%d%d%d%d%d%d%d%d" /* 10 1 */
1018 "%d%d%d%d%d%d%d%d%d%d" /* 10 2 */
1019 "%d%d%d%d%d%d%d%d%d%d" /* 10 3 */
1020 "%d%d%d%d%d%d%d%d%d%d" /* 10 4 */
1021 "%d%d%d%d%d%d%d%d%d%d" /* 10 5 */
1022 "%d%d%d%d%d%d%d%d%d%d" /* 10 6 */
1023 "%d%d%d%d%d%d%d%d%d%d" /* 10 7 */
1024 "%d%d%d%d%d%d%d%d%d%d" /* 10 8 */
1025 "%d%d%d%d%d%d%d%d%d%d" /* 10 9 */
1026 "%d%d%d%d%d%d%d%d%d%d" /* 10 10 */
1027 "%d%d%d%d%d%d%d%d%d%d" /* 10 11 */
1028 "%d%d%d%d%d%d%d%d%d" /* 9 */
1029 ,
1030 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 */
1031 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 1 */
1032 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 2 */
1033 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 3 */
1034 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 4 */
1035 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 5 */
1036 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 6 */
1037 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 7 */
1038 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 8 */
1039 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 9 */
1040 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 10 */
1041 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 10 11 */
1042 0, 1, 2, 3, 4, 5, 6, 7, 8); /* 9 */
1044 if(rc) {
1045 curl_mprintf("curl_mprintf() returned %d and not 0\n", rc);
1046 errors++;
1047 }
1049 errors += string_check(buf, "");
1051 errors += test_width_precision();
1053 if(errors)
1054 curl_mprintf("Some curl_mprintf() weird arguments tests failed!\n");
1056 return errors;
1057}
1059static int double_check(void)
1060{
1061 const long double val = 1.234567890123456789L;
1062 int mismatches = 0;
1063 unsigned int i;
1064 struct dbcheck {
1065 const char *fmt;
1066 const char *prefix; /* starts with this */
1067 const char *suffix; /* ends with this */
1068 };
1069 /* because floats are annoying beasts, different libc's produce different
1070 outputs so we cannot compare exact output, only prefix + suffix */
1071 struct dbcheck c[] = {
1072 { "%.17Lf", /* "1.23456789012345669" */
1073 "1.23456789012345", "", },
1074/* VS2013 and earlier CRT vsnprintf() return slightly different results */
1075#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
1076 { "%.17Le", /* "1.23456789012345669e+00" */
1077 "1.234567890123456", "e+00" },
1078 { "%.17LE", /* "1.23456789012345669E+00" */
1079 "1.234567890123456", "E+00" },
1080#endif
1081 { "%.17Lg", /* "1.2345678901234567" */
1082 "1.234567890123456", "" },
1083 { "%.17LG", /* "1.2345678901234567" */
1084 "1.234567890123456", ""}
1085 };
1086 for(i = 0; i < CURL_ARRAYSIZE(c); i++) {
1087 char curl_out[128];
1088 size_t len =
1089 curl_msnprintf(curl_out, sizeof(curl_out), c[i].fmt, val);
1090 if(strncmp(curl_out, c[i].prefix, strlen(c[i].prefix))) {
1091 curl_mprintf("MISMATCH (prefix): %s curl=%s libc=%s\n",
1092 c[i].fmt, curl_out, c[i].prefix);
1093 mismatches++;
1094 }
1095 if((len < strlen(c[i].suffix) ||
1096 strncmp(curl_out + len - strlen(c[i].suffix),
1097 c[i].suffix, strlen(c[i].suffix)))) {
1098 curl_mprintf("MISMATCH (suffix): %s curl=%s libc=%s\n",
1099 c[i].fmt, curl_out, c[i].suffix);
1100 mismatches++;
1101 }
1102 }
1103 curl_mfprintf(stderr, "mismatches=%d/%zu\n", mismatches, CURL_ARRAYSIZE(c));
1104 return mismatches;
1105}
1107/* DBL_MAX value from Linux */
1108#define MAXIMIZE (-1.7976931348623157081452E+308)
1110static int test_float_formatting(void)
1111{
1112 int errors = 0;
1113 char buf[512]; /* larger than max float size */
1114 curl_msnprintf(buf, sizeof(buf), "%f", 9.0);
1115 errors += string_check(buf, "9.000000");
1117/* VS2013 and earlier CRT vsnprintf() does not support this mask */
1118#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
1119 curl_msnprintf(buf, sizeof(buf), "%F", 9.0);
1120 errors += string_check(buf, "9.000000");
1121#endif
1123 curl_msnprintf(buf, sizeof(buf), "%.1f", 9.1);
1124 errors += string_check(buf, "9.1");
1126 curl_msnprintf(buf, sizeof(buf), "%.2f", 9.1);
1127 errors += string_check(buf, "9.10");
1129 curl_msnprintf(buf, sizeof(buf), "%.0f", 9.1);
1130 errors += string_check(buf, "9");
1132 curl_msnprintf(buf, sizeof(buf), "%0f", 9.1);
1133 errors += string_check(buf, "9.100000");
1135 curl_msnprintf(buf, sizeof(buf), "%10f", 9.1);
1136 errors += string_check(buf, " 9.100000");
1138 curl_msnprintf(buf, sizeof(buf), "%10.3f", 9.1);
1139 errors += string_check(buf, " 9.100");
1141 curl_msnprintf(buf, sizeof(buf), "%-10.3f", 9.1);
1142 errors += string_check(buf, "9.100 ");
1144 curl_msnprintf(buf, sizeof(buf), "%-10.3f", 9.123456);
1145 errors += string_check(buf, "9.123 ");
1147 curl_msnprintf(buf, sizeof(buf), "%.-2f", 9.1);
1148 errors += string_check(buf, "9.100000");
1150 curl_msnprintf(buf, sizeof(buf), "%*f", 10, 9.1);
1151 errors += string_check(buf, " 9.100000");
1153 curl_msnprintf(buf, sizeof(buf), "%*f", 3, 9.1);
1154 errors += string_check(buf, "9.100000");
1156 curl_msnprintf(buf, sizeof(buf), "%*f", 6, 9.2987654);
1157 errors += string_check(buf, "9.298765");
1159 curl_msnprintf(buf, sizeof(buf), "%*f", 6, 9.298765);
1160 errors += string_check(buf, "9.298765");
1162 curl_msnprintf(buf, sizeof(buf), "%*f", 6, 9.29876);
1163 errors += string_check(buf, "9.298760");
1165 curl_msnprintf(buf, sizeof(buf), "%.*f", 6, 9.2987654);
1166 errors += string_check(buf, "9.298765");
1167 curl_msnprintf(buf, sizeof(buf), "%.*f", 5, 9.2987654);
1168 errors += string_check(buf, "9.29877");
1169 curl_msnprintf(buf, sizeof(buf), "%.*f", 4, 9.2987654);
1170 errors += string_check(buf, "9.2988");
1171 curl_msnprintf(buf, sizeof(buf), "%.*f", 3, 9.2987654);
1172 errors += string_check(buf, "9.299");
1173 curl_msnprintf(buf, sizeof(buf), "%.*f", 2, 9.2987654);
1174 errors += string_check(buf, "9.30");
1175 curl_msnprintf(buf, sizeof(buf), "%.*f", 1, 9.2987654);
1176 errors += string_check(buf, "9.3");
1177 curl_msnprintf(buf, sizeof(buf), "%.*f", 0, 9.2987654);
1178 errors += string_check(buf, "9");
1180 /* large precisions easily turn into system specific outputs so we only
1181 check the output buffer length here as we know the internal limit */
1183 curl_msnprintf(buf, sizeof(buf), "%.*f", (1 << 30), 9.2987654);
1184 errors += strlen_check(buf, 325);
1186 curl_msnprintf(buf, sizeof(buf), "%10000.10000f", 9.2987654);
1187 errors += strlen_check(buf, 325);
1189 curl_msnprintf(buf, sizeof(buf), "%240.10000f",
1190 123456789123456789123456789.2987654);
1191 errors += strlen_check(buf, 325);
1193 /* check negative width argument when used signed, is treated as positive
1194 and maxes out the internal float width == 325 */
1195 curl_msnprintf(buf, sizeof(buf), "%*f", INT_MIN, 9.1);
1196 errors += string_check(buf, "9.100000 "
1197 " "
1198 " "
1199 " "
1200 " ");
1202 /* curl_msnprintf() limits a single float output to 325 bytes maximum
1203 width */
1204 curl_msnprintf(buf, sizeof(buf), "%*f", (1 << 30), 9.1);
1205 errors += string_check(buf, " "
1206 " "
1207 " "
1208 " "
1209 " 9.100000");
1210 curl_msnprintf(buf, sizeof(buf), "%100000f", 9.1);
1211 errors += string_check(buf, " "
1212 " "
1213 " "
1214 " "
1215 " 9.100000");
1217 curl_msnprintf(buf, sizeof(buf), "%f", MAXIMIZE);
1218 errors += strlen_check(buf, 317);
1220 curl_msnprintf(buf, 2, "%f", MAXIMIZE);
1221 errors += strlen_check(buf, 1);
1222 curl_msnprintf(buf, 3, "%f", MAXIMIZE);
1223 errors += strlen_check(buf, 2);
1224 curl_msnprintf(buf, 4, "%f", MAXIMIZE);
1225 errors += strlen_check(buf, 3);
1226 curl_msnprintf(buf, 5, "%f", MAXIMIZE);
1227 errors += strlen_check(buf, 4);
1228 curl_msnprintf(buf, 6, "%f", MAXIMIZE);
1229 errors += strlen_check(buf, 5);
1231 errors += double_check();
1233 if(!errors)
1234 curl_mprintf("All float strings tests OK!\n");
1235 else
1236 curl_mprintf("test_float_formatting Failed!\n");
1238 return errors;
1239}
1241static int test_oct_hex_formatting(void)
1242{
1243 int errors = 0;
1244 char buf[256];
1246 curl_msnprintf(buf, sizeof(buf), "%ho %hx %hX %+X %+x",
1247 0xFA10U, 0xFA10U, 0xFA10U, 0xFA10, 0xFA10);
1248 errors += string_check(buf, "175020 fa10 FA10 +FA10 +fa10");
1250 curl_msnprintf(buf, sizeof(buf), "%o %x %X %+o",
1251 0xFABC1230U, 0xFABC1230U, 0xFABC1230U, 1234U);
1252 errors += string_check(buf, "37257011060 fabc1230 FABC1230 +2322");
1254#if SIZEOF_LONG == 4
1255 curl_msnprintf(buf, sizeof(buf), "%lo %lx %lX %+lo",
1256 0xFABC1230UL, 0xFABC1230UL, 0xFABC1230UL, 1234UL);
1257 errors += string_check(buf, "37257011060 fabc1230 FABC1230 +2322");
1258#elif SIZEOF_LONG == 8
1259 curl_msnprintf(buf, sizeof(buf), "%lo %lx %lX %+lo",
1260 0xFABCDEF123456780UL, 0xFABCDEF123456780UL,
1261 0xFABCDEF123456780UL, 1234UL);
1262 errors += string_check(buf, "1752746757044321263600 fabcdef123456780 "
1263 "FABCDEF123456780 +2322");
1264#endif
1266 if(!errors)
1267 curl_mprintf("All curl_mprintf() octal and hexadecimal tests OK!\n");
1268 else
1269 curl_mprintf("Some curl_mprintf() octal or hexadecimal tests Failed!\n");
1271 return errors;
1272}
1274static int test_return_codes(void)
1275{
1276 char buf[128];
1277 int rc;
1279 rc = curl_msnprintf(buf, 100, "%d", 9999);
1280 if(rc != 4)
1281 return 1;
1283 rc = curl_msnprintf(buf, 100, "%d", 99999);
1284 if(rc != 5)
1285 return 1;
1287 /* returns the length excluding the NUL byte */
1288 rc = curl_msnprintf(buf, 5, "%d", 99999);
1289 if(rc != 4)
1290 return 1;
1292 /* returns the length excluding the NUL byte */
1293 rc = curl_msnprintf(buf, 5, "%s", "helloooooooo");
1294 if(rc != 4)
1295 return 1;
1297 /* returns the length excluding the NUL byte */
1298 rc = curl_msnprintf(buf, 6, "%s", "helloooooooo");
1299 if(rc != 5)
1300 return 1;
1302 return 0;
1303}
1305/*
1306 Basic verification of the vararg versions of the printf functions:
1308 - curl_mvfprintf
1309 - curl_mvprintf
1310 - curl_mvsnprintf
1311 - curl_mvsprintf
1312 - curl_mvaprintf
1313 */
1314static int var557(int expected_len, const char *format, ...)
1315{
1316 va_list arg;
1317 int len;
1318 int errors = 1;
1319 char buffer[80];
1320 char *ptr;
1321 va_start(arg, format);
1323 len = curl_mvfprintf(stderr, format, arg);
1324 if(len != expected_len) {
1325 curl_mfprintf(stderr, "curl_mvfprintf: expected length %d but got %d\n",
1326 expected_len, len);
1327 goto error;
1328 }
1330 va_end(arg);
1331 va_start(arg, format);
1332 /* this unfortunately writes to stdout but we can't prevent it */
1333 len = curl_mvprintf(format, arg);
1334 if(len != expected_len) {
1335 curl_mfprintf(stderr, "curl_mvprintf: expected length %d but got %d\n",
1336 expected_len, len);
1337 goto error;
1338 }
1340 va_end(arg);
1341 va_start(arg, format);
1342 len = curl_mvsnprintf(buffer, sizeof(buffer), format, arg);
1343 if(len != expected_len) {
1344 curl_mfprintf(stderr, "curl_mvsnprintf: expected length %d but got %d\n",
1345 expected_len, len);
1346 goto error;
1347 }
1349 va_end(arg);
1350 va_start(arg, format);
1351 /* no buffer size, but we know it fits */
1352 len = curl_mvsprintf(buffer, format, arg);
1353 if(len != expected_len) {
1354 curl_mfprintf(stderr, "curl_mvsprintf: expected length %d but got %d\n",
1355 expected_len, len);
1356 goto error;
1357 }
1359 va_end(arg);
1360 va_start(arg, format);
1361 ptr = curl_mvaprintf(format, arg);
1362 len = ptr ? (int)strlen(ptr) : 0;
1363 curl_free(ptr);
1364 if(len != expected_len) {
1365 curl_mfprintf(stderr, "curl_mvaprintf: expected length %d but got %d\n",
1366 expected_len, len);
1367 goto error;
1368 }
1370 errors = 0; /* success */
1371error:
1372 va_end(arg);
1373 if(!errors)
1374 curl_mprintf("All v-functions test OK!\n");
1375 else
1376 curl_mprintf("The v-functions test failed!\n");
1377 return errors;
1378}
1380static int test_vversions(void)
1381{
1382 int rc = var557(51, "testing %s and %d is %s and %ld\n",
1383 "a string", -443, "super fun", (long)9876543);
1384 return rc;
1385}
1387static CURLcode test_lib557(const char *URL)
1388{
1389 int errors = 0;
1390 (void)URL;
1392#ifdef HAVE_SETLOCALE
1393 /*
1394 * The test makes assumptions about the numeric locale (specifically,
1395 * RADIXCHAR) so set it to a known working (and portable) one.
1396 */
1397 setlocale(LC_NUMERIC, "C");
1398#endif
1400 errors += test_pos_arguments();
1401 errors += test_weird_arguments();
1402 errors += test_unsigned_short_formatting();
1403 errors += test_signed_short_formatting();
1404 errors += test_unsigned_int_formatting();
1405 errors += test_signed_int_formatting();
1406 errors += test_unsigned_long_formatting();
1407 errors += test_signed_long_formatting();
1408 errors += test_curl_off_t_formatting();
1409 errors += test_string_formatting();
1410 errors += test_float_formatting();
1411 errors += test_oct_hex_formatting();
1412 errors += test_return_codes();
1413 errors += test_vversions();
1415 if(errors)
1416 return TEST_ERR_MAJOR_BAD;
1417 else
1418 return CURLE_OK;
1419}
1421#ifdef CURL_HAVE_DIAG
1422#pragma GCC diagnostic pop
1423#endif
1424#ifdef __clang__
1425#pragma clang diagnostic pop
1426#endif
Diagnostics4 git calls · 183 ms
CallStatusSizeTime0183 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch20010 KiB178 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=178 git.response.bytes=10300 git.response.cache=MISS git.response.duration_ms=178 git.fetch.wants=24cb1bfd2554d0f6e9061dbd04d5a1b438565656 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=10300 git.pkt.payload.max=10279 git.sideband.band1.bytes=10278 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e31afdcd5c3e6e
- Request
- 5637d218…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format