X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ftest.c;h=7d521b8033a9b290e9ee200a403cd3505dcb299c;hb=48bd1822e09cb4e5545c3e0a0178e45a664da8c6;hp=f6dd704d311e8c76e89e8e54f370afc2eaf011f2;hpb=228ac8e67af8286708bf4ef65622e3d742272d61;p=yaz-moved-to-github.git diff --git a/src/test.c b/src/test.c index f6dd704..7d521b8 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.6 2006-04-26 16:58:27 heikki Exp $ + * $Id: test.c,v 1.8 2006-07-06 13:10:31 heikki Exp $ */ /** \file test.c @@ -16,14 +16,17 @@ #include #include #include +#include #include +#include 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_verbose = 1; static char *test_prog = 0; +static int log_tests = 0; static FILE *get_file() { @@ -80,6 +83,7 @@ void yaz_check_init1(int *argc_p, char ***argv_p) " 1=Report+Summary only if tests fail.\n" " 2=Report failures. Print summary always\n" " 3=Report + summary always\n" + " 4=Report + summary + extra prints from tests\n" ); exit(0); } @@ -101,6 +105,18 @@ void yaz_check_init1(int *argc_p, char ***argv_p) *argv_p += i; } +/** \brief Initialize the log system */ +void yaz_check_init_log(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_term1(void) { /* summary */ @@ -139,6 +155,7 @@ void yaz_check_print1(int type, const char *file, int line, const char *expr) { const char *msg = "unknown"; + int printit=1; test_total++; switch(type) @@ -147,19 +164,29 @@ void yaz_check_print1(int type, const char *file, int line, test_failed++; msg = "FAILED"; if (test_verbose < 1) - return; + printit=0; break; case YAZ_TEST_TYPE_OK: msg = "ok"; if (test_verbose < 3) - return; + printit=0; break; } - fprintf(get_file(), "%s:%d %s: ", file, line, msg); - fprintf(get_file(), "%s\n", expr); + if (printit) { + fprintf(get_file(), "%s:%d %s: ", file, line, msg); + fprintf(get_file(), "%s\n", expr); + } + if (log_tests) { + yaz_log(YLOG_LOG, "%s:%d %s: ", file, line, msg); + yaz_log(YLOG_LOG, "%s\n", expr); + } } +int yaz_test_get_verbosity(){ + return test_verbose; +} + /* * Local variables: * c-basic-offset: 4