From 5ed3b6561d90d13f64be7f9ae8beaf4a0b3f8e32 Mon Sep 17 00:00:00 2001 From: Heikki Levanto Date: Fri, 7 Jul 2006 13:39:02 +0000 Subject: [PATCH] Added YAZ_CHECK_TODO macro, used it in nfaxmltest1. Added rm *.log in tests make distclean. --- include/yaz/test.h | 20 +++++++++++++++++- src/test.c | 31 ++++++++++++++++++++------- test/Makefile.am | 4 +++- test/nfaxmltest1.c | 59 ++++++++++++++++++++++++++++++++++++---------------- 4 files changed, 87 insertions(+), 27 deletions(-) diff --git a/include/yaz/test.h b/include/yaz/test.h index fa42267..402f551 100644 --- a/include/yaz/test.h +++ b/include/yaz/test.h @@ -2,7 +2,7 @@ * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: test.h,v 1.8 2006-07-07 06:59:49 adam Exp $ + * $Id: test.h,v 1.9 2006-07-07 13:39:02 heikki Exp $ */ /** \file test.h @@ -32,6 +32,22 @@ int yaz_test_get_verbosity(); } \ } +/** \brief a test we know will fail at this time. + * + * Later, when the bug is fixed, this test will suddenly pass, + * which will be reported as an error, to remind you to go and fix + * your tests. + */ + +#define YAZ_CHECK_TODO(as) { \ + yaz_check_inc_todo(); \ + if (!as) { \ + yaz_check_print1(YAZ_TEST_TYPE_OK, __FILE__, __LINE__, "TODO: " #as); \ + } else { \ + yaz_check_print1(YAZ_TEST_TYPE_FAIL, __FILE__, __LINE__, "TODO: "#as); \ + } \ +} + /** \brief equality test. left, right only evaluated once */ #define YAZ_CHECK_EQ(left, right) { \ int lval = left; \ @@ -71,6 +87,8 @@ YAZ_EXPORT void yaz_check_print1(int type, const char *file, int line, YAZ_EXPORT void yaz_check_eq1(int type, const char *file, int line, const char *left, const char *right, int lval, int rval); +/** \brief used by macro. Should not be called directly */ +YAZ_EXPORT void yaz_check_inc_todo(void); YAZ_END_CDECL #endif diff --git a/src/test.c b/src/test.c index b39d221..7803177 100644 --- a/src/test.c +++ b/src/test.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: test.c,v 1.9 2006-07-07 06:59:49 adam Exp $ + * $Id: test.c,v 1.10 2006-07-07 13:39:04 heikki Exp $ */ /** \file test.c @@ -26,6 +26,7 @@ static FILE *test_fout = 0; /* can't use '= stdout' on some systems */ static int test_total = 0; static int test_failed = 0; +static int test_todo = 0; static int test_verbose = 1; static const char *test_prog = 0; static int log_tests = 0; @@ -113,26 +114,42 @@ void yaz_check_init_log(const char *argv0) char logfilename[2048]; log_tests = 1; sprintf(logfilename,"%s.log", progname(argv0) ); - unlink(logfilename); yaz_log_init_file(logfilename); yaz_log_trunc(); } +void yaz_check_inc_todo(void) +{ + test_todo++; +} + void yaz_check_term1(void) { /* summary */ if (test_failed) { - if (test_verbose >= 1) - fprintf(get_file(), "%d out of %d tests failed for program %s\n", + if (test_verbose >= 1) { + if (test_todo) + fprintf(get_file(), "%d out of %d tests failed for program %s" + " (%d TODO's remaining)\n", + test_failed, test_total, test_prog,test_todo); + else + fprintf(get_file(), "%d out of %d tests failed for program %s\n", test_failed, test_total, test_prog); + } } else { - if (test_verbose >= 2) - fprintf(get_file(), "%d tests passed for program %s\n", + if (test_verbose >= 2) { + if (test_todo) + fprintf(get_file(), "%d tests passed for program %s" + " (%d TODO's remaining)\n", + test_total, test_prog,test_todo); + else + fprintf(get_file(), "%d tests passed for program %s\n", test_total, test_prog); + } } if (test_fout) fclose(test_fout); @@ -182,7 +199,7 @@ void yaz_check_print1(int type, const char *file, int line, if (log_tests) { yaz_log(YLOG_LOG, "%s:%d %s: ", file, line, msg); - yaz_log(YLOG_LOG, "%s\n", expr); + yaz_log(YLOG_LOG, "%s", expr); } } diff --git a/test/Makefile.am b/test/Makefile.am index 014aada..bbce667 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,6 +1,6 @@ ## Copyright (C) 1994-2006, Index Data ApS ## All rights reserved. -## $Id: Makefile.am,v 1.22 2006-07-05 14:45:57 adam Exp $ +## $Id: Makefile.am,v 1.23 2006-07-07 13:39:05 heikki Exp $ check_PROGRAMS = tsticonv tstnmem tstmatchstr tstwrbuf tstodr tstccl tstlog \ tstsoap1 tstsoap2 tstodrstack tstlogthread tstxmlquery tstpquery \ @@ -39,6 +39,8 @@ tstodrcodec.c tstodrcodec.h: tstodr.asn $(YAZCOMP) LDADD = ../src/libyaz.la +CONFIG_CLEAN_FILES=*.log + tsticonv_SOURCES = tsticonv.c tstnmem_SOURCES = tstnmem.c tstmatchstr_SOURCES = tstmatchstr.c diff --git a/test/nfaxmltest1.c b/test/nfaxmltest1.c index 296dd97..b6cf6d5 100644 --- a/test/nfaxmltest1.c +++ b/test/nfaxmltest1.c @@ -1,7 +1,7 @@ /* Copyright (C) 2006, Index Data ApS * See the file LICENSE for details. * - * $Id: nfaxmltest1.c,v 1.5 2006-07-07 07:14:30 adam Exp $ + * $Id: nfaxmltest1.c,v 1.6 2006-07-07 13:39:05 heikki Exp $ * */ @@ -19,35 +19,57 @@ /** \brief Test parsing of a minimal, valid xml string */ void test1() { - char *xmlstr=" " - " " - " foo " - " bar " - "" - ""; - yaz_nfa *nfa=yaz_nfa_parse_xml_memory(xmlstr); -#if 0 -/* doesn't parse */ - YAZ_CHECK(nfa); -#endif + char *xmlstr = " " + " " + " foo " + " bar " + "" + ""; + yaz_nfa *nfa = yaz_nfa_parse_xml_memory(xmlstr); + YAZ_CHECK_TODO(nfa); } - /** \brief Test parsing of a minimal, invalid xml string */ void test2() { yaz_nfa *nfa; - char *xmlstr=" " - " " - " foo " - " bar " - ""; + char *xmlstr = " " + " " + " foo " + " bar " + ""; /* missing "" */ yaz_log(YLOG_LOG,"Parsing bad xml, expecting errors:"); nfa = yaz_nfa_parse_xml_memory(xmlstr); YAZ_CHECK(!nfa); } +/** \brief Test parsing a few minimal xml files */ +void test3() { + char *goodfilenames[] = { + "nfaxml-simple.xml", + "nfaxml-main.xml", /* x-includes nfaxml-include */ + 0}; + char *badfilenames[] = { + "nfaxml-missing.xml", /* file not there at all */ + "nfaxml-badinclude.xml", /* bad xinclude in it */ + 0}; + yaz_nfa *nfa; + char **f = goodfilenames; + do { + yaz_log(YLOG_LOG,"Parsing (good) xml file '%s'", *f); + nfa=yaz_nfa_parse_xml_file(*f); + YAZ_CHECK_TODO(nfa); + } while (*++f); + + f = badfilenames; + do { + yaz_log(YLOG_LOG,"Parsing bad xml file '%s'. Expecting errors", *f); + nfa = yaz_nfa_parse_xml_file(*f); + YAZ_CHECK(!nfa); + } while (*++f); +} + int main(int argc, char **argv) { @@ -57,6 +79,7 @@ int main(int argc, char **argv) test1(); test2(); + test3(); nmem_exit (); YAZ_CHECK_TERM; -- 1.7.10.4