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