26c138c9e8be9066d9d203bb34da754d1fd35e38
[debian/amanda] / common-src / testutils.h
1 /*
2  * Copyright (c) 2005-2008 Zmanda Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16  *
17  * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
18  * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19  */
20
21 #ifndef TESTUTILS_H
22 #define TESTUTILS_H
23
24 /*
25  * A library of utilities for writing 'make check'-based tests.
26  *
27  * Use this module like this:
28  *   int test_one(void) {
29  *      ...
30  *      tu_dbg("yep, worked: %p", someptr);
31  *      ...
32  *      return TRUE;
33  *   }
34  *
35  *   int main(int argc, char **argv)
36  *   {
37  *      TestUtilsTest tests[] = {
38  *          TU_TEST(test_one, 5),
39  *          TU_TEST(test_two, 6),
40  *          ...
41  *          TU_END()
42  *      }
43  *
44  *      return testutils_run_tests(argc, argv, tests);
45  *   }
46  */
47
48 /*
49  * Defining tests
50  */
51
52 /* A test function, returning a boolean */
53 typedef int (*TestFunction)(void);
54
55 /* A struct for test functions */
56 typedef struct TestUtilsTest {
57     TestFunction fn;
58     char *name;
59     int timeout;
60     int selected;
61 } TestUtilsTest;
62
63 /* Macro to define a test array element */
64 #define TU_TEST(fn, to) { fn, #fn, to, FALSE }
65 #define TU_END() { NULL, NULL, 0, FALSE }
66
67 /*
68  * Debugging
69  */
70
71 /* Debugging macro taking printf arguments.  This is only enabled if the '-d' flag
72  * is given on the commandline.  You can use g_debug, too, if you'd prefer. */
73 #define tu_dbg(...) if (tu_debugging_enabled) { g_fprintf(stderr, __VA_ARGS__); }
74
75 /* Is debugging enabled for this test run? (set internally) */
76 int tu_debugging_enabled;
77
78 /*
79  * Main loop
80  */
81
82 int testutils_run_tests(int argc, char **argv, TestUtilsTest *tests);
83
84 #endif /* TESTUTILS_H */