chiark / gitweb /
fatal() testing for dateparse()
authorRichard Kettlewell <rjk@greenend.org.uk>
Tue, 27 May 2008 21:37:05 +0000 (22:37 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Tue, 27 May 2008 21:37:05 +0000 (22:37 +0100)
.bzrignore
lib/Makefile.am
libtests/Makefile.am
libtests/t-dateparse.c
libtests/test.c
libtests/test.h

index 8824dd58daffd7d5b3b750c3075122b9ea36c984..9a601a232b103222ab043fe2eb3cc3cf6d287a80 100644 (file)
@@ -193,3 +193,4 @@ libtests/t-event
 libtests/t-dateparse
 libtests/Makefile
 cgi/Makefile
+libtests/index.html
index 95f6d01926ac42f79d442ede41da327e7036ef32..ba537926820fa6647e09a90f9ad62cf37380f14a 100644 (file)
@@ -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
index f5fbb00d73eb64f2b8fb87d20967f69048253411..5c7cc5498b3241e3382043e0214de9d049e680b4 100644 (file)
@@ -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
index 1e07c742f2cccc2e0d20db7ce200149d12306cad..a0d8e3120c7e69d4c7d0eebd78facb1d8bebe826 100644 (file)
@@ -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);
index f5dd036d443eff8581549c539b8b6ab4e38e592a..d37d70fa78a41212e9b99ab49a3701ed825659a4 100644 (file)
@@ -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' },
index cb26b62068369aa3f8fef7a7ad768f82afc90f49..8af85d515c5fead40b1d624d28a58adde1ec431a 100644 (file)
@@ -37,6 +37,7 @@
 #include <netinet/in.h>
 #include <sys/un.h>
 #include <pcre.h>
+#include <setjmp.h>
 
 #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);                                              \