Mercurial > hg > th-libs
changeset 596:4ea7b0e9dcba
Improve string printf() tests.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 13 Jan 2020 17:13:13 +0200 |
parents | 308531ac74e7 |
children | 00ad3f0e208b |
files | tests.c |
diffstat | 1 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/tests.c Mon Jan 13 17:12:54 2020 +0200 +++ b/tests.c Mon Jan 13 17:13:13 2020 +0200 @@ -587,7 +587,7 @@ // Test series for printf() // char *i_fmts[] = { "", "05", "6", ".4", "1.1", "1.0", "8.5", "08.5", "3", "2.1", "3", "1", "18", "018", ".0", "0" }; - char *i_mods[] = { "", "-", "+", "#", }; + char *i_mods[] = { "", "-", "+", "#", " ", }; char *i_types[] = { "d", "u", "i", "x", "X", "o", }; if (test_set_start("printf() integer")) @@ -651,12 +651,16 @@ if (test_set_start("printf() string")) { char *s_vals[] = { "", "XYZXYZ", "xxx yyy zzz ppp fff", NULL, "X", "abcde", "dx", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", }; - char *s_fmts[] = { "%s", "%2s", "%-2s", "%5s", "%-5s", "%16s", "%-16s", "%1s", "%-1s", "% 2s", "%03s", "% -12s", "% 03s", "%-.15s", "%.8s" }; + // char *s_fmts[] = { "%s", "%2s", "%-2s", "%5s", "%-5s", "%16s", "%-16s", "%1s", "%-1s", "% 2s", "%03s", "% -12s", "% 03s", "%-.15s", "%.8s" }; + char *s_fmts[] = { "", "-" " ", "0", " 0", ".", "-.", }; + int s_widths[] = { 0, 1, 2, 5, 16, }; for (i1 = 0; i1 < NCOUNT(s_vals); i1++) + for (i2 = 0; i2 < NCOUNT(s_fmts); i2++) + for (i3 = 0; i3 < NCOUNT(s_widths); i3++) { - for (i2 = 0; i2 < NCOUNT(s_fmts); i2++) - test_snprintf(s_vals[i1], s_fmts[i2], s_vals[i1]); + snprintf(buf, sizeof(buf), "%%%s%ds", s_fmts[i2], s_widths[i3]); + test_snprintf(s_vals[i1], buf, s_vals[i1]); } }