222b0d43aaaedda0307dda873233705a14d7505c
[strongswan.git] / Source / charon / utils / tester.h
1 /**
2 * @file tester.h
3 *
4 * @brief Test module for automatic testing
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef TESTER_H_
24 #define TESTER_H_
25
26 #include <stdio.h>
27
28 #include <types.h>
29
30
31
32 typedef struct test_t test_t;
33
34 typedef struct tester_t tester_t;
35
36 /**
37 * @brief Specifies a test
38 */
39 struct test_t {
40 void (*test_function) (tester_t * tester);
41 char * test_name;
42 };
43
44 /**
45 * @brief A tester object to perform tests with
46 */
47 struct tester_t {
48
49 /**
50 * @brief Tests all testcases in array tests with specific tester object
51 *
52 * @param tester tester object
53 * @param pointer to a array of test_t-pointers.
54 * the last item has to be NULL.
55 * @return SUCCESSFUL if succeeded, FAILED otherwise
56 */
57 status_t (*perform_tests) (tester_t *tester,test_t **tests);
58
59 /**
60 * @brief run a specific test case
61 *
62 * @param this tester object
63 * @param test pointer to a test_t object which will be performed
64 * @param Name of the Test
65 */
66 status_t (*perform_test) (tester_t *tester, test_t *test);
67
68 /**
69 * @brief is called in a testcase to check a specific situation for TRUE
70 *
71 * Log-Values to the tester output are protected from multiple access
72 *
73 * @warning this function should only be called in a test_function
74 *
75 * @param this tester object
76 * @param to_be_true assert which has to be TRUE
77 * @param Name of the assertion
78 */
79 void (*assert_true) (tester_t *tester, bool to_be_true, char *assert_name);
80
81 /**
82 * @brief is called in a testcase to check a specific situation for FALSE
83 *
84 * Log-Values to the tester output are protected from multiple access
85 *
86 * @warning this function should only be called in a test_function
87 *
88 * @param this tester object
89 * @param to_be_false assert which has to be FALSE
90 * @param Name of the assertion
91 */
92 void (*assert_false) (tester_t *tester, bool to_be_false, char *assert_name);
93
94 /**
95 * @brief Destroys a tester object
96 *
97 * @param tester tester object
98 * @return SUCCESSFUL if succeeded, FAILED otherwise
99 */
100 status_t (*destroy) (tester_t *tester);
101 };
102
103 /**
104 * @brief creates a tester object needed to perform tests
105 *
106 * @param output test output is written to this output
107 * @param display_succeeded_asserts has to be TRUE, if all asserts should be displayed,
108 * else otherwise
109 *
110 * @return tester object
111 */
112 tester_t *tester_create(FILE *output, bool display_succeeded_asserts);
113
114 #endif /*TESTER_H_*/