2
0

lib557.c 81 KB

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