00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
00036 #define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
00037
00038
00039 #ifndef GTEST_INCLUDE_GTEST_GTEST_H_
00040 # error Do not include gtest_pred_impl.h directly. Include gtest.h instead.
00041 #endif // GTEST_INCLUDE_GTEST_GTEST_H_
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #define GTEST_ASSERT_(expression, on_failure) \
00076 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
00077 if (const ::testing::AssertionResult gtest_ar = (expression)) \
00078 ; \
00079 else \
00080 on_failure(gtest_ar.failure_message())
00081
00082
00083
00084
00085 template <typename Pred,
00086 typename T1>
00087 AssertionResult AssertPred1Helper(const char* pred_text,
00088 const char* e1,
00089 Pred pred,
00090 const T1& v1) {
00091 if (pred(v1)) return AssertionSuccess();
00092
00093 return AssertionFailure() << pred_text << "("
00094 << e1 << ") evaluates to false, where"
00095 << "\n" << e1 << " evaluates to " << v1;
00096 }
00097
00098
00099
00100 #define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
00101 GTEST_ASSERT_(pred_format(#v1, v1), \
00102 on_failure)
00103
00104
00105
00106 #define GTEST_PRED1_(pred, v1, on_failure)\
00107 GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \
00108 #v1, \
00109 pred, \
00110 v1), on_failure)
00111
00112
00113 #define EXPECT_PRED_FORMAT1(pred_format, v1) \
00114 GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
00115 #define EXPECT_PRED1(pred, v1) \
00116 GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
00117 #define ASSERT_PRED_FORMAT1(pred_format, v1) \
00118 GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
00119 #define ASSERT_PRED1(pred, v1) \
00120 GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
00121
00122
00123
00124
00125
00126 template <typename Pred,
00127 typename T1,
00128 typename T2>
00129 AssertionResult AssertPred2Helper(const char* pred_text,
00130 const char* e1,
00131 const char* e2,
00132 Pred pred,
00133 const T1& v1,
00134 const T2& v2) {
00135 if (pred(v1, v2)) return AssertionSuccess();
00136
00137 return AssertionFailure() << pred_text << "("
00138 << e1 << ", "
00139 << e2 << ") evaluates to false, where"
00140 << "\n" << e1 << " evaluates to " << v1
00141 << "\n" << e2 << " evaluates to " << v2;
00142 }
00143
00144
00145
00146 #define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
00147 GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
00148 on_failure)
00149
00150
00151
00152 #define GTEST_PRED2_(pred, v1, v2, on_failure)\
00153 GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \
00154 #v1, \
00155 #v2, \
00156 pred, \
00157 v1, \
00158 v2), on_failure)
00159
00160
00161 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
00162 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
00163 #define EXPECT_PRED2(pred, v1, v2) \
00164 GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)
00165 #define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
00166 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
00167 #define ASSERT_PRED2(pred, v1, v2) \
00168 GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
00169
00170
00171
00172
00173
00174 template <typename Pred,
00175 typename T1,
00176 typename T2,
00177 typename T3>
00178 AssertionResult AssertPred3Helper(const char* pred_text,
00179 const char* e1,
00180 const char* e2,
00181 const char* e3,
00182 Pred pred,
00183 const T1& v1,
00184 const T2& v2,
00185 const T3& v3) {
00186 if (pred(v1, v2, v3)) return AssertionSuccess();
00187
00188 return AssertionFailure() << pred_text << "("
00189 << e1 << ", "
00190 << e2 << ", "
00191 << e3 << ") evaluates to false, where"
00192 << "\n" << e1 << " evaluates to " << v1
00193 << "\n" << e2 << " evaluates to " << v2
00194 << "\n" << e3 << " evaluates to " << v3;
00195 }
00196
00197
00198
00199 #define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
00200 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \
00201 on_failure)
00202
00203
00204
00205 #define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\
00206 GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \
00207 #v1, \
00208 #v2, \
00209 #v3, \
00210 pred, \
00211 v1, \
00212 v2, \
00213 v3), on_failure)
00214
00215
00216 #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
00217 GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
00218 #define EXPECT_PRED3(pred, v1, v2, v3) \
00219 GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
00220 #define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
00221 GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)
00222 #define ASSERT_PRED3(pred, v1, v2, v3) \
00223 GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
00224
00225
00226
00227
00228
00229 template <typename Pred,
00230 typename T1,
00231 typename T2,
00232 typename T3,
00233 typename T4>
00234 AssertionResult AssertPred4Helper(const char* pred_text,
00235 const char* e1,
00236 const char* e2,
00237 const char* e3,
00238 const char* e4,
00239 Pred pred,
00240 const T1& v1,
00241 const T2& v2,
00242 const T3& v3,
00243 const T4& v4) {
00244 if (pred(v1, v2, v3, v4)) return AssertionSuccess();
00245
00246 return AssertionFailure() << pred_text << "("
00247 << e1 << ", "
00248 << e2 << ", "
00249 << e3 << ", "
00250 << e4 << ") evaluates to false, where"
00251 << "\n" << e1 << " evaluates to " << v1
00252 << "\n" << e2 << " evaluates to " << v2
00253 << "\n" << e3 << " evaluates to " << v3
00254 << "\n" << e4 << " evaluates to " << v4;
00255 }
00256
00257
00258
00259 #define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
00260 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \
00261 on_failure)
00262
00263
00264
00265 #define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\
00266 GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \
00267 #v1, \
00268 #v2, \
00269 #v3, \
00270 #v4, \
00271 pred, \
00272 v1, \
00273 v2, \
00274 v3, \
00275 v4), on_failure)
00276
00277
00278 #define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
00279 GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
00280 #define EXPECT_PRED4(pred, v1, v2, v3, v4) \
00281 GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
00282 #define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
00283 GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
00284 #define ASSERT_PRED4(pred, v1, v2, v3, v4) \
00285 GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
00286
00287
00288
00289
00290
00291 template <typename Pred,
00292 typename T1,
00293 typename T2,
00294 typename T3,
00295 typename T4,
00296 typename T5>
00297 AssertionResult AssertPred5Helper(const char* pred_text,
00298 const char* e1,
00299 const char* e2,
00300 const char* e3,
00301 const char* e4,
00302 const char* e5,
00303 Pred pred,
00304 const T1& v1,
00305 const T2& v2,
00306 const T3& v3,
00307 const T4& v4,
00308 const T5& v5) {
00309 if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
00310
00311 return AssertionFailure() << pred_text << "("
00312 << e1 << ", "
00313 << e2 << ", "
00314 << e3 << ", "
00315 << e4 << ", "
00316 << e5 << ") evaluates to false, where"
00317 << "\n" << e1 << " evaluates to " << v1
00318 << "\n" << e2 << " evaluates to " << v2
00319 << "\n" << e3 << " evaluates to " << v3
00320 << "\n" << e4 << " evaluates to " << v4
00321 << "\n" << e5 << " evaluates to " << v5;
00322 }
00323
00324
00325
00326 #define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
00327 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \
00328 on_failure)
00329
00330
00331
00332 #define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\
00333 GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \
00334 #v1, \
00335 #v2, \
00336 #v3, \
00337 #v4, \
00338 #v5, \
00339 pred, \
00340 v1, \
00341 v2, \
00342 v3, \
00343 v4, \
00344 v5), on_failure)
00345
00346
00347 #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
00348 GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
00349 #define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
00350 GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
00351 #define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
00352 GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
00353 #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
00354 GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
00355
00356
00357
00358 #endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_