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