X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Ftest.c;h=7beefb1256e39aa818560993a448e930c23c7e25;hp=7d521b8033a9b290e9ee200a403cd3505dcb299c;hb=4f8ea8cfaf2f3d95e4efcf9494526c2b4be43eb8;hpb=fc42e0dc251df1d80ffc4c9279478d64d8a7027c diff --git a/src/test.c b/src/test.c index 7d521b8..7beefb1 100644 --- a/src/test.c +++ b/src/test.c @@ -1,8 +1,8 @@ /* - * Copyright (C) 1995-2005, Index Data ApS + * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: test.c,v 1.8 2006-07-06 13:10:31 heikki Exp $ + * $Id: test.c,v 1.12 2007-01-03 08:42:15 adam Exp $ */ /** \file test.c @@ -16,7 +16,9 @@ #include #include #include +#if HAVE_UNISTSD_H #include +#endif #include #include @@ -24,20 +26,21 @@ 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 char *test_prog = 0; +static const char *test_prog = 0; static int log_tests = 0; -static FILE *get_file() +static FILE *get_file(void) { if (test_fout) return test_fout; return stdout; } -static char *progname(char *argv0) +static const char *progname(const char *argv0) { - char *cp = strrchr(argv0, '/'); + const char *cp = strrchr(argv0, '/'); if (cp) return cp+1; cp = strrchr(argv0, '\\'); @@ -106,31 +109,47 @@ void yaz_check_init1(int *argc_p, char ***argv_p) } /** \brief Initialize the log system */ -void yaz_check_init_log(char *argv0) +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); @@ -144,7 +163,7 @@ void yaz_check_eq1(int type, const char *file, int line, { char formstr[2048]; - if (type==YAZ_TEST_TYPE_OK) + if (type == YAZ_TEST_TYPE_OK) sprintf(formstr, "%.500s == %.500s ", left, right); else sprintf(formstr, "%.500s != %.500s\n %d != %d", left, right, lval,rval); @@ -155,7 +174,7 @@ void yaz_check_print1(int type, const char *file, int line, const char *expr) { const char *msg = "unknown"; - int printit=1; + int printit = 1; test_total++; switch(type) @@ -164,26 +183,29 @@ void yaz_check_print1(int type, const char *file, int line, test_failed++; msg = "FAILED"; if (test_verbose < 1) - printit=0; + printit = 0; break; case YAZ_TEST_TYPE_OK: msg = "ok"; if (test_verbose < 3) - printit=0; + printit = 0; break; } - if (printit) { + if (printit) + { fprintf(get_file(), "%s:%d %s: ", file, line, msg); fprintf(get_file(), "%s\n", expr); } - if (log_tests) { + 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); } } -int yaz_test_get_verbosity(){ +int yaz_test_get_verbosity() +{ return test_verbose; }