added missing includes
[strongswan.git] / src / charon / plugins / unit_tester / unit_tester.c
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * $Id$
16 */
17
18 #include "unit_tester.h"
19
20 #include <daemon.h>
21
22 typedef struct private_unit_tester_t private_unit_tester_t;
23 typedef struct unit_test_t unit_test_t;
24 typedef enum test_status_t test_status_t;
25
26 /**
27 * private data of unit_tester
28 */
29 struct private_unit_tester_t {
30
31 /**
32 * public functions
33 */
34 unit_tester_t public;
35 };
36
37 struct unit_test_t {
38
39 /**
40 * name of the test
41 */
42 char *name;
43
44 /**
45 * test function
46 */
47 bool (*test)(void);
48
49 /**
50 * run the test?
51 */
52 bool enabled;
53 };
54
55 #undef DEFINE_TEST
56 #define DEFINE_TEST(name, function, enabled) bool function();
57 #include <plugins/unit_tester/tests.h>
58 #undef DEFINE_TEST
59 #define DEFINE_TEST(name, function, enabled) {name, function, enabled},
60 static unit_test_t tests[] = {
61 #include <plugins/unit_tester/tests.h>
62 };
63
64 static void run_tests(private_unit_tester_t *this)
65 {
66 int i, run = 0, failed = 0, success = 0, skipped = 0;
67
68 DBG1(DBG_CFG, "running unit tests, %d tests registered",
69 sizeof(tests)/sizeof(unit_test_t));
70
71 for (i = 0; i < sizeof(tests)/sizeof(unit_test_t); i++)
72 {
73 if (tests[i].enabled)
74 {
75 run++;
76 if (tests[i].test())
77 {
78 DBG1(DBG_CFG, "test '%s' successful", tests[i].name);
79 success++;
80 }
81 else
82 {
83 DBG1(DBG_CFG, "test '%s' failed", tests[i].name);
84 failed++;
85 }
86 }
87 else
88 {
89 DBG1(DBG_CFG, "test '%s' disabled", tests[i].name);
90 skipped++;
91 }
92 }
93 DBG1(DBG_CFG, "%d/%d tests successful (%d failed, %d disabled)",
94 success, run, failed, skipped);
95 }
96
97 /**
98 * Implementation of 2007_t.destroy
99 */
100 static void destroy(private_unit_tester_t *this)
101 {
102 free(this);
103 }
104
105 /*
106 * see header file
107 */
108 plugin_t *plugin_create()
109 {
110 private_unit_tester_t *this = malloc_thing(private_unit_tester_t);
111
112 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
113
114 run_tests(this);
115
116 return &this->public.plugin;
117 }
118