X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=include%2Fyaz%2Ftest.h;h=fa42267fdc9ada36b0cb2836206c636203b1d86e;hb=5c35a542079457f2f5bcb9f367d6c449a2879822;hp=93ecb06e9346b8f82971b684bf51d06471b1747f;hpb=cf75a1bc424083953d4f29e38177f178821de55f;p=yaz-moved-to-github.git diff --git a/include/yaz/test.h b/include/yaz/test.h index 93ecb06..fa42267 100644 --- a/include/yaz/test.h +++ b/include/yaz/test.h @@ -1,28 +1,78 @@ /* - * Copyright (C) 1995-2005, Index Data ApS + * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: test.h,v 1.1 2006-01-27 17:30:44 adam Exp $ + * $Id: test.h,v 1.8 2006-07-07 06:59:49 adam Exp $ */ +/** \file test.h + \brief Unit Test for YAZ +*/ + #ifndef YAZ_TEST_H #define YAZ_TEST_H #include #include -#define YAZ_CHECK_INIT(thename) \ -static char *yaz_unit_test_name = #thename; -static FILE *yaz_unit_file = 0; \ -static int yaz_unit_test_number = 0; \ +/** \brief Get the verbosity level */ +int yaz_test_get_verbosity(); + +/** \brief Test OK */ +#define YAZ_TEST_TYPE_OK 1 +/** \brief Test failed */ +#define YAZ_TEST_TYPE_FAIL 2 + +/** \brief boolean test. as only evaluated once */ +#define YAZ_CHECK(as) { \ + if (as) { \ + yaz_check_print1(YAZ_TEST_TYPE_OK, __FILE__, __LINE__, #as); \ + } else { \ + yaz_check_print1(YAZ_TEST_TYPE_FAIL, __FILE__, __LINE__, #as); \ + } \ +} -#define YAZ_CHECK(as) \ -yaz_unit_test_number++; \ -if (!yaz_unit_file) yaz_unit_file = stderr; \ -if (!as) { \ - fprintf(yaz_unit_file, "%s:%d test failed: %s\n", __FILE__, __LINE__, #as); \ +/** \brief equality test. left, right only evaluated once */ +#define YAZ_CHECK_EQ(left, right) { \ + int lval = left; \ + int rval = right; \ + if (lval == rval) { \ + yaz_check_eq1(YAZ_TEST_TYPE_OK, __FILE__, __LINE__, \ + #left, #right, lval, rval); \ + } else { \ + yaz_check_eq1(YAZ_TEST_TYPE_FAIL, __FILE__, __LINE__, \ + #left, #right, lval, rval); \ + } \ } +/** \brief Macro to initialize the system (in start of main typically) */ +#define YAZ_CHECK_INIT(argc, argv) yaz_check_init1(&argc, &argv) +/** \brief Macro to terminate the system (end of main, normally) */ +#define YAZ_CHECK_TERM yaz_check_term1(); return 0 + +/** \brief Macro to enable and initialize the yaz_log(start of main) */ +#define YAZ_CHECK_LOG() yaz_check_init_log(argv[0]) + +YAZ_BEGIN_CDECL + +/** \brief used by macro. Should not be called directly */ +YAZ_EXPORT void yaz_check_init1(int *argc, char ***argv); + +/** \brief used by macro. Should not be called directly */ +YAZ_EXPORT void yaz_check_term1(void); + +/** \brief used by macro. Should not be called directly */ +YAZ_EXPORT void yaz_check_init_log(const char *argv0); + +/** \brief used by macro. Should not be called directly */ +YAZ_EXPORT void yaz_check_print1(int type, const char *file, int line, + const char *expr); +/** \brief used by macro. Should not be called directly */ +YAZ_EXPORT void yaz_check_eq1(int type, const char *file, int line, + const char *left, const char *right, + int lval, int rval); +YAZ_END_CDECL + #endif /* * Local variables: