From d6f483519871bc57bed6ff76fcdb37163b9f8931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Tue, 5 Sep 2006 08:01:04 +0000 Subject: [PATCH] add tests for size_t printf formater git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@17999 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/roken/snprintf-test.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/roken/snprintf-test.c b/lib/roken/snprintf-test.c index f39e86ec0..eeed81972 100644 --- a/lib/roken/snprintf-test.c +++ b/lib/roken/snprintf-test.c @@ -33,10 +33,10 @@ #ifdef HAVE_CONFIG_H #include #endif -#include "snprintf-test.h" #include "roken.h" #include +#include "snprintf-test.h" RCSID("$Id$"); @@ -226,18 +226,30 @@ test_null (void) } static int -test_length (void) +test_sizet (void) { - char ch = 'a'; - snprintf (&ch, 0, "foo"); - return ch != 'a'; + int tot = 0; + size_t sizet_values[] = { 0, 1, 2, 200, 4294967295u }; /* SIZE_MAX */ + char *result[] = { "0", "1", "2", "200", "4294967295" }; + int i; + + for (i = 0; i < sizeof(sizet_values) / sizeof(sizet_values[0]); ++i) { +#if 0 + tot += try("%zu", sizet_values[i]); + tot += try("%zx", sizet_values[i]); + tot += try("%zX", sizet_values[i]); +#else + char buf[256]; + snprintf(buf, sizeof(buf), "%zu", sizet_values[i]); + if (strcmp(buf, result[i]) != 0) { + printf("%s != %s", buf, result[i]); + tot++; + } +#endif + } + return tot; } -static int -test_simple (void) -{ - return try(""); -} int main (int argc, char **argv) @@ -250,8 +262,6 @@ main (int argc, char **argv) ret += cmp_with_sprintf_long_long (); #endif ret += test_null (); - ret += test_length (); - ret += test_simple(); - + ret += test_sizet (); return ret; }