comparison tests.c @ 331:6e42d50c08c4

Add tests for 64bit int prints.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 23 Feb 2016 12:55:45 +0200
parents 0146aa9a9524
children 799e38f867da
comparison
equal deleted inserted replaced
330:b2c4b0b4d44f 331:6e42d50c08c4
316 test_snprintf(buf, buf2, i_vals[i1]); 316 test_snprintf(buf, buf2, i_vals[i1]);
317 } 317 }
318 } 318 }
319 } 319 }
320 320
321 if (test_set_start("printf() integer 64bit"))
322 {
323 int64_t i_vals[] = { 0, -0, -1, 2, -2, 612342, -612342, 0x3342344341fff, 0x1f8000000, };
324 char *i_fmts[] = { "%", "%05", "%5", "%-5", "%.5", "%5.5", "%05.5", "% ", "% 3", "% 3.2", "%+3", };
325 char *i_types[] = { "d", "x", "X", "o", };
326
327 for (i1 = 0; i1 < NCOUNT(i_vals); i1++)
328 {
329 snprintf(buf, sizeof(buf), "%lld", i_vals[i1]);
330
331 for (i3 = 0; i3 < sizeof(i_types) / sizeof(i_types[0]); i3++)
332 for (i2 = 0; i2 < sizeof(i_fmts) / sizeof(i_fmts[0]); i2++)
333 {
334 snprintf(buf2, sizeof(buf2), "%sll%s", i_fmts[i2], i_types[i3]);
335 test_snprintf(buf, buf2, i_vals[i1]);
336 }
337 }
338 }
339
321 if (test_set_start("printf() float")) 340 if (test_set_start("printf() float"))
322 { 341 {
323 double f_vals[] = { 2.02, 612342.234, -2.07, -612342.12, 437692.9876543219, 0x1fff, 0x8000000, }; 342 double f_vals[] = { 2.02, 612342.234, -2.07, -612342.12, 437692.9876543219, 0x1fff, 0x8000000, };
324 char *f_fmts[] = { "%f", "%1.1f", "%5.5f", "%5f", "%-5f", "", "%-2.2f", "%05.5f" }; 343 char *f_fmts[] = { "%f", "%1.1f", "%5.5f", "%5f", "%-5f", "", "%-2.2f", "%05.5f" };
325 344