PageRenderTime 201ms CodeModel.GetById 15ms app.highlight 165ms RepoModel.GetById 1ms app.codeStats 1ms

/curl/tests/libtest/lib557.c

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

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