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