From: Szabolcs Nagy Date: Fri, 26 Oct 2012 23:32:16 +0000 (+0200) Subject: general: fix snprintf and swprintf format tests X-Git-Url: http://nsz.repo.hu/git/?p=libc-test;a=commitdiff_plain;h=f10a03ad1613d53338c9781e595c666aea57f50a general: fix snprintf and swprintf format tests --- diff --git a/src/general/snprintf.c b/src/general/snprintf.c index 1187fd7..fefe814 100644 --- a/src/general/snprintf.c +++ b/src/general/snprintf.c @@ -160,13 +160,23 @@ int main(void) TEST(i, errno, EOVERFLOW, "after overflow: %d != %d"); #endif for (j=0; int_tests[j].fmt; j++) { - TEST(i, snprintf(b, sizeof b, int_tests[j].fmt, int_tests[j].i), strlen(b), "%d != %d"); - TEST_S(b, int_tests[j].expect, "bad integer conversion"); + i = snprintf(b, sizeof b, int_tests[j].fmt, int_tests[j].i); + if (i != strlen(int_tests[j].expect)) { + error("snprintf(b, sizeof b, \"%s\", %d) returned %d wanted %d\n", + int_tests[j].fmt, int_tests[j].i, i, strlen(int_tests[j].expect)); + } + if (strcmp(b, int_tests[j].expect) != 0) + error("bad integer conversion: got \"%s\", want \"%s\"\n", b, int_tests[j].expect); } for (j=0; fp_tests[j].fmt; j++) { - TEST(i, snprintf(b, sizeof b, fp_tests[j].fmt, fp_tests[j].f), strlen(b), "%d != %d"); - TEST_S(b, fp_tests[j].expect, "bad floating point conversion"); + i = snprintf(b, sizeof b, fp_tests[j].fmt, fp_tests[j].f); + if (i != strlen(fp_tests[j].expect)) { + error("snprintf(b, sizeof b, \"%s\", %f) returned %d wanted %d\n", + fp_tests[j].fmt, fp_tests[j].f, i, strlen(fp_tests[j].expect)); + } + if (strcmp(b, fp_tests[j].expect) != 0) + error("bad floating-point conversion: got \"%s\", want \"%s\"\n", b, fp_tests[j].expect); } TEST(i, snprintf(0, 0, "%.4a", 1.0), 11, "%d != %d"); diff --git a/src/general/swprintf.c b/src/general/swprintf.c index 189de33..10a8380 100644 --- a/src/general/swprintf.c +++ b/src/general/swprintf.c @@ -129,13 +129,23 @@ int main(void) TEST(i, b[5], 'x', "buffer overrun"); for (j=0; int_tests[j].fmt; j++) { - TEST(i, swprintf(b, sizeof b/sizeof *b, int_tests[j].fmt, int_tests[j].i), wcslen(b), "%d != %d"); - TEST_S(b, int_tests[j].expect, "bad integer conversion"); + i = swprintf(b, sizeof b, int_tests[j].fmt, int_tests[j].i); + if (i != wcslen(int_tests[j].expect)) { + error("swprintf(b, sizeof b, \"%ls\", %d) returned %d wanted %d\n", + int_tests[j].fmt, int_tests[j].i, i, wcslen(int_tests[j].expect)); + } + if (wcscmp(b, int_tests[j].expect) != 0) + error("bad integer conversion: got \"%ls\", want \"%ls\"\n", b, int_tests[j].expect); } for (j=0; fp_tests[j].fmt; j++) { - TEST(i, swprintf(b, sizeof b/sizeof *b, fp_tests[j].fmt, fp_tests[j].f), wcslen(b), "%d != %d"); - TEST_S(b, fp_tests[j].expect, "bad floating point conversion"); + i = swprintf(b, sizeof b, fp_tests[j].fmt, fp_tests[j].f); + if (i != wcslen(fp_tests[j].expect)) { + error("swprintf(b, sizeof b, \"%ls\", %f) returned %d wanted %d\n", + fp_tests[j].fmt, fp_tests[j].f, i, wcslen(fp_tests[j].expect)); + } + if (wcscmp(b, fp_tests[j].expect) != 0) + error("bad floating-point conversion: got \"%ls\", want \"%ls\"\n", b, fp_tests[j].expect); } return test_status; }