1 /* 2 * This file was generated from printf-tests.txt included 3 * as a part of the printf test suite developed by 4 * Bart Massey: 5 * 6 * https://github.com/BartMassey/printf-tests 7 * 8 * printf-tests.txt carries the following Copyright, which 9 * probably extends to this file as well given the transformations 10 * are fairly mechanical: 11 * 12 # Various printf tests compiled from various sources 13 # Copyright © 2013 Bart Massey 14 # This program is licensed under the GPL version 2 or later. 15 # Please see the file COPYING.GPL2 in this distribution for 16 # license terms. 17 18 */ 19 20 #ifndef __PICOLIBC__ 21 # define _WANT_IO_C99_FORMATS 22 # define _WANT_IO_LONG_LONG 23 # define _WANT_IO_POS_ARGS 24 #elif defined(TINY_STDIO) 25 # ifdef _HAS_IO_PERCENT_B 26 # define BINARY_FORMAT 27 # endif 28 # ifdef _HAS_IO_DOUBLE 29 # if __SIZEOF_DOUBLE__ == 4 30 # define LOW_FLOAT 31 # endif 32 # elif defined(_HAS_IO_FLOAT) 33 # define LOW_FLOAT 34 # else 35 # define NO_FLOAT 36 # endif 37 # ifndef _HAS_IO_LONG_LONG 38 # define NO_LONGLONG 39 # endif 40 # ifndef _HAS_IO_POS_ARGS 41 # define NO_POS_ARGS 42 # endif 43 # ifdef PICOLIBC_MINIMAL_PRINTF_SCANF 44 # define NO_WIDTH_PREC 45 # define NO_CASE_HEX 46 # endif 47 #else 48 # if __SIZEOF_DOUBLE__ == 4 49 # define LOW_FLOAT 50 # endif 51 # ifdef NO_FLOATING_POINT 52 # define NO_FLOAT 53 # endif 54 # ifndef _WANT_IO_LONG_LONG 55 # define NO_LONGLONG 56 # endif 57 # ifndef _WANT_IO_POS_ARGS 58 # define NO_POS_ARGS 59 # endif 60 # define NORMALIZED_A 61 #endif 62 63 64 #if __SIZEOF_INT__ < 4 65 #define I(a,b) (b) 66 #else 67 #define I(a,b) (a) 68 #endif 69 70 //{ 71 /* XXX This code generated automatically by gen-testcases.hs 72 from ../../printf-tests.txt . You probably do not want to 73 manually edit this file. */ 74 #ifndef NO_FLOAT 75 result |= test(__LINE__, "0", "%.7g", 0.0); 76 result |= test(__LINE__, "0.33", "%.*f", 2, 0.33333333); 77 #endif 78 #ifndef NO_WIDTH_PREC 79 result |= test(__LINE__, "foo", "%.3s", "foobar"); 80 result |= test(__LINE__, " 00004", "%10.5d", 4); 81 result |= test(__LINE__, " 42", "% d", 42); 82 #endif 83 result |= test(__LINE__, "-42", "% d", -42); 84 #ifndef NO_WIDTH_PREC 85 result |= test(__LINE__, " 42", "% 5d", 42); 86 result |= test(__LINE__, " -42", "% 5d", -42); 87 result |= test(__LINE__, " 42", "% 15d", 42); 88 result |= test(__LINE__, " -42", "% 15d", -42); 89 result |= test(__LINE__, "+42", "%+d", 42); 90 result |= test(__LINE__, "-42", "%+d", -42); 91 result |= test(__LINE__, " +42", "%+5d", 42); 92 result |= test(__LINE__, " -42", "%+5d", -42); 93 result |= test(__LINE__, " +42", "%+15d", 42); 94 result |= test(__LINE__, " -42", "%+15d", -42); 95 #endif 96 result |= test(__LINE__, "42", "%0d", 42); 97 result |= test(__LINE__, "-42", "%0d", -42); 98 #ifndef NO_WIDTH_PREC 99 result |= test(__LINE__, "00042", "%05d", 42); 100 result |= test(__LINE__, "-0042", "%05d", -42); 101 result |= test(__LINE__, "000000000000042", "%015d", 42); 102 result |= test(__LINE__, "-00000000000042", "%015d", -42); 103 #endif 104 result |= test(__LINE__, "42", "%-d", 42); 105 result |= test(__LINE__, "-42", "%-d", -42); 106 #ifndef NO_WIDTH_PREC 107 result |= test(__LINE__, "42 ", "%-5d", 42); 108 result |= test(__LINE__, "-42 ", "%-5d", -42); 109 result |= test(__LINE__, "42 ", "%-15d", 42); 110 result |= test(__LINE__, "-42 ", "%-15d", -42); 111 #endif 112 result |= test(__LINE__, "42", "%-0d", 42); 113 result |= test(__LINE__, "-42", "%-0d", -42); 114 #ifndef NO_WIDTH_PREC 115 result |= test(__LINE__, "42 ", "%-05d", 42); 116 result |= test(__LINE__, "-42 ", "%-05d", -42); 117 result |= test(__LINE__, "42 ", "%-015d", 42); 118 result |= test(__LINE__, "-42 ", "%-015d", -42); 119 #endif 120 result |= test(__LINE__, "42", "%0-d", 42); 121 result |= test(__LINE__, "-42", "%0-d", -42); 122 #ifndef NO_WIDTH_PREC 123 result |= test(__LINE__, "42 ", "%0-5d", 42); 124 result |= test(__LINE__, "-42 ", "%0-5d", -42); 125 result |= test(__LINE__, "42 ", "%0-15d", 42); 126 result |= test(__LINE__, "-42 ", "%0-15d", -42); 127 #endif 128 #ifndef NO_FLOAT 129 result |= test(__LINE__, "42.90", "%.2f", 42.8952); 130 result |= test(__LINE__, "42.90", "%.2F", 42.8952); 131 #ifdef LOW_FLOAT 132 result |= test(__LINE__, "42.89520", "%.5f", 42.8952); 133 #else 134 result |= test(__LINE__, "42.8952000000", "%.10f", 42.8952); 135 #endif 136 result |= test(__LINE__, "42.90", "%1.2f", 42.8952); 137 result |= test(__LINE__, " 42.90", "%6.2f", 42.8952); 138 result |= test(__LINE__, "+42.90", "%+6.2f", 42.8952); 139 #ifdef LOW_FLOAT 140 result |= test(__LINE__, "42.89520", "%5.5f", 42.8952); 141 #else 142 result |= test(__LINE__, "42.8952000000", "%5.10f", 42.8952); 143 #endif 144 #endif /* NO_FLOAT */ 145 /* 51: anti-test */ 146 /* 52: anti-test */ 147 /* 53: excluded for C */ 148 #if !defined(NO_POS_ARGS) 149 result |= test(__LINE__, "Hot Pocket", "%1$s %2$s", "Hot", "Pocket"); 150 result |= test(__LINE__, "Pocket Hot", "%2$s %1$s", "Hot", "Pocket"); 151 result |= test(__LINE__, "0002 1 hi", "%2$04d %1$*3$d %4$s", 1, 2, 3, "hi"); 152 result |= test(__LINE__, " ab", "%1$*2$.*3$s", "abc", 5, 2); 153 #ifndef NO_FLOAT 154 result |= test(__LINE__, "12.0 Hot Pockets", "%1$.1f %2$s %3$ss", printf_float(12.0), "Hot", "Pocket"); 155 result |= test(__LINE__, "12.0 Hot Pockets", "%1$.*4$f %2$s %3$ss", printf_float(12.0), "Hot", "Pocket", 1); 156 result |= test(__LINE__, " 12.0 Hot Pockets", "%1$*5$.*4$f %2$s %3$ss", printf_float(12.0), "Hot", "Pocket", 1, 5); 157 result |= test(__LINE__, " 12.0 Hot Pockets 5", "%1$5.*4$f %2$s %3$ss %5$d", printf_float(12.0), "Hot", "Pocket", 1, 5); 158 #if !defined(TINY_STDIO) || defined(_IO_FLOAT_EXACT) 159 result |= test(__LINE__, 160 " 12345 1234 11145401322 321.765400 3.217654e+02 5 test-string", 161 "%1$*5$d %2$*6$hi %3$*7$lo %4$*8$f %9$*12$e %10$*13$g %11$*14$s", 162 12345, 1234, 1234567890, printf_float(321.7654), 8, 5, 14, 14, 163 printf_float(321.7654), printf_float(5.0000001), "test-string", 14, 3, 14); 164 #endif 165 #endif 166 #endif 167 /* 58: anti-test */ 168 #ifdef TINY_STDIO 169 result |= test(__LINE__, "%(foo", "%(foo"); 170 #endif 171 #ifndef NO_WIDTH_PREC 172 result |= test(__LINE__, " foo", "%*s", 4, "foo"); 173 #endif 174 #ifndef NO_FLOAT 175 result |= test(__LINE__, " 3.14", "%*.*f", 10, 2, 3.14159265); 176 result |= test(__LINE__, "3.14 ", "%-*.*f", 10, 2, 3.14159265); 177 # if !(defined(TINY_STDIO) && !defined(_IO_FLOAT_EXACT)) 178 # ifndef LOW_FLOAT 179 # ifdef TINY_STDIO 180 # define SQRT2_60 "1414213562373095000000000000000000000000000000000000000000000.000" 181 # else 182 # define SQRT2_60 "1414213562373095053224405813183213153460812619236586568024064.000" 183 # endif 184 result |= test(__LINE__, SQRT2_60, "%.3f", 1.4142135623730950e60); 185 # endif 186 # endif 187 #endif 188 /* 64: anti-test */ 189 /* 65: anti-test */ 190 result |= test(__LINE__, "+hello+", "+%s+", "hello"); 191 result |= test(__LINE__, "+10+", "+%d+", 10); 192 result |= test(__LINE__, "a", "%c", 'a'); 193 result |= test(__LINE__, " ", "%c", 32); 194 result |= test(__LINE__, "$", "%c", 36); 195 result |= test(__LINE__, "10", "%d", 10); 196 197 #ifndef _NANO_FORMATTED_IO 198 result |= test(__LINE__, I("1000000","16960"), "%'d", 1000000); 199 #endif 200 /* 72: anti-test */ 201 /* 73: anti-test */ 202 /* 74: excluded for C */ 203 /* 75: excluded for C */ 204 #ifndef NO_FLOAT 205 #ifdef LOW_FLOAT 206 result |= test(__LINE__, " +7.894561e+08", "%+#22.6e", 7.89456123e8); 207 result |= test(__LINE__, "7.894561e+08 ", "%-#22.6e", 7.89456123e8); 208 result |= test(__LINE__, " 7.894561e+08", "%#22.6e", 7.89456123e8); 209 #else 210 result |= test(__LINE__, "+7.894561230000000e+08", "%+#22.15e", 7.89456123e8); 211 result |= test(__LINE__, "7.894561230000000e+08 ", "%-#22.15e", 7.89456123e8); 212 result |= test(__LINE__, " 7.894561230000000e+08", "%#22.15e", 7.89456123e8); 213 #endif 214 result |= test(__LINE__, "8.e+08", "%#1.1g", 7.89456123e8); 215 #endif 216 #ifndef NO_LONGLONG 217 #ifndef NO_WIDTH_PREC 218 result |= test(__LINE__, " +100", "%+8lld", 100LL); 219 #if defined(TINY_STDIO) || !defined(__PICOLIBC__) 220 result |= test(__LINE__, " +100", "%+8Ld", 100LL); 221 #endif 222 result |= test(__LINE__, "+00000100", "%+.8lld", 100LL); 223 result |= test(__LINE__, " +00000100", "%+10.8lld", 100LL); 224 #endif 225 #ifdef TINY_STDIO 226 result |= test(__LINE__, "%_1lld", "%_1lld", 100LL); 227 #endif 228 #ifndef NO_WIDTH_PREC 229 result |= test(__LINE__, "-00100", "%-1.5lld", -100LL); 230 result |= test(__LINE__, " 100", "%5lld", 100LL); 231 result |= test(__LINE__, " -100", "%5lld", -100LL); 232 result |= test(__LINE__, "100 ", "%-5lld", 100LL); 233 result |= test(__LINE__, "-100 ", "%-5lld", -100LL); 234 result |= test(__LINE__, "00100", "%-.5lld", 100LL); 235 result |= test(__LINE__, "-00100", "%-.5lld", -100LL); 236 result |= test(__LINE__, "00100 ", "%-8.5lld", 100LL); 237 result |= test(__LINE__, "-00100 ", "%-8.5lld", -100LL); 238 result |= test(__LINE__, "00100", "%05lld", 100LL); 239 result |= test(__LINE__, "-0100", "%05lld", -100LL); 240 result |= test(__LINE__, " 100", "% lld", 100LL); 241 result |= test(__LINE__, "-100", "% lld", -100LL); 242 result |= test(__LINE__, " 100", "% 5lld", 100LL); 243 result |= test(__LINE__, " -100", "% 5lld", -100LL); 244 result |= test(__LINE__, " 00100", "% .5lld", 100LL); 245 result |= test(__LINE__, "-00100", "% .5lld", -100LL); 246 result |= test(__LINE__, " 00100", "% 8.5lld", 100LL); 247 result |= test(__LINE__, " -00100", "% 8.5lld", -100LL); 248 result |= test(__LINE__, "", "%.0lld", 0LL); 249 result |= test(__LINE__, " 0x00ffffffffffffff9c", "%#+21.18llx", -100LL); 250 result |= test(__LINE__, "0001777777777777777777634", "%#.25llo", -100LL); 251 result |= test(__LINE__, " 01777777777777777777634", "%#+24.20llo", -100LL); 252 result |= test(__LINE__, "0X00000FFFFFFFFFFFFFF9C", "%#+18.21llX", -100LL); 253 result |= test(__LINE__, "001777777777777777777634", "%#+20.24llo", -100LL); 254 result |= test(__LINE__, " 0018446744073709551615", "%#+25.22llu", -1LL); 255 result |= test(__LINE__, " 0018446744073709551615", "%#+25.22llu", -1LL); 256 result |= test(__LINE__, " 0000018446744073709551615", "%#+30.25llu", -1LL); 257 result |= test(__LINE__, " -0000000000000000000001", "%+#25.22lld", -1LL); 258 result |= test(__LINE__, "00144 ", "%#-8.5llo", 100LL); 259 result |= test(__LINE__, "+00100 ", "%#-+ 08.5lld", 100LL); 260 result |= test(__LINE__, "+00100 ", "%#-+ 08.5lld", 100LL); 261 result |= test(__LINE__, "0000000000000000000000000000000000000001", "%.40lld", 1LL); 262 result |= test(__LINE__, " 0000000000000000000000000000000000000001", "% .40lld", 1LL); 263 #endif 264 #endif 265 #ifndef NO_WIDTH_PREC 266 result |= test(__LINE__, " 0000000000000000000000000000000000000001", "% .40d", 1); 267 #endif 268 /* 121: excluded for C */ 269 /* 124: excluded for C */ 270 #ifndef NO_WIDTH_PREC 271 result |= test(__LINE__, " 1", "% d", 1); 272 result |= test(__LINE__, "+1", "%+ d", 1); 273 result |= test(__LINE__, "0x0000000001", "%#012x", 1); 274 result |= test(__LINE__, "0x00000001", "%#04.8x", 1); 275 result |= test(__LINE__, "0x01 ", "%#-08.2x", 1); 276 result |= test(__LINE__, "00000001", "%#08o", 1); 277 #endif 278 result |= test(__LINE__, "0x39", "%p", (void *)57ULL); 279 result |= test(__LINE__, "0x39", "%p", (void *)57U); 280 #ifndef NO_WIDTH_PREC 281 result |= test(__LINE__, "f", "%.1s", "foo"); 282 result |= test(__LINE__, "f", "%.*s", 1, "foo"); 283 result |= test(__LINE__, "foo ", "%*s", -5, "foo"); 284 #endif 285 result |= test(__LINE__, "hello", "hello"); 286 #if defined(TINY_STDIO) && !defined(_HAS_IO_PERCENT_B) 287 result |= test(__LINE__, "%b", "%b"); 288 #endif 289 #ifndef NO_WIDTH_PREC 290 result |= test(__LINE__, " a", "%3c", 'a'); 291 #endif 292 result |= test(__LINE__, "1234", "%3d", 1234); 293 /* 150: excluded for C */ 294 result |= test(__LINE__, "2", "%-1d", 2); 295 #ifndef NO_FLOAT 296 result |= test(__LINE__, "8.6000", "%2.4f", 8.6); 297 result |= test(__LINE__, "0.600000", "%0f", 0.6); 298 result |= test(__LINE__, "1", "%.0f", 0.6); 299 result |= test(__LINE__, "8.6000e+00", "%2.4e", 8.6); 300 result |= test(__LINE__, " 8.6000e+00", "% 2.4e", 8.6); 301 result |= test(__LINE__, "-8.6000e+00", "% 2.4e", -8.6); 302 result |= test(__LINE__, "+8.6000e+00", "%+2.4e", 8.6); 303 result |= test(__LINE__, "8.6", "%2.4g", 8.6); 304 #endif 305 result |= test(__LINE__, "-1", "%-i", -1); 306 result |= test(__LINE__, "1", "%-i", 1); 307 #ifndef NO_WIDTH_PREC 308 result |= test(__LINE__, "+1", "%+i", 1); 309 #endif 310 result |= test(__LINE__, "12", "%o", 10); 311 /* 166: excluded for C */ 312 /* 167: excluded for C */ 313 #ifdef TINY_STDIO 314 result |= test(__LINE__, "(null)", "%s", NULL); 315 #endif 316 result |= test(__LINE__, "%%%%", "%s", "%%%%"); 317 result |= test(__LINE__, I("4294967295", "65535"), "%u", -1); 318 #ifdef TINY_STDIO 319 result |= test(__LINE__, "%w", "%w", -1); 320 #endif 321 /* 172: excluded for C */ 322 /* 173: excluded for C */ 323 /* 174: excluded for C */ 324 #ifdef TINY_STDIO 325 result |= test(__LINE__, "%H", "%H", -1); 326 #endif 327 result |= test(__LINE__, "%0", "%%0"); 328 result |= test(__LINE__, "2345", "%hx", 74565); 329 #ifndef _NANO_FORMATTED_IO 330 result |= test(__LINE__, "61", "%hhx", 0x61); 331 result |= test(__LINE__, "61", "%hhx", 0x161); 332 result |= test(__LINE__, "97", "%hhd", 0x61); 333 result |= test(__LINE__, "97", "%hhd", 0x161); 334 result |= test(__LINE__, "-97", "%hhd", -0x61); 335 result |= test(__LINE__, "-97", "%hhd", -0x161); 336 #endif 337 result |= test(__LINE__, "Hallo heimur", "Hallo heimur"); 338 result |= test(__LINE__, "Hallo heimur", "%s", "Hallo heimur"); 339 result |= test(__LINE__, "1024", "%d", 1024); 340 result |= test(__LINE__, "-1024", "%d", -1024); 341 result |= test(__LINE__, "1024", "%i", 1024); 342 result |= test(__LINE__, "-1024", "%i", -1024); 343 result |= test(__LINE__, "1024", "%u", 1024); 344 result |= test(__LINE__, I("4294966272", "64512"), "%u", 4294966272U); 345 result |= test(__LINE__, "777", "%o", 511); 346 result |= test(__LINE__, I("37777777001", "177001"), "%o", 4294966785U); 347 result |= test(__LINE__, I("1234abcd", "abcd"), "%x", 305441741); 348 result |= test(__LINE__, I("edcb5433", "5433"), "%x", 3989525555U); 349 result |= test(__LINE__, I("1234ABCD", "ABCD"), "%X", 305441741); 350 result |= test(__LINE__, I("EDCB5433", "5433"), "%X", 3989525555U); 351 #ifdef BINARY_FORMAT 352 result |= test(__LINE__, I("10010001101001010101111001101", "1010101111001101"), "%b", 305441741); 353 result |= test(__LINE__, I("11101101110010110101010000110011", "101010000110011"), "%b", 3989525555U); 354 result |= test(__LINE__, I("10010001101001010101111001101", "1010101111001101"), "%B", 305441741); 355 result |= test(__LINE__, I("11101101110010110101010000110011", "101010000110011"), "%B", 3989525555U); 356 #endif 357 result |= test(__LINE__, "x", "%c", 'x'); 358 result |= test(__LINE__, "%", "%%"); 359 result |= test(__LINE__, "Hallo heimur", "%+s", "Hallo heimur"); 360 #ifndef NO_WIDTH_PREC 361 result |= test(__LINE__, "+1024", "%+d", 1024); 362 #endif 363 result |= test(__LINE__, "-1024", "%+d", -1024); 364 #ifndef NO_WIDTH_PREC 365 result |= test(__LINE__, "+1024", "%+i", 1024); 366 #endif 367 result |= test(__LINE__, "-1024", "%+i", -1024); 368 result |= test(__LINE__, "1024", "%+u", 1024); 369 result |= test(__LINE__, I("4294966272", "64512"), "%+u", 4294966272U); 370 result |= test(__LINE__, "777", "%+o", 511); 371 result |= test(__LINE__, I("37777777001", "177001"), "%+o", 4294966785U); 372 result |= test(__LINE__, I("1234abcd", "abcd"), "%+x", 305441741); 373 result |= test(__LINE__, I("edcb5433", "5433"), "%+x", 3989525555U); 374 result |= test(__LINE__, I("1234ABCD", "ABCD"), "%+X", 305441741); 375 result |= test(__LINE__, I("EDCB5433", "5433"), "%+X", 3989525555U); 376 result |= test(__LINE__, "x", "%+c", 'x'); 377 result |= test(__LINE__, "Hallo heimur", "% s", "Hallo heimur"); 378 #ifndef NO_WIDTH_PREC 379 result |= test(__LINE__, " 1024", "% d", 1024); 380 #endif 381 result |= test(__LINE__, "-1024", "% d", -1024); 382 #ifndef NO_WIDTH_PREC 383 result |= test(__LINE__, " 1024", "% i", 1024); 384 #endif 385 result |= test(__LINE__, "-1024", "% i", -1024); 386 result |= test(__LINE__, "1024", "% u", 1024); 387 result |= test(__LINE__, I("4294966272", "64512"), "% u", 4294966272U); 388 result |= test(__LINE__, "777", "% o", 511); 389 result |= test(__LINE__, I("37777777001", "177001"), "% o", 4294966785U); 390 result |= test(__LINE__, I("1234abcd", "abcd"), "% x", 305441741); 391 result |= test(__LINE__, I("edcb5433", "5433"), "% x", 3989525555U); 392 result |= test(__LINE__, I("1234ABCD", "ABCD"), "% X", 305441741); 393 result |= test(__LINE__, I("EDCB5433", "5433"), "% X", 3989525555U); 394 result |= test(__LINE__, "x", "% c", 'x'); 395 result |= test(__LINE__, "Hallo heimur", "%+ s", "Hallo heimur"); 396 #ifndef NO_WIDTH_PREC 397 result |= test(__LINE__, "+1024", "%+ d", 1024); 398 #endif 399 result |= test(__LINE__, "-1024", "%+ d", -1024); 400 #ifndef NO_WIDTH_PREC 401 result |= test(__LINE__, "+1024", "%+ i", 1024); 402 #endif 403 result |= test(__LINE__, "-1024", "%+ i", -1024); 404 result |= test(__LINE__, "1024", "%+ u", 1024); 405 result |= test(__LINE__, I("4294966272", "64512"), "%+ u", 4294966272U); 406 result |= test(__LINE__, "777", "%+ o", 511); 407 result |= test(__LINE__, I("37777777001", "177001"), "%+ o", 4294966785U); 408 result |= test(__LINE__, I("1234abcd", "abcd"), "%+ x", 305441741); 409 result |= test(__LINE__, I("edcb5433", "5433"), "%+ x", 3989525555U); 410 result |= test(__LINE__, I("1234ABCD", "ABCD"), "%+ X", 305441741); 411 result |= test(__LINE__, I("EDCB5433", "5433"), "%+ X", 3989525555U); 412 result |= test(__LINE__, "x", "%+ c", 'x'); 413 result |= test(__LINE__, "0777", "%#o", 511); 414 result |= test(__LINE__, I("037777777001", "0177001"), "%#o", 4294966785U); 415 result |= test(__LINE__, I("0x1234abcd", "0xabcd"), "%#x", 305441741); 416 result |= test(__LINE__, I("0xedcb5433", "0x5433"), "%#x", 3989525555U); 417 #ifndef NO_CASE_HEX 418 result |= test(__LINE__, I("0X1234ABCD", "0XABCD"), "%#X", 305441741); 419 result |= test(__LINE__, I("0XEDCB5433", "0X5433"), "%#X", 3989525555U); 420 #endif 421 #ifdef BINARY_FORMAT 422 result |= test(__LINE__, I("0b10010001101001010101111001101", "0b1010101111001101"), "%#b", 305441741); 423 result |= test(__LINE__, I("0b11101101110010110101010000110011", "0b101010000110011"), "%#b", 3989525555U); 424 result |= test(__LINE__, I("0B10010001101001010101111001101", "0B1010101111001101"), "%#B", 305441741); 425 result |= test(__LINE__, I("0B11101101110010110101010000110011", "0B101010000110011"), "%#B", 3989525555U); 426 #endif 427 result |= test(__LINE__, "0", "%#o", 0U); 428 result |= test(__LINE__, "0", "%#x", 0U); 429 result |= test(__LINE__, "0", "%#X", 0U); 430 result |= test(__LINE__, "Hallo heimur", "%1s", "Hallo heimur"); 431 result |= test(__LINE__, "1024", "%1d", 1024); 432 result |= test(__LINE__, "-1024", "%1d", -1024); 433 result |= test(__LINE__, "1024", "%1i", 1024); 434 result |= test(__LINE__, "-1024", "%1i", -1024); 435 result |= test(__LINE__, "1024", "%1u", 1024); 436 result |= test(__LINE__, I("4294966272", "64512"), "%1u", 4294966272U); 437 result |= test(__LINE__, "777", "%1o", 511); 438 result |= test(__LINE__, I("37777777001", "177001"), "%1o", 4294966785U); 439 result |= test(__LINE__, I("1234abcd", "abcd"), "%1x", 305441741); 440 result |= test(__LINE__, I("edcb5433", "5433"), "%1x", 3989525555U); 441 result |= test(__LINE__, I("1234ABCD", "ABCD"), "%1X", 305441741); 442 result |= test(__LINE__, I("EDCB5433", "5433"), "%1X", 3989525555U); 443 result |= test(__LINE__, "x", "%1c", 'x'); 444 #ifndef NO_WIDTH_PREC 445 result |= test(__LINE__, " Hallo", "%20s", "Hallo"); 446 result |= test(__LINE__, " 1024", "%20d", 1024); 447 result |= test(__LINE__, " -1024", "%20d", -1024); 448 result |= test(__LINE__, " 1024", "%20i", 1024); 449 result |= test(__LINE__, " -1024", "%20i", -1024); 450 result |= test(__LINE__, " 1024", "%20u", 1024); 451 result |= test(__LINE__, I(" 4294966272", " 64512"), "%20u", 4294966272U); 452 result |= test(__LINE__, " 777", "%20o", 511); 453 result |= test(__LINE__, I(" 37777777001", " 177001"), "%20o", 4294966785U); 454 result |= test(__LINE__, I(" 1234abcd", " abcd"), "%20x", 305441741); 455 result |= test(__LINE__, I(" edcb5433", " 5433"), "%20x", 3989525555U); 456 result |= test(__LINE__, I(" 1234ABCD", " ABCD"), "%20X", 305441741); 457 result |= test(__LINE__, I(" EDCB5433", " 5433"), "%20X", 3989525555U); 458 result |= test(__LINE__, " x", "%20c", 'x'); 459 result |= test(__LINE__, "Hallo ", "%-20s", "Hallo"); 460 result |= test(__LINE__, "1024 ", "%-20d", 1024); 461 result |= test(__LINE__, "-1024 ", "%-20d", -1024); 462 result |= test(__LINE__, "1024 ", "%-20i", 1024); 463 result |= test(__LINE__, "-1024 ", "%-20i", -1024); 464 result |= test(__LINE__, "1024 ", "%-20u", 1024); 465 result |= test(__LINE__, I("4294966272 ", "64512 "), "%-20u", 4294966272U); 466 result |= test(__LINE__, "777 ", "%-20o", 511); 467 result |= test(__LINE__, I("37777777001 ", "177001 "), "%-20o", 4294966785U); 468 result |= test(__LINE__, I("1234abcd ", "abcd "), "%-20x", 305441741); 469 result |= test(__LINE__, I("edcb5433 ", "5433 "), "%-20x", 3989525555U); 470 result |= test(__LINE__, I("1234ABCD ", "ABCD "), "%-20X", 305441741); 471 result |= test(__LINE__, I("EDCB5433 ", "5433 "), "%-20X", 3989525555U); 472 result |= test(__LINE__, "x ", "%-20c", 'x'); 473 result |= test(__LINE__, "00000000000000001024", "%020d", 1024); 474 result |= test(__LINE__, "-0000000000000001024", "%020d", -1024); 475 result |= test(__LINE__, "00000000000000001024", "%020i", 1024); 476 result |= test(__LINE__, "-0000000000000001024", "%020i", -1024); 477 result |= test(__LINE__, "00000000000000001024", "%020u", 1024); 478 result |= test(__LINE__, I("00000000004294966272", "00000000000000064512"), "%020u", 4294966272U); 479 result |= test(__LINE__, "00000000000000000777", "%020o", 511); 480 result |= test(__LINE__, I("00000000037777777001", "00000000000000177001"), "%020o", 4294966785U); 481 result |= test(__LINE__, I("0000000000001234abcd", "0000000000000000abcd"), "%020x", 305441741); 482 result |= test(__LINE__, I("000000000000edcb5433", "00000000000000005433"), "%020x", 3989525555U); 483 result |= test(__LINE__, I("0000000000001234ABCD", "0000000000000000ABCD"), "%020X", 305441741); 484 result |= test(__LINE__, I("000000000000EDCB5433", "00000000000000005433"), "%020X", 3989525555U); 485 result |= test(__LINE__, " 0777", "%#20o", 511); 486 result |= test(__LINE__, I(" 037777777001", " 0177001"), "%#20o", 4294966785U); 487 result |= test(__LINE__, I(" 0x1234abcd", " 0xabcd"), "%#20x", 305441741); 488 result |= test(__LINE__, I(" 0xedcb5433", " 0x5433"), "%#20x", 3989525555U); 489 result |= test(__LINE__, I(" 0X1234ABCD", " 0XABCD"), "%#20X", 305441741); 490 result |= test(__LINE__, I(" 0XEDCB5433", " 0X5433"), "%#20X", 3989525555U); 491 result |= test(__LINE__, "00000000000000000777", "%#020o", 511); 492 result |= test(__LINE__, I("00000000037777777001", "00000000000000177001"), "%#020o", 4294966785U); 493 result |= test(__LINE__, I("0x00000000001234abcd", "0x00000000000000abcd"), "%#020x", 305441741); 494 result |= test(__LINE__, I("0x0000000000edcb5433", "0x000000000000005433"), "%#020x", 3989525555U); 495 result |= test(__LINE__, I("0X00000000001234ABCD", "0X00000000000000ABCD"), "%#020X", 305441741); 496 result |= test(__LINE__, I("0X0000000000EDCB5433", "0X000000000000005433"), "%#020X", 3989525555U); 497 result |= test(__LINE__, "Hallo ", "%0-20s", "Hallo"); 498 result |= test(__LINE__, "1024 ", "%0-20d", 1024); 499 result |= test(__LINE__, "-1024 ", "%0-20d", -1024); 500 result |= test(__LINE__, "1024 ", "%0-20i", 1024); 501 result |= test(__LINE__, "-1024 ", "%0-20i", -1024); 502 result |= test(__LINE__, "1024 ", "%0-20u", 1024); 503 result |= test(__LINE__, I("4294966272 ", "64512 "), "%0-20u", 4294966272U); 504 result |= test(__LINE__, "777 ", "%-020o", 511); 505 result |= test(__LINE__, I("37777777001 ", "177001 "), "%-020o", 4294966785U); 506 result |= test(__LINE__, I("1234abcd ", "abcd "), "%-020x", 305441741); 507 result |= test(__LINE__, I("edcb5433 ", "5433 "), "%-020x", 3989525555U); 508 result |= test(__LINE__, I("1234ABCD ", "ABCD "), "%-020X", 305441741); 509 result |= test(__LINE__, I("EDCB5433 ", "5433 "), "%-020X", 3989525555U); 510 result |= test(__LINE__, "x ", "%-020c", 'x'); 511 result |= test(__LINE__, " Hallo", "%*s", 20, "Hallo"); 512 result |= test(__LINE__, " 1024", "%*d", 20, 1024); 513 result |= test(__LINE__, " -1024", "%*d", 20, -1024); 514 result |= test(__LINE__, " 1024", "%*i", 20, 1024); 515 result |= test(__LINE__, " -1024", "%*i", 20, -1024); 516 result |= test(__LINE__, " 1024", "%*u", 20, 1024); 517 result |= test(__LINE__, I(" 4294966272", " 64512"), "%*u", 20, 4294966272U); 518 result |= test(__LINE__, " 777", "%*o", 20, 511); 519 result |= test(__LINE__, I(" 37777777001", " 177001"), "%*o", 20, 4294966785U); 520 result |= test(__LINE__, I(" 1234abcd", " abcd"), "%*x", 20, 305441741); 521 result |= test(__LINE__, I(" edcb5433", " 5433"), "%*x", 20, 3989525555U); 522 result |= test(__LINE__, I(" 1234ABCD", " ABCD"), "%*X", 20, 305441741); 523 result |= test(__LINE__, I(" EDCB5433", " 5433"), "%*X", 20, 3989525555U); 524 result |= test(__LINE__, " x", "%*c", 20, 'x'); 525 result |= test(__LINE__, "Hallo heimur", "%.20s", "Hallo heimur"); 526 result |= test(__LINE__, "00000000000000001024", "%.20d", 1024); 527 result |= test(__LINE__, "-00000000000000001024", "%.20d", -1024); 528 result |= test(__LINE__, "00000000000000001024", "%.20i", 1024); 529 result |= test(__LINE__, "-00000000000000001024", "%.20i", -1024); 530 result |= test(__LINE__, "00000000000000001024", "%.20u", 1024); 531 result |= test(__LINE__, I("00000000004294966272", "00000000000000064512"), "%.20u", 4294966272U); 532 result |= test(__LINE__, "00000000000000000777", "%.20o", 511); 533 result |= test(__LINE__, I("00000000037777777001", "00000000000000177001"), "%.20o", 4294966785U); 534 result |= test(__LINE__, I("0000000000001234abcd", "0000000000000000abcd"), "%.20x", 305441741); 535 result |= test(__LINE__, I("000000000000edcb5433", "00000000000000005433"), "%.20x", 3989525555U); 536 result |= test(__LINE__, I("0000000000001234ABCD", "0000000000000000ABCD"), "%.20X", 305441741); 537 result |= test(__LINE__, I("000000000000EDCB5433", "00000000000000005433"), "%.20X", 3989525555U); 538 result |= test(__LINE__, " Hallo", "%20.5s", "Hallo heimur"); 539 result |= test(__LINE__, " 01024", "%20.5d", 1024); 540 result |= test(__LINE__, " -01024", "%20.5d", -1024); 541 result |= test(__LINE__, " 01024", "%20.5i", 1024); 542 result |= test(__LINE__, " -01024", "%20.5i", -1024); 543 result |= test(__LINE__, " 01024", "%20.5u", 1024); 544 result |= test(__LINE__, I(" 4294966272", " 64512"), "%20.5u", 4294966272U); 545 result |= test(__LINE__, " 00777", "%20.5o", 511); 546 result |= test(__LINE__, I(" 37777777001", " 177001"), "%20.5o", 4294966785U); 547 result |= test(__LINE__, I(" 1234abcd", " 0abcd"), "%20.5x", 305441741); 548 result |= test(__LINE__, I(" 00edcb5433", " 0000005433"), "%20.10x", 3989525555U); 549 result |= test(__LINE__, I(" 1234ABCD", " 0ABCD"), "%20.5X", 305441741); 550 result |= test(__LINE__, I(" 00EDCB5433", " 0000005433"), "%20.10X", 3989525555U); 551 result |= test(__LINE__, " 01024", "%020.5d", 1024); 552 result |= test(__LINE__, " -01024", "%020.5d", -1024); 553 result |= test(__LINE__, " 01024", "%020.5i", 1024); 554 result |= test(__LINE__, " -01024", "%020.5i", -1024); 555 result |= test(__LINE__, " 01024", "%020.5u", 1024); 556 result |= test(__LINE__, I(" 4294966272", " 64512"), "%020.5u", 4294966272U); 557 result |= test(__LINE__, " 00777", "%020.5o", 511); 558 result |= test(__LINE__, I(" 37777777001", " 177001"), "%020.5o", 4294966785U); 559 result |= test(__LINE__, I(" 1234abcd", " 0abcd"), "%020.5x", 305441741); 560 result |= test(__LINE__, I(" 00edcb5433", " 0000005433"), "%020.10x", 3989525555U); 561 result |= test(__LINE__, I(" 1234ABCD", " 0ABCD"), "%020.5X", 305441741); 562 result |= test(__LINE__, I(" 00EDCB5433", " 0000005433"), "%020.10X", 3989525555U); 563 result |= test(__LINE__, "", "%.0s", "Hallo heimur"); 564 result |= test(__LINE__, " ", "%20.0s", "Hallo heimur"); 565 result |= test(__LINE__, "", "%.s", "Hallo heimur"); 566 result |= test(__LINE__, " ", "%20.s", "Hallo heimur"); 567 result |= test(__LINE__, " 1024", "%20.0d", 1024); 568 result |= test(__LINE__, " -1024", "%20.d", -1024); 569 result |= test(__LINE__, " ", "%20.d", 0); 570 result |= test(__LINE__, " 1024", "%20.0i", 1024); 571 result |= test(__LINE__, " -1024", "%20.i", -1024); 572 result |= test(__LINE__, " ", "%20.i", 0); 573 result |= test(__LINE__, " 1024", "%20.u", 1024); 574 result |= test(__LINE__, I(" 4294966272", " 64512") , "%20.0u", 4294966272U); 575 result |= test(__LINE__, " ", "%20.u", 0U); 576 result |= test(__LINE__, " 777", "%20.o", 511); 577 result |= test(__LINE__, I(" 37777777001", " 177001"), "%20.0o", 4294966785U); 578 result |= test(__LINE__, " ", "%20.o", 0U); 579 result |= test(__LINE__, I(" 1234abcd", " abcd"), "%20.x", 305441741); 580 result |= test(__LINE__, I(" edcb5433", " 5433"), "%20.0x", 3989525555U); 581 result |= test(__LINE__, " ", "%20.x", 0U); 582 result |= test(__LINE__, I(" 1234ABCD", " ABCD"), "%20.X", 305441741); 583 result |= test(__LINE__, I(" EDCB5433", " 5433"), "%20.0X", 3989525555U); 584 result |= test(__LINE__, " ", "%20.X", 0U); 585 result |= test(__LINE__, "Hallo ", "% -0+*.*s", 20, 5, "Hallo heimur"); 586 result |= test(__LINE__, "+01024 ", "% -0+*.*d", 20, 5, 1024); 587 result |= test(__LINE__, "-01024 ", "% -0+*.*d", 20, 5, -1024); 588 result |= test(__LINE__, "+01024 ", "% -0+*.*i", 20, 5, 1024); 589 result |= test(__LINE__, "-01024 ", "% 0-+*.*i", 20, 5, -1024); 590 result |= test(__LINE__, "01024 ", "% 0-+*.*u", 20, 5, 1024); 591 result |= test(__LINE__, I("4294966272 ", "64512 "), "% 0-+*.*u", 20, 5, 4294966272U); 592 result |= test(__LINE__, "00777 ", "%+ -0*.*o", 20, 5, 511); 593 result |= test(__LINE__, I("37777777001 ", "177001 "), "%+ -0*.*o", 20, 5, 4294966785U); 594 result |= test(__LINE__, I("1234abcd ", "0abcd "), "%+ -0*.*x", 20, 5, 305441741); 595 result |= test(__LINE__, I("00edcb5433 ", "0000005433 "), "%+ -0*.*x", 20, 10, 3989525555U); 596 result |= test(__LINE__, I("1234ABCD ", "0ABCD "), "% -+0*.*X", 20, 5, 305441741); 597 result |= test(__LINE__, I("00EDCB5433 ", "0000005433 "), "% -+0*.*X", 20, 10, 3989525555U); 598 result |= test(__LINE__, "hi x", "%*sx", -3, "hi"); 599 #endif 600 #ifndef NO_FLOAT 601 result |= test(__LINE__, "1.000e-38", "%.3e", 1e-38); 602 #ifndef LOW_FLOAT 603 result |= test(__LINE__, "1.000e-308", "%.3e", 1e-308); 604 #endif 605 #endif 606 #ifndef _NANO_FORMATTED_IO 607 #ifndef NO_LONGLONG 608 result |= test(__LINE__, "1, 1", "%-*.llu, %-*.llu",1,1ULL,1,1ULL); 609 #endif 610 #endif 611 #ifndef NO_FLOAT 612 result |= test(__LINE__, "1e-09", "%g", 0.000000001); 613 result |= test(__LINE__, "1e-08", "%g", 0.00000001); 614 result |= test(__LINE__, "1e-07", "%g", 0.0000001); 615 result |= test(__LINE__, "1e-06", "%g", 0.000001); 616 result |= test(__LINE__, "0.0001", "%g", 0.0001); 617 result |= test(__LINE__, "0.001", "%g", 0.001); 618 result |= test(__LINE__, "0.01", "%g", 0.01); 619 result |= test(__LINE__, "0.1", "%g", 0.1); 620 result |= test(__LINE__, "1", "%g", 1.0); 621 result |= test(__LINE__, "10", "%g", 10.0); 622 result |= test(__LINE__, "100", "%g", 100.0); 623 result |= test(__LINE__, "1000", "%g", 1000.0); 624 result |= test(__LINE__, "10000", "%g", 10000.0); 625 result |= test(__LINE__, "100000", "%g", 100000.0); 626 result |= test(__LINE__, "1e+06", "%g", 1000000.0); 627 result |= test(__LINE__, "1e+07", "%g", 10000000.0); 628 result |= test(__LINE__, "1e+08", "%g", 100000000.0); 629 result |= test(__LINE__, "10.0000", "%#.6g", 10.0); 630 result |= test(__LINE__, "10", "%.6g", 10.0); 631 result |= test(__LINE__, "10.00000000000000000000", "%#.22g", 10.0); 632 #endif 633 634 // Regression test for wrong behavior with negative precision in tinystdio 635 // this might fail for configurations not using tinystdio, so for a first 636 // PR, only run these test for tinystdio. 637 #ifndef NO_WIDTH_PREC 638 result |= test(__LINE__, "", "%.*s", 0, "123456"); 639 result |= test(__LINE__, "1234", "%.*s", 4, "123456"); 640 result |= test(__LINE__, "123456", "%.*s", -4, "123456"); 641 result |= test(__LINE__, "42", "%.*d", 0, 42); 642 result |= test(__LINE__, "000042", "%.*d", 6, 42); 643 result |= test(__LINE__, "42", "%.*d", -6, 42); 644 #endif 645 #ifndef NO_FLOAT 646 result |= test(__LINE__, "0", "%.*f", 0, 0.123); 647 result |= test(__LINE__, "0.1", "%.*f", 1, 0.123); 648 result |= test(__LINE__, "0.123000", "%.*f", -1, 0.123); 649 #endif 650 #ifdef _WANT_IO_C99_FORMATS 651 { 652 char c[64]; 653 #ifndef _WANT_IO_LONG_LONG 654 if (sizeof (intmax_t) <= sizeof(long)) 655 #endif 656 #ifndef _NANO_FORMATTED_IO 657 #ifndef NO_WIDTH_PREC 658 result |= test(__LINE__, " 42", "%4jd", (intmax_t)42L); 659 #endif 660 result |= test(__LINE__, "64", "%zu", sizeof c); 661 result |= test(__LINE__, "12", "%td", (c+12) - c); 662 #else 663 (void) c; 664 #endif 665 #ifndef NO_FLOAT 666 result |= test(__LINE__, "0x1p+0", "%a", 0x1p+0); 667 result |= test(__LINE__, "0x0p+0", "%a", 0.0); 668 result |= test(__LINE__, "-0x0p+0", "%a", -0.0); 669 result |= test(__LINE__, "0x1.9p+4", "%.1a", 0x1.89p+4); 670 result |= test(__LINE__, "0x1.8p+4", "%.1a", 0x1.88p+4); 671 result |= test(__LINE__, "0x1.8p+4", "%.1a", 0x1.78p+4); 672 result |= test(__LINE__, "0x1.7p+4", "%.1a", 0x1.77p+4); 673 result |= test(__LINE__, "0x1.fffffep+126", "%a", (double) 0x1.fffffep+126f); 674 result |= test(__LINE__, "0x1.234564p-126", "%a", (double) 0x1.234564p-126f); 675 result |= test(__LINE__, "0x1.234566p-126", "%a", (double) 0x1.234566p-126f); 676 result |= test(__LINE__, "0X1.FFFFFEP+126", "%A", (double) 0x1.fffffep+126f); 677 result |= test(__LINE__, "0X1.234564P-126", "%A", (double) 0x1.234564p-126f); 678 result |= test(__LINE__, "0X1.234566P-126", "%A", (double) 0x1.234566p-126f); 679 result |= test(__LINE__, "0x1.6p+1", "%.1a", (double) 0x1.6789ap+1f); 680 result |= test(__LINE__, "0x1.68p+1", "%.2a", (double) 0x1.6789ap+1f); 681 result |= test(__LINE__, "0x1.679p+1", "%.3a", (double) 0x1.6789ap+1f); 682 result |= test(__LINE__, "0x1.678ap+1", "%.4a", (double) 0x1.6789ap+1f); 683 result |= test(__LINE__, "0x1.6789ap+1", "%.5a", (double) 0x1.6789ap+1f); 684 result |= test(__LINE__, "0x1.6789a0p+1", "%.6a", (double) 0x1.6789ap+1f); 685 result |= test(__LINE__, "0x1.ffp+1", "%.2a", (double) 0x1.ffp+1f); 686 result |= test(__LINE__, "0x2.0p+1", "%.1a", (double) 0x1.ffp+1f); 687 result |= test(__LINE__, "nan", "%a", (double) NAN); 688 result |= test(__LINE__, "inf", "%a", (double) INFINITY); 689 result |= test(__LINE__, "-inf", "%a", (double) -INFINITY); 690 result |= test(__LINE__, "NAN", "%A", (double) NAN); 691 result |= test(__LINE__, "INF", "%A", (double) INFINITY); 692 result |= test(__LINE__, "-INF", "%A", (double) -INFINITY); 693 #ifdef LOW_FLOAT 694 #ifdef NORMALIZED_A 695 result |= test(__LINE__, "0x1p-149", "%a", 0x1p-149); 696 #else 697 result |= test(__LINE__, "0x0.000002p-126", "%a", 0x1p-149); 698 #endif 699 #else 700 #ifdef NORMALIZED_A 701 /* newlib legacy stdio normalizes %a format */ 702 result |= test(__LINE__, "0x1p-1074", "%a", 0x1p-1074); 703 #else 704 /* glibc and picolibc show denorms like this */ 705 result |= test(__LINE__, "0x0.0000000000001p-1022", "%a", 0x1p-1074); 706 #endif 707 result |= test(__LINE__, "0x1.fffffffffffffp+1022", "%a", 0x1.fffffffffffffp+1022); 708 result |= test(__LINE__, "0x1.23456789abcdep-1022", "%a", 0x1.23456789abcdep-1022); 709 result |= test(__LINE__, "0x1.23456789abcdfp-1022", "%a", 0x1.23456789abcdfp-1022); 710 result |= test(__LINE__, "0X1.FFFFFFFFFFFFFP+1022", "%A", 0x1.fffffffffffffp+1022); 711 result |= test(__LINE__, "0X1.23456789ABCDEP-1022", "%A", 0x1.23456789abcdep-1022); 712 result |= test(__LINE__, "0X1.23456789ABCDFP-1022", "%A", 0x1.23456789abcdfp-1022); 713 #endif 714 #endif 715 /* test %ls for wchar_t string */ 716 result |= testw(__LINE__, L"foo", L"%.3ls", L"foobar"); 717 /* test %s for mbchar string */ 718 result |= testw(__LINE__, L"foo", L"%.3s", "foobar"); 719 720 wchar_t wc = 0x1234; 721 722 /* test %lc for wchar_t */ 723 wchar_t wb[2] = { 0x1234, 0 }; 724 result |= testw(__LINE__, wb, L"%lc", wc); 725 726 /* make sure %c truncates to char */ 727 wb[0] = 0x34; 728 result |= testw(__LINE__, wb, L"%c", wc); 729 } 730 #endif 731