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