lib557.c 81 KB

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