From d8b5dd586db230db3f09bedba9bfc0bdb254fe57 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 24 Nov 2008 00:56:48 +0000 Subject: Fix number parsing and make test code automatically determine correctness. More test data, which covers everything. Fix includes in libcss/types.h svn path=/trunk/libcss/; revision=5764 --- test/number.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test/number.c') diff --git a/test/number.c b/test/number.c index 87dcbcd..7e793a2 100644 --- a/test/number.c +++ b/test/number.c @@ -52,7 +52,7 @@ int main(int argc, char **argv) /* and run final test */ if (ctx.bufused > 0) - run_test(ctx.buf, ctx.bufused, ctx.exp, ctx.explen); + run_test(ctx.buf, ctx.bufused - 1, ctx.exp, ctx.explen); free(ctx.buf); @@ -69,7 +69,7 @@ bool handle_line(const char *data, size_t datalen, void *pw) if (ctx->inexp) { /* This marks end of testcase, so run it */ - run_test(ctx->buf, ctx->bufused, + run_test(ctx->buf, ctx->bufused - 1, ctx->exp, ctx->explen); ctx->buf[0] = '\0'; @@ -110,13 +110,17 @@ void run_test(const uint8_t *data, size_t len, const char *exp, size_t explen) css_string in = { (uint8_t *) data, len }; size_t consumed; fixed result; + char buf[256]; UNUSED(exp); UNUSED(explen); result = number_from_css_string(&in, &consumed); - /** \todo some kind of verification of the result */ - printf("%d\n", result); + snprintf(buf, sizeof buf, "%.3f", FIXTOFLT(result)); + + printf("got: %s expected: %.*s\n", buf, (int) explen, exp); + + assert(strncmp(buf, exp, explen) == 0); } -- cgit v1.2.3