gtest_pred_impl.h 14.8 KB
Newer Older
shiqian's avatar
shiqian committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright 2006, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

30
// This file is AUTOMATICALLY GENERATED on 10/31/2011 by command
shiqian's avatar
shiqian committed
31
32
33
34
35
36
37
38
39
// 'gen_gtest_pred_impl.py 5'.  DO NOT EDIT BY HAND!
//
// Implements a family of generic predicate assertion macros.

#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
#define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_

// Makes sure this header is not included before gtest.h.
#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
40
# error Do not include gtest_pred_impl.h directly.  Include gtest.h instead.
shiqian's avatar
shiqian committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#endif  // GTEST_INCLUDE_GTEST_GTEST_H_

// This header implements a family of generic predicate assertion
// macros:
//
//   ASSERT_PRED_FORMAT1(pred_format, v1)
//   ASSERT_PRED_FORMAT2(pred_format, v1, v2)
//   ...
//
// where pred_format is a function or functor that takes n (in the
// case of ASSERT_PRED_FORMATn) values and their source expression
// text, and returns a testing::AssertionResult.  See the definition
// of ASSERT_EQ in gtest.h for an example.
//
// If you don't care about formatting, you can use the more
// restrictive version:
//
//   ASSERT_PRED1(pred, v1)
//   ASSERT_PRED2(pred, v1, v2)
//   ...
//
// where pred is an n-ary function or functor that returns bool,
// and the values v1, v2, ..., must support the << operator for
// streaming to std::ostream.
//
// We also define the EXPECT_* variations.
//
// For now we only support predicates whose arity is at most 5.
// Please email googletestframework@googlegroups.com if you need
// support for higher arities.

shiqian's avatar
shiqian committed
72
// GTEST_ASSERT_ is the basic statement to which all of the assertions
shiqian's avatar
shiqian committed
73
74
// in this file reduce.  Don't use this in your code.

shiqian's avatar
shiqian committed
75
76
#define GTEST_ASSERT_(expression, on_failure) \
  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
shiqian's avatar
shiqian committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  if (const ::testing::AssertionResult gtest_ar = (expression)) \
    ; \
  else \
    on_failure(gtest_ar.failure_message())


// Helper function for implementing {EXPECT|ASSERT}_PRED1.  Don't use
// this in your code.
template <typename Pred,
          typename T1>
AssertionResult AssertPred1Helper(const char* pred_text,
                                  const char* e1,
                                  Pred pred,
                                  const T1& v1) {
  if (pred(v1)) return AssertionSuccess();

93
94
95
  return AssertionFailure() << pred_text << "("
                            << e1 << ") evaluates to false, where"
                            << "\n" << e1 << " evaluates to " << v1;
shiqian's avatar
shiqian committed
96
97
98
99
}

// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
// Don't use this in your code.
shiqian's avatar
shiqian committed
100
#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
101
  GTEST_ASSERT_(pred_format(#v1, v1), \
shiqian's avatar
shiqian committed
102
                on_failure)
shiqian's avatar
shiqian committed
103
104
105

// Internal macro for implementing {EXPECT|ASSERT}_PRED1.  Don't use
// this in your code.
shiqian's avatar
shiqian committed
106
107
108
109
110
#define GTEST_PRED1_(pred, v1, on_failure)\
  GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \
                                             #v1, \
                                             pred, \
                                             v1), on_failure)
shiqian's avatar
shiqian committed
111
112
113

// Unary predicate assertion macros.
#define EXPECT_PRED_FORMAT1(pred_format, v1) \
shiqian's avatar
shiqian committed
114
  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
shiqian's avatar
shiqian committed
115
#define EXPECT_PRED1(pred, v1) \
shiqian's avatar
shiqian committed
116
  GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
shiqian's avatar
shiqian committed
117
#define ASSERT_PRED_FORMAT1(pred_format, v1) \
shiqian's avatar
shiqian committed
118
  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
shiqian's avatar
shiqian committed
119
#define ASSERT_PRED1(pred, v1) \
shiqian's avatar
shiqian committed
120
  GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
shiqian's avatar
shiqian committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136



// Helper function for implementing {EXPECT|ASSERT}_PRED2.  Don't use
// this in your code.
template <typename Pred,
          typename T1,
          typename T2>
AssertionResult AssertPred2Helper(const char* pred_text,
                                  const char* e1,
                                  const char* e2,
                                  Pred pred,
                                  const T1& v1,
                                  const T2& v2) {
  if (pred(v1, v2)) return AssertionSuccess();

137
138
139
140
141
  return AssertionFailure() << pred_text << "("
                            << e1 << ", "
                            << e2 << ") evaluates to false, where"
                            << "\n" << e1 << " evaluates to " << v1
                            << "\n" << e2 << " evaluates to " << v2;
shiqian's avatar
shiqian committed
142
143
144
145
}

// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
// Don't use this in your code.
shiqian's avatar
shiqian committed
146
#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
147
  GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
shiqian's avatar
shiqian committed
148
                on_failure)
shiqian's avatar
shiqian committed
149
150
151

// Internal macro for implementing {EXPECT|ASSERT}_PRED2.  Don't use
// this in your code.
shiqian's avatar
shiqian committed
152
153
154
155
156
157
158
#define GTEST_PRED2_(pred, v1, v2, on_failure)\
  GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \
                                             #v1, \
                                             #v2, \
                                             pred, \
                                             v1, \
                                             v2), on_failure)
shiqian's avatar
shiqian committed
159
160
161

// Binary predicate assertion macros.
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
shiqian's avatar
shiqian committed
162
  GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
shiqian's avatar
shiqian committed
163
#define EXPECT_PRED2(pred, v1, v2) \
shiqian's avatar
shiqian committed
164
  GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)
shiqian's avatar
shiqian committed
165
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
shiqian's avatar
shiqian committed
166
  GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
shiqian's avatar
shiqian committed
167
#define ASSERT_PRED2(pred, v1, v2) \
shiqian's avatar
shiqian committed
168
  GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
shiqian's avatar
shiqian committed
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187



// Helper function for implementing {EXPECT|ASSERT}_PRED3.  Don't use
// this in your code.
template <typename Pred,
          typename T1,
          typename T2,
          typename T3>
AssertionResult 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) {
  if (pred(v1, v2, v3)) return AssertionSuccess();

188
189
190
191
192
193
194
  return AssertionFailure() << pred_text << "("
                            << e1 << ", "
                            << e2 << ", "
                            << e3 << ") evaluates to false, where"
                            << "\n" << e1 << " evaluates to " << v1
                            << "\n" << e2 << " evaluates to " << v2
                            << "\n" << e3 << " evaluates to " << v3;
shiqian's avatar
shiqian committed
195
196
197
198
}

// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
// Don't use this in your code.
shiqian's avatar
shiqian committed
199
#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
200
  GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \
shiqian's avatar
shiqian committed
201
                on_failure)
shiqian's avatar
shiqian committed
202
203
204

// Internal macro for implementing {EXPECT|ASSERT}_PRED3.  Don't use
// this in your code.
shiqian's avatar
shiqian committed
205
206
207
208
209
210
211
212
213
#define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\
  GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \
                                             #v1, \
                                             #v2, \
                                             #v3, \
                                             pred, \
                                             v1, \
                                             v2, \
                                             v3), on_failure)
shiqian's avatar
shiqian committed
214
215
216

// Ternary predicate assertion macros.
#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
shiqian's avatar
shiqian committed
217
  GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
shiqian's avatar
shiqian committed
218
#define EXPECT_PRED3(pred, v1, v2, v3) \
shiqian's avatar
shiqian committed
219
  GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
shiqian's avatar
shiqian committed
220
#define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
shiqian's avatar
shiqian committed
221
  GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)
shiqian's avatar
shiqian committed
222
#define ASSERT_PRED3(pred, v1, v2, v3) \
shiqian's avatar
shiqian committed
223
  GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
shiqian's avatar
shiqian committed
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245



// Helper function for implementing {EXPECT|ASSERT}_PRED4.  Don't use
// this in your code.
template <typename Pred,
          typename T1,
          typename T2,
          typename T3,
          typename T4>
AssertionResult 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) {
  if (pred(v1, v2, v3, v4)) return AssertionSuccess();

246
247
248
249
250
251
252
253
254
  return AssertionFailure() << pred_text << "("
                            << e1 << ", "
                            << e2 << ", "
                            << e3 << ", "
                            << e4 << ") evaluates to false, where"
                            << "\n" << e1 << " evaluates to " << v1
                            << "\n" << e2 << " evaluates to " << v2
                            << "\n" << e3 << " evaluates to " << v3
                            << "\n" << e4 << " evaluates to " << v4;
shiqian's avatar
shiqian committed
255
256
257
258
}

// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
// Don't use this in your code.
shiqian's avatar
shiqian committed
259
#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
260
  GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \
shiqian's avatar
shiqian committed
261
                on_failure)
shiqian's avatar
shiqian committed
262
263
264

// Internal macro for implementing {EXPECT|ASSERT}_PRED4.  Don't use
// this in your code.
shiqian's avatar
shiqian committed
265
266
267
268
269
270
271
272
273
274
275
#define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\
  GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \
                                             #v1, \
                                             #v2, \
                                             #v3, \
                                             #v4, \
                                             pred, \
                                             v1, \
                                             v2, \
                                             v3, \
                                             v4), on_failure)
shiqian's avatar
shiqian committed
276
277
278

// 4-ary predicate assertion macros.
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
shiqian's avatar
shiqian committed
279
  GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
shiqian's avatar
shiqian committed
280
#define EXPECT_PRED4(pred, v1, v2, v3, v4) \
shiqian's avatar
shiqian committed
281
  GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
shiqian's avatar
shiqian committed
282
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
shiqian's avatar
shiqian committed
283
  GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
shiqian's avatar
shiqian committed
284
#define ASSERT_PRED4(pred, v1, v2, v3, v4) \
shiqian's avatar
shiqian committed
285
  GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
shiqian's avatar
shiqian committed
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310



// Helper function for implementing {EXPECT|ASSERT}_PRED5.  Don't use
// this in your code.
template <typename Pred,
          typename T1,
          typename T2,
          typename T3,
          typename T4,
          typename T5>
AssertionResult 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) {
  if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();

311
312
313
314
315
316
317
318
319
320
321
  return AssertionFailure() << pred_text << "("
                            << e1 << ", "
                            << e2 << ", "
                            << e3 << ", "
                            << e4 << ", "
                            << e5 << ") evaluates to false, where"
                            << "\n" << e1 << " evaluates to " << v1
                            << "\n" << e2 << " evaluates to " << v2
                            << "\n" << e3 << " evaluates to " << v3
                            << "\n" << e4 << " evaluates to " << v4
                            << "\n" << e5 << " evaluates to " << v5;
shiqian's avatar
shiqian committed
322
323
324
325
}

// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
// Don't use this in your code.
shiqian's avatar
shiqian committed
326
#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
327
  GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \
shiqian's avatar
shiqian committed
328
                on_failure)
shiqian's avatar
shiqian committed
329
330
331

// Internal macro for implementing {EXPECT|ASSERT}_PRED5.  Don't use
// this in your code.
shiqian's avatar
shiqian committed
332
333
334
335
336
337
338
339
340
341
342
343
344
#define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\
  GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \
                                             #v1, \
                                             #v2, \
                                             #v3, \
                                             #v4, \
                                             #v5, \
                                             pred, \
                                             v1, \
                                             v2, \
                                             v3, \
                                             v4, \
                                             v5), on_failure)
shiqian's avatar
shiqian committed
345
346
347

// 5-ary predicate assertion macros.
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
shiqian's avatar
shiqian committed
348
  GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
shiqian's avatar
shiqian committed
349
#define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
shiqian's avatar
shiqian committed
350
  GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
shiqian's avatar
shiqian committed
351
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
shiqian's avatar
shiqian committed
352
  GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
shiqian's avatar
shiqian committed
353
#define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
shiqian's avatar
shiqian committed
354
  GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
shiqian's avatar
shiqian committed
355
356
357
358



#endif  // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_