1 // Copyright 2006, 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.
30 // This file is AUTOMATICALLY GENERATED on 01/02/2019 by command
31 // 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
33 // Implements a family of generic predicate assertion macros.
34 // GOOGLETEST_CM0001 DO NOT DELETE
36 // IWYU pragma: private, include "gtest/gtest.h"
37 // IWYU pragma: friend gtest/.*
38 // IWYU pragma: friend gmock/.*
40 #ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
41 #define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
43 #include "gtest/gtest.h"
47 // This header implements a family of generic predicate assertion
50 // ASSERT_PRED_FORMAT1(pred_format, v1)
51 // ASSERT_PRED_FORMAT2(pred_format, v1, v2)
54 // where pred_format is a function or functor that takes n (in the
55 // case of ASSERT_PRED_FORMATn) values and their source expression
56 // text, and returns a testing::AssertionResult. See the definition
57 // of ASSERT_EQ in gtest.h for an example.
59 // If you don't care about formatting, you can use the more
60 // restrictive version:
62 // ASSERT_PRED1(pred, v1)
63 // ASSERT_PRED2(pred, v1, v2)
66 // where pred is an n-ary function or functor that returns bool,
67 // and the values v1, v2, ..., must support the << operator for
68 // streaming to std::ostream.
70 // We also define the EXPECT_* variations.
72 // For now we only support predicates whose arity is at most 5.
73 // Please email googletestframework@googlegroups.com if you need
74 // support for higher arities.
76 // GTEST_ASSERT_ is the basic statement to which all of the assertions
77 // in this file reduce. Don't use this in your code.
79 #define GTEST_ASSERT_(expression, on_failure) \
80 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
81 if (const ::testing::AssertionResult gtest_ar = (expression)) \
84 on_failure(gtest_ar.failure_message())
87 // Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use
89 template <typename Pred
,
91 AssertionResult
AssertPred1Helper(const char* pred_text
,
95 if (pred(v1
)) return AssertionSuccess();
97 return AssertionFailure()
98 << pred_text
<< "(" << e1
<< ") evaluates to false, where"
100 << e1
<< " evaluates to " << ::testing::PrintToString(v1
);
103 // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
104 // Don't use this in your code.
105 #define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
106 GTEST_ASSERT_(pred_format(#v1, v1), \
109 // Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
110 // this in your code.
111 #define GTEST_PRED1_(pred, v1, on_failure)\
112 GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \
117 // Unary predicate assertion macros.
118 #define EXPECT_PRED_FORMAT1(pred_format, v1) \
119 GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
120 #define EXPECT_PRED1(pred, v1) \
121 GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
122 #define ASSERT_PRED_FORMAT1(pred_format, v1) \
123 GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
124 #define ASSERT_PRED1(pred, v1) \
125 GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
129 // Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use
130 // this in your code.
131 template <typename Pred
,
134 AssertionResult
AssertPred2Helper(const char* pred_text
,
140 if (pred(v1
, v2
)) return AssertionSuccess();
142 return AssertionFailure()
143 << pred_text
<< "(" << e1
<< ", " << e2
144 << ") evaluates to false, where"
146 << e1
<< " evaluates to " << ::testing::PrintToString(v1
) << "\n"
147 << e2
<< " evaluates to " << ::testing::PrintToString(v2
);
150 // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
151 // Don't use this in your code.
152 #define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
153 GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
156 // Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
157 // this in your code.
158 #define GTEST_PRED2_(pred, v1, v2, on_failure)\
159 GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \
166 // Binary predicate assertion macros.
167 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
168 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
169 #define EXPECT_PRED2(pred, v1, v2) \
170 GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)
171 #define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
172 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
173 #define ASSERT_PRED2(pred, v1, v2) \
174 GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
178 // Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use
179 // this in your code.
180 template <typename Pred
,
184 AssertionResult
AssertPred3Helper(const char* pred_text
,
192 if (pred(v1
, v2
, v3
)) return AssertionSuccess();
194 return AssertionFailure()
195 << pred_text
<< "(" << e1
<< ", " << e2
<< ", " << e3
196 << ") evaluates to false, where"
198 << e1
<< " evaluates to " << ::testing::PrintToString(v1
) << "\n"
199 << e2
<< " evaluates to " << ::testing::PrintToString(v2
) << "\n"
200 << e3
<< " evaluates to " << ::testing::PrintToString(v3
);
203 // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
204 // Don't use this in your code.
205 #define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
206 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \
209 // Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
210 // this in your code.
211 #define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\
212 GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \
221 // Ternary predicate assertion macros.
222 #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
223 GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
224 #define EXPECT_PRED3(pred, v1, v2, v3) \
225 GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
226 #define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
227 GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)
228 #define ASSERT_PRED3(pred, v1, v2, v3) \
229 GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
233 // Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use
234 // this in your code.
235 template <typename Pred
,
240 AssertionResult
AssertPred4Helper(const char* pred_text
,
250 if (pred(v1
, v2
, v3
, v4
)) return AssertionSuccess();
252 return AssertionFailure()
253 << pred_text
<< "(" << e1
<< ", " << e2
<< ", " << e3
<< ", " << e4
254 << ") evaluates to false, where"
256 << e1
<< " evaluates to " << ::testing::PrintToString(v1
) << "\n"
257 << e2
<< " evaluates to " << ::testing::PrintToString(v2
) << "\n"
258 << e3
<< " evaluates to " << ::testing::PrintToString(v3
) << "\n"
259 << e4
<< " evaluates to " << ::testing::PrintToString(v4
);
262 // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
263 // Don't use this in your code.
264 #define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
265 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \
268 // Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
269 // this in your code.
270 #define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\
271 GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \
282 // 4-ary predicate assertion macros.
283 #define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
284 GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
285 #define EXPECT_PRED4(pred, v1, v2, v3, v4) \
286 GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
287 #define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
288 GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
289 #define ASSERT_PRED4(pred, v1, v2, v3, v4) \
290 GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
294 // Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use
295 // this in your code.
296 template <typename Pred
,
302 AssertionResult
AssertPred5Helper(const char* pred_text
,
314 if (pred(v1
, v2
, v3
, v4
, v5
)) return AssertionSuccess();
316 return AssertionFailure()
317 << pred_text
<< "(" << e1
<< ", " << e2
<< ", " << e3
<< ", " << e4
318 << ", " << e5
<< ") evaluates to false, where"
320 << e1
<< " evaluates to " << ::testing::PrintToString(v1
) << "\n"
321 << e2
<< " evaluates to " << ::testing::PrintToString(v2
) << "\n"
322 << e3
<< " evaluates to " << ::testing::PrintToString(v3
) << "\n"
323 << e4
<< " evaluates to " << ::testing::PrintToString(v4
) << "\n"
324 << e5
<< " evaluates to " << ::testing::PrintToString(v5
);
327 // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
328 // Don't use this in your code.
329 #define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
330 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \
333 // Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
334 // this in your code.
335 #define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\
336 GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \
349 // 5-ary predicate assertion macros.
350 #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
351 GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
352 #define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
353 GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
354 #define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
355 GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
356 #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
357 GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
361 } // namespace testing
363 #endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_