1
// Copyright (c) 2010, Google Inc.
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
8
// * Redistributions of source code must retain the above copyright
9
// notice, this list of conditions and the following disclaimer.
10
// * Redistributions in binary form must reproduce the above
11
// copyright notice, this list of conditions and the following disclaimer
12
// in the documentation and/or other materials provided with the
14
// * Neither the name of Google Inc. nor the names of its
15
// contributors may be used to endorse or promote products derived from
16
// this software without specific prior written permission.
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
// Author: Craig Silverstein
33
// This macro mimics a unittest framework, but is a bit less flexible
34
// than most. It requires a superclass to derive from, and does all
35
// work in global constructors. The tricky part is implementing
38
#ifndef SPARSEHASH_TEST_UTIL_H_
39
#define SPARSEHASH_TEST_UTIL_H_
44
_START_GOOGLE_NAMESPACE_
48
#define EXPECT_TRUE(cond) do { \
50
::fputs("Test failed: " #cond "\n", stderr); \
55
#define EXPECT_FALSE(a) EXPECT_TRUE(!(a))
56
#define EXPECT_EQ(a, b) EXPECT_TRUE((a) == (b))
57
#define EXPECT_LT(a, b) EXPECT_TRUE((a) < (b))
58
#define EXPECT_GT(a, b) EXPECT_TRUE((a) > (b))
59
#define EXPECT_LE(a, b) EXPECT_TRUE((a) <= (b))
60
#define EXPECT_GE(a, b) EXPECT_TRUE((a) >= (b))
62
#define TEST(suitename, testname) \
63
class TEST_##suitename##_##testname { \
65
TEST_##suitename##_##testname() { \
66
::fputs("Running " #suitename "." #testname "\n", stderr); \
71
static TEST_##suitename##_##testname \
72
test_instance_##suitename##_##testname; \
73
void TEST_##suitename##_##testname::Run()
76
template<typename C1, typename C2, typename C3, typename C4, typename C5,
77
typename C6> struct TypeList6 {
86
// I need to list 18 types here, for code below to compile, though
87
// only the first 6 are ever used.
88
#define TYPED_TEST_CASE_6(classname, typelist) \
89
typedef typelist::type1 classname##_type1; \
90
typedef typelist::type2 classname##_type2; \
91
typedef typelist::type3 classname##_type3; \
92
typedef typelist::type4 classname##_type4; \
93
typedef typelist::type5 classname##_type5; \
94
typedef typelist::type6 classname##_type6; \
95
static const int classname##_numtypes = 6; \
96
typedef typelist::type1 classname##_type7; \
97
typedef typelist::type1 classname##_type8; \
98
typedef typelist::type1 classname##_type9; \
99
typedef typelist::type1 classname##_type10; \
100
typedef typelist::type1 classname##_type11; \
101
typedef typelist::type1 classname##_type12; \
102
typedef typelist::type1 classname##_type13; \
103
typedef typelist::type1 classname##_type14; \
104
typedef typelist::type1 classname##_type15; \
105
typedef typelist::type1 classname##_type16; \
106
typedef typelist::type1 classname##_type17; \
107
typedef typelist::type1 classname##_type18;
109
template<typename C1, typename C2, typename C3, typename C4, typename C5,
110
typename C6, typename C7, typename C8, typename C9, typename C10,
111
typename C11, typename C12, typename C13, typename C14, typename C15,
112
typename C16, typename C17, typename C18> struct TypeList18 {
133
#define TYPED_TEST_CASE_18(classname, typelist) \
134
typedef typelist::type1 classname##_type1; \
135
typedef typelist::type2 classname##_type2; \
136
typedef typelist::type3 classname##_type3; \
137
typedef typelist::type4 classname##_type4; \
138
typedef typelist::type5 classname##_type5; \
139
typedef typelist::type6 classname##_type6; \
140
typedef typelist::type7 classname##_type7; \
141
typedef typelist::type8 classname##_type8; \
142
typedef typelist::type9 classname##_type9; \
143
typedef typelist::type10 classname##_type10; \
144
typedef typelist::type11 classname##_type11; \
145
typedef typelist::type12 classname##_type12; \
146
typedef typelist::type13 classname##_type13; \
147
typedef typelist::type14 classname##_type14; \
148
typedef typelist::type15 classname##_type15; \
149
typedef typelist::type16 classname##_type16; \
150
typedef typelist::type17 classname##_type17; \
151
typedef typelist::type18 classname##_type18; \
152
static const int classname##_numtypes = 18;
154
#define TYPED_TEST(superclass, testname) \
155
template<typename TypeParam> \
156
class TEST_onetype_##superclass##_##testname : \
157
public superclass<TypeParam> { \
159
TEST_onetype_##superclass##_##testname() { \
165
class TEST_typed_##superclass##_##testname { \
167
explicit TEST_typed_##superclass##_##testname() { \
168
if (superclass##_numtypes >= 1) { \
169
::fputs("Running " #superclass "." #testname ".1\n", stderr); \
170
TEST_onetype_##superclass##_##testname<superclass##_type1> t; \
172
if (superclass##_numtypes >= 2) { \
173
::fputs("Running " #superclass "." #testname ".2\n", stderr); \
174
TEST_onetype_##superclass##_##testname<superclass##_type2> t; \
176
if (superclass##_numtypes >= 3) { \
177
::fputs("Running " #superclass "." #testname ".3\n", stderr); \
178
TEST_onetype_##superclass##_##testname<superclass##_type3> t; \
180
if (superclass##_numtypes >= 4) { \
181
::fputs("Running " #superclass "." #testname ".4\n", stderr); \
182
TEST_onetype_##superclass##_##testname<superclass##_type4> t; \
184
if (superclass##_numtypes >= 5) { \
185
::fputs("Running " #superclass "." #testname ".5\n", stderr); \
186
TEST_onetype_##superclass##_##testname<superclass##_type5> t; \
188
if (superclass##_numtypes >= 6) { \
189
::fputs("Running " #superclass "." #testname ".6\n", stderr); \
190
TEST_onetype_##superclass##_##testname<superclass##_type6> t; \
192
if (superclass##_numtypes >= 7) { \
193
::fputs("Running " #superclass "." #testname ".7\n", stderr); \
194
TEST_onetype_##superclass##_##testname<superclass##_type7> t; \
196
if (superclass##_numtypes >= 8) { \
197
::fputs("Running " #superclass "." #testname ".8\n", stderr); \
198
TEST_onetype_##superclass##_##testname<superclass##_type8> t; \
200
if (superclass##_numtypes >= 9) { \
201
::fputs("Running " #superclass "." #testname ".9\n", stderr); \
202
TEST_onetype_##superclass##_##testname<superclass##_type9> t; \
204
if (superclass##_numtypes >= 10) { \
205
::fputs("Running " #superclass "." #testname ".10\n", stderr); \
206
TEST_onetype_##superclass##_##testname<superclass##_type10> t; \
208
if (superclass##_numtypes >= 11) { \
209
::fputs("Running " #superclass "." #testname ".11\n", stderr); \
210
TEST_onetype_##superclass##_##testname<superclass##_type11> t; \
212
if (superclass##_numtypes >= 12) { \
213
::fputs("Running " #superclass "." #testname ".12\n", stderr); \
214
TEST_onetype_##superclass##_##testname<superclass##_type12> t; \
216
if (superclass##_numtypes >= 13) { \
217
::fputs("Running " #superclass "." #testname ".13\n", stderr); \
218
TEST_onetype_##superclass##_##testname<superclass##_type13> t; \
220
if (superclass##_numtypes >= 14) { \
221
::fputs("Running " #superclass "." #testname ".14\n", stderr); \
222
TEST_onetype_##superclass##_##testname<superclass##_type14> t; \
224
if (superclass##_numtypes >= 15) { \
225
::fputs("Running " #superclass "." #testname ".15\n", stderr); \
226
TEST_onetype_##superclass##_##testname<superclass##_type15> t; \
228
if (superclass##_numtypes >= 16) { \
229
::fputs("Running " #superclass "." #testname ".16\n", stderr); \
230
TEST_onetype_##superclass##_##testname<superclass##_type16> t; \
232
if (superclass##_numtypes >= 17) { \
233
::fputs("Running " #superclass "." #testname ".17\n", stderr); \
234
TEST_onetype_##superclass##_##testname<superclass##_type17> t; \
236
if (superclass##_numtypes >= 18) { \
237
::fputs("Running " #superclass "." #testname ".18\n", stderr); \
238
TEST_onetype_##superclass##_##testname<superclass##_type18> t; \
242
static TEST_typed_##superclass##_##testname \
243
test_instance_typed_##superclass##_##testname; \
244
template<class TypeParam> \
245
void TEST_onetype_##superclass##_##testname<TypeParam>::Run()
247
} // namespace testing
249
_END_GOOGLE_NAMESPACE_
251
#endif // SPARSEHASH_TEST_UTIL_H_