PageRenderTime 11ms CodeModel.GetById 4ms app.highlight 134ms RepoModel.GetById 1ms app.codeStats 0ms

/3rd-party/curl-7.20.1/tests/libtest/lib557.c

https://bitbucket.org/super119/plu2youku
C | 1388 lines | 1075 code | 301 blank | 12 comment | 50 complexity | f51b24957f13b85a681a07a79cf076f9 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*****************************************************************************
   2 *                                  _   _ ____  _
   3 *  Project                     ___| | | |  _ \| |
   4 *                             / __| | | | |_) | |
   5 *                            | (__| |_| |  _ <| |___
   6 *                             \___|\___/|_| \_\_____|
   7 *
   8 */
   9
  10/*
  11 * The purpose of this test is to minimally exercise libcurl's internal
  12 * curl_m*printf formatting capabilities and handling of some data types.
  13 */
  14
  15#include "test.h"
  16
  17#include <curl/mprintf.h>
  18
  19#include "memdebug.h"
  20
  21
  22#if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
  23#  define MPRNT_SUFFIX_CURL_OFF_T  LL
  24#else
  25#  define MPRNT_SUFFIX_CURL_OFF_T  L
  26#endif
  27
  28
  29#ifdef CURL_ISOCPP
  30#  define MPRNT_OFF_T_C_HELPER2(Val,Suffix) Val ## Suffix
  31#else
  32#  define MPRNT_OFF_T_C_HELPER2(Val,Suffix) Val/**/Suffix
  33#endif
  34#define MPRNT_OFF_T_C_HELPER1(Val,Suffix) MPRNT_OFF_T_C_HELPER2(Val,Suffix)
  35#define MPRNT_OFF_T_C(Val)  MPRNT_OFF_T_C_HELPER1(Val,MPRNT_SUFFIX_CURL_OFF_T)
  36
  37
  38#define BUFSZ    256
  39#define USHORT_TESTS_ARRSZ 1 + 100
  40#define SSHORT_TESTS_ARRSZ 1 + 100
  41#define UINT_TESTS_ARRSZ   1 + 100
  42#define SINT_TESTS_ARRSZ   1 + 100
  43#define ULONG_TESTS_ARRSZ  1 + 100
  44#define SLONG_TESTS_ARRSZ  1 + 100
  45#define COFFT_TESTS_ARRSZ  1 + 100
  46
  47
  48struct unsshort_st {
  49  unsigned short num;   /* unsigned short  */
  50  const char *expected; /* expected string */
  51  char result[BUFSZ];   /* result string   */
  52};
  53
  54
  55struct sigshort_st {
  56  short num;            /* signed short    */
  57  const char *expected; /* expected string */
  58  char result[BUFSZ];   /* result string   */
  59};
  60
  61
  62struct unsint_st {
  63  unsigned int num;     /* unsigned int    */
  64  const char *expected; /* expected string */
  65  char result[BUFSZ];   /* result string   */
  66};
  67
  68
  69struct sigint_st {
  70  int num;              /* signed int      */
  71  const char *expected; /* expected string */
  72  char result[BUFSZ];   /* result string   */
  73};
  74
  75
  76struct unslong_st {
  77  unsigned long num;    /* unsigned long   */
  78  const char *expected; /* expected string */
  79  char result[BUFSZ];   /* result string   */
  80};
  81
  82
  83struct siglong_st {
  84  long num;             /* signed long     */
  85  const char *expected; /* expected string */
  86  char result[BUFSZ];   /* result string   */
  87};
  88
  89
  90struct curloff_st {
  91  curl_off_t num;       /* curl_off_t      */
  92  const char *expected; /* expected string */
  93  char result[BUFSZ];   /* result string   */
  94};
  95
  96
  97static struct unsshort_st us_test[USHORT_TESTS_ARRSZ];
  98static struct sigshort_st ss_test[SSHORT_TESTS_ARRSZ];
  99static struct unsint_st   ui_test[UINT_TESTS_ARRSZ];
 100static struct sigint_st   si_test[SINT_TESTS_ARRSZ];
 101static struct unslong_st  ul_test[ULONG_TESTS_ARRSZ];
 102static struct siglong_st  sl_test[SLONG_TESTS_ARRSZ];
 103static struct curloff_st  co_test[COFFT_TESTS_ARRSZ];
 104
 105
 106static int test_unsigned_short_formatting(void)
 107{
 108  int i, j;
 109  int num_ushort_tests;
 110  int failed = 0;
 111
 112#if (SIZEOF_SHORT == 1)
 113
 114  i=1; us_test[i].num = 0xFFU; us_test[i].expected = "256";
 115  i++; us_test[i].num = 0xF0U; us_test[i].expected = "240";
 116  i++; us_test[i].num = 0x0FU; us_test[i].expected = "15";
 117
 118  i++; us_test[i].num = 0xE0U; us_test[i].expected = "224";
 119  i++; us_test[i].num = 0x0EU; us_test[i].expected = "14";
 120
 121  i++; us_test[i].num = 0xC0U; us_test[i].expected = "192";
 122  i++; us_test[i].num = 0x0CU; us_test[i].expected = "12";
 123
 124  i++; us_test[i].num = 0x01U; us_test[i].expected = "1";
 125  i++; us_test[i].num = 0x00U; us_test[i].expected = "0";
 126
 127  num_ushort_tests = i;
 128
 129#elif (SIZEOF_SHORT == 2)
 130
 131  i=1; us_test[i].num = 0xFFFFU; us_test[i].expected = "65535";
 132  i++; us_test[i].num = 0xFF00U; us_test[i].expected = "65280";
 133  i++; us_test[i].num = 0x00FFU; us_test[i].expected = "255";
 134
 135  i++; us_test[i].num = 0xF000U; us_test[i].expected = "61440";
 136  i++; us_test[i].num = 0x0F00U; us_test[i].expected = "3840";
 137  i++; us_test[i].num = 0x00F0U; us_test[i].expected = "240";
 138  i++; us_test[i].num = 0x000FU; us_test[i].expected = "15";
 139
 140  i++; us_test[i].num = 0xC000U; us_test[i].expected = "49152";
 141  i++; us_test[i].num = 0x0C00U; us_test[i].expected = "3072";
 142  i++; us_test[i].num = 0x00C0U; us_test[i].expected = "192";
 143  i++; us_test[i].num = 0x000CU; us_test[i].expected = "12";
 144
 145  i++; us_test[i].num = 0x0001U; us_test[i].expected = "1";
 146  i++; us_test[i].num = 0x0000U; us_test[i].expected = "0";
 147
 148  num_ushort_tests = i;
 149
 150#elif (SIZEOF_SHORT == 4)
 151
 152  i=1; us_test[i].num = 0xFFFFFFFFU; us_test[i].expected = "4294967295";
 153  i++; us_test[i].num = 0xFFFF0000U; us_test[i].expected = "4294901760";
 154  i++; us_test[i].num = 0x0000FFFFU; us_test[i].expected = "65535";
 155
 156  i++; us_test[i].num = 0xFF000000U; us_test[i].expected = "4278190080";
 157  i++; us_test[i].num = 0x00FF0000U; us_test[i].expected = "16711680";
 158  i++; us_test[i].num = 0x0000FF00U; us_test[i].expected = "65280";
 159  i++; us_test[i].num = 0x000000FFU; us_test[i].expected = "255";
 160
 161  i++; us_test[i].num = 0xF0000000U; us_test[i].expected = "4026531840";
 162  i++; us_test[i].num = 0x0F000000U; us_test[i].expected = "251658240";
 163  i++; us_test[i].num = 0x00F00000U; us_test[i].expected = "15728640";
 164  i++; us_test[i].num = 0x000F0000U; us_test[i].expected = "983040";
 165  i++; us_test[i].num = 0x0000F000U; us_test[i].expected = "61440";
 166  i++; us_test[i].num = 0x00000F00U; us_test[i].expected = "3840";
 167  i++; us_test[i].num = 0x000000F0U; us_test[i].expected = "240";
 168  i++; us_test[i].num = 0x0000000FU; us_test[i].expected = "15";
 169
 170  i++; us_test[i].num = 0xC0000000U; us_test[i].expected = "3221225472";
 171  i++; us_test[i].num = 0x0C000000U; us_test[i].expected = "201326592";
 172  i++; us_test[i].num = 0x00C00000U; us_test[i].expected = "12582912";
 173  i++; us_test[i].num = 0x000C0000U; us_test[i].expected = "786432";
 174  i++; us_test[i].num = 0x0000C000U; us_test[i].expected = "49152";
 175  i++; us_test[i].num = 0x00000C00U; us_test[i].expected = "3072";
 176  i++; us_test[i].num = 0x000000C0U; us_test[i].expected = "192";
 177  i++; us_test[i].num = 0x0000000CU; us_test[i].expected = "12";
 178
 179  i++; us_test[i].num = 0x00000001U; us_test[i].expected = "1";
 180  i++; us_test[i].num = 0x00000000U; us_test[i].expected = "0";
 181
 182  num_ushort_tests = i;
 183
 184#endif
 185
 186  for(i=1; i<=num_ushort_tests; i++) {
 187
 188    for(j=0; j<BUFSZ; j++)
 189      us_test[i].result[j] = 'X';
 190    us_test[i].result[BUFSZ-1] = '\0';
 191
 192    (void)curl_msprintf(us_test[i].result, "%hu", us_test[i].num);
 193
 194    if(memcmp(us_test[i].result,
 195               us_test[i].expected,
 196               strlen(us_test[i].expected))) {
 197      printf("unsigned short test #%.2d: Failed (Expected: %s Got: %s)\n",
 198             i, us_test[i].expected, us_test[i].result);
 199      failed++;
 200    }
 201
 202  }
 203
 204  if(!failed)
 205    printf("All curl_mprintf() unsigned short tests OK!\n");
 206  else
 207    printf("Some curl_mprintf() unsigned short tests Failed!\n");
 208
 209  return failed;
 210}
 211
 212
 213static int test_signed_short_formatting(void)
 214{
 215  int i, j;
 216  int num_sshort_tests;
 217  int failed = 0;
 218
 219#if (SIZEOF_SHORT == 1)
 220
 221  i=1; ss_test[i].num = 0x7F; ss_test[i].expected = "127";
 222
 223  i++; ss_test[i].num = 0x70; ss_test[i].expected = "112";
 224  i++; ss_test[i].num = 0x07; ss_test[i].expected = "7";
 225
 226  i++; ss_test[i].num = 0x50; ss_test[i].expected = "80";
 227  i++; ss_test[i].num = 0x05; ss_test[i].expected = "5";
 228
 229  i++; ss_test[i].num = 0x01; ss_test[i].expected = "1";
 230  i++; ss_test[i].num = 0x00; ss_test[i].expected = "0";
 231
 232  i++; ss_test[i].num = -0x7F -1; ss_test[i].expected = "-128";
 233
 234  i++; ss_test[i].num = -0x70 -1; ss_test[i].expected = "-113";
 235  i++; ss_test[i].num = -0x07 -1; ss_test[i].expected = "-8";
 236
 237  i++; ss_test[i].num = -0x50 -1; ss_test[i].expected = "-81";
 238  i++; ss_test[i].num = -0x05 -1; ss_test[i].expected = "-6";
 239
 240  i++; ss_test[i].num =  0x00 -1; ss_test[i].expected = "-1";
 241
 242  num_sshort_tests = i;
 243
 244#elif (SIZEOF_SHORT == 2)
 245
 246  i=1; ss_test[i].num = 0x7FFF; ss_test[i].expected = "32767";
 247  i++; ss_test[i].num = 0x7FFE; ss_test[i].expected = "32766";
 248  i++; ss_test[i].num = 0x7FFD; ss_test[i].expected = "32765";
 249  i++; ss_test[i].num = 0x7F00; ss_test[i].expected = "32512";
 250  i++; ss_test[i].num = 0x07F0; ss_test[i].expected = "2032";
 251  i++; ss_test[i].num = 0x007F; ss_test[i].expected = "127";
 252
 253  i++; ss_test[i].num = 0x7000; ss_test[i].expected = "28672";
 254  i++; ss_test[i].num = 0x0700; ss_test[i].expected = "1792";
 255  i++; ss_test[i].num = 0x0070; ss_test[i].expected = "112";
 256  i++; ss_test[i].num = 0x0007; ss_test[i].expected = "7";
 257
 258  i++; ss_test[i].num = 0x5000; ss_test[i].expected = "20480";
 259  i++; ss_test[i].num = 0x0500; ss_test[i].expected = "1280";
 260  i++; ss_test[i].num = 0x0050; ss_test[i].expected = "80";
 261  i++; ss_test[i].num = 0x0005; ss_test[i].expected = "5";
 262
 263  i++; ss_test[i].num = 0x0001; ss_test[i].expected = "1";
 264  i++; ss_test[i].num = 0x0000; ss_test[i].expected = "0";
 265
 266  i++; ss_test[i].num = -0x7FFF -1; ss_test[i].expected = "-32768";
 267  i++; ss_test[i].num = -0x7FFE -1; ss_test[i].expected = "-32767";
 268  i++; ss_test[i].num = -0x7FFD -1; ss_test[i].expected = "-32766";
 269  i++; ss_test[i].num = -0x7F00 -1; ss_test[i].expected = "-32513";
 270  i++; ss_test[i].num = -0x07F0 -1; ss_test[i].expected = "-2033";
 271  i++; ss_test[i].num = -0x007F -1; ss_test[i].expected = "-128";
 272
 273  i++; ss_test[i].num = -0x7000 -1; ss_test[i].expected = "-28673";
 274  i++; ss_test[i].num = -0x0700 -1; ss_test[i].expected = "-1793";
 275  i++; ss_test[i].num = -0x0070 -1; ss_test[i].expected = "-113";
 276  i++; ss_test[i].num = -0x0007 -1; ss_test[i].expected = "-8";
 277
 278  i++; ss_test[i].num = -0x5000 -1; ss_test[i].expected = "-20481";
 279  i++; ss_test[i].num = -0x0500 -1; ss_test[i].expected = "-1281";
 280  i++; ss_test[i].num = -0x0050 -1; ss_test[i].expected = "-81";
 281  i++; ss_test[i].num = -0x0005 -1; ss_test[i].expected = "-6";
 282
 283  i++; ss_test[i].num =  0x0000 -1; ss_test[i].expected = "-1";
 284
 285  num_sshort_tests = i;
 286
 287#elif (SIZEOF_SHORT == 4)
 288
 289  i=1; ss_test[i].num = 0x7FFFFFFF; ss_test[i].expected = "2147483647";
 290  i++; ss_test[i].num = 0x7FFFFFFE; ss_test[i].expected = "2147483646";
 291  i++; ss_test[i].num = 0x7FFFFFFD; ss_test[i].expected = "2147483645";
 292  i++; ss_test[i].num = 0x7FFF0000; ss_test[i].expected = "2147418112";
 293  i++; ss_test[i].num = 0x00007FFF; ss_test[i].expected = "32767";
 294
 295  i++; ss_test[i].num = 0x7F000000; ss_test[i].expected = "2130706432";
 296  i++; ss_test[i].num = 0x007F0000; ss_test[i].expected = "8323072";
 297  i++; ss_test[i].num = 0x00007F00; ss_test[i].expected = "32512";
 298  i++; ss_test[i].num = 0x0000007F; ss_test[i].expected = "127";
 299
 300  i++; ss_test[i].num = 0x70000000; ss_test[i].expected = "1879048192";
 301  i++; ss_test[i].num = 0x07000000; ss_test[i].expected = "117440512";
 302  i++; ss_test[i].num = 0x00700000; ss_test[i].expected = "7340032";
 303  i++; ss_test[i].num = 0x00070000; ss_test[i].expected = "458752";
 304  i++; ss_test[i].num = 0x00007000; ss_test[i].expected = "28672";
 305  i++; ss_test[i].num = 0x00000700; ss_test[i].expected = "1792";
 306  i++; ss_test[i].num = 0x00000070; ss_test[i].expected = "112";
 307  i++; ss_test[i].num = 0x00000007; ss_test[i].expected = "7";
 308
 309  i++; ss_test[i].num = 0x50000000; ss_test[i].expected = "1342177280";
 310  i++; ss_test[i].num = 0x05000000; ss_test[i].expected = "83886080";
 311  i++; ss_test[i].num = 0x00500000; ss_test[i].expected = "5242880";
 312  i++; ss_test[i].num = 0x00050000; ss_test[i].expected = "327680";
 313  i++; ss_test[i].num = 0x00005000; ss_test[i].expected = "20480";
 314  i++; ss_test[i].num = 0x00000500; ss_test[i].expected = "1280";
 315  i++; ss_test[i].num = 0x00000050; ss_test[i].expected = "80";
 316  i++; ss_test[i].num = 0x00000005; ss_test[i].expected = "5";
 317
 318  i++; ss_test[i].num = 0x00000001; ss_test[i].expected = "1";
 319  i++; ss_test[i].num = 0x00000000; ss_test[i].expected = "0";
 320
 321  i++; ss_test[i].num = -0x7FFFFFFF -1; ss_test[i].expected = "-2147483648";
 322  i++; ss_test[i].num = -0x7FFFFFFE -1; ss_test[i].expected = "-2147483647";
 323  i++; ss_test[i].num = -0x7FFFFFFD -1; ss_test[i].expected = "-2147483646";
 324  i++; ss_test[i].num = -0x7FFF0000 -1; ss_test[i].expected = "-2147418113";
 325  i++; ss_test[i].num = -0x00007FFF -1; ss_test[i].expected = "-32768";
 326
 327  i++; ss_test[i].num = -0x7F000000 -1; ss_test[i].expected = "-2130706433";
 328  i++; ss_test[i].num = -0x007F0000 -1; ss_test[i].expected = "-8323073";
 329  i++; ss_test[i].num = -0x00007F00 -1; ss_test[i].expected = "-32513";
 330  i++; ss_test[i].num = -0x0000007F -1; ss_test[i].expected = "-128";
 331
 332  i++; ss_test[i].num = -0x70000000 -1; ss_test[i].expected = "-1879048193";
 333  i++; ss_test[i].num = -0x07000000 -1; ss_test[i].expected = "-117440513";
 334  i++; ss_test[i].num = -0x00700000 -1; ss_test[i].expected = "-7340033";
 335  i++; ss_test[i].num = -0x00070000 -1; ss_test[i].expected = "-458753";
 336  i++; ss_test[i].num = -0x00007000 -1; ss_test[i].expected = "-28673";
 337  i++; ss_test[i].num = -0x00000700 -1; ss_test[i].expected = "-1793";
 338  i++; ss_test[i].num = -0x00000070 -1; ss_test[i].expected = "-113";
 339  i++; ss_test[i].num = -0x00000007 -1; ss_test[i].expected = "-8";
 340
 341  i++; ss_test[i].num = -0x50000000 -1; ss_test[i].expected = "-1342177281";
 342  i++; ss_test[i].num = -0x05000000 -1; ss_test[i].expected = "-83886081";
 343  i++; ss_test[i].num = -0x00500000 -1; ss_test[i].expected = "-5242881";
 344  i++; ss_test[i].num = -0x00050000 -1; ss_test[i].expected = "-327681";
 345  i++; ss_test[i].num = -0x00005000 -1; ss_test[i].expected = "-20481";
 346  i++; ss_test[i].num = -0x00000500 -1; ss_test[i].expected = "-1281";
 347  i++; ss_test[i].num = -0x00000050 -1; ss_test[i].expected = "-81";
 348  i++; ss_test[i].num = -0x00000005 -1; ss_test[i].expected = "-6";
 349
 350  i++; ss_test[i].num =  0x00000000 -1; ss_test[i].expected = "-1";
 351
 352  num_sshort_tests = i;
 353
 354#endif
 355
 356  for(i=1; i<=num_sshort_tests; i++) {
 357
 358    for(j=0; j<BUFSZ; j++)
 359      ss_test[i].result[j] = 'X';
 360    ss_test[i].result[BUFSZ-1] = '\0';
 361
 362    (void)curl_msprintf(ss_test[i].result, "%hd", ss_test[i].num);
 363
 364    if(memcmp(ss_test[i].result,
 365              ss_test[i].expected,
 366              strlen(ss_test[i].expected))) {
 367      printf("signed short test #%.2d: Failed (Expected: %s Got: %s)\n",
 368             i, ss_test[i].expected, ss_test[i].result);
 369      failed++;
 370    }
 371
 372  }
 373
 374  if(!failed)
 375    printf("All curl_mprintf() signed short tests OK!\n");
 376  else
 377    printf("Some curl_mprintf() signed short tests Failed!\n");
 378
 379  return failed;
 380}
 381
 382
 383static int test_unsigned_int_formatting(void)
 384{
 385  int i, j;
 386  int num_uint_tests;
 387  int failed = 0;
 388
 389#if (SIZEOF_INT == 2)
 390
 391  i=1; ui_test[i].num = 0xFFFFU; ui_test[i].expected = "65535";
 392  i++; ui_test[i].num = 0xFF00U; ui_test[i].expected = "65280";
 393  i++; ui_test[i].num = 0x00FFU; ui_test[i].expected = "255";
 394
 395  i++; ui_test[i].num = 0xF000U; ui_test[i].expected = "61440";
 396  i++; ui_test[i].num = 0x0F00U; ui_test[i].expected = "3840";
 397  i++; ui_test[i].num = 0x00F0U; ui_test[i].expected = "240";
 398  i++; ui_test[i].num = 0x000FU; ui_test[i].expected = "15";
 399
 400  i++; ui_test[i].num = 0xC000U; ui_test[i].expected = "49152";
 401  i++; ui_test[i].num = 0x0C00U; ui_test[i].expected = "3072";
 402  i++; ui_test[i].num = 0x00C0U; ui_test[i].expected = "192";
 403  i++; ui_test[i].num = 0x000CU; ui_test[i].expected = "12";
 404
 405  i++; ui_test[i].num = 0x0001U; ui_test[i].expected = "1";
 406  i++; ui_test[i].num = 0x0000U; ui_test[i].expected = "0";
 407
 408  num_uint_tests = i;
 409
 410#elif (SIZEOF_INT == 4)
 411
 412  i=1; ui_test[i].num = 0xFFFFFFFFU; ui_test[i].expected = "4294967295";
 413  i++; ui_test[i].num = 0xFFFF0000U; ui_test[i].expected = "4294901760";
 414  i++; ui_test[i].num = 0x0000FFFFU; ui_test[i].expected = "65535";
 415
 416  i++; ui_test[i].num = 0xFF000000U; ui_test[i].expected = "4278190080";
 417  i++; ui_test[i].num = 0x00FF0000U; ui_test[i].expected = "16711680";
 418  i++; ui_test[i].num = 0x0000FF00U; ui_test[i].expected = "65280";
 419  i++; ui_test[i].num = 0x000000FFU; ui_test[i].expected = "255";
 420
 421  i++; ui_test[i].num = 0xF0000000U; ui_test[i].expected = "4026531840";
 422  i++; ui_test[i].num = 0x0F000000U; ui_test[i].expected = "251658240";
 423  i++; ui_test[i].num = 0x00F00000U; ui_test[i].expected = "15728640";
 424  i++; ui_test[i].num = 0x000F0000U; ui_test[i].expected = "983040";
 425  i++; ui_test[i].num = 0x0000F000U; ui_test[i].expected = "61440";
 426  i++; ui_test[i].num = 0x00000F00U; ui_test[i].expected = "3840";
 427  i++; ui_test[i].num = 0x000000F0U; ui_test[i].expected = "240";
 428  i++; ui_test[i].num = 0x0000000FU; ui_test[i].expected = "15";
 429
 430  i++; ui_test[i].num = 0xC0000000U; ui_test[i].expected = "3221225472";
 431  i++; ui_test[i].num = 0x0C000000U; ui_test[i].expected = "201326592";
 432  i++; ui_test[i].num = 0x00C00000U; ui_test[i].expected = "12582912";
 433  i++; ui_test[i].num = 0x000C0000U; ui_test[i].expected = "786432";
 434  i++; ui_test[i].num = 0x0000C000U; ui_test[i].expected = "49152";
 435  i++; ui_test[i].num = 0x00000C00U; ui_test[i].expected = "3072";
 436  i++; ui_test[i].num = 0x000000C0U; ui_test[i].expected = "192";
 437  i++; ui_test[i].num = 0x0000000CU; ui_test[i].expected = "12";
 438
 439  i++; ui_test[i].num = 0x00000001U; ui_test[i].expected = "1";
 440  i++; ui_test[i].num = 0x00000000U; ui_test[i].expected = "0";
 441
 442  num_uint_tests = i;
 443
 444#elif (SIZEOF_INT == 8)
 445
 446  i=1; ui_test[i].num = 0xFFFFFFFFFFFFFFFFU; ui_test[i].expected = "18446744073709551615";
 447  i++; ui_test[i].num = 0xFFFFFFFF00000000U; ui_test[i].expected = "18446744069414584320";
 448  i++; ui_test[i].num = 0x00000000FFFFFFFFU; ui_test[i].expected = "4294967295";
 449
 450  i++; ui_test[i].num = 0xFFFF000000000000U; ui_test[i].expected = "18446462598732840960";
 451  i++; ui_test[i].num = 0x0000FFFF00000000U; ui_test[i].expected = "281470681743360";
 452  i++; ui_test[i].num = 0x00000000FFFF0000U; ui_test[i].expected = "4294901760";
 453  i++; ui_test[i].num = 0x000000000000FFFFU; ui_test[i].expected = "65535";
 454
 455  i++; ui_test[i].num = 0xFF00000000000000U; ui_test[i].expected = "18374686479671623680";
 456  i++; ui_test[i].num = 0x00FF000000000000U; ui_test[i].expected = "71776119061217280";
 457  i++; ui_test[i].num = 0x0000FF0000000000U; ui_test[i].expected = "280375465082880";
 458  i++; ui_test[i].num = 0x000000FF00000000U; ui_test[i].expected = "1095216660480";
 459  i++; ui_test[i].num = 0x00000000FF000000U; ui_test[i].expected = "4278190080";
 460  i++; ui_test[i].num = 0x0000000000FF0000U; ui_test[i].expected = "16711680";
 461  i++; ui_test[i].num = 0x000000000000FF00U; ui_test[i].expected = "65280";
 462  i++; ui_test[i].num = 0x00000000000000FFU; ui_test[i].expected = "255";
 463
 464  i++; ui_test[i].num = 0xF000000000000000U; ui_test[i].expected = "17293822569102704640";
 465  i++; ui_test[i].num = 0x0F00000000000000U; ui_test[i].expected = "1080863910568919040";
 466  i++; ui_test[i].num = 0x00F0000000000000U; ui_test[i].expected = "67553994410557440";
 467  i++; ui_test[i].num = 0x000F000000000000U; ui_test[i].expected = "4222124650659840";
 468  i++; ui_test[i].num = 0x0000F00000000000U; ui_test[i].expected = "263882790666240";
 469  i++; ui_test[i].num = 0x00000F0000000000U; ui_test[i].expected = "16492674416640";
 470  i++; ui_test[i].num = 0x000000F000000000U; ui_test[i].expected = "1030792151040";
 471  i++; ui_test[i].num = 0x0000000F00000000U; ui_test[i].expected = "64424509440";
 472  i++; ui_test[i].num = 0x00000000F0000000U; ui_test[i].expected = "4026531840";
 473  i++; ui_test[i].num = 0x000000000F000000U; ui_test[i].expected = "251658240";
 474  i++; ui_test[i].num = 0x0000000000F00000U; ui_test[i].expected = "15728640";
 475  i++; ui_test[i].num = 0x00000000000F0000U; ui_test[i].expected = "983040";
 476  i++; ui_test[i].num = 0x000000000000F000U; ui_test[i].expected = "61440";
 477  i++; ui_test[i].num = 0x0000000000000F00U; ui_test[i].expected = "3840";
 478  i++; ui_test[i].num = 0x00000000000000F0U; ui_test[i].expected = "240";
 479  i++; ui_test[i].num = 0x000000000000000FU; ui_test[i].expected = "15";
 480
 481  i++; ui_test[i].num = 0xC000000000000000U; ui_test[i].expected = "13835058055282163712";
 482  i++; ui_test[i].num = 0x0C00000000000000U; ui_test[i].expected = "864691128455135232";
 483  i++; ui_test[i].num = 0x00C0000000000000U; ui_test[i].expected = "54043195528445952";
 484  i++; ui_test[i].num = 0x000C000000000000U; ui_test[i].expected = "3377699720527872";
 485  i++; ui_test[i].num = 0x0000C00000000000U; ui_test[i].expected = "211106232532992";
 486  i++; ui_test[i].num = 0x00000C0000000000U; ui_test[i].expected = "13194139533312";
 487  i++; ui_test[i].num = 0x000000C000000000U; ui_test[i].expected = "824633720832";
 488  i++; ui_test[i].num = 0x0000000C00000000U; ui_test[i].expected = "51539607552";
 489  i++; ui_test[i].num = 0x00000000C0000000U; ui_test[i].expected = "3221225472";
 490  i++; ui_test[i].num = 0x000000000C000000U; ui_test[i].expected = "201326592";
 491  i++; ui_test[i].num = 0x0000000000C00000U; ui_test[i].expected = "12582912";
 492  i++; ui_test[i].num = 0x00000000000C0000U; ui_test[i].expected = "786432";
 493  i++; ui_test[i].num = 0x000000000000C000U; ui_test[i].expected = "49152";
 494  i++; ui_test[i].num = 0x0000000000000C00U; ui_test[i].expected = "3072";
 495  i++; ui_test[i].num = 0x00000000000000C0U; ui_test[i].expected = "192";
 496  i++; ui_test[i].num = 0x000000000000000CU; ui_test[i].expected = "12";
 497
 498  i++; ui_test[i].num = 0x00000001U; ui_test[i].expected = "1";
 499  i++; ui_test[i].num = 0x00000000U; ui_test[i].expected = "0";
 500
 501  num_uint_tests = i;
 502
 503#endif
 504
 505  for(i=1; i<=num_uint_tests; i++) {
 506
 507    for(j=0; j<BUFSZ; j++)
 508      ui_test[i].result[j] = 'X';
 509    ui_test[i].result[BUFSZ-1] = '\0';
 510
 511    (void)curl_msprintf(ui_test[i].result, "%u", ui_test[i].num);
 512
 513    if(memcmp(ui_test[i].result,
 514               ui_test[i].expected,
 515               strlen(ui_test[i].expected))) {
 516      printf("unsigned int test #%.2d: Failed (Expected: %s Got: %s)\n",
 517             i, ui_test[i].expected, ui_test[i].result);
 518      failed++;
 519    }
 520
 521  }
 522
 523  if(!failed)
 524    printf("All curl_mprintf() unsigned int tests OK!\n");
 525  else
 526    printf("Some curl_mprintf() unsigned int tests Failed!\n");
 527
 528  return failed;
 529}
 530
 531
 532static int test_signed_int_formatting(void)
 533{
 534  int i, j;
 535  int num_sint_tests;
 536  int failed = 0;
 537
 538#if (SIZEOF_INT == 2)
 539
 540  i=1; si_test[i].num = 0x7FFF; si_test[i].expected = "32767";
 541  i++; si_test[i].num = 0x7FFE; si_test[i].expected = "32766";
 542  i++; si_test[i].num = 0x7FFD; si_test[i].expected = "32765";
 543  i++; si_test[i].num = 0x7F00; si_test[i].expected = "32512";
 544  i++; si_test[i].num = 0x07F0; si_test[i].expected = "2032";
 545  i++; si_test[i].num = 0x007F; si_test[i].expected = "127";
 546
 547  i++; si_test[i].num = 0x7000; si_test[i].expected = "28672";
 548  i++; si_test[i].num = 0x0700; si_test[i].expected = "1792";
 549  i++; si_test[i].num = 0x0070; si_test[i].expected = "112";
 550  i++; si_test[i].num = 0x0007; si_test[i].expected = "7";
 551
 552  i++; si_test[i].num = 0x5000; si_test[i].expected = "20480";
 553  i++; si_test[i].num = 0x0500; si_test[i].expected = "1280";
 554  i++; si_test[i].num = 0x0050; si_test[i].expected = "80";
 555  i++; si_test[i].num = 0x0005; si_test[i].expected = "5";
 556
 557  i++; si_test[i].num = 0x0001; si_test[i].expected = "1";
 558  i++; si_test[i].num = 0x0000; si_test[i].expected = "0";
 559
 560  i++; si_test[i].num = -0x7FFF -1; si_test[i].expected = "-32768";
 561  i++; si_test[i].num = -0x7FFE -1; si_test[i].expected = "-32767";
 562  i++; si_test[i].num = -0x7FFD -1; si_test[i].expected = "-32766";
 563  i++; si_test[i].num = -0x7F00 -1; si_test[i].expected = "-32513";
 564  i++; si_test[i].num = -0x07F0 -1; si_test[i].expected = "-2033";
 565  i++; si_test[i].num = -0x007F -1; si_test[i].expected = "-128";
 566
 567  i++; si_test[i].num = -0x7000 -1; si_test[i].expected = "-28673";
 568  i++; si_test[i].num = -0x0700 -1; si_test[i].expected = "-1793";
 569  i++; si_test[i].num = -0x0070 -1; si_test[i].expected = "-113";
 570  i++; si_test[i].num = -0x0007 -1; si_test[i].expected = "-8";
 571
 572  i++; si_test[i].num = -0x5000 -1; si_test[i].expected = "-20481";
 573  i++; si_test[i].num = -0x0500 -1; si_test[i].expected = "-1281";
 574  i++; si_test[i].num = -0x0050 -1; si_test[i].expected = "-81";
 575  i++; si_test[i].num = -0x0005 -1; si_test[i].expected = "-6";
 576
 577  i++; si_test[i].num =  0x0000 -1; si_test[i].expected = "-1";
 578
 579  num_sint_tests = i;
 580
 581#elif (SIZEOF_INT == 4)
 582
 583  i=1; si_test[i].num = 0x7FFFFFFF; si_test[i].expected = "2147483647";
 584  i++; si_test[i].num = 0x7FFFFFFE; si_test[i].expected = "2147483646";
 585  i++; si_test[i].num = 0x7FFFFFFD; si_test[i].expected = "2147483645";
 586  i++; si_test[i].num = 0x7FFF0000; si_test[i].expected = "2147418112";
 587  i++; si_test[i].num = 0x00007FFF; si_test[i].expected = "32767";
 588
 589  i++; si_test[i].num = 0x7F000000; si_test[i].expected = "2130706432";
 590  i++; si_test[i].num = 0x007F0000; si_test[i].expected = "8323072";
 591  i++; si_test[i].num = 0x00007F00; si_test[i].expected = "32512";
 592  i++; si_test[i].num = 0x0000007F; si_test[i].expected = "127";
 593
 594  i++; si_test[i].num = 0x70000000; si_test[i].expected = "1879048192";
 595  i++; si_test[i].num = 0x07000000; si_test[i].expected = "117440512";
 596  i++; si_test[i].num = 0x00700000; si_test[i].expected = "7340032";
 597  i++; si_test[i].num = 0x00070000; si_test[i].expected = "458752";
 598  i++; si_test[i].num = 0x00007000; si_test[i].expected = "28672";
 599  i++; si_test[i].num = 0x00000700; si_test[i].expected = "1792";
 600  i++; si_test[i].num = 0x00000070; si_test[i].expected = "112";
 601  i++; si_test[i].num = 0x00000007; si_test[i].expected = "7";
 602
 603  i++; si_test[i].num = 0x50000000; si_test[i].expected = "1342177280";
 604  i++; si_test[i].num = 0x05000000; si_test[i].expected = "83886080";
 605  i++; si_test[i].num = 0x00500000; si_test[i].expected = "5242880";
 606  i++; si_test[i].num = 0x00050000; si_test[i].expected = "327680";
 607  i++; si_test[i].num = 0x00005000; si_test[i].expected = "20480";
 608  i++; si_test[i].num = 0x00000500; si_test[i].expected = "1280";
 609  i++; si_test[i].num = 0x00000050; si_test[i].expected = "80";
 610  i++; si_test[i].num = 0x00000005; si_test[i].expected = "5";
 611
 612  i++; si_test[i].num = 0x00000001; si_test[i].expected = "1";
 613  i++; si_test[i].num = 0x00000000; si_test[i].expected = "0";
 614
 615  i++; si_test[i].num = -0x7FFFFFFF -1; si_test[i].expected = "-2147483648";
 616  i++; si_test[i].num = -0x7FFFFFFE -1; si_test[i].expected = "-2147483647";
 617  i++; si_test[i].num = -0x7FFFFFFD -1; si_test[i].expected = "-2147483646";
 618  i++; si_test[i].num = -0x7FFF0000 -1; si_test[i].expected = "-2147418113";
 619  i++; si_test[i].num = -0x00007FFF -1; si_test[i].expected = "-32768";
 620
 621  i++; si_test[i].num = -0x7F000000 -1; si_test[i].expected = "-2130706433";
 622  i++; si_test[i].num = -0x007F0000 -1; si_test[i].expected = "-8323073";
 623  i++; si_test[i].num = -0x00007F00 -1; si_test[i].expected = "-32513";
 624  i++; si_test[i].num = -0x0000007F -1; si_test[i].expected = "-128";
 625
 626  i++; si_test[i].num = -0x70000000 -1; si_test[i].expected = "-1879048193";
 627  i++; si_test[i].num = -0x07000000 -1; si_test[i].expected = "-117440513";
 628  i++; si_test[i].num = -0x00700000 -1; si_test[i].expected = "-7340033";
 629  i++; si_test[i].num = -0x00070000 -1; si_test[i].expected = "-458753";
 630  i++; si_test[i].num = -0x00007000 -1; si_test[i].expected = "-28673";
 631  i++; si_test[i].num = -0x00000700 -1; si_test[i].expected = "-1793";
 632  i++; si_test[i].num = -0x00000070 -1; si_test[i].expected = "-113";
 633  i++; si_test[i].num = -0x00000007 -1; si_test[i].expected = "-8";
 634
 635  i++; si_test[i].num = -0x50000000 -1; si_test[i].expected = "-1342177281";
 636  i++; si_test[i].num = -0x05000000 -1; si_test[i].expected = "-83886081";
 637  i++; si_test[i].num = -0x00500000 -1; si_test[i].expected = "-5242881";
 638  i++; si_test[i].num = -0x00050000 -1; si_test[i].expected = "-327681";
 639  i++; si_test[i].num = -0x00005000 -1; si_test[i].expected = "-20481";
 640  i++; si_test[i].num = -0x00000500 -1; si_test[i].expected = "-1281";
 641  i++; si_test[i].num = -0x00000050 -1; si_test[i].expected = "-81";
 642  i++; si_test[i].num = -0x00000005 -1; si_test[i].expected = "-6";
 643
 644  i++; si_test[i].num =  0x00000000 -1; si_test[i].expected = "-1";
 645
 646  num_sint_tests = i;
 647
 648#elif (SIZEOF_INT == 8)
 649
 650  i=1; si_test[i].num = 0x7FFFFFFFFFFFFFFF; si_test[i].expected = "9223372036854775807";
 651  i++; si_test[i].num = 0x7FFFFFFFFFFFFFFE; si_test[i].expected = "9223372036854775806";
 652  i++; si_test[i].num = 0x7FFFFFFFFFFFFFFD; si_test[i].expected = "9223372036854775805";
 653  i++; si_test[i].num = 0x7FFFFFFF00000000; si_test[i].expected = "9223372032559808512";
 654  i++; si_test[i].num = 0x000000007FFFFFFF; si_test[i].expected = "2147483647";
 655
 656  i++; si_test[i].num = 0x7FFF000000000000; si_test[i].expected = "9223090561878065152";
 657  i++; si_test[i].num = 0x00007FFF00000000; si_test[i].expected = "140733193388032";
 658  i++; si_test[i].num = 0x000000007FFF0000; si_test[i].expected = "2147418112";
 659  i++; si_test[i].num = 0x0000000000007FFF; si_test[i].expected = "32767";
 660
 661  i++; si_test[i].num = 0x7F00000000000000; si_test[i].expected = "9151314442816847872";
 662  i++; si_test[i].num = 0x007F000000000000; si_test[i].expected = "35747322042253312";
 663  i++; si_test[i].num = 0x00007F0000000000; si_test[i].expected = "139637976727552";
 664  i++; si_test[i].num = 0x0000007F00000000; si_test[i].expected = "545460846592";
 665  i++; si_test[i].num = 0x000000007F000000; si_test[i].expected = "2130706432";
 666  i++; si_test[i].num = 0x00000000007F0000; si_test[i].expected = "8323072";
 667  i++; si_test[i].num = 0x0000000000007F00; si_test[i].expected = "32512";
 668  i++; si_test[i].num = 0x000000000000007F; si_test[i].expected = "127";
 669
 670  i++; si_test[i].num = 0x7000000000000000; si_test[i].expected = "8070450532247928832";
 671  i++; si_test[i].num = 0x0700000000000000; si_test[i].expected = "504403158265495552";
 672  i++; si_test[i].num = 0x0070000000000000; si_test[i].expected = "31525197391593472";
 673  i++; si_test[i].num = 0x0007000000000000; si_test[i].expected = "1970324836974592";
 674  i++; si_test[i].num = 0x0000700000000000; si_test[i].expected = "123145302310912";
 675  i++; si_test[i].num = 0x0000070000000000; si_test[i].expected = "7696581394432";
 676  i++; si_test[i].num = 0x0000007000000000; si_test[i].expected = "481036337152";
 677  i++; si_test[i].num = 0x0000000700000000; si_test[i].expected = "30064771072";
 678  i++; si_test[i].num = 0x0000000070000000; si_test[i].expected = "1879048192";
 679  i++; si_test[i].num = 0x0000000007000000; si_test[i].expected = "117440512";
 680  i++; si_test[i].num = 0x0000000000700000; si_test[i].expected = "7340032";
 681  i++; si_test[i].num = 0x0000000000070000; si_test[i].expected = "458752";
 682  i++; si_test[i].num = 0x0000000000007000; si_test[i].expected = "28672";
 683  i++; si_test[i].num = 0x0000000000000700; si_test[i].expected = "1792";
 684  i++; si_test[i].num = 0x0000000000000070; si_test[i].expected = "112";
 685  i++; si_test[i].num = 0x0000000000000007; si_test[i].expected = "7";
 686
 687  i++; si_test[i].num = 0x0000000000000001; si_test[i].expected = "1";
 688  i++; si_test[i].num = 0x0000000000000000; si_test[i].expected = "0";
 689
 690  i++; si_test[i].num = -0x7FFFFFFFFFFFFFFF -1; si_test[i].expected = "-9223372036854775808";
 691  i++; si_test[i].num = -0x7FFFFFFFFFFFFFFE -1; si_test[i].expected = "-9223372036854775807";
 692  i++; si_test[i].num = -0x7FFFFFFFFFFFFFFD -1; si_test[i].expected = "-9223372036854775806";
 693  i++; si_test[i].num = -0x7FFFFFFF00000000 -1; si_test[i].expected = "-9223372032559808513";
 694  i++; si_test[i].num = -0x000000007FFFFFFF -1; si_test[i].expected = "-2147483648";
 695
 696  i++; si_test[i].num = -0x7FFF000000000000 -1; si_test[i].expected = "-9223090561878065153";
 697  i++; si_test[i].num = -0x00007FFF00000000 -1; si_test[i].expected = "-140733193388033";
 698  i++; si_test[i].num = -0x000000007FFF0000 -1; si_test[i].expected = "-2147418113";
 699  i++; si_test[i].num = -0x0000000000007FFF -1; si_test[i].expected = "-32768";
 700
 701  i++; si_test[i].num = -0x7F00000000000000 -1; si_test[i].expected = "-9151314442816847873";
 702  i++; si_test[i].num = -0x007F000000000000 -1; si_test[i].expected = "-35747322042253313";
 703  i++; si_test[i].num = -0x00007F0000000000 -1; si_test[i].expected = "-139637976727553";
 704  i++; si_test[i].num = -0x0000007F00000000 -1; si_test[i].expected = "-545460846593";
 705  i++; si_test[i].num = -0x000000007F000000 -1; si_test[i].expected = "-2130706433";
 706  i++; si_test[i].num = -0x00000000007F0000 -1; si_test[i].expected = "-8323073";
 707  i++; si_test[i].num = -0x0000000000007F00 -1; si_test[i].expected = "-32513";
 708  i++; si_test[i].num = -0x000000000000007F -1; si_test[i].expected = "-128";
 709
 710  i++; si_test[i].num = -0x7000000000000000 -1; si_test[i].expected = "-8070450532247928833";
 711  i++; si_test[i].num = -0x0700000000000000 -1; si_test[i].expected = "-504403158265495553";
 712  i++; si_test[i].num = -0x0070000000000000 -1; si_test[i].expected = "-31525197391593473";
 713  i++; si_test[i].num = -0x0007000000000000 -1; si_test[i].expected = "-1970324836974593";
 714  i++; si_test[i].num = -0x0000700000000000 -1; si_test[i].expected = "-123145302310913";
 715  i++; si_test[i].num = -0x0000070000000000 -1; si_test[i].expected = "-7696581394433";
 716  i++; si_test[i].num = -0x0000007000000000 -1; si_test[i].expected = "-481036337153";
 717  i++; si_test[i].num = -0x0000000700000000 -1; si_test[i].expected = "-30064771073";
 718  i++; si_test[i].num = -0x0000000070000000 -1; si_test[i].expected = "-1879048193";
 719  i++; si_test[i].num = -0x0000000007000000 -1; si_test[i].expected = "-117440513";
 720  i++; si_test[i].num = -0x0000000000700000 -1; si_test[i].expected = "-7340033";
 721  i++; si_test[i].num = -0x0000000000070000 -1; si_test[i].expected = "-458753";
 722  i++; si_test[i].num = -0x0000000000007000 -1; si_test[i].expected = "-28673";
 723  i++; si_test[i].num = -0x0000000000000700 -1; si_test[i].expected = "-1793";
 724  i++; si_test[i].num = -0x0000000000000070 -1; si_test[i].expected = "-113";
 725  i++; si_test[i].num = -0x0000000000000007 -1; si_test[i].expected = "-8";
 726
 727  i++; si_test[i].num =  0x0000000000000000 -1; si_test[i].expected = "-1";
 728
 729  num_sint_tests = i;
 730
 731#endif
 732
 733  for(i=1; i<=num_sint_tests; i++) {
 734
 735    for(j=0; j<BUFSZ; j++)
 736      si_test[i].result[j] = 'X';
 737    si_test[i].result[BUFSZ-1] = '\0';
 738
 739    (void)curl_msprintf(si_test[i].result, "%d", si_test[i].num);
 740
 741    if(memcmp(si_test[i].result,
 742              si_test[i].expected,
 743              strlen(si_test[i].expected))) {
 744      printf("signed int test #%.2d: Failed (Expected: %s Got: %s)\n",
 745             i, si_test[i].expected, si_test[i].result);
 746      failed++;
 747    }
 748
 749  }
 750
 751  if(!failed)
 752    printf("All curl_mprintf() signed int tests OK!\n");
 753  else
 754    printf("Some curl_mprintf() signed int tests Failed!\n");
 755
 756  return failed;
 757}
 758
 759
 760static int test_unsigned_long_formatting(void)
 761{
 762  int i, j;
 763  int num_ulong_tests;
 764  int failed = 0;
 765
 766#if (CURL_SIZEOF_LONG == 2)
 767
 768  i=1; ul_test[i].num = 0xFFFFUL; ul_test[i].expected = "65535";
 769  i++; ul_test[i].num = 0xFF00UL; ul_test[i].expected = "65280";
 770  i++; ul_test[i].num = 0x00FFUL; ul_test[i].expected = "255";
 771
 772  i++; ul_test[i].num = 0xF000UL; ul_test[i].expected = "61440";
 773  i++; ul_test[i].num = 0x0F00UL; ul_test[i].expected = "3840";
 774  i++; ul_test[i].num = 0x00F0UL; ul_test[i].expected = "240";
 775  i++; ul_test[i].num = 0x000FUL; ul_test[i].expected = "15";
 776
 777  i++; ul_test[i].num = 0xC000UL; ul_test[i].expected = "49152";
 778  i++; ul_test[i].num = 0x0C00UL; ul_test[i].expected = "3072";
 779  i++; ul_test[i].num = 0x00C0UL; ul_test[i].expected = "192";
 780  i++; ul_test[i].num = 0x000CUL; ul_test[i].expected = "12";
 781
 782  i++; ul_test[i].num = 0x0001UL; ul_test[i].expected = "1";
 783  i++; ul_test[i].num = 0x0000UL; ul_test[i].expected = "0";
 784
 785  num_ulong_tests = i;
 786
 787#elif (CURL_SIZEOF_LONG == 4)
 788
 789  i=1; ul_test[i].num = 0xFFFFFFFFUL; ul_test[i].expected = "4294967295";
 790  i++; ul_test[i].num = 0xFFFF0000UL; ul_test[i].expected = "4294901760";
 791  i++; ul_test[i].num = 0x0000FFFFUL; ul_test[i].expected = "65535";
 792
 793  i++; ul_test[i].num = 0xFF000000UL; ul_test[i].expected = "4278190080";
 794  i++; ul_test[i].num = 0x00FF0000UL; ul_test[i].expected = "16711680";
 795  i++; ul_test[i].num = 0x0000FF00UL; ul_test[i].expected = "65280";
 796  i++; ul_test[i].num = 0x000000FFUL; ul_test[i].expected = "255";
 797
 798  i++; ul_test[i].num = 0xF0000000UL; ul_test[i].expected = "4026531840";
 799  i++; ul_test[i].num = 0x0F000000UL; ul_test[i].expected = "251658240";
 800  i++; ul_test[i].num = 0x00F00000UL; ul_test[i].expected = "15728640";
 801  i++; ul_test[i].num = 0x000F0000UL; ul_test[i].expected = "983040";
 802  i++; ul_test[i].num = 0x0000F000UL; ul_test[i].expected = "61440";
 803  i++; ul_test[i].num = 0x00000F00UL; ul_test[i].expected = "3840";
 804  i++; ul_test[i].num = 0x000000F0UL; ul_test[i].expected = "240";
 805  i++; ul_test[i].num = 0x0000000FUL; ul_test[i].expected = "15";
 806
 807  i++; ul_test[i].num = 0xC0000000UL; ul_test[i].expected = "3221225472";
 808  i++; ul_test[i].num = 0x0C000000UL; ul_test[i].expected = "201326592";
 809  i++; ul_test[i].num = 0x00C00000UL; ul_test[i].expected = "12582912";
 810  i++; ul_test[i].num = 0x000C0000UL; ul_test[i].expected = "786432";
 811  i++; ul_test[i].num = 0x0000C000UL; ul_test[i].expected = "49152";
 812  i++; ul_test[i].num = 0x00000C00UL; ul_test[i].expected = "3072";
 813  i++; ul_test[i].num = 0x000000C0UL; ul_test[i].expected = "192";
 814  i++; ul_test[i].num = 0x0000000CUL; ul_test[i].expected = "12";
 815
 816  i++; ul_test[i].num = 0x00000001UL; ul_test[i].expected = "1";
 817  i++; ul_test[i].num = 0x00000000UL; ul_test[i].expected = "0";
 818
 819  num_ulong_tests = i;
 820
 821#elif (CURL_SIZEOF_LONG == 8)
 822
 823  i=1; ul_test[i].num = 0xFFFFFFFFFFFFFFFFUL; ul_test[i].expected = "18446744073709551615";
 824  i++; ul_test[i].num = 0xFFFFFFFF00000000UL; ul_test[i].expected = "18446744069414584320";
 825  i++; ul_test[i].num = 0x00000000FFFFFFFFUL; ul_test[i].expected = "4294967295";
 826
 827  i++; ul_test[i].num = 0xFFFF000000000000UL; ul_test[i].expected = "18446462598732840960";
 828  i++; ul_test[i].num = 0x0000FFFF00000000UL; ul_test[i].expected = "281470681743360";
 829  i++; ul_test[i].num = 0x00000000FFFF0000UL; ul_test[i].expected = "4294901760";
 830  i++; ul_test[i].num = 0x000000000000FFFFUL; ul_test[i].expected = "65535";
 831
 832  i++; ul_test[i].num = 0xFF00000000000000UL; ul_test[i].expected = "18374686479671623680";
 833  i++; ul_test[i].num = 0x00FF000000000000UL; ul_test[i].expected = "71776119061217280";
 834  i++; ul_test[i].num = 0x0000FF0000000000UL; ul_test[i].expected = "280375465082880";
 835  i++; ul_test[i].num = 0x000000FF00000000UL; ul_test[i].expected = "1095216660480";
 836  i++; ul_test[i].num = 0x00000000FF000000UL; ul_test[i].expected = "4278190080";
 837  i++; ul_test[i].num = 0x0000000000FF0000UL; ul_test[i].expected = "16711680";
 838  i++; ul_test[i].num = 0x000000000000FF00UL; ul_test[i].expected = "65280";
 839  i++; ul_test[i].num = 0x00000000000000FFUL; ul_test[i].expected = "255";
 840
 841  i++; ul_test[i].num = 0xF000000000000000UL; ul_test[i].expected = "17293822569102704640";
 842  i++; ul_test[i].num = 0x0F00000000000000UL; ul_test[i].expected = "1080863910568919040";
 843  i++; ul_test[i].num = 0x00F0000000000000UL; ul_test[i].expected = "67553994410557440";
 844  i++; ul_test[i].num = 0x000F000000000000UL; ul_test[i].expected = "4222124650659840";
 845  i++; ul_test[i].num = 0x0000F00000000000UL; ul_test[i].expected = "263882790666240";
 846  i++; ul_test[i].num = 0x00000F0000000000UL; ul_test[i].expected = "16492674416640";
 847  i++; ul_test[i].num = 0x000000F000000000UL; ul_test[i].expected = "1030792151040";
 848  i++; ul_test[i].num = 0x0000000F00000000UL; ul_test[i].expected = "64424509440";
 849  i++; ul_test[i].num = 0x00000000F0000000UL; ul_test[i].expected = "4026531840";
 850  i++; ul_test[i].num = 0x000000000F000000UL; ul_test[i].expected = "251658240";
 851  i++; ul_test[i].num = 0x0000000000F00000UL; ul_test[i].expected = "15728640";
 852  i++; ul_test[i].num = 0x00000000000F0000UL; ul_test[i].expected = "983040";
 853  i++; ul_test[i].num = 0x000000000000F000UL; ul_test[i].expected = "61440";
 854  i++; ul_test[i].num = 0x0000000000000F00UL; ul_test[i].expected = "3840";
 855  i++; ul_test[i].num = 0x00000000000000F0UL; ul_test[i].expected = "240";
 856  i++; ul_test[i].num = 0x000000000000000FUL; ul_test[i].expected = "15";
 857
 858  i++; ul_test[i].num = 0xC000000000000000UL; ul_test[i].expected = "13835058055282163712";
 859  i++; ul_test[i].num = 0x0C00000000000000UL; ul_test[i].expected = "864691128455135232";
 860  i++; ul_test[i].num = 0x00C0000000000000UL; ul_test[i].expected = "54043195528445952";
 861  i++; ul_test[i].num = 0x000C000000000000UL; ul_test[i].expected = "3377699720527872";
 862  i++; ul_test[i].num = 0x0000C00000000000UL; ul_test[i].expected = "211106232532992";
 863  i++; ul_test[i].num = 0x00000C0000000000UL; ul_test[i].expected = "13194139533312";
 864  i++; ul_test[i].num = 0x000000C000000000UL; ul_test[i].expected = "824633720832";
 865  i++; ul_test[i].num = 0x0000000C00000000UL; ul_test[i].expected = "51539607552";
 866  i++; ul_test[i].num = 0x00000000C0000000UL; ul_test[i].expected = "3221225472";
 867  i++; ul_test[i].num = 0x000000000C000000UL; ul_test[i].expected = "201326592";
 868  i++; ul_test[i].num = 0x0000000000C00000UL; ul_test[i].expected = "12582912";
 869  i++; ul_test[i].num = 0x00000000000C0000UL; ul_test[i].expected = "786432";
 870  i++; ul_test[i].num = 0x000000000000C000UL; ul_test[i].expected = "49152";
 871  i++; ul_test[i].num = 0x0000000000000C00UL; ul_test[i].expected = "3072";
 872  i++; ul_test[i].num = 0x00000000000000C0UL; ul_test[i].expected = "192";
 873  i++; ul_test[i].num = 0x000000000000000CUL; ul_test[i].expected = "12";
 874
 875  i++; ul_test[i].num = 0x00000001UL; ul_test[i].expected = "1";
 876  i++; ul_test[i].num = 0x00000000UL; ul_test[i].expected = "0";
 877
 878  num_ulong_tests = i;
 879
 880#endif
 881
 882  for(i=1; i<=num_ulong_tests; i++) {
 883
 884    for(j=0; j<BUFSZ; j++)
 885      ul_test[i].result[j] = 'X';
 886    ul_test[i].result[BUFSZ-1] = '\0';
 887
 888    (void)curl_msprintf(ul_test[i].result, "%lu", ul_test[i].num);
 889
 890    if(memcmp(ul_test[i].result,
 891               ul_test[i].expected,
 892               strlen(ul_test[i].expected))) {
 893      printf("unsigned long test #%.2d: Failed (Expected: %s Got: %s)\n",
 894             i, ul_test[i].expected, ul_test[i].result);
 895      failed++;
 896    }
 897
 898  }
 899
 900  if(!failed)
 901    printf("All curl_mprintf() unsigned long tests OK!\n");
 902  else
 903    printf("Some curl_mprintf() unsigned long tests Failed!\n");
 904
 905  return failed;
 906}
 907
 908
 909static int test_signed_long_formatting(void)
 910{
 911  int i, j;
 912  int num_slong_tests;
 913  int failed = 0;
 914
 915#if (CURL_SIZEOF_LONG == 2)
 916
 917  i=1; sl_test[i].num = 0x7FFFL; sl_test[i].expected = "32767";
 918  i++; sl_test[i].num = 0x7FFEL; sl_test[i].expected = "32766";
 919  i++; sl_test[i].num = 0x7FFDL; sl_test[i].expected = "32765";
 920  i++; sl_test[i].num = 0x7F00L; sl_test[i].expected = "32512";
 921  i++; sl_test[i].num = 0x07F0L; sl_test[i].expected = "2032";
 922  i++; sl_test[i].num = 0x007FL; sl_test[i].expected = "127";
 923
 924  i++; sl_test[i].num = 0x7000L; sl_test[i].expected = "28672";
 925  i++; sl_test[i].num = 0x0700L; sl_test[i].expected = "1792";
 926  i++; sl_test[i].num = 0x0070L; sl_test[i].expected = "112";
 927  i++; sl_test[i].num = 0x0007L; sl_test[i].expected = "7";
 928
 929  i++; sl_test[i].num = 0x5000L; sl_test[i].expected = "20480";
 930  i++; sl_test[i].num = 0x0500L; sl_test[i].expected = "1280";
 931  i++; sl_test[i].num = 0x0050L; sl_test[i].expected = "80";
 932  i++; sl_test[i].num = 0x0005L; sl_test[i].expected = "5";
 933
 934  i++; sl_test[i].num = 0x0001L; sl_test[i].expected = "1";
 935  i++; sl_test[i].num = 0x0000L; sl_test[i].expected = "0";
 936
 937  i++; sl_test[i].num = -0x7FFFL -1L; sl_test[i].expected = "-32768";
 938  i++; sl_test[i].num = -0x7FFEL -1L; sl_test[i].expected = "-32767";
 939  i++; sl_test[i].num = -0x7FFDL -1L; sl_test[i].expected = "-32766";
 940  i++; sl_test[i].num = -0x7F00L -1L; sl_test[i].expected = "-32513";
 941  i++; sl_test[i].num = -0x07F0L -1L; sl_test[i].expected = "-2033";
 942  i++; sl_test[i].num = -0x007FL -1L; sl_test[i].expected = "-128";
 943
 944  i++; sl_test[i].num = -0x7000L -1L; sl_test[i].expected = "-28673";
 945  i++; sl_test[i].num = -0x0700L -1L; sl_test[i].expected = "-1793";
 946  i++; sl_test[i].num = -0x0070L -1L; sl_test[i].expected = "-113";
 947  i++; sl_test[i].num = -0x0007L -1L; sl_test[i].expected = "-8";
 948
 949  i++; sl_test[i].num = -0x5000L -1L; sl_test[i].expected = "-20481";
 950  i++; sl_test[i].num = -0x0500L -1L; sl_test[i].expected = "-1281";
 951  i++; sl_test[i].num = -0x0050L -1L; sl_test[i].expected = "-81";
 952  i++; sl_test[i].num = -0x0005L -1L; sl_test[i].expected = "-6";
 953
 954  i++; sl_test[i].num =  0x0000L -1L; sl_test[i].expected = "-1";
 955
 956  num_slong_tests = i;
 957
 958#elif (CURL_SIZEOF_LONG == 4)
 959
 960  i=1; sl_test[i].num = 0x7FFFFFFFL; sl_test[i].expected = "2147483647";
 961  i++; sl_test[i].num = 0x7FFFFFFEL; sl_test[i].expected = "2147483646";
 962  i++; sl_test[i].num = 0x7FFFFFFDL; sl_test[i].expected = "2147483645";
 963  i++; sl_test[i].num = 0x7FFF0000L; sl_test[i].expected = "2147418112";
 964  i++; sl_test[i].num = 0x00007FFFL; sl_test[i].expected = "32767";
 965
 966  i++; sl_test[i].num = 0x7F000000L; sl_test[i].expected = "2130706432";
 967  i++; sl_test[i].num = 0x007F0000L; sl_test[i].expected = "8323072";
 968  i++; sl_test[i].num = 0x00007F00L; sl_test[i].expected = "32512";
 969  i++; sl_test[i].num = 0x0000007FL; sl_test[i].expected = "127";
 970
 971  i++; sl_test[i].num = 0x70000000L; sl_test[i].expected = "1879048192";
 972  i++; sl_test[i].num = 0x07000000L; sl_test[i].expected = "117440512";
 973  i++; sl_test[i].num = 0x00700000L; sl_test[i].expected = "7340032";
 974  i++; sl_test[i].num = 0x00070000L; sl_test[i].expected = "458752";
 975  i++; sl_test[i].num = 0x00007000L; sl_test[i].expected = "28672";
 976  i++; sl_test[i].num = 0x00000700L; sl_test[i].expected = "1792";
 977  i++; sl_test[i].num = 0x00000070L; sl_test[i].expected = "112";
 978  i++; sl_test[i].num = 0x00000007L; sl_test[i].expected = "7";
 979
 980  i++; sl_test[i].num = 0x50000000L; sl_test[i].expected = "1342177280";
 981  i++; sl_test[i].num = 0x05000000L; sl_test[i].expected = "83886080";
 982  i++; sl_test[i].num = 0x00500000L; sl_test[i].expected = "5242880";
 983  i++; sl_test[i].num = 0x00050000L; sl_test[i].expected = "327680";
 984  i++; sl_test[i].num = 0x00005000L; sl_test[i].expected = "20480";
 985  i++; sl_test[i].num = 0x00000500L; sl_test[i].expected = "1280";
 986  i++; sl_test[i].num = 0x00000050L; sl_test[i].expected = "80";
 987  i++; sl_test[i].num = 0x00000005L; sl_test[i].expected = "5";
 988
 989  i++; sl_test[i].num = 0x00000001L; sl_test[i].expected = "1";
 990  i++; sl_test[i].num = 0x00000000L; sl_test[i].expected = "0";
 991
 992  i++; sl_test[i].num = -0x7FFFFFFFL -1L; sl_test[i].expected = "-2147483648";
 993  i++; sl_test[i].num = -0x7FFFFFFEL -1L; sl_test[i].expected = "-2147483647";
 994  i++; sl_test[i].num = -0x7FFFFFFDL -1L; sl_test[i].expected = "-2147483646";
 995  i++; sl_test[i].num = -0x7FFF0000L -1L; sl_test[i].expected = "-2147418113";
 996  i++; sl_test[i].num = -0x00007FFFL -1L; sl_test[i].expected = "-32768";
 997
 998  i++; sl_test[i].num = -0x7F000000L -1L; sl_test[i].expected = "-2130706433";
 999  i++; sl_test[i].num = -0x007F0000L -1L; sl_test[i].expected = "-8323073";
1000  i++; sl_test[i].num = -0x00007F00L -1L; sl_test[i].expected = "-32513";
1001  i++; sl_test[i].num = -0x0000007FL -1L; sl_test[i].expected = "-128";
1002
1003  i++; sl_test[i].num = -0x70000000L -1L; sl_test[i].expected = "-1879048193";
1004  i++; sl_test[i].num = -0x07000000L -1L; sl_test[i].expected = "-117440513";
1005  i++; sl_test[i].num = -0x00700000L -1L; sl_test[i].expected = "-7340033";
1006  i++; sl_test[i].num = -0x00070000L -1L; sl_test[i].expected = "-458753";
1007  i++; sl_test[i].num = -0x00007000L -1L; sl_test[i].expected = "-28673";
1008  i++; sl_test[i].num = -0x00000700L -1L; sl_test[i].expected = "-1793";
1009  i++; sl_test[i].num = -0x00000070L -1L; sl_test[i].expected = "-113";
1010  i++; sl_test[i].num = -0x00000007L -1L; sl_test[i].expected = "-8";
1011
1012  i++; sl_test[i].num = -0x50000000L -1L; sl_test[i].expected = "-1342177281";
1013  i++; sl_test[i].num = -0x05000000L -1L; sl_test[i].expected = "-83886081";
1014  i++; sl_test[i].num = -0x00500000L -1L; sl_test[i].expected = "-5242881";
1015  i++; sl_test[i].num = -0x00050000L -1L; sl_test[i].expected = "-327681";
1016  i++; sl_test[i].num = -0x00005000L -1L; sl_test[i].expected = "-20481";
1017  i++; sl_test[i].num = -0x00000500L -1L; sl_test[i].expected = "-1281";
1018  i++; sl_test[i].num = -0x00000050L -1L; sl_test[i].expected = "-81";
1019  i++; sl_test[i].num = -0x00000005L -1L; sl_test[i].expected = "-6";
1020
1021  i++; sl_test[i].num =  0x00000000L -1L; sl_test[i].expected = "-1";
1022
1023  num_slong_tests = i;
1024
1025#elif (CURL_SIZEOF_LONG == 8)
1026
1027  i=1; sl_test[i].num = 0x7FFFFFFFFFFFFFFFL; sl_test[i].expected = "9223372036854775807";
1028  i++; sl_test[i].num = 0x7FFFFFFFFFFFFFFEL; sl_test[i].expected = "9223372036854775806";
1029  i++; sl_test[i].num = 0x7FFFFFFFFFFFFFFDL; sl_test[i].expected = "9223372036854775805";
1030  i++; sl_test[i].num = 0x7FFFFFFF00000000L; sl_test[i].expected = "9223372032559808512";
1031  i++; sl_test[i].num = 0x000000007FFFFFFFL; sl_test[i].expected = "2147483647";
1032
1033  i++; sl_test[i].num = 0x7FFF000000000000L; sl_test[i].expected = "9223090561878065152";
1034  i++; sl_test[i].num = 0x00007FFF00000000L; sl_test[i].expected = "140733193388032";
1035  i++; sl_test[i].num = 0x000000007FFF0000L; sl_test[i].expected = "2147418112";
1036  i++; sl_test[i].num = 0x0000000000007FFFL; sl_test[i].expected = "32767";
1037
1038  i++; sl_test[i].num = 0x7F00000000000000L; sl_test[i].expected = "9151314442816847872";
1039  i++; sl_test[i].num = 0x007F000000000000L; sl_test[i].expected = "35747322042253312";
1040  i++; sl_test[i].num = 0x00007F0000000000L; sl_test[i].expected = "139637976727552";
1041  i++; sl_test[i].num = 0x0000007F00000000L; sl_test[i].expected = "545460846592";
1042  i++; sl_test[i].num = 0x000000007F000000L; sl_test[i].expected = "2130706432";
1043  i++; sl_test[i].num = 0x00000000007F0000L; sl_test[i].expected = "8323072";
1044  i++; sl_test[i].num = 0x0000000000007F00L; sl_test[i].expected = "32512";
1045  i++; sl_test[i].num = 0x000000000000007FL; sl_test[i].expected = "127";
1046
1047  i++; sl_test[i].num = 0x7000000000000000L; sl_test[i].expected = "8070450532247928832";
1048  i++; sl_test[i].num = 0x0700000000000000L; sl_test[i].expected = "504403158265495552";
1049  i++; sl_test[i].num = 0x0070000000000000L; sl_test[i].expected = "31525197391593472";
1050  i++; sl_test[i].num = 0x0007000000000000L; sl_test[i].expected = "1970324836974592";
1051  i++; sl_test[i].num = 0x0000700000000000L; sl_test[i].expected = "123145302310912";
1052  i++; sl_test[i].num = 0x0000070000000000L; sl_test[i].expected = "7696581394432";
1053  i++; sl_test[i].num = 0x0000007000000000L; sl_test[i].expected = "481036337152";
1054  i++; sl_test[i].num = 0x0000000700000000L; sl_test[i].expected = "30064771072";
1055  i++; sl_test[i].num = 0x0000000070000000L; sl_test[i].expected = "1879048192";
1056  i++; sl_test[i].num = 0x0000000007000000L; sl_tes

Large files files are truncated, but you can click here to view the full file