Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
gtest_pred_impl.h
Go to the documentation of this file.
1// Copyright 2006, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
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
13// distribution.
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.
17//
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.
29
30// This file is AUTOMATICALLY GENERATED on 01/02/2018 by command
31// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
32//
33// Implements a family of generic predicate assertion macros.
34
35#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
36#define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
37
38#include "gtest/gtest.h"
39
40namespace testing {
41
42// This header implements a family of generic predicate assertion
43// macros:
44//
45// ASSERT_PRED_FORMAT1(pred_format, v1)
46// ASSERT_PRED_FORMAT2(pred_format, v1, v2)
47// ...
48//
49// where pred_format is a function or functor that takes n (in the
50// case of ASSERT_PRED_FORMATn) values and their source expression
51// text, and returns a testing::AssertionResult. See the definition
52// of ASSERT_EQ in gtest.h for an example.
53//
54// If you don't care about formatting, you can use the more
55// restrictive version:
56//
57// ASSERT_PRED1(pred, v1)
58// ASSERT_PRED2(pred, v1, v2)
59// ...
60//
61// where pred is an n-ary function or functor that returns bool,
62// and the values v1, v2, ..., must support the << operator for
63// streaming to std::ostream.
64//
65// We also define the EXPECT_* variations.
66//
67// For now we only support predicates whose arity is at most 5.
68
69// GTEST_ASSERT_ is the basic statement to which all of the assertions
70// in this file reduce. Don't use this in your code.
71
72#define GTEST_ASSERT_(expression, on_failure) \
73 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
74 if (const ::testing::AssertionResult gtest_ar = (expression)) \
75 ; \
76 else \
77 on_failure(gtest_ar.failure_message())
78
79
80// Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use
81// this in your code.
82template <typename Pred,
83 typename T1>
84AssertionResult AssertPred1Helper(const char* pred_text,
85 const char* e1,
86 Pred pred,
87 const T1& v1) {
88 if (pred(v1)) return AssertionSuccess();
89
90 return AssertionFailure() << pred_text << "("
91 << e1 << ") evaluates to false, where"
92 << "\n" << e1 << " evaluates to " << v1;
93}
94
95// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
96// Don't use this in your code.
97#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
98 GTEST_ASSERT_(pred_format(#v1, v1), \
99 on_failure)
100
101// Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
102// this in your code.
103#define GTEST_PRED1_(pred, v1, on_failure)\
104 GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \
105 #v1, \
106 pred, \
107 v1), on_failure)
108
109// Unary predicate assertion macros.
110#define EXPECT_PRED_FORMAT1(pred_format, v1) \
111 GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
112#define EXPECT_PRED1(pred, v1) \
113 GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
114#define ASSERT_PRED_FORMAT1(pred_format, v1) \
115 GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
116#define ASSERT_PRED1(pred, v1) \
117 GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
118
119
120
121// Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use
122// this in your code.
123template <typename Pred,
124 typename T1,
125 typename T2>
126AssertionResult AssertPred2Helper(const char* pred_text,
127 const char* e1,
128 const char* e2,
129 Pred pred,
130 const T1& v1,
131 const T2& v2) {
132 if (pred(v1, v2)) return AssertionSuccess();
133
134 return AssertionFailure() << pred_text << "("
135 << e1 << ", "
136 << e2 << ") evaluates to false, where"
137 << "\n" << e1 << " evaluates to " << v1
138 << "\n" << e2 << " evaluates to " << v2;
139}
140
141// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
142// Don't use this in your code.
143#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
144 GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
145 on_failure)
146
147// Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
148// this in your code.
149#define GTEST_PRED2_(pred, v1, v2, on_failure)\
150 GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \
151 #v1, \
152 #v2, \
153 pred, \
154 v1, \
155 v2), on_failure)
156
157// Binary predicate assertion macros.
158#define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
159 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
160#define EXPECT_PRED2(pred, v1, v2) \
161 GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)
162#define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
163 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
164#define ASSERT_PRED2(pred, v1, v2) \
165 GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
166
167
168
169// Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use
170// this in your code.
171template <typename Pred,
172 typename T1,
173 typename T2,
174 typename T3>
175AssertionResult AssertPred3Helper(const char* pred_text,
176 const char* e1,
177 const char* e2,
178 const char* e3,
179 Pred pred,
180 const T1& v1,
181 const T2& v2,
182 const T3& v3) {
183 if (pred(v1, v2, v3)) return AssertionSuccess();
184
185 return AssertionFailure() << pred_text << "("
186 << e1 << ", "
187 << e2 << ", "
188 << e3 << ") evaluates to false, where"
189 << "\n" << e1 << " evaluates to " << v1
190 << "\n" << e2 << " evaluates to " << v2
191 << "\n" << e3 << " evaluates to " << v3;
192}
193
194// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
195// Don't use this in your code.
196#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
197 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \
198 on_failure)
199
200// Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
201// this in your code.
202#define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\
203 GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \
204 #v1, \
205 #v2, \
206 #v3, \
207 pred, \
208 v1, \
209 v2, \
210 v3), on_failure)
211
212// Ternary predicate assertion macros.
213#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
214 GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
215#define EXPECT_PRED3(pred, v1, v2, v3) \
216 GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
217#define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
218 GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)
219#define ASSERT_PRED3(pred, v1, v2, v3) \
220 GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
221
222
223
224// Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use
225// this in your code.
226template <typename Pred,
227 typename T1,
228 typename T2,
229 typename T3,
230 typename T4>
231AssertionResult AssertPred4Helper(const char* pred_text,
232 const char* e1,
233 const char* e2,
234 const char* e3,
235 const char* e4,
236 Pred pred,
237 const T1& v1,
238 const T2& v2,
239 const T3& v3,
240 const T4& v4) {
241 if (pred(v1, v2, v3, v4)) return AssertionSuccess();
242
243 return AssertionFailure() << pred_text << "("
244 << e1 << ", "
245 << e2 << ", "
246 << e3 << ", "
247 << e4 << ") evaluates to false, where"
248 << "\n" << e1 << " evaluates to " << v1
249 << "\n" << e2 << " evaluates to " << v2
250 << "\n" << e3 << " evaluates to " << v3
251 << "\n" << e4 << " evaluates to " << v4;
252}
253
254// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
255// Don't use this in your code.
256#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
257 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \
258 on_failure)
259
260// Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
261// this in your code.
262#define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\
263 GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \
264 #v1, \
265 #v2, \
266 #v3, \
267 #v4, \
268 pred, \
269 v1, \
270 v2, \
271 v3, \
272 v4), on_failure)
273
274// 4-ary predicate assertion macros.
275#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
276 GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
277#define EXPECT_PRED4(pred, v1, v2, v3, v4) \
278 GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
279#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
280 GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
281#define ASSERT_PRED4(pred, v1, v2, v3, v4) \
282 GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
283
284
285
286// Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use
287// this in your code.
288template <typename Pred,
289 typename T1,
290 typename T2,
291 typename T3,
292 typename T4,
293 typename T5>
294AssertionResult AssertPred5Helper(const char* pred_text,
295 const char* e1,
296 const char* e2,
297 const char* e3,
298 const char* e4,
299 const char* e5,
300 Pred pred,
301 const T1& v1,
302 const T2& v2,
303 const T3& v3,
304 const T4& v4,
305 const T5& v5) {
306 if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
307
308 return AssertionFailure() << pred_text << "("
309 << e1 << ", "
310 << e2 << ", "
311 << e3 << ", "
312 << e4 << ", "
313 << e5 << ") evaluates to false, where"
314 << "\n" << e1 << " evaluates to " << v1
315 << "\n" << e2 << " evaluates to " << v2
316 << "\n" << e3 << " evaluates to " << v3
317 << "\n" << e4 << " evaluates to " << v4
318 << "\n" << e5 << " evaluates to " << v5;
319}
320
321// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
322// Don't use this in your code.
323#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
324 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \
325 on_failure)
326
327// Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
328// this in your code.
329#define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\
330 GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \
331 #v1, \
332 #v2, \
333 #v3, \
334 #v4, \
335 #v5, \
336 pred, \
337 v1, \
338 v2, \
339 v3, \
340 v4, \
341 v5), on_failure)
342
343// 5-ary predicate assertion macros.
344#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
345 GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
346#define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
347 GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
348#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
349 GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
350#define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
351 GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
352
353
354
355} // namespace testing
356
357#endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
GTEST_API_ AssertionResult AssertionFailure()
Definition gtest.cc:1029
AssertionResult AssertPred1Helper(const char *pred_text, const char *e1, Pred pred, const T1 &v1)
AssertionResult AssertPred2Helper(const char *pred_text, const char *e1, const char *e2, Pred pred, const T1 &v1, const T2 &v2)
GTEST_API_ AssertionResult AssertionSuccess()
Definition gtest.cc:1024
AssertionResult AssertPred3Helper(const char *pred_text, const char *e1, const char *e2, const char *e3, Pred pred, const T1 &v1, const T2 &v2, const T3 &v3)
AssertionResult AssertPred5Helper(const char *pred_text, const char *e1, const char *e2, const char *e3, const char *e4, const char *e5, Pred pred, const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5)
AssertionResult AssertPred4Helper(const char *pred_text, const char *e1, const char *e2, const char *e3, const char *e4, Pred pred, const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4)