2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: test.c,v 1.3 2006-01-29 21:59:13 adam Exp $
17 static FILE *test_fout = 0; /* can't use '= stdout' on some systems */
18 static int test_total = 0;
19 static int test_failed = 0;
20 static int test_verbose = 1;
21 static char *test_prog = 0;
23 static FILE *get_file()
30 static char *progname(char *argv0)
32 char *cp = strrchr(argv0, '/');
35 cp = strrchr(argv0, '\\');
41 void yaz_check_init1(int *argc_p, char ***argv_p)
45 char **argv = *argv_p;
47 test_prog = progname(argv[0]);
49 for (i = 1; i<argc; i++)
51 if (strlen(argv[i]) >= 7 && !memcmp(argv[i], "--test-", 7))
53 const char *suf = argv[i]+7;
54 if (i < argc-1 && !strcmp(suf, "file"))
59 test_fout = fopen(argv[i], "w");
62 else if (i < argc-1 && !strcmp(suf, "verbose"))
65 test_verbose = atoi(argv[i]);
68 else if (!strcmp(suf, "help"))
72 "--test-file fname output to fname\n"
73 "--test-verbose level verbose level\n"
74 " 0=Quiet. Only exit code tells what's wrong\n"
75 " 1=Report+Summary only if tests fail.\n"
76 " 2=Report failures. Print summary always\n"
77 " 3=Report + summary always\n"
83 fprintf(stderr, "Unrecognized option for YAZ test: %s\n",
85 fprintf(stderr, "Use --test-help for more info\n");
92 /* remove --test- options from argc, argv so that they disappear */
93 (*argv_p)[i-1] = **argv_p; /* program name */
99 void yaz_check_term1(void)
104 if (test_verbose >= 1)
105 fprintf(get_file(), "%d out of %d tests failed for program %s\n",
106 test_failed, test_total, test_prog);
110 if (test_verbose >= 2)
111 fprintf(get_file(), "%d tests passed for program %s\n",
112 test_total, test_prog);
121 void yaz_check_print1(int type, const char *file, int line, const char *expr)
123 const char *msg = "unknown";
128 case YAZ_TEST_TYPE_FAIL:
131 if (test_verbose < 1)
134 case YAZ_TEST_TYPE_OK:
136 if (test_verbose < 3)
140 fprintf(get_file(), "%s:%d %s: %s\n", file, line, msg, expr);
147 * indent-tabs-mode: nil
149 * vim: shiftwidth=4 tabstop=8 expandtab