2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: test.c,v 1.5 2006-04-20 20:50:51 adam 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"
88 fprintf(stderr, "Unrecognized option for YAZ test: %s\n",
90 fprintf(stderr, "Use --test-help for more info\n");
97 /* remove --test- options from argc, argv so that they disappear */
98 (*argv_p)[i-1] = **argv_p; /* program name */
104 void yaz_check_term1(void)
109 if (test_verbose >= 1)
110 fprintf(get_file(), "%d out of %d tests failed for program %s\n",
111 test_failed, test_total, test_prog);
115 if (test_verbose >= 2)
116 fprintf(get_file(), "%d tests passed for program %s\n",
117 test_total, test_prog);
126 void yaz_check_eq1(int type, const char *file, int line,
127 const char *left, const char *right, int lval, int rval)
131 sprintf(formstr, "%.500s != %.500s\n%d != %d", left, right, lval, rval);
132 yaz_check_print1(type, file, line, formstr);
135 void yaz_check_print1(int type, const char *file, int line,
138 const char *msg = "unknown";
143 case YAZ_TEST_TYPE_FAIL:
146 if (test_verbose < 1)
149 case YAZ_TEST_TYPE_OK:
151 if (test_verbose < 3)
155 fprintf(get_file(), "%s:%d %s: ", file, line, msg);
156 fprintf(get_file(), "%s\n", expr);
163 * indent-tabs-mode: nil
165 * vim: shiftwidth=4 tabstop=8 expandtab