Change K&R-style empty function declarations to explicit ANSI-C (void) prototypes
[yaz-moved-to-github.git] / include / yaz / test.h
1 /*
2  * Copyright (C) 1995-2006, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: test.h,v 1.10 2006-10-04 16:59:33 mike Exp $
6  */
7
8 /** \file test.h
9     \brief Unit Test for YAZ
10 */
11
12 #ifndef YAZ_TEST_H
13 #define YAZ_TEST_H
14
15 #include <yaz/yconfig.h>
16 #include <stdio.h>
17
18 /** \brief Get the verbosity level */
19 int yaz_test_get_verbosity(void);
20
21 /** \brief Test OK */
22 #define YAZ_TEST_TYPE_OK 1
23 /** \brief Test failed */
24 #define YAZ_TEST_TYPE_FAIL 2
25
26 /** \brief boolean test. as only evaluated once */
27 #define YAZ_CHECK(as) { \
28   if (as) { \
29     yaz_check_print1(YAZ_TEST_TYPE_OK, __FILE__, __LINE__, #as); \
30   } else { \
31     yaz_check_print1(YAZ_TEST_TYPE_FAIL, __FILE__, __LINE__, #as); \
32   } \
33 }
34
35 /** \brief a test we know will fail at this time. 
36  *
37  * Later, when the bug is fixed, this test will suddenly pass,
38  * which will be reported as an error, to remind you to go and fix 
39  * your tests.
40  */
41
42 #define YAZ_CHECK_TODO(as) { \
43   yaz_check_inc_todo(); \
44   if (!as) { \
45     yaz_check_print1(YAZ_TEST_TYPE_OK, __FILE__, __LINE__, "TODO: " #as); \
46   } else { \
47     yaz_check_print1(YAZ_TEST_TYPE_FAIL, __FILE__, __LINE__, "TODO: "#as); \
48   } \
49 }
50
51 /** \brief equality test. left, right only evaluated once */
52 #define YAZ_CHECK_EQ(left, right) { \
53   int lval = left; \
54   int rval = right; \
55   if (lval == rval) { \
56     yaz_check_eq1(YAZ_TEST_TYPE_OK, __FILE__, __LINE__, \
57      #left, #right, lval, rval); \
58   } else { \
59     yaz_check_eq1(YAZ_TEST_TYPE_FAIL, __FILE__, __LINE__, \
60      #left, #right, lval, rval); \
61   } \
62 }
63
64 /** \brief Macro to initialize the system (in start of main typically) */
65 #define YAZ_CHECK_INIT(argc, argv) yaz_check_init1(&argc, &argv)
66 /** \brief Macro to terminate the system (end of main, normally) */
67 #define YAZ_CHECK_TERM yaz_check_term1(); return 0
68
69 /** \brief Macro to enable and initialize the yaz_log(start of main) */
70 #define YAZ_CHECK_LOG() yaz_check_init_log(argv[0])
71
72 YAZ_BEGIN_CDECL
73
74 /** \brief used by macro. Should not be called directly */
75 YAZ_EXPORT void yaz_check_init1(int *argc, char ***argv);
76
77 /** \brief used by macro. Should not be called directly */
78 YAZ_EXPORT void yaz_check_term1(void);
79
80 /** \brief used by macro. Should not be called directly */
81 YAZ_EXPORT void yaz_check_init_log(const char *argv0);
82
83 /** \brief used by macro. Should not be called directly */
84 YAZ_EXPORT void yaz_check_print1(int type, const char *file, int line,
85                                  const char *expr);
86 /** \brief used by macro. Should not be called directly */
87 YAZ_EXPORT void yaz_check_eq1(int type, const char *file, int line,
88                               const char *left, const char *right,
89                               int lval, int rval);
90 /** \brief used by macro. Should not be called directly */
91 YAZ_EXPORT void  yaz_check_inc_todo(void);
92 YAZ_END_CDECL
93
94 #endif
95 /*
96  * Local variables:
97  * c-basic-offset: 4
98  * indent-tabs-mode: nil
99  * End:
100  * vim: shiftwidth=4 tabstop=8 expandtab
101  */
102