From: Richard Kettlewell Date: Tue, 27 May 2008 21:37:05 +0000 (+0100) Subject: fatal() testing for dateparse() X-Git-Tag: 4.0~47 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/3943e9eceb6a7fb8d93c9fa8d23422eae8aabafd fatal() testing for dateparse() --- diff --git a/.bzrignore b/.bzrignore index 8824dd5..9a601a2 100644 --- a/.bzrignore +++ b/.bzrignore @@ -193,3 +193,4 @@ libtests/t-event libtests/t-dateparse libtests/Makefile cgi/Makefile +libtests/index.html diff --git a/lib/Makefile.am b/lib/Makefile.am index 95f6d01..ba53792 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -125,6 +125,7 @@ rebuild-unicode: $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) -c $< > $@.new mv $@.new $@ -CLEANFILES=definitions.h definitions.h.new version-string versionstring.h +CLEANFILES=definitions.h definitions.h.new version-string versionstring.h \ + *.gcda *.gcov *.gcno EXTRA_DIST=trackdb.c trackdb-stub.c diff --git a/libtests/Makefile.am b/libtests/Makefile.am index f5fbb00..5c7cc54 100644 --- a/libtests/Makefile.am +++ b/libtests/Makefile.am @@ -70,5 +70,7 @@ make-coverage-reports: EXTRA_DIST=t-macros-1.tmpl t-macros-2 +CLEANFILES=*.gcda *.gcov *.gcno + DISTCLEANFILES=GraphemeBreakTest.txt NormalizationTest.txt \ WordBreakTest.txt diff --git a/libtests/t-dateparse.c b/libtests/t-dateparse.c index 1e07c74..a0d8e31 100644 --- a/libtests/t-dateparse.c +++ b/libtests/t-dateparse.c @@ -48,6 +48,13 @@ static void test_dateparse(void) { check_date(now, "%H:%M:%S", localtime); /* This one needs a bodge: */ check_date(now - now % 60, "%H:%M", localtime); + /* Reject invalid formats */ + check_fatal(dateparse("12")); + check_fatal(dateparse("12:34:56:23")); + /* Reject invalid values */ + check_fatal(dateparse("25:34")); + check_fatal(dateparse("23:61")); + check_fatal(dateparse("23:23:62")); } TEST(dateparse); diff --git a/libtests/test.c b/libtests/test.c index f5dd036..d37d70f 100644 --- a/libtests/test.c +++ b/libtests/test.c @@ -93,6 +93,13 @@ const char *do_printf(const char *fmt, ...) { return s; } +jmp_buf fatal_env; + +void test_exitfn(int rc) { + assert(rc != 0); + longjmp(fatal_env, rc); +} + static const struct option options[] = { { "verbose", no_argument, 0, 'v' }, { "fail-first", no_argument, 0, 'F' }, diff --git a/libtests/test.h b/libtests/test.h index cb26b62..8af85d5 100644 --- a/libtests/test.h +++ b/libtests/test.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "mem.h" #include "log.h" @@ -121,6 +122,21 @@ extern int verbose; ++tests; \ } while(0) +#define check_fatal(WHAT) do { \ + void (*const save_exitfn)(int) attribute((noreturn)) = exitfn; \ + \ + exitfn = test_exitfn; \ + if(setjmp(fatal_env) == 0) { \ + fprintf(stderr, "Expect an error:\n "); \ + (void)(WHAT); \ + fprintf(stderr, "\n%s:%d: %s unexpectedly returned\n", \ + __FILE__, __LINE__, #WHAT); \ + count_error(); \ + } \ + ++tests; \ + exitfn = save_exitfn; \ +} while(0) + void count_error(void); const char *format(const char *s); const char *format_utf32(const uint32_t *s); @@ -128,6 +144,9 @@ uint32_t *ucs4parse(const char *s); const char *do_printf(const char *fmt, ...); void test_init(int argc, char **argv); +extern jmp_buf fatal_env; +void test_exitfn(int) attribute((noreturn)); + #define TEST(name) \ int main(int argc, char **argv) { \ test_init(argc, argv); \