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