Added yaz_log_trunc() to truncate the log file
[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.7 2006-07-06 13:10:29 heikki 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();
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 equality test. left, right only evaluated once */
36 #define YAZ_CHECK_EQ(left, right) { \
37   int lval = left; \
38   int rval = right; \
39   if (lval == rval) { \
40     yaz_check_eq1(YAZ_TEST_TYPE_OK, __FILE__, __LINE__, \
41      #left, #right, lval, rval); \
42   } else { \
43     yaz_check_eq1(YAZ_TEST_TYPE_FAIL, __FILE__, __LINE__, \
44      #left, #right, lval, rval); \
45   } \
46 }
47
48 /** \brief Macro to initialize the system (in start of main typically) */
49 #define YAZ_CHECK_INIT(argc, argv) yaz_check_init1(&argc, &argv)
50 /** \brief Macro to terminate the system (end of main, normally) */
51 #define YAZ_CHECK_TERM yaz_check_term1(); return 0
52
53 /** \brief Macro to enable and initialize the yaz_log(start of main) */
54 #define YAZ_CHECK_LOG() yaz_check_init_log(argv[0])
55
56 YAZ_BEGIN_CDECL
57
58 /** \brief used by macro. Should not be called directly */
59 YAZ_EXPORT void yaz_check_init1(int *argc, char ***argv);
60
61 /** \brief used by macro. Should not be called directly */
62 YAZ_EXPORT void yaz_check_term1(void);
63
64 /** \brief used by macro. Should not be called directly */
65 YAZ_EXPORT void yaz_check_init_log(char *argv0);
66
67 /** \brief used by macro. Should not be called directly */
68 YAZ_EXPORT void yaz_check_print1(int type, const char *file, int line,
69                                  const char *expr);
70 /** \brief used by macro. Should not be called directly */
71 YAZ_EXPORT void yaz_check_eq1(int type, const char *file, int line,
72                               const char *left, const char *right,
73                               int lval, int rval);
74 YAZ_END_CDECL
75
76 #endif
77 /*
78  * Local variables:
79  * c-basic-offset: 4
80  * indent-tabs-mode: nil
81  * End:
82  * vim: shiftwidth=4 tabstop=8 expandtab
83  */
84