2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: test.c,v 1.7 2006-05-10 12:52:28 heikki Exp $
9 \brief Unit Test for YAZ
22 static FILE *test_fout = 0; /* can't use '= stdout' on some systems */
23 static int test_total = 0;
24 static int test_failed = 0;
25 static int test_verbose = 1;
26 static char *test_prog = 0;
28 static FILE *get_file()
35 static char *progname(char *argv0)
37 char *cp = strrchr(argv0, '/');
40 cp = strrchr(argv0, '\\');
46 void yaz_check_init1(int *argc_p, char ***argv_p)
50 char **argv = *argv_p;
52 test_prog = progname(argv[0]);
54 for (i = 1; i<argc; i++)
56 if (strlen(argv[i]) >= 7 && !memcmp(argv[i], "--test-", 7))
58 const char *suf = argv[i]+7;
59 if (i < argc-1 && !strcmp(suf, "file"))
64 test_fout = fopen(argv[i], "w");
67 else if (i < argc-1 && !strcmp(suf, "verbose"))
70 test_verbose = atoi(argv[i]);
73 else if (!strcmp(suf, "help"))
77 "--test-file fname output to fname\n"
78 "--test-verbose level verbose level\n"
79 " 0=Quiet. Only exit code tells what's wrong\n"
80 " 1=Report+Summary only if tests fail.\n"
81 " 2=Report failures. Print summary always\n"
82 " 3=Report + summary always\n"
83 " 4=Report + summary + extra prints from tests\n"
89 fprintf(stderr, "Unrecognized option for YAZ test: %s\n",
91 fprintf(stderr, "Use --test-help for more info\n");
98 /* remove --test- options from argc, argv so that they disappear */
99 (*argv_p)[i-1] = **argv_p; /* program name */
105 void yaz_check_term1(void)
110 if (test_verbose >= 1)
111 fprintf(get_file(), "%d out of %d tests failed for program %s\n",
112 test_failed, test_total, test_prog);
116 if (test_verbose >= 2)
117 fprintf(get_file(), "%d tests passed for program %s\n",
118 test_total, test_prog);
127 void yaz_check_eq1(int type, const char *file, int line,
128 const char *left, const char *right, int lval, int rval)
132 if (type==YAZ_TEST_TYPE_OK)
133 sprintf(formstr, "%.500s == %.500s ", left, right);
135 sprintf(formstr, "%.500s != %.500s\n %d != %d", left, right, lval,rval);
136 yaz_check_print1(type, file, line, formstr);
139 void yaz_check_print1(int type, const char *file, int line,
142 const char *msg = "unknown";
147 case YAZ_TEST_TYPE_FAIL:
150 if (test_verbose < 1)
153 case YAZ_TEST_TYPE_OK:
155 if (test_verbose < 3)
159 fprintf(get_file(), "%s:%d %s: ", file, line, msg);
160 fprintf(get_file(), "%s\n", expr);
164 int yaz_test_get_verbosity(){
171 * indent-tabs-mode: nil
173 * vim: shiftwidth=4 tabstop=8 expandtab