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 // IWYU pragma: private, include "gtest/gtest.h"
37 // IWYU pragma: friend gtest/.*
38 // IWYU pragma: friend gmock/.*
39 
40 #ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
41 #define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
42 
43 #include "gtest/gtest.h"
44 
45 namespace testing {
46 
47 // This header implements a family of generic predicate assertion
48 // macros:
49 //
50 //   ASSERT_PRED_FORMAT1(pred_format, v1)
51 //   ASSERT_PRED_FORMAT2(pred_format, v1, v2)
52 //   ...
53 //
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.
58 //
59 // If you don't care about formatting, you can use the more
60 // restrictive version:
61 //
62 //   ASSERT_PRED1(pred, v1)
63 //   ASSERT_PRED2(pred, v1, v2)
64 //   ...
65 //
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.
69 //
70 // We also define the EXPECT_* variations.
71 //
72 // For now we only support predicates whose arity is at most 5.
73 // Please email [email protected] if you need
74 // support for higher arities.
75 
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.
78 
79 #define GTEST_ASSERT_(expression, on_failure) \
80   GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
81   if (const ::testing::AssertionResult gtest_ar = (expression)) \
82     ; \
83   else \
84     on_failure(gtest_ar.failure_message())
85 
86 
87 // Helper function for implementing {EXPECT|ASSERT}_PRED1.  Don't use
88 // this in your code.
89 template <typename Pred,
90           typename T1>
AssertPred1Helper(const char * pred_text,const char * e1,Pred pred,const T1 & v1)91 AssertionResult AssertPred1Helper(const char* pred_text,
92                                   const char* e1,
93                                   Pred pred,
94                                   const T1& v1) {
95   if (pred(v1)) return AssertionSuccess();
96 
97   return AssertionFailure()
98          << pred_text << "(" << e1 << ") evaluates to false, where"
99          << "\n"
100          << e1 << " evaluates to " << ::testing::PrintToString(v1);
101 }
102 
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), \
107                 on_failure)
108 
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, \
113                                              #v1, \
114                                              pred, \
115                                              v1), on_failure)
116 
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_)
126 
127 
128 
129 // Helper function for implementing {EXPECT|ASSERT}_PRED2.  Don't use
130 // this in your code.
131 template <typename Pred,
132           typename T1,
133           typename T2>
AssertPred2Helper(const char * pred_text,const char * e1,const char * e2,Pred pred,const T1 & v1,const T2 & v2)134 AssertionResult AssertPred2Helper(const char* pred_text,
135                                   const char* e1,
136                                   const char* e2,
137                                   Pred pred,
138                                   const T1& v1,
139                                   const T2& v2) {
140   if (pred(v1, v2)) return AssertionSuccess();
141 
142   return AssertionFailure()
143          << pred_text << "(" << e1 << ", " << e2
144          << ") evaluates to false, where"
145          << "\n"
146          << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
147          << e2 << " evaluates to " << ::testing::PrintToString(v2);
148 }
149 
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), \
154                 on_failure)
155 
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, \
160                                              #v1, \
161                                              #v2, \
162                                              pred, \
163                                              v1, \
164                                              v2), on_failure)
165 
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_)
175 
176 
177 
178 // Helper function for implementing {EXPECT|ASSERT}_PRED3.  Don't use
179 // this in your code.
180 template <typename Pred,
181           typename T1,
182           typename T2,
183           typename T3>
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)184 AssertionResult AssertPred3Helper(const char* pred_text,
185                                   const char* e1,
186                                   const char* e2,
187                                   const char* e3,
188                                   Pred pred,
189                                   const T1& v1,
190                                   const T2& v2,
191                                   const T3& v3) {
192   if (pred(v1, v2, v3)) return AssertionSuccess();
193 
194   return AssertionFailure()
195          << pred_text << "(" << e1 << ", " << e2 << ", " << e3
196          << ") evaluates to false, where"
197          << "\n"
198          << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
199          << e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
200          << e3 << " evaluates to " << ::testing::PrintToString(v3);
201 }
202 
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), \
207                 on_failure)
208 
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, \
213                                              #v1, \
214                                              #v2, \
215                                              #v3, \
216                                              pred, \
217                                              v1, \
218                                              v2, \
219                                              v3), on_failure)
220 
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_)
230 
231 
232 
233 // Helper function for implementing {EXPECT|ASSERT}_PRED4.  Don't use
234 // this in your code.
235 template <typename Pred,
236           typename T1,
237           typename T2,
238           typename T3,
239           typename T4>
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)240 AssertionResult AssertPred4Helper(const char* pred_text,
241                                   const char* e1,
242                                   const char* e2,
243                                   const char* e3,
244                                   const char* e4,
245                                   Pred pred,
246                                   const T1& v1,
247                                   const T2& v2,
248                                   const T3& v3,
249                                   const T4& v4) {
250   if (pred(v1, v2, v3, v4)) return AssertionSuccess();
251 
252   return AssertionFailure()
253          << pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
254          << ") evaluates to false, where"
255          << "\n"
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);
260 }
261 
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), \
266                 on_failure)
267 
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, \
272                                              #v1, \
273                                              #v2, \
274                                              #v3, \
275                                              #v4, \
276                                              pred, \
277                                              v1, \
278                                              v2, \
279                                              v3, \
280                                              v4), on_failure)
281 
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_)
291 
292 
293 
294 // Helper function for implementing {EXPECT|ASSERT}_PRED5.  Don't use
295 // this in your code.
296 template <typename Pred,
297           typename T1,
298           typename T2,
299           typename T3,
300           typename T4,
301           typename T5>
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)302 AssertionResult AssertPred5Helper(const char* pred_text,
303                                   const char* e1,
304                                   const char* e2,
305                                   const char* e3,
306                                   const char* e4,
307                                   const char* e5,
308                                   Pred pred,
309                                   const T1& v1,
310                                   const T2& v2,
311                                   const T3& v3,
312                                   const T4& v4,
313                                   const T5& v5) {
314   if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
315 
316   return AssertionFailure()
317          << pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
318          << ", " << e5 << ") evaluates to false, where"
319          << "\n"
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);
325 }
326 
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), \
331                 on_failure)
332 
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, \
337                                              #v1, \
338                                              #v2, \
339                                              #v3, \
340                                              #v4, \
341                                              #v5, \
342                                              pred, \
343                                              v1, \
344                                              v2, \
345                                              v3, \
346                                              v4, \
347                                              v5), on_failure)
348 
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_)
358 
359 
360 
361 }  // namespace testing
362 
363 #endif  // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
364