* 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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
#include <yaz/test.h>
+#include <yaz/log.h>
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()
{
" 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);
}
*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 */
const char *expr)
{
const char *msg = "unknown";
+ int printit=1;
test_total++;
switch(type)
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