resetting manifest requested domain to floor
[platform/upstream/ccache.git] / test / framework.h
1 /*
2  * Copyright (C) 2010 Joel Rosdahl
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 as published by the Free
6  * Software Foundation; either version 3 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #ifndef TEST_FRAMEWORK_H
20 #define TEST_FRAMEWORK_H
21
22 #include "ccache.h"
23
24 /*****************************************************************************/
25
26 #define TEST_SUITE(name) \
27         unsigned suite_##name(unsigned _start_point) \
28         { \
29                 unsigned _test_counter = 0; \
30                 cct_suite_begin(#name); \
31                 { \
32                         /* Empty due to macro trickery. */
33
34 #define TEST(name) \
35                         cct_test_end(); \
36                 } \
37                 ++_test_counter; \
38                 { static int name = 0; (void)name; /* Verify test name. */ } \
39                 if (_test_counter >= _start_point) { \
40                         cct_test_begin(#name);
41
42 #define TEST_SUITE_END \
43                         cct_test_end(); \
44                 } \
45                 cct_suite_end(); \
46                 return 0; /* We have reached the end. */ \
47         }
48
49 /*****************************************************************************/
50
51 #define CHECK(assertion) \
52         do { \
53                 if ((assertion)) { \
54                         cct_check_passed(__FILE__, __LINE__, #assertion); \
55                 } else { \
56                         cct_check_failed(__FILE__, __LINE__, #assertion, NULL, NULL); \
57                         cct_test_end(); \
58                         cct_suite_end(); \
59                         return _test_counter; \
60                 } \
61         } while (0)
62
63 #define CHECK_POINTER_EQ_BASE(t, e, a, f1, f2)        \
64         do { \
65                 if (!cct_check_##t##_eq(__FILE__, __LINE__, #a, (e), (a), (f1), (f2))) { \
66                         cct_test_end(); \
67                         cct_suite_end(); \
68                         return _test_counter; \
69                 } \
70         } while (0)
71
72 /*****************************************************************************/
73
74 #define CHECK_INT_EQ(expected, actual) \
75         do { \
76                 if (!cct_check_int_eq(__FILE__, __LINE__, #actual, (expected), (actual))) { \
77                         cct_test_end(); \
78                         cct_suite_end(); \
79                         return _test_counter; \
80                 } \
81         } while (0)
82
83 #define CHECK_UNS_EQ(expected, actual) \
84         do { \
85                 if (!cct_check_int_eq(__FILE__, __LINE__, #actual, (expected), (actual))) { \
86                         cct_test_end(); \
87                         cct_suite_end(); \
88                         return _test_counter; \
89                 } \
90         } while (0)
91
92 /*****************************************************************************/
93
94 #define CHECK_STR_EQ(expected, actual) \
95         CHECK_POINTER_EQ_BASE(str, expected, actual, 0, 0)
96
97 #define CHECK_STR_EQ_FREE1(expected, actual) \
98         CHECK_POINTER_EQ_BASE(str, expected, actual, 1, 0)
99
100 #define CHECK_STR_EQ_FREE2(expected, actual) \
101         CHECK_POINTER_EQ_BASE(str, expected, actual, 0, 1)
102
103 #define CHECK_STR_EQ_FREE12(expected, actual) \
104         CHECK_POINTER_EQ_BASE(str, expected, actual, 1, 1)
105
106 /*****************************************************************************/
107
108 #define CHECK_ARGS_EQ(expected, actual) \
109         CHECK_POINTER_EQ_BASE(args, expected, actual, 0, 0)
110
111 #define CHECK_ARGS_EQ_FREE1(expected, actual) \
112         CHECK_POINTER_EQ_BASE(args, expected, actual, 1, 0)
113
114 #define CHECK_ARGS_EQ_FREE2(expected, actual) \
115         CHECK_POINTER_EQ_BASE(args, expected, actual, 0, 1)
116
117 #define CHECK_ARGS_EQ_FREE12(expected, actual) \
118         CHECK_POINTER_EQ_BASE(args, expected, actual, 1, 1)
119
120 /*****************************************************************************/
121
122 typedef unsigned (*suite_fn)(unsigned);
123 int cct_run(suite_fn *suites, int verbose);
124
125 void cct_suite_begin(const char *name);
126 void cct_suite_end();
127 void cct_test_begin(const char *name);
128 void cct_test_end();
129 void cct_check_passed(const char *file, int line, const char *assertion);
130 void cct_check_failed(const char *file, int line, const char *assertion,
131                       const char *expected, const char *actual);
132 int cct_check_int_eq(const char *file, int line, const char *expression,
133                      int expected, int actual);
134 int cct_check_uns_eq(const char *file, int line, const char *expression,
135                      unsigned expected, unsigned actual);
136 int cct_check_str_eq(const char *file, int line, const char *expression,
137                      const char *expected, const char *actual, int free1,
138                      int free2);
139 int cct_check_args_eq(const char *file, int line, const char *expression,
140                       struct args *expected, struct args *actual,
141                       int free1, int free2);
142 void cct_chdir(const char *path);
143 void cct_wipe(const char *path);
144 void cct_create_fresh_dir(const char *path);
145
146 #endif