lib557.c 70 KB

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