lib557.c 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  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. /* Do not skip sanity checks with parameters! */
  1230. buf[0] = 0;
  1231. rc = curl_msnprintf(buf, sizeof(buf), "%d, %.*1$d", 500, 1);
  1232. if(rc != sizeof(buf) - 1) {
  1233. printf("curl_mprintf() returned %d and not %d!\n", rc,
  1234. sizeof(buf) - 1);
  1235. errors++;
  1236. }
  1237. errors += strlen_check(buf, 255);
  1238. if(errors)
  1239. printf("Some curl_mprintf() weird arguments tests failed!\n");
  1240. return errors;
  1241. }
  1242. /* DBL_MAX value from Linux */
  1243. #define MAXIMIZE -1.7976931348623157081452E+308
  1244. static int test_float_formatting(void)
  1245. {
  1246. int errors = 0;
  1247. char buf[512]; /* larger than max float size */
  1248. curl_msnprintf(buf, sizeof(buf), "%f", 9.0);
  1249. errors += string_check(buf, "9.000000");
  1250. curl_msnprintf(buf, sizeof(buf), "%.1f", 9.1);
  1251. errors += string_check(buf, "9.1");
  1252. curl_msnprintf(buf, sizeof(buf), "%.2f", 9.1);
  1253. errors += string_check(buf, "9.10");
  1254. curl_msnprintf(buf, sizeof(buf), "%.0f", 9.1);
  1255. errors += string_check(buf, "9");
  1256. curl_msnprintf(buf, sizeof(buf), "%0f", 9.1);
  1257. errors += string_check(buf, "9.100000");
  1258. curl_msnprintf(buf, sizeof(buf), "%10f", 9.1);
  1259. errors += string_check(buf, " 9.100000");
  1260. curl_msnprintf(buf, sizeof(buf), "%10.3f", 9.1);
  1261. errors += string_check(buf, " 9.100");
  1262. curl_msnprintf(buf, sizeof(buf), "%-10.3f", 9.1);
  1263. errors += string_check(buf, "9.100 ");
  1264. curl_msnprintf(buf, sizeof(buf), "%-10.3f", 9.123456);
  1265. errors += string_check(buf, "9.123 ");
  1266. curl_msnprintf(buf, sizeof(buf), "%.-2f", 9.1);
  1267. errors += string_check(buf, "9.100000");
  1268. curl_msnprintf(buf, sizeof(buf), "%*f", 10, 9.1);
  1269. errors += string_check(buf, " 9.100000");
  1270. curl_msnprintf(buf, sizeof(buf), "%*f", 3, 9.1);
  1271. errors += string_check(buf, "9.100000");
  1272. curl_msnprintf(buf, sizeof(buf), "%*f", 6, 9.2987654);
  1273. errors += string_check(buf, "9.298765");
  1274. curl_msnprintf(buf, sizeof(buf), "%*f", 6, 9.298765);
  1275. errors += string_check(buf, "9.298765");
  1276. curl_msnprintf(buf, sizeof(buf), "%*f", 6, 9.29876);
  1277. errors += string_check(buf, "9.298760");
  1278. curl_msnprintf(buf, sizeof(buf), "%.*f", 6, 9.2987654);
  1279. errors += string_check(buf, "9.298765");
  1280. curl_msnprintf(buf, sizeof(buf), "%.*f", 5, 9.2987654);
  1281. errors += string_check(buf, "9.29877");
  1282. curl_msnprintf(buf, sizeof(buf), "%.*f", 4, 9.2987654);
  1283. errors += string_check(buf, "9.2988");
  1284. curl_msnprintf(buf, sizeof(buf), "%.*f", 3, 9.2987654);
  1285. errors += string_check(buf, "9.299");
  1286. curl_msnprintf(buf, sizeof(buf), "%.*f", 2, 9.2987654);
  1287. errors += string_check(buf, "9.30");
  1288. curl_msnprintf(buf, sizeof(buf), "%.*f", 1, 9.2987654);
  1289. errors += string_check(buf, "9.3");
  1290. curl_msnprintf(buf, sizeof(buf), "%.*f", 0, 9.2987654);
  1291. errors += string_check(buf, "9");
  1292. /* very large precisions easily turn into system specific outputs so we only
  1293. check the output buffer length here as we know the internal limit */
  1294. curl_msnprintf(buf, sizeof(buf), "%.*f", (1<<30), 9.2987654);
  1295. errors += strlen_check(buf, 325);
  1296. curl_msnprintf(buf, sizeof(buf), "%10000.10000f", 9.2987654);
  1297. errors += strlen_check(buf, 325);
  1298. curl_msnprintf(buf, sizeof(buf), "%240.10000f",
  1299. 123456789123456789123456789.2987654);
  1300. errors += strlen_check(buf, 325);
  1301. /* check negative when used signed */
  1302. curl_msnprintf(buf, sizeof(buf), "%*f", INT_MIN, 9.1);
  1303. errors += string_check(buf, "9.100000");
  1304. /* curl_msnprintf() limits a single float output to 325 bytes maximum
  1305. width */
  1306. curl_msnprintf(buf, sizeof(buf), "%*f", (1<<30), 9.1);
  1307. errors += string_check(buf, " 9.100000");
  1308. curl_msnprintf(buf, sizeof(buf), "%100000f", 9.1);
  1309. errors += string_check(buf, " 9.100000");
  1310. curl_msnprintf(buf, sizeof(buf), "%f", MAXIMIZE);
  1311. errors += strlen_check(buf, 317);
  1312. curl_msnprintf(buf, 2, "%f", MAXIMIZE);
  1313. errors += strlen_check(buf, 1);
  1314. curl_msnprintf(buf, 3, "%f", MAXIMIZE);
  1315. errors += strlen_check(buf, 2);
  1316. curl_msnprintf(buf, 4, "%f", MAXIMIZE);
  1317. errors += strlen_check(buf, 3);
  1318. curl_msnprintf(buf, 5, "%f", MAXIMIZE);
  1319. errors += strlen_check(buf, 4);
  1320. curl_msnprintf(buf, 6, "%f", MAXIMIZE);
  1321. errors += strlen_check(buf, 5);
  1322. if(!errors)
  1323. printf("All float strings tests OK!\n");
  1324. else
  1325. printf("test_float_formatting Failed!\n");
  1326. return errors;
  1327. }
  1328. /* !checksrc! enable LONGLINE */
  1329. static int test_return_codes(void)
  1330. {
  1331. char buf[128];
  1332. int rc;
  1333. rc = curl_msnprintf(buf, 100, "%d", 9999);
  1334. if(rc != 4)
  1335. return 1;
  1336. rc = curl_msnprintf(buf, 100, "%d", 99999);
  1337. if(rc != 5)
  1338. return 1;
  1339. /* returns the length excluding the nul byte */
  1340. rc = curl_msnprintf(buf, 5, "%d", 99999);
  1341. if(rc != 4)
  1342. return 1;
  1343. /* returns the length excluding the nul byte */
  1344. rc = curl_msnprintf(buf, 5, "%s", "helloooooooo");
  1345. if(rc != 4)
  1346. return 1;
  1347. /* returns the length excluding the nul byte */
  1348. rc = curl_msnprintf(buf, 6, "%s", "helloooooooo");
  1349. if(rc != 5)
  1350. return 1;
  1351. return 0;
  1352. }
  1353. int test(char *URL)
  1354. {
  1355. int errors = 0;
  1356. (void)URL; /* not used */
  1357. #ifdef HAVE_SETLOCALE
  1358. /*
  1359. * The test makes assumptions about the numeric locale (specifically,
  1360. * RADIXCHAR) so set it to a known working (and portable) one.
  1361. */
  1362. setlocale(LC_NUMERIC, "C");
  1363. #endif
  1364. errors += test_weird_arguments();
  1365. errors += test_unsigned_short_formatting();
  1366. errors += test_signed_short_formatting();
  1367. errors += test_unsigned_int_formatting();
  1368. errors += test_signed_int_formatting();
  1369. errors += test_unsigned_long_formatting();
  1370. errors += test_signed_long_formatting();
  1371. errors += test_curl_off_t_formatting();
  1372. errors += test_string_formatting();
  1373. errors += test_float_formatting();
  1374. errors += test_return_codes();
  1375. if(errors)
  1376. return TEST_ERR_MAJOR_BAD;
  1377. else
  1378. return 0;
  1379. }