| 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 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ |
| 43 |
#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ |
| 44 |
|
| 45 |
#include <math.h> |
| 46 |
#include <algorithm> |
| 47 |
#include <initializer_list> |
| 48 |
#include <iterator> |
| 49 |
#include <limits> |
| 50 |
#include <memory> |
| 51 |
#include <ostream> |
| 52 |
#include <sstream> |
| 53 |
#include <string> |
| 54 |
#include <type_traits> |
| 55 |
#include <utility> |
| 56 |
#include <vector> |
| 57 |
#include "gmock/internal/gmock-internal-utils.h" |
| 58 |
#include "gmock/internal/gmock-port.h" |
| 59 |
#include "gtest/gtest.h" |
| 60 |
|
| 61 |
|
| 62 |
#if defined(_MSC_VER) && _MSC_VER >= 1915 |
| 63 |
#define GMOCK_MAYBE_5046_ 5046 |
| 64 |
#else |
| 65 |
#define GMOCK_MAYBE_5046_ |
| 66 |
#endif |
| 67 |
|
| 68 |
GTEST_DISABLE_MSC_WARNINGS_PUSH_( |
| 69 |
4251 GMOCK_MAYBE_5046_ |
| 70 |
|
| 71 |
) |
| 72 |
|
| 73 |
namespace testing { |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
class StringMatchResultListener : public MatchResultListener { |
| 89 |
public: |
| 90 |
StringMatchResultListener() : MatchResultListener(&ss_) {} |
| 91 |
|
| 92 |
|
| 93 |
std::string str() const { return ss_.str(); } |
| 94 |
|
| 95 |
|
| 96 |
void Clear() { ss_.str(""); } |
| 97 |
|
| 98 |
private: |
| 99 |
::std::stringstream ss_; |
| 100 |
|
| 101 |
GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener); |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
namespace internal { |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
template <typename T, typename M> |
| 119 |
class MatcherCastImpl { |
| 120 |
public: |
| 121 |
static Matcher<T> Cast(const M& polymorphic_matcher_or_value) { |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
return CastImpl(polymorphic_matcher_or_value, |
| 136 |
std::is_convertible<M, Matcher<T>>{}, |
| 137 |
std::is_convertible<M, T>{}); |
| 138 |
} |
| 139 |
|
| 140 |
private: |
| 141 |
template <bool Ignore> |
| 142 |
static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value, |
| 143 |
std::true_type , |
| 144 |
bool_constant<Ignore>) { |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
return polymorphic_matcher_or_value; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
static Matcher<T> CastImpl(const M& value, |
| 160 |
std::false_type , |
| 161 |
std::true_type ) { |
| 162 |
return Matcher<T>(ImplicitCast_<T>(value)); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
static Matcher<T> CastImpl(const M& value, |
| 176 |
std::false_type , |
| 177 |
std::false_type ); |
| 178 |
}; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
template <typename T, typename U> |
| 184 |
class MatcherCastImpl<T, Matcher<U> > { |
| 185 |
public: |
| 186 |
static Matcher<T> Cast(const Matcher<U>& source_matcher) { |
| 187 |
return Matcher<T>(new Impl(source_matcher)); |
| 188 |
} |
| 189 |
|
| 190 |
private: |
| 191 |
class Impl : public MatcherInterface<T> { |
| 192 |
public: |
| 193 |
explicit Impl(const Matcher<U>& source_matcher) |
| 194 |
: source_matcher_(source_matcher) {} |
| 195 |
|
| 196 |
|
| 197 |
bool MatchAndExplain(T x, MatchResultListener* listener) const override { |
| 198 |
using FromType = typename std::remove_cv<typename std::remove_pointer< |
| 199 |
typename std::remove_reference<T>::type>::type>::type; |
| 200 |
using ToType = typename std::remove_cv<typename std::remove_pointer< |
| 201 |
typename std::remove_reference<U>::type>::type>::type; |
| 202 |
|
| 203 |
static_assert( |
| 204 |
|
| 205 |
|
| 206 |
(std::is_pointer<typename std::remove_reference<T>::type>::value != |
| 207 |
std::is_pointer<typename std::remove_reference<U>::type>::value) || |
| 208 |
std::is_same<FromType, ToType>::value || |
| 209 |
!std::is_base_of<FromType, ToType>::value, |
| 210 |
"Can't implicitly convert from <base> to <derived>"); |
| 211 |
|
| 212 |
return source_matcher_.MatchAndExplain(static_cast<U>(x), listener); |
| 213 |
} |
| 214 |
|
| 215 |
void DescribeTo(::std::ostream* os) const override { |
| 216 |
source_matcher_.DescribeTo(os); |
| 217 |
} |
| 218 |
|
| 219 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 220 |
source_matcher_.DescribeNegationTo(os); |
| 221 |
} |
| 222 |
|
| 223 |
private: |
| 224 |
const Matcher<U> source_matcher_; |
| 225 |
|
| 226 |
GTEST_DISALLOW_ASSIGN_(Impl); |
| 227 |
}; |
| 228 |
}; |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
template <typename T> |
| 233 |
class MatcherCastImpl<T, Matcher<T> > { |
| 234 |
public: |
| 235 |
static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; } |
| 236 |
}; |
| 237 |
|
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
template <typename T, typename M> |
| 245 |
inline Matcher<T> MatcherCast(const M& matcher) { |
| 246 |
return internal::MatcherCastImpl<T, M>::Cast(matcher); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
template <typename T> |
| 254 |
class SafeMatcherCastImpl { |
| 255 |
public: |
| 256 |
|
| 257 |
|
| 258 |
template <typename M> |
| 259 |
static inline Matcher<T> Cast(const M& polymorphic_matcher_or_value) { |
| 260 |
return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value); |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
template <typename U> |
| 273 |
static inline Matcher<T> Cast(const Matcher<U>& matcher) { |
| 274 |
|
| 275 |
GTEST_COMPILE_ASSERT_((std::is_convertible<T, U>::value), |
| 276 |
"T must be implicitly convertible to U"); |
| 277 |
|
| 278 |
|
| 279 |
GTEST_COMPILE_ASSERT_( |
| 280 |
std::is_reference<T>::value || !std::is_reference<U>::value, |
| 281 |
cannot_convert_non_reference_arg_to_reference); |
| 282 |
|
| 283 |
|
| 284 |
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT; |
| 285 |
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU; |
| 286 |
const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther; |
| 287 |
const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther; |
| 288 |
GTEST_COMPILE_ASSERT_( |
| 289 |
kTIsOther || kUIsOther || |
| 290 |
(internal::LosslessArithmeticConvertible<RawT, RawU>::value), |
| 291 |
conversion_of_arithmetic_types_must_be_lossless); |
| 292 |
return MatcherCast<T>(matcher); |
| 293 |
} |
| 294 |
}; |
| 295 |
|
| 296 |
template <typename T, typename M> |
| 297 |
inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) { |
| 298 |
return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher); |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
template <typename T> |
| 303 |
Matcher<T> A(); |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
namespace internal { |
| 308 |
|
| 309 |
|
| 310 |
inline void PrintIfNotEmpty(const std::string& explanation, |
| 311 |
::std::ostream* os) { |
| 312 |
if (explanation != "" && os != nullptr) { |
| 313 |
*os << ", " << explanation; |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
inline bool IsReadableTypeName(const std::string& type_name) { |
| 321 |
|
| 322 |
|
| 323 |
return (type_name.length() <= 20 || |
| 324 |
type_name.find_first_of("<(") == std::string::npos); |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
template <typename Value, typename T> |
| 333 |
bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher, |
| 334 |
MatchResultListener* listener) { |
| 335 |
if (!listener->IsInterested()) { |
| 336 |
|
| 337 |
|
| 338 |
return matcher.Matches(value); |
| 339 |
} |
| 340 |
|
| 341 |
StringMatchResultListener inner_listener; |
| 342 |
const bool match = matcher.MatchAndExplain(value, &inner_listener); |
| 343 |
|
| 344 |
UniversalPrint(value, listener->stream()); |
| 345 |
#if GTEST_HAS_RTTI |
| 346 |
const std::string& type_name = GetTypeName<Value>(); |
| 347 |
if (IsReadableTypeName(type_name)) |
| 348 |
*listener->stream() << " (of type " << type_name << ")"; |
| 349 |
#endif |
| 350 |
PrintIfNotEmpty(inner_listener.str(), listener->stream()); |
| 351 |
|
| 352 |
return match; |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
template <size_t N> |
| 358 |
class TuplePrefix { |
| 359 |
public: |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
template <typename MatcherTuple, typename ValueTuple> |
| 364 |
static bool Matches(const MatcherTuple& matcher_tuple, |
| 365 |
const ValueTuple& value_tuple) { |
| 366 |
return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple) && |
| 367 |
std::get<N - 1>(matcher_tuple).Matches(std::get<N - 1>(value_tuple)); |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
template <typename MatcherTuple, typename ValueTuple> |
| 375 |
static void ExplainMatchFailuresTo(const MatcherTuple& matchers, |
| 376 |
const ValueTuple& values, |
| 377 |
::std::ostream* os) { |
| 378 |
|
| 379 |
TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os); |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
typename std::tuple_element<N - 1, MatcherTuple>::type matcher = |
| 384 |
std::get<N - 1>(matchers); |
| 385 |
typedef typename std::tuple_element<N - 1, ValueTuple>::type Value; |
| 386 |
const Value& value = std::get<N - 1>(values); |
| 387 |
StringMatchResultListener listener; |
| 388 |
if (!matcher.MatchAndExplain(value, &listener)) { |
| 389 |
*os << " Expected arg #" << N - 1 << ": "; |
| 390 |
std::get<N - 1>(matchers).DescribeTo(os); |
| 391 |
*os << "\n Actual: "; |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
internal::UniversalPrint(value, os); |
| 398 |
PrintIfNotEmpty(listener.str(), os); |
| 399 |
*os << "\n"; |
| 400 |
} |
| 401 |
} |
| 402 |
}; |
| 403 |
|
| 404 |
|
| 405 |
template <> |
| 406 |
class TuplePrefix<0> { |
| 407 |
public: |
| 408 |
template <typename MatcherTuple, typename ValueTuple> |
| 409 |
static bool Matches(const MatcherTuple& , |
| 410 |
const ValueTuple& ) { |
| 411 |
return true; |
| 412 |
} |
| 413 |
|
| 414 |
template <typename MatcherTuple, typename ValueTuple> |
| 415 |
static void ExplainMatchFailuresTo(const MatcherTuple& , |
| 416 |
const ValueTuple& , |
| 417 |
::std::ostream* ) {} |
| 418 |
}; |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
template <typename MatcherTuple, typename ValueTuple> |
| 426 |
bool TupleMatches(const MatcherTuple& matcher_tuple, |
| 427 |
const ValueTuple& value_tuple) { |
| 428 |
|
| 429 |
|
| 430 |
GTEST_COMPILE_ASSERT_(std::tuple_size<MatcherTuple>::value == |
| 431 |
std::tuple_size<ValueTuple>::value, |
| 432 |
matcher_and_value_have_different_numbers_of_fields); |
| 433 |
return TuplePrefix<std::tuple_size<ValueTuple>::value>::Matches(matcher_tuple, |
| 434 |
value_tuple); |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
template <typename MatcherTuple, typename ValueTuple> |
| 440 |
void ExplainMatchFailureTupleTo(const MatcherTuple& matchers, |
| 441 |
const ValueTuple& values, |
| 442 |
::std::ostream* os) { |
| 443 |
TuplePrefix<std::tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo( |
| 444 |
matchers, values, os); |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
template <typename Tuple, typename Func, typename OutIter> |
| 452 |
class TransformTupleValuesHelper { |
| 453 |
private: |
| 454 |
typedef ::std::tuple_size<Tuple> TupleSize; |
| 455 |
|
| 456 |
public: |
| 457 |
|
| 458 |
|
| 459 |
static OutIter Run(Func f, const Tuple& t, OutIter out) { |
| 460 |
return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out); |
| 461 |
} |
| 462 |
|
| 463 |
private: |
| 464 |
template <typename Tup, size_t kRemainingSize> |
| 465 |
struct IterateOverTuple { |
| 466 |
OutIter operator() (Func f, const Tup& t, OutIter out) const { |
| 467 |
*out++ = f(::std::get<TupleSize::value - kRemainingSize>(t)); |
| 468 |
return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out); |
| 469 |
} |
| 470 |
}; |
| 471 |
template <typename Tup> |
| 472 |
struct IterateOverTuple<Tup, 0> { |
| 473 |
OutIter operator() (Func , const Tup& , OutIter out) const { |
| 474 |
return out; |
| 475 |
} |
| 476 |
}; |
| 477 |
}; |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
template <typename Tuple, typename Func, typename OutIter> |
| 483 |
OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) { |
| 484 |
return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out); |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
template <typename T> |
| 489 |
class AnyMatcherImpl : public MatcherInterface<const T&> { |
| 490 |
public: |
| 491 |
bool MatchAndExplain(const T& , |
| 492 |
MatchResultListener* ) const override { |
| 493 |
return true; |
| 494 |
} |
| 495 |
void DescribeTo(::std::ostream* os) const override { *os << "is anything"; } |
| 496 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
*os << "never matches"; |
| 501 |
} |
| 502 |
}; |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
class AnythingMatcher { |
| 509 |
public: |
| 510 |
template <typename T> |
| 511 |
operator Matcher<T>() const { return A<T>(); } |
| 512 |
}; |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
class IsNullMatcher { |
| 517 |
public: |
| 518 |
template <typename Pointer> |
| 519 |
bool MatchAndExplain(const Pointer& p, |
| 520 |
MatchResultListener* ) const { |
| 521 |
return p == nullptr; |
| 522 |
} |
| 523 |
|
| 524 |
void DescribeTo(::std::ostream* os) const { *os << "is NULL"; } |
| 525 |
void DescribeNegationTo(::std::ostream* os) const { |
| 526 |
*os << "isn't NULL"; |
| 527 |
} |
| 528 |
}; |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
class NotNullMatcher { |
| 533 |
public: |
| 534 |
template <typename Pointer> |
| 535 |
bool MatchAndExplain(const Pointer& p, |
| 536 |
MatchResultListener* ) const { |
| 537 |
return p != nullptr; |
| 538 |
} |
| 539 |
|
| 540 |
void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; } |
| 541 |
void DescribeNegationTo(::std::ostream* os) const { |
| 542 |
*os << "is NULL"; |
| 543 |
} |
| 544 |
}; |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
template <typename T> |
| 560 |
class RefMatcher; |
| 561 |
|
| 562 |
template <typename T> |
| 563 |
class RefMatcher<T&> { |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
public: |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
explicit RefMatcher(T& x) : object_(x) {} |
| 574 |
|
| 575 |
template <typename Super> |
| 576 |
operator Matcher<Super&>() const { |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
return MakeMatcher(new Impl<Super>(object_)); |
| 583 |
} |
| 584 |
|
| 585 |
private: |
| 586 |
template <typename Super> |
| 587 |
class Impl : public MatcherInterface<Super&> { |
| 588 |
public: |
| 589 |
explicit Impl(Super& x) : object_(x) {} |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
bool MatchAndExplain(Super& x, |
| 594 |
MatchResultListener* listener) const override { |
| 595 |
*listener << "which is located @" << static_cast<const void*>(&x); |
| 596 |
return &x == &object_; |
| 597 |
} |
| 598 |
|
| 599 |
void DescribeTo(::std::ostream* os) const override { |
| 600 |
*os << "references the variable "; |
| 601 |
UniversalPrinter<Super&>::Print(object_, os); |
| 602 |
} |
| 603 |
|
| 604 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 605 |
*os << "does not reference the variable "; |
| 606 |
UniversalPrinter<Super&>::Print(object_, os); |
| 607 |
} |
| 608 |
|
| 609 |
private: |
| 610 |
const Super& object_; |
| 611 |
|
| 612 |
GTEST_DISALLOW_ASSIGN_(Impl); |
| 613 |
}; |
| 614 |
|
| 615 |
T& object_; |
| 616 |
|
| 617 |
GTEST_DISALLOW_ASSIGN_(RefMatcher); |
| 618 |
}; |
| 619 |
|
| 620 |
|
| 621 |
inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) { |
| 622 |
return String::CaseInsensitiveCStringEquals(lhs, rhs); |
| 623 |
} |
| 624 |
|
| 625 |
inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs, |
| 626 |
const wchar_t* rhs) { |
| 627 |
return String::CaseInsensitiveWideCStringEquals(lhs, rhs); |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
template <typename StringType> |
| 633 |
bool CaseInsensitiveStringEquals(const StringType& s1, |
| 634 |
const StringType& s2) { |
| 635 |
|
| 636 |
if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) { |
| 637 |
return false; |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
const typename StringType::value_type nul = 0; |
| 642 |
const size_t i1 = s1.find(nul), i2 = s2.find(nul); |
| 643 |
|
| 644 |
|
| 645 |
if (i1 == StringType::npos || i2 == StringType::npos) { |
| 646 |
return i1 == i2; |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1)); |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
template <typename StringType> |
| 657 |
class StrEqualityMatcher { |
| 658 |
public: |
| 659 |
StrEqualityMatcher(const StringType& str, bool expect_eq, |
| 660 |
bool case_sensitive) |
| 661 |
: string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {} |
| 662 |
|
| 663 |
#if GTEST_HAS_ABSL |
| 664 |
bool MatchAndExplain(const absl::string_view& s, |
| 665 |
MatchResultListener* listener) const { |
| 666 |
|
| 667 |
|
| 668 |
const StringType& str = std::string(s); |
| 669 |
return MatchAndExplain(str, listener); |
| 670 |
} |
| 671 |
#endif |
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
template <typename CharType> |
| 679 |
bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { |
| 680 |
if (s == nullptr) { |
| 681 |
return !expect_eq_; |
| 682 |
} |
| 683 |
return MatchAndExplain(StringType(s), listener); |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
template <typename MatcheeStringType> |
| 691 |
bool MatchAndExplain(const MatcheeStringType& s, |
| 692 |
MatchResultListener* ) const { |
| 693 |
const StringType& s2(s); |
| 694 |
const bool eq = case_sensitive_ ? s2 == string_ : |
| 695 |
CaseInsensitiveStringEquals(s2, string_); |
| 696 |
return expect_eq_ == eq; |
| 697 |
} |
| 698 |
|
| 699 |
void DescribeTo(::std::ostream* os) const { |
| 700 |
DescribeToHelper(expect_eq_, os); |
| 701 |
} |
| 702 |
|
| 703 |
void DescribeNegationTo(::std::ostream* os) const { |
| 704 |
DescribeToHelper(!expect_eq_, os); |
| 705 |
} |
| 706 |
|
| 707 |
private: |
| 708 |
void DescribeToHelper(bool expect_eq, ::std::ostream* os) const { |
| 709 |
*os << (expect_eq ? "is " : "isn't "); |
| 710 |
*os << "equal to "; |
| 711 |
if (!case_sensitive_) { |
| 712 |
*os << "(ignoring case) "; |
| 713 |
} |
| 714 |
UniversalPrint(string_, os); |
| 715 |
} |
| 716 |
|
| 717 |
const StringType string_; |
| 718 |
const bool expect_eq_; |
| 719 |
const bool case_sensitive_; |
| 720 |
|
| 721 |
GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher); |
| 722 |
}; |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
template <typename StringType> |
| 728 |
class HasSubstrMatcher { |
| 729 |
public: |
| 730 |
explicit HasSubstrMatcher(const StringType& substring) |
| 731 |
: substring_(substring) {} |
| 732 |
|
| 733 |
#if GTEST_HAS_ABSL |
| 734 |
bool MatchAndExplain(const absl::string_view& s, |
| 735 |
MatchResultListener* listener) const { |
| 736 |
|
| 737 |
|
| 738 |
const StringType& str = std::string(s); |
| 739 |
return MatchAndExplain(str, listener); |
| 740 |
} |
| 741 |
#endif |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
template <typename CharType> |
| 749 |
bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { |
| 750 |
return s != nullptr && MatchAndExplain(StringType(s), listener); |
| 751 |
} |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
template <typename MatcheeStringType> |
| 758 |
bool MatchAndExplain(const MatcheeStringType& s, |
| 759 |
MatchResultListener* ) const { |
| 760 |
const StringType& s2(s); |
| 761 |
return s2.find(substring_) != StringType::npos; |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
void DescribeTo(::std::ostream* os) const { |
| 766 |
*os << "has substring "; |
| 767 |
UniversalPrint(substring_, os); |
| 768 |
} |
| 769 |
|
| 770 |
void DescribeNegationTo(::std::ostream* os) const { |
| 771 |
*os << "has no substring "; |
| 772 |
UniversalPrint(substring_, os); |
| 773 |
} |
| 774 |
|
| 775 |
private: |
| 776 |
const StringType substring_; |
| 777 |
|
| 778 |
GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher); |
| 779 |
}; |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
template <typename StringType> |
| 785 |
class StartsWithMatcher { |
| 786 |
public: |
| 787 |
explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) { |
| 788 |
} |
| 789 |
|
| 790 |
#if GTEST_HAS_ABSL |
| 791 |
bool MatchAndExplain(const absl::string_view& s, |
| 792 |
MatchResultListener* listener) const { |
| 793 |
|
| 794 |
|
| 795 |
const StringType& str = std::string(s); |
| 796 |
return MatchAndExplain(str, listener); |
| 797 |
} |
| 798 |
#endif |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
template <typename CharType> |
| 806 |
bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { |
| 807 |
return s != nullptr && MatchAndExplain(StringType(s), listener); |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
template <typename MatcheeStringType> |
| 815 |
bool MatchAndExplain(const MatcheeStringType& s, |
| 816 |
MatchResultListener* ) const { |
| 817 |
const StringType& s2(s); |
| 818 |
return s2.length() >= prefix_.length() && |
| 819 |
s2.substr(0, prefix_.length()) == prefix_; |
| 820 |
} |
| 821 |
|
| 822 |
void DescribeTo(::std::ostream* os) const { |
| 823 |
*os << "starts with "; |
| 824 |
UniversalPrint(prefix_, os); |
| 825 |
} |
| 826 |
|
| 827 |
void DescribeNegationTo(::std::ostream* os) const { |
| 828 |
*os << "doesn't start with "; |
| 829 |
UniversalPrint(prefix_, os); |
| 830 |
} |
| 831 |
|
| 832 |
private: |
| 833 |
const StringType prefix_; |
| 834 |
|
| 835 |
GTEST_DISALLOW_ASSIGN_(StartsWithMatcher); |
| 836 |
}; |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
template <typename StringType> |
| 842 |
class EndsWithMatcher { |
| 843 |
public: |
| 844 |
explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {} |
| 845 |
|
| 846 |
#if GTEST_HAS_ABSL |
| 847 |
bool MatchAndExplain(const absl::string_view& s, |
| 848 |
MatchResultListener* listener) const { |
| 849 |
|
| 850 |
|
| 851 |
const StringType& str = std::string(s); |
| 852 |
return MatchAndExplain(str, listener); |
| 853 |
} |
| 854 |
#endif |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
template <typename CharType> |
| 862 |
bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { |
| 863 |
return s != nullptr && MatchAndExplain(StringType(s), listener); |
| 864 |
} |
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
template <typename MatcheeStringType> |
| 871 |
bool MatchAndExplain(const MatcheeStringType& s, |
| 872 |
MatchResultListener* ) const { |
| 873 |
const StringType& s2(s); |
| 874 |
return s2.length() >= suffix_.length() && |
| 875 |
s2.substr(s2.length() - suffix_.length()) == suffix_; |
| 876 |
} |
| 877 |
|
| 878 |
void DescribeTo(::std::ostream* os) const { |
| 879 |
*os << "ends with "; |
| 880 |
UniversalPrint(suffix_, os); |
| 881 |
} |
| 882 |
|
| 883 |
void DescribeNegationTo(::std::ostream* os) const { |
| 884 |
*os << "doesn't end with "; |
| 885 |
UniversalPrint(suffix_, os); |
| 886 |
} |
| 887 |
|
| 888 |
private: |
| 889 |
const StringType suffix_; |
| 890 |
|
| 891 |
GTEST_DISALLOW_ASSIGN_(EndsWithMatcher); |
| 892 |
}; |
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
template <typename D, typename Op> |
| 903 |
class PairMatchBase { |
| 904 |
public: |
| 905 |
template <typename T1, typename T2> |
| 906 |
operator Matcher<::std::tuple<T1, T2>>() const { |
| 907 |
return Matcher<::std::tuple<T1, T2>>(new Impl<const ::std::tuple<T1, T2>&>); |
| 908 |
} |
| 909 |
template <typename T1, typename T2> |
| 910 |
operator Matcher<const ::std::tuple<T1, T2>&>() const { |
| 911 |
return MakeMatcher(new Impl<const ::std::tuple<T1, T2>&>); |
| 912 |
} |
| 913 |
|
| 914 |
private: |
| 915 |
static ::std::ostream& GetDesc(::std::ostream& os) { |
| 916 |
return os << D::Desc(); |
| 917 |
} |
| 918 |
|
| 919 |
template <typename Tuple> |
| 920 |
class Impl : public MatcherInterface<Tuple> { |
| 921 |
public: |
| 922 |
bool MatchAndExplain(Tuple args, |
| 923 |
MatchResultListener* ) const override { |
| 924 |
return Op()(::std::get<0>(args), ::std::get<1>(args)); |
| 925 |
} |
| 926 |
void DescribeTo(::std::ostream* os) const override { |
| 927 |
*os << "are " << GetDesc; |
| 928 |
} |
| 929 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 930 |
*os << "aren't " << GetDesc; |
| 931 |
} |
| 932 |
}; |
| 933 |
}; |
| 934 |
|
| 935 |
class Eq2Matcher : public PairMatchBase<Eq2Matcher, AnyEq> { |
| 936 |
public: |
| 937 |
static const char* Desc() { return "an equal pair"; } |
| 938 |
}; |
| 939 |
class Ne2Matcher : public PairMatchBase<Ne2Matcher, AnyNe> { |
| 940 |
public: |
| 941 |
static const char* Desc() { return "an unequal pair"; } |
| 942 |
}; |
| 943 |
class Lt2Matcher : public PairMatchBase<Lt2Matcher, AnyLt> { |
| 944 |
public: |
| 945 |
static const char* Desc() { return "a pair where the first < the second"; } |
| 946 |
}; |
| 947 |
class Gt2Matcher : public PairMatchBase<Gt2Matcher, AnyGt> { |
| 948 |
public: |
| 949 |
static const char* Desc() { return "a pair where the first > the second"; } |
| 950 |
}; |
| 951 |
class Le2Matcher : public PairMatchBase<Le2Matcher, AnyLe> { |
| 952 |
public: |
| 953 |
static const char* Desc() { return "a pair where the first <= the second"; } |
| 954 |
}; |
| 955 |
class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> { |
| 956 |
public: |
| 957 |
static const char* Desc() { return "a pair where the first >= the second"; } |
| 958 |
}; |
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
template <typename T> |
| 965 |
class NotMatcherImpl : public MatcherInterface<const T&> { |
| 966 |
public: |
| 967 |
explicit NotMatcherImpl(const Matcher<T>& matcher) |
| 968 |
: matcher_(matcher) {} |
| 969 |
|
| 970 |
bool MatchAndExplain(const T& x, |
| 971 |
MatchResultListener* listener) const override { |
| 972 |
return !matcher_.MatchAndExplain(x, listener); |
| 973 |
} |
| 974 |
|
| 975 |
void DescribeTo(::std::ostream* os) const override { |
| 976 |
matcher_.DescribeNegationTo(os); |
| 977 |
} |
| 978 |
|
| 979 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 980 |
matcher_.DescribeTo(os); |
| 981 |
} |
| 982 |
|
| 983 |
private: |
| 984 |
const Matcher<T> matcher_; |
| 985 |
|
| 986 |
GTEST_DISALLOW_ASSIGN_(NotMatcherImpl); |
| 987 |
}; |
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
template <typename InnerMatcher> |
| 992 |
class NotMatcher { |
| 993 |
public: |
| 994 |
explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {} |
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
template <typename T> |
| 999 |
operator Matcher<T>() const { |
| 1000 |
return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_))); |
| 1001 |
} |
| 1002 |
|
| 1003 |
private: |
| 1004 |
InnerMatcher matcher_; |
| 1005 |
|
| 1006 |
GTEST_DISALLOW_ASSIGN_(NotMatcher); |
| 1007 |
}; |
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
template <typename T> |
| 1014 |
class AllOfMatcherImpl : public MatcherInterface<const T&> { |
| 1015 |
public: |
| 1016 |
explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers) |
| 1017 |
: matchers_(std::move(matchers)) {} |
| 1018 |
|
| 1019 |
void DescribeTo(::std::ostream* os) const override { |
| 1020 |
*os << "("; |
| 1021 |
for (size_t i = 0; i < matchers_.size(); ++i) { |
| 1022 |
if (i != 0) *os << ") and ("; |
| 1023 |
matchers_[i].DescribeTo(os); |
| 1024 |
} |
| 1025 |
*os << ")"; |
| 1026 |
} |
| 1027 |
|
| 1028 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 1029 |
*os << "("; |
| 1030 |
for (size_t i = 0; i < matchers_.size(); ++i) { |
| 1031 |
if (i != 0) *os << ") or ("; |
| 1032 |
matchers_[i].DescribeNegationTo(os); |
| 1033 |
} |
| 1034 |
*os << ")"; |
| 1035 |
} |
| 1036 |
|
| 1037 |
bool MatchAndExplain(const T& x, |
| 1038 |
MatchResultListener* listener) const override { |
| 1039 |
|
| 1040 |
|
| 1041 |
std::string all_match_result; |
| 1042 |
|
| 1043 |
for (size_t i = 0; i < matchers_.size(); ++i) { |
| 1044 |
StringMatchResultListener slistener; |
| 1045 |
if (matchers_[i].MatchAndExplain(x, &slistener)) { |
| 1046 |
if (all_match_result.empty()) { |
| 1047 |
all_match_result = slistener.str(); |
| 1048 |
} else { |
| 1049 |
std::string result = slistener.str(); |
| 1050 |
if (!result.empty()) { |
| 1051 |
all_match_result += ", and "; |
| 1052 |
all_match_result += result; |
| 1053 |
} |
| 1054 |
} |
| 1055 |
} else { |
| 1056 |
*listener << slistener.str(); |
| 1057 |
return false; |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
|
| 1062 |
*listener << all_match_result; |
| 1063 |
return true; |
| 1064 |
} |
| 1065 |
|
| 1066 |
private: |
| 1067 |
const std::vector<Matcher<T> > matchers_; |
| 1068 |
|
| 1069 |
GTEST_DISALLOW_ASSIGN_(AllOfMatcherImpl); |
| 1070 |
}; |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
template <template <typename T> class CombiningMatcher, typename... Args> |
| 1077 |
class VariadicMatcher { |
| 1078 |
public: |
| 1079 |
VariadicMatcher(const Args&... matchers) |
| 1080 |
: matchers_(matchers...) { |
| 1081 |
static_assert(sizeof...(Args) > 0, "Must have at least one matcher."); |
| 1082 |
} |
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
template <typename T> |
| 1088 |
operator Matcher<T>() const { |
| 1089 |
std::vector<Matcher<T> > values; |
| 1090 |
CreateVariadicMatcher<T>(&values, std::integral_constant<size_t, 0>()); |
| 1091 |
return Matcher<T>(new CombiningMatcher<T>(std::move(values))); |
| 1092 |
} |
| 1093 |
|
| 1094 |
private: |
| 1095 |
template <typename T, size_t I> |
| 1096 |
void CreateVariadicMatcher(std::vector<Matcher<T> >* values, |
| 1097 |
std::integral_constant<size_t, I>) const { |
| 1098 |
values->push_back(SafeMatcherCast<T>(std::get<I>(matchers_))); |
| 1099 |
CreateVariadicMatcher<T>(values, std::integral_constant<size_t, I + 1>()); |
| 1100 |
} |
| 1101 |
|
| 1102 |
template <typename T> |
| 1103 |
void CreateVariadicMatcher( |
| 1104 |
std::vector<Matcher<T> >*, |
| 1105 |
std::integral_constant<size_t, sizeof...(Args)>) const {} |
| 1106 |
|
| 1107 |
std::tuple<Args...> matchers_; |
| 1108 |
|
| 1109 |
GTEST_DISALLOW_ASSIGN_(VariadicMatcher); |
| 1110 |
}; |
| 1111 |
|
| 1112 |
template <typename... Args> |
| 1113 |
using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>; |
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
template <typename T> |
| 1120 |
class AnyOfMatcherImpl : public MatcherInterface<const T&> { |
| 1121 |
public: |
| 1122 |
explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers) |
| 1123 |
: matchers_(std::move(matchers)) {} |
| 1124 |
|
| 1125 |
void DescribeTo(::std::ostream* os) const override { |
| 1126 |
*os << "("; |
| 1127 |
for (size_t i = 0; i < matchers_.size(); ++i) { |
| 1128 |
if (i != 0) *os << ") or ("; |
| 1129 |
matchers_[i].DescribeTo(os); |
| 1130 |
} |
| 1131 |
*os << ")"; |
| 1132 |
} |
| 1133 |
|
| 1134 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 1135 |
*os << "("; |
| 1136 |
for (size_t i = 0; i < matchers_.size(); ++i) { |
| 1137 |
if (i != 0) *os << ") and ("; |
| 1138 |
matchers_[i].DescribeNegationTo(os); |
| 1139 |
} |
| 1140 |
*os << ")"; |
| 1141 |
} |
| 1142 |
|
| 1143 |
bool MatchAndExplain(const T& x, |
| 1144 |
MatchResultListener* listener) const override { |
| 1145 |
std::string no_match_result; |
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
for (size_t i = 0; i < matchers_.size(); ++i) { |
| 1150 |
StringMatchResultListener slistener; |
| 1151 |
if (matchers_[i].MatchAndExplain(x, &slistener)) { |
| 1152 |
*listener << slistener.str(); |
| 1153 |
return true; |
| 1154 |
} else { |
| 1155 |
if (no_match_result.empty()) { |
| 1156 |
no_match_result = slistener.str(); |
| 1157 |
} else { |
| 1158 |
std::string result = slistener.str(); |
| 1159 |
if (!result.empty()) { |
| 1160 |
no_match_result += ", and "; |
| 1161 |
no_match_result += result; |
| 1162 |
} |
| 1163 |
} |
| 1164 |
} |
| 1165 |
} |
| 1166 |
|
| 1167 |
|
| 1168 |
*listener << no_match_result; |
| 1169 |
return false; |
| 1170 |
} |
| 1171 |
|
| 1172 |
private: |
| 1173 |
const std::vector<Matcher<T> > matchers_; |
| 1174 |
|
| 1175 |
GTEST_DISALLOW_ASSIGN_(AnyOfMatcherImpl); |
| 1176 |
}; |
| 1177 |
|
| 1178 |
|
| 1179 |
template <typename... Args> |
| 1180 |
using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>; |
| 1181 |
|
| 1182 |
|
| 1183 |
template <template <class> class MatcherImpl, typename T> |
| 1184 |
class SomeOfArrayMatcher { |
| 1185 |
public: |
| 1186 |
|
| 1187 |
|
| 1188 |
template <typename Iter> |
| 1189 |
SomeOfArrayMatcher(Iter first, Iter last) : matchers_(first, last) {} |
| 1190 |
|
| 1191 |
template <typename U> |
| 1192 |
operator Matcher<U>() const { |
| 1193 |
using RawU = typename std::decay<U>::type; |
| 1194 |
std::vector<Matcher<RawU>> matchers; |
| 1195 |
for (const auto& matcher : matchers_) { |
| 1196 |
matchers.push_back(MatcherCast<RawU>(matcher)); |
| 1197 |
} |
| 1198 |
return Matcher<U>(new MatcherImpl<RawU>(std::move(matchers))); |
| 1199 |
} |
| 1200 |
|
| 1201 |
private: |
| 1202 |
const ::std::vector<T> matchers_; |
| 1203 |
|
| 1204 |
GTEST_DISALLOW_ASSIGN_(SomeOfArrayMatcher); |
| 1205 |
}; |
| 1206 |
|
| 1207 |
template <typename T> |
| 1208 |
using AllOfArrayMatcher = SomeOfArrayMatcher<AllOfMatcherImpl, T>; |
| 1209 |
|
| 1210 |
template <typename T> |
| 1211 |
using AnyOfArrayMatcher = SomeOfArrayMatcher<AnyOfMatcherImpl, T>; |
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
template <typename Predicate> |
| 1216 |
class TrulyMatcher { |
| 1217 |
public: |
| 1218 |
explicit TrulyMatcher(Predicate pred) : predicate_(pred) {} |
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
template <typename T> |
| 1225 |
bool MatchAndExplain(T& x, |
| 1226 |
MatchResultListener* ) const { |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
if (predicate_(x)) |
| 1234 |
return true; |
| 1235 |
return false; |
| 1236 |
} |
| 1237 |
|
| 1238 |
void DescribeTo(::std::ostream* os) const { |
| 1239 |
*os << "satisfies the given predicate"; |
| 1240 |
} |
| 1241 |
|
| 1242 |
void DescribeNegationTo(::std::ostream* os) const { |
| 1243 |
*os << "doesn't satisfy the given predicate"; |
| 1244 |
} |
| 1245 |
|
| 1246 |
private: |
| 1247 |
Predicate predicate_; |
| 1248 |
|
| 1249 |
GTEST_DISALLOW_ASSIGN_(TrulyMatcher); |
| 1250 |
}; |
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
template <typename M> |
| 1255 |
class MatcherAsPredicate { |
| 1256 |
public: |
| 1257 |
explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {} |
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
template <typename T> |
| 1266 |
bool operator()(const T& x) const { |
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
return MatcherCast<const T&>(matcher_).Matches(x); |
| 1282 |
} |
| 1283 |
|
| 1284 |
private: |
| 1285 |
M matcher_; |
| 1286 |
|
| 1287 |
GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate); |
| 1288 |
}; |
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
template <typename M> |
| 1293 |
class PredicateFormatterFromMatcher { |
| 1294 |
public: |
| 1295 |
explicit PredicateFormatterFromMatcher(M m) : matcher_(std::move(m)) {} |
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
template <typename T> |
| 1301 |
AssertionResult operator()(const char* value_text, const T& x) const { |
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_); |
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
if (matcher.Matches(x)) { |
| 1318 |
return AssertionSuccess(); |
| 1319 |
} |
| 1320 |
|
| 1321 |
::std::stringstream ss; |
| 1322 |
ss << "Value of: " << value_text << "\n" |
| 1323 |
<< "Expected: "; |
| 1324 |
matcher.DescribeTo(&ss); |
| 1325 |
|
| 1326 |
|
| 1327 |
StringMatchResultListener listener; |
| 1328 |
if (MatchPrintAndExplain(x, matcher, &listener)) { |
| 1329 |
ss << "\n The matcher failed on the initial attempt; but passed when " |
| 1330 |
"rerun to generate the explanation."; |
| 1331 |
} |
| 1332 |
ss << "\n Actual: " << listener.str(); |
| 1333 |
return AssertionFailure() << ss.str(); |
| 1334 |
} |
| 1335 |
|
| 1336 |
private: |
| 1337 |
const M matcher_; |
| 1338 |
|
| 1339 |
GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher); |
| 1340 |
}; |
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
template <typename M> |
| 1347 |
inline PredicateFormatterFromMatcher<M> |
| 1348 |
MakePredicateFormatterFromMatcher(M matcher) { |
| 1349 |
return PredicateFormatterFromMatcher<M>(std::move(matcher)); |
| 1350 |
} |
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
template <typename FloatType> |
| 1357 |
class FloatingEqMatcher { |
| 1358 |
public: |
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
FloatingEqMatcher(FloatType expected, bool nan_eq_nan) : |
| 1366 |
expected_(expected), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) { |
| 1367 |
} |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
FloatingEqMatcher(FloatType expected, bool nan_eq_nan, |
| 1373 |
FloatType max_abs_error) |
| 1374 |
: expected_(expected), |
| 1375 |
nan_eq_nan_(nan_eq_nan), |
| 1376 |
max_abs_error_(max_abs_error) { |
| 1377 |
GTEST_CHECK_(max_abs_error >= 0) |
| 1378 |
<< ", where max_abs_error is" << max_abs_error; |
| 1379 |
} |
| 1380 |
|
| 1381 |
|
| 1382 |
template <typename T> |
| 1383 |
class Impl : public MatcherInterface<T> { |
| 1384 |
public: |
| 1385 |
Impl(FloatType expected, bool nan_eq_nan, FloatType max_abs_error) |
| 1386 |
: expected_(expected), |
| 1387 |
nan_eq_nan_(nan_eq_nan), |
| 1388 |
max_abs_error_(max_abs_error) {} |
| 1389 |
|
| 1390 |
bool MatchAndExplain(T value, |
| 1391 |
MatchResultListener* listener) const override { |
| 1392 |
const FloatingPoint<FloatType> actual(value), expected(expected_); |
| 1393 |
|
| 1394 |
|
| 1395 |
if (actual.is_nan() || expected.is_nan()) { |
| 1396 |
if (actual.is_nan() && expected.is_nan()) { |
| 1397 |
return nan_eq_nan_; |
| 1398 |
} |
| 1399 |
|
| 1400 |
return false; |
| 1401 |
} |
| 1402 |
if (HasMaxAbsError()) { |
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
if (value == expected_) { |
| 1408 |
return true; |
| 1409 |
} |
| 1410 |
|
| 1411 |
const FloatType diff = value - expected_; |
| 1412 |
if (fabs(diff) <= max_abs_error_) { |
| 1413 |
return true; |
| 1414 |
} |
| 1415 |
|
| 1416 |
if (listener->IsInterested()) { |
| 1417 |
*listener << "which is " << diff << " from " << expected_; |
| 1418 |
} |
| 1419 |
return false; |
| 1420 |
} else { |
| 1421 |
return actual.AlmostEquals(expected); |
| 1422 |
} |
| 1423 |
} |
| 1424 |
|
| 1425 |
void DescribeTo(::std::ostream* os) const override { |
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
const ::std::streamsize old_precision = os->precision( |
| 1430 |
::std::numeric_limits<FloatType>::digits10 + 2); |
| 1431 |
if (FloatingPoint<FloatType>(expected_).is_nan()) { |
| 1432 |
if (nan_eq_nan_) { |
| 1433 |
*os << "is NaN"; |
| 1434 |
} else { |
| 1435 |
*os << "never matches"; |
| 1436 |
} |
| 1437 |
} else { |
| 1438 |
*os << "is approximately " << expected_; |
| 1439 |
if (HasMaxAbsError()) { |
| 1440 |
*os << " (absolute error <= " << max_abs_error_ << ")"; |
| 1441 |
} |
| 1442 |
} |
| 1443 |
os->precision(old_precision); |
| 1444 |
} |
| 1445 |
|
| 1446 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 1447 |
|
| 1448 |
const ::std::streamsize old_precision = os->precision( |
| 1449 |
::std::numeric_limits<FloatType>::digits10 + 2); |
| 1450 |
if (FloatingPoint<FloatType>(expected_).is_nan()) { |
| 1451 |
if (nan_eq_nan_) { |
| 1452 |
*os << "isn't NaN"; |
| 1453 |
} else { |
| 1454 |
*os << "is anything"; |
| 1455 |
} |
| 1456 |
} else { |
| 1457 |
*os << "isn't approximately " << expected_; |
| 1458 |
if (HasMaxAbsError()) { |
| 1459 |
*os << " (absolute error > " << max_abs_error_ << ")"; |
| 1460 |
} |
| 1461 |
} |
| 1462 |
|
| 1463 |
os->precision(old_precision); |
| 1464 |
} |
| 1465 |
|
| 1466 |
private: |
| 1467 |
bool HasMaxAbsError() const { |
| 1468 |
return max_abs_error_ >= 0; |
| 1469 |
} |
| 1470 |
|
| 1471 |
const FloatType expected_; |
| 1472 |
const bool nan_eq_nan_; |
| 1473 |
|
| 1474 |
const FloatType max_abs_error_; |
| 1475 |
|
| 1476 |
GTEST_DISALLOW_ASSIGN_(Impl); |
| 1477 |
}; |
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
operator Matcher<FloatType>() const { |
| 1486 |
return MakeMatcher( |
| 1487 |
new Impl<FloatType>(expected_, nan_eq_nan_, max_abs_error_)); |
| 1488 |
} |
| 1489 |
|
| 1490 |
operator Matcher<const FloatType&>() const { |
| 1491 |
return MakeMatcher( |
| 1492 |
new Impl<const FloatType&>(expected_, nan_eq_nan_, max_abs_error_)); |
| 1493 |
} |
| 1494 |
|
| 1495 |
operator Matcher<FloatType&>() const { |
| 1496 |
return MakeMatcher( |
| 1497 |
new Impl<FloatType&>(expected_, nan_eq_nan_, max_abs_error_)); |
| 1498 |
} |
| 1499 |
|
| 1500 |
private: |
| 1501 |
const FloatType expected_; |
| 1502 |
const bool nan_eq_nan_; |
| 1503 |
|
| 1504 |
const FloatType max_abs_error_; |
| 1505 |
|
| 1506 |
GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher); |
| 1507 |
}; |
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
template <typename FloatType> |
| 1515 |
class FloatingEq2Matcher { |
| 1516 |
public: |
| 1517 |
FloatingEq2Matcher() { Init(-1, false); } |
| 1518 |
|
| 1519 |
explicit FloatingEq2Matcher(bool nan_eq_nan) { Init(-1, nan_eq_nan); } |
| 1520 |
|
| 1521 |
explicit FloatingEq2Matcher(FloatType max_abs_error) { |
| 1522 |
Init(max_abs_error, false); |
| 1523 |
} |
| 1524 |
|
| 1525 |
FloatingEq2Matcher(FloatType max_abs_error, bool nan_eq_nan) { |
| 1526 |
Init(max_abs_error, nan_eq_nan); |
| 1527 |
} |
| 1528 |
|
| 1529 |
template <typename T1, typename T2> |
| 1530 |
operator Matcher<::std::tuple<T1, T2>>() const { |
| 1531 |
return MakeMatcher( |
| 1532 |
new Impl<::std::tuple<T1, T2>>(max_abs_error_, nan_eq_nan_)); |
| 1533 |
} |
| 1534 |
template <typename T1, typename T2> |
| 1535 |
operator Matcher<const ::std::tuple<T1, T2>&>() const { |
| 1536 |
return MakeMatcher( |
| 1537 |
new Impl<const ::std::tuple<T1, T2>&>(max_abs_error_, nan_eq_nan_)); |
| 1538 |
} |
| 1539 |
|
| 1540 |
private: |
| 1541 |
static ::std::ostream& GetDesc(::std::ostream& os) { |
| 1542 |
return os << "an almost-equal pair"; |
| 1543 |
} |
| 1544 |
|
| 1545 |
template <typename Tuple> |
| 1546 |
class Impl : public MatcherInterface<Tuple> { |
| 1547 |
public: |
| 1548 |
Impl(FloatType max_abs_error, bool nan_eq_nan) : |
| 1549 |
max_abs_error_(max_abs_error), |
| 1550 |
nan_eq_nan_(nan_eq_nan) {} |
| 1551 |
|
| 1552 |
bool MatchAndExplain(Tuple args, |
| 1553 |
MatchResultListener* listener) const override { |
| 1554 |
if (max_abs_error_ == -1) { |
| 1555 |
FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_); |
| 1556 |
return static_cast<Matcher<FloatType>>(fm).MatchAndExplain( |
| 1557 |
::std::get<1>(args), listener); |
| 1558 |
} else { |
| 1559 |
FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_, |
| 1560 |
max_abs_error_); |
| 1561 |
return static_cast<Matcher<FloatType>>(fm).MatchAndExplain( |
| 1562 |
::std::get<1>(args), listener); |
| 1563 |
} |
| 1564 |
} |
| 1565 |
void DescribeTo(::std::ostream* os) const override { |
| 1566 |
*os << "are " << GetDesc; |
| 1567 |
} |
| 1568 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 1569 |
*os << "aren't " << GetDesc; |
| 1570 |
} |
| 1571 |
|
| 1572 |
private: |
| 1573 |
FloatType max_abs_error_; |
| 1574 |
const bool nan_eq_nan_; |
| 1575 |
}; |
| 1576 |
|
| 1577 |
void Init(FloatType max_abs_error_val, bool nan_eq_nan_val) { |
| 1578 |
max_abs_error_ = max_abs_error_val; |
| 1579 |
nan_eq_nan_ = nan_eq_nan_val; |
| 1580 |
} |
| 1581 |
FloatType max_abs_error_; |
| 1582 |
bool nan_eq_nan_; |
| 1583 |
}; |
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
template <typename InnerMatcher> |
| 1588 |
class PointeeMatcher { |
| 1589 |
public: |
| 1590 |
explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {} |
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
template <typename Pointer> |
| 1601 |
operator Matcher<Pointer>() const { |
| 1602 |
return Matcher<Pointer>(new Impl<const Pointer&>(matcher_)); |
| 1603 |
} |
| 1604 |
|
| 1605 |
private: |
| 1606 |
|
| 1607 |
template <typename Pointer> |
| 1608 |
class Impl : public MatcherInterface<Pointer> { |
| 1609 |
public: |
| 1610 |
typedef typename PointeeOf<typename std::remove_const< |
| 1611 |
typename std::remove_reference<Pointer>::type>::type>::type Pointee; |
| 1612 |
|
| 1613 |
explicit Impl(const InnerMatcher& matcher) |
| 1614 |
: matcher_(MatcherCast<const Pointee&>(matcher)) {} |
| 1615 |
|
| 1616 |
void DescribeTo(::std::ostream* os) const override { |
| 1617 |
*os << "points to a value that "; |
| 1618 |
matcher_.DescribeTo(os); |
| 1619 |
} |
| 1620 |
|
| 1621 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 1622 |
*os << "does not point to a value that "; |
| 1623 |
matcher_.DescribeTo(os); |
| 1624 |
} |
| 1625 |
|
| 1626 |
bool MatchAndExplain(Pointer pointer, |
| 1627 |
MatchResultListener* listener) const override { |
| 1628 |
if (GetRawPointer(pointer) == nullptr) return false; |
| 1629 |
|
| 1630 |
*listener << "which points to "; |
| 1631 |
return MatchPrintAndExplain(*pointer, matcher_, listener); |
| 1632 |
} |
| 1633 |
|
| 1634 |
private: |
| 1635 |
const Matcher<const Pointee&> matcher_; |
| 1636 |
|
| 1637 |
GTEST_DISALLOW_ASSIGN_(Impl); |
| 1638 |
}; |
| 1639 |
|
| 1640 |
const InnerMatcher matcher_; |
| 1641 |
|
| 1642 |
GTEST_DISALLOW_ASSIGN_(PointeeMatcher); |
| 1643 |
}; |
| 1644 |
|
| 1645 |
#if GTEST_HAS_RTTI |
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
template <typename To> |
| 1653 |
class WhenDynamicCastToMatcherBase { |
| 1654 |
public: |
| 1655 |
explicit WhenDynamicCastToMatcherBase(const Matcher<To>& matcher) |
| 1656 |
: matcher_(matcher) {} |
| 1657 |
|
| 1658 |
void DescribeTo(::std::ostream* os) const { |
| 1659 |
GetCastTypeDescription(os); |
| 1660 |
matcher_.DescribeTo(os); |
| 1661 |
} |
| 1662 |
|
| 1663 |
void DescribeNegationTo(::std::ostream* os) const { |
| 1664 |
GetCastTypeDescription(os); |
| 1665 |
matcher_.DescribeNegationTo(os); |
| 1666 |
} |
| 1667 |
|
| 1668 |
protected: |
| 1669 |
const Matcher<To> matcher_; |
| 1670 |
|
| 1671 |
static std::string GetToName() { |
| 1672 |
return GetTypeName<To>(); |
| 1673 |
} |
| 1674 |
|
| 1675 |
private: |
| 1676 |
static void GetCastTypeDescription(::std::ostream* os) { |
| 1677 |
*os << "when dynamic_cast to " << GetToName() << ", "; |
| 1678 |
} |
| 1679 |
|
| 1680 |
GTEST_DISALLOW_ASSIGN_(WhenDynamicCastToMatcherBase); |
| 1681 |
}; |
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
template <typename To> |
| 1686 |
class WhenDynamicCastToMatcher : public WhenDynamicCastToMatcherBase<To> { |
| 1687 |
public: |
| 1688 |
explicit WhenDynamicCastToMatcher(const Matcher<To>& matcher) |
| 1689 |
: WhenDynamicCastToMatcherBase<To>(matcher) {} |
| 1690 |
|
| 1691 |
template <typename From> |
| 1692 |
bool MatchAndExplain(From from, MatchResultListener* listener) const { |
| 1693 |
To to = dynamic_cast<To>(from); |
| 1694 |
return MatchPrintAndExplain(to, this->matcher_, listener); |
| 1695 |
} |
| 1696 |
}; |
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
template <typename To> |
| 1701 |
class WhenDynamicCastToMatcher<To&> : public WhenDynamicCastToMatcherBase<To&> { |
| 1702 |
public: |
| 1703 |
explicit WhenDynamicCastToMatcher(const Matcher<To&>& matcher) |
| 1704 |
: WhenDynamicCastToMatcherBase<To&>(matcher) {} |
| 1705 |
|
| 1706 |
template <typename From> |
| 1707 |
bool MatchAndExplain(From& from, MatchResultListener* listener) const { |
| 1708 |
|
| 1709 |
To* to = dynamic_cast<To*>(&from); |
| 1710 |
if (to == nullptr) { |
| 1711 |
*listener << "which cannot be dynamic_cast to " << this->GetToName(); |
| 1712 |
return false; |
| 1713 |
} |
| 1714 |
return MatchPrintAndExplain(*to, this->matcher_, listener); |
| 1715 |
} |
| 1716 |
}; |
| 1717 |
#endif |
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
template <typename Class, typename FieldType> |
| 1722 |
class FieldMatcher { |
| 1723 |
public: |
| 1724 |
FieldMatcher(FieldType Class::*field, |
| 1725 |
const Matcher<const FieldType&>& matcher) |
| 1726 |
: field_(field), matcher_(matcher), whose_field_("whose given field ") {} |
| 1727 |
|
| 1728 |
FieldMatcher(const std::string& field_name, FieldType Class::*field, |
| 1729 |
const Matcher<const FieldType&>& matcher) |
| 1730 |
: field_(field), |
| 1731 |
matcher_(matcher), |
| 1732 |
whose_field_("whose field `" + field_name + "` ") {} |
| 1733 |
|
| 1734 |
void DescribeTo(::std::ostream* os) const { |
| 1735 |
*os << "is an object " << whose_field_; |
| 1736 |
matcher_.DescribeTo(os); |
| 1737 |
} |
| 1738 |
|
| 1739 |
void DescribeNegationTo(::std::ostream* os) const { |
| 1740 |
*os << "is an object " << whose_field_; |
| 1741 |
matcher_.DescribeNegationTo(os); |
| 1742 |
} |
| 1743 |
|
| 1744 |
template <typename T> |
| 1745 |
bool MatchAndExplain(const T& value, MatchResultListener* listener) const { |
| 1746 |
|
| 1747 |
|
| 1748 |
return MatchAndExplainImpl( |
| 1749 |
typename std::is_pointer<typename std::remove_const<T>::type>::type(), |
| 1750 |
value, listener); |
| 1751 |
} |
| 1752 |
|
| 1753 |
private: |
| 1754 |
bool MatchAndExplainImpl(std::false_type , |
| 1755 |
const Class& obj, |
| 1756 |
MatchResultListener* listener) const { |
| 1757 |
*listener << whose_field_ << "is "; |
| 1758 |
return MatchPrintAndExplain(obj.*field_, matcher_, listener); |
| 1759 |
} |
| 1760 |
|
| 1761 |
bool MatchAndExplainImpl(std::true_type , const Class* p, |
| 1762 |
MatchResultListener* listener) const { |
| 1763 |
if (p == nullptr) return false; |
| 1764 |
|
| 1765 |
*listener << "which points to an object "; |
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
return MatchAndExplainImpl(std::false_type(), *p, listener); |
| 1770 |
} |
| 1771 |
|
| 1772 |
const FieldType Class::*field_; |
| 1773 |
const Matcher<const FieldType&> matcher_; |
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
const std::string whose_field_; |
| 1778 |
|
| 1779 |
GTEST_DISALLOW_ASSIGN_(FieldMatcher); |
| 1780 |
}; |
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
template <typename Class, typename PropertyType, typename Property> |
| 1788 |
class PropertyMatcher { |
| 1789 |
public: |
| 1790 |
typedef const PropertyType& RefToConstProperty; |
| 1791 |
|
| 1792 |
PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher) |
| 1793 |
: property_(property), |
| 1794 |
matcher_(matcher), |
| 1795 |
whose_property_("whose given property ") {} |
| 1796 |
|
| 1797 |
PropertyMatcher(const std::string& property_name, Property property, |
| 1798 |
const Matcher<RefToConstProperty>& matcher) |
| 1799 |
: property_(property), |
| 1800 |
matcher_(matcher), |
| 1801 |
whose_property_("whose property `" + property_name + "` ") {} |
| 1802 |
|
| 1803 |
void DescribeTo(::std::ostream* os) const { |
| 1804 |
*os << "is an object " << whose_property_; |
| 1805 |
matcher_.DescribeTo(os); |
| 1806 |
} |
| 1807 |
|
| 1808 |
void DescribeNegationTo(::std::ostream* os) const { |
| 1809 |
*os << "is an object " << whose_property_; |
| 1810 |
matcher_.DescribeNegationTo(os); |
| 1811 |
} |
| 1812 |
|
| 1813 |
template <typename T> |
| 1814 |
bool MatchAndExplain(const T&value, MatchResultListener* listener) const { |
| 1815 |
return MatchAndExplainImpl( |
| 1816 |
typename std::is_pointer<typename std::remove_const<T>::type>::type(), |
| 1817 |
value, listener); |
| 1818 |
} |
| 1819 |
|
| 1820 |
private: |
| 1821 |
bool MatchAndExplainImpl(std::false_type , |
| 1822 |
const Class& obj, |
| 1823 |
MatchResultListener* listener) const { |
| 1824 |
*listener << whose_property_ << "is "; |
| 1825 |
|
| 1826 |
|
| 1827 |
RefToConstProperty result = (obj.*property_)(); |
| 1828 |
return MatchPrintAndExplain(result, matcher_, listener); |
| 1829 |
} |
| 1830 |
|
| 1831 |
bool MatchAndExplainImpl(std::true_type , const Class* p, |
| 1832 |
MatchResultListener* listener) const { |
| 1833 |
if (p == nullptr) return false; |
| 1834 |
|
| 1835 |
*listener << "which points to an object "; |
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
return MatchAndExplainImpl(std::false_type(), *p, listener); |
| 1840 |
} |
| 1841 |
|
| 1842 |
Property property_; |
| 1843 |
const Matcher<RefToConstProperty> matcher_; |
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
const std::string whose_property_; |
| 1848 |
|
| 1849 |
GTEST_DISALLOW_ASSIGN_(PropertyMatcher); |
| 1850 |
}; |
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
template <typename Functor> |
| 1855 |
struct CallableTraits { |
| 1856 |
typedef Functor StorageType; |
| 1857 |
|
| 1858 |
static void CheckIsValid(Functor ) {} |
| 1859 |
|
| 1860 |
template <typename T> |
| 1861 |
static auto Invoke(Functor f, const T& arg) -> decltype(f(arg)) { |
| 1862 |
return f(arg); |
| 1863 |
} |
| 1864 |
}; |
| 1865 |
|
| 1866 |
|
| 1867 |
template <typename ArgType, typename ResType> |
| 1868 |
struct CallableTraits<ResType(*)(ArgType)> { |
| 1869 |
typedef ResType ResultType; |
| 1870 |
typedef ResType(*StorageType)(ArgType); |
| 1871 |
|
| 1872 |
static void CheckIsValid(ResType(*f)(ArgType)) { |
| 1873 |
GTEST_CHECK_(f != nullptr) |
| 1874 |
<< "NULL function pointer is passed into ResultOf()."; |
| 1875 |
} |
| 1876 |
template <typename T> |
| 1877 |
static ResType Invoke(ResType(*f)(ArgType), T arg) { |
| 1878 |
return (*f)(arg); |
| 1879 |
} |
| 1880 |
}; |
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
template <typename Callable, typename InnerMatcher> |
| 1885 |
class ResultOfMatcher { |
| 1886 |
public: |
| 1887 |
ResultOfMatcher(Callable callable, InnerMatcher matcher) |
| 1888 |
: callable_(std::move(callable)), matcher_(std::move(matcher)) { |
| 1889 |
CallableTraits<Callable>::CheckIsValid(callable_); |
| 1890 |
} |
| 1891 |
|
| 1892 |
template <typename T> |
| 1893 |
operator Matcher<T>() const { |
| 1894 |
return Matcher<T>(new Impl<const T&>(callable_, matcher_)); |
| 1895 |
} |
| 1896 |
|
| 1897 |
private: |
| 1898 |
typedef typename CallableTraits<Callable>::StorageType CallableStorageType; |
| 1899 |
|
| 1900 |
template <typename T> |
| 1901 |
class Impl : public MatcherInterface<T> { |
| 1902 |
using ResultType = decltype(CallableTraits<Callable>::template Invoke<T>( |
| 1903 |
std::declval<CallableStorageType>(), std::declval<T>())); |
| 1904 |
|
| 1905 |
public: |
| 1906 |
template <typename M> |
| 1907 |
Impl(const CallableStorageType& callable, const M& matcher) |
| 1908 |
: callable_(callable), matcher_(MatcherCast<ResultType>(matcher)) {} |
| 1909 |
|
| 1910 |
void DescribeTo(::std::ostream* os) const override { |
| 1911 |
*os << "is mapped by the given callable to a value that "; |
| 1912 |
matcher_.DescribeTo(os); |
| 1913 |
} |
| 1914 |
|
| 1915 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 1916 |
*os << "is mapped by the given callable to a value that "; |
| 1917 |
matcher_.DescribeNegationTo(os); |
| 1918 |
} |
| 1919 |
|
| 1920 |
bool MatchAndExplain(T obj, MatchResultListener* listener) const override { |
| 1921 |
*listener << "which is mapped by the given callable to "; |
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
ResultType result = |
| 1927 |
CallableTraits<Callable>::template Invoke<T>(callable_, obj); |
| 1928 |
return MatchPrintAndExplain(result, matcher_, listener); |
| 1929 |
} |
| 1930 |
|
| 1931 |
private: |
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
mutable CallableStorageType callable_; |
| 1938 |
const Matcher<ResultType> matcher_; |
| 1939 |
|
| 1940 |
GTEST_DISALLOW_ASSIGN_(Impl); |
| 1941 |
}; |
| 1942 |
|
| 1943 |
const CallableStorageType callable_; |
| 1944 |
const InnerMatcher matcher_; |
| 1945 |
|
| 1946 |
GTEST_DISALLOW_ASSIGN_(ResultOfMatcher); |
| 1947 |
}; |
| 1948 |
|
| 1949 |
|
| 1950 |
template <typename SizeMatcher> |
| 1951 |
class SizeIsMatcher { |
| 1952 |
public: |
| 1953 |
explicit SizeIsMatcher(const SizeMatcher& size_matcher) |
| 1954 |
: size_matcher_(size_matcher) { |
| 1955 |
} |
| 1956 |
|
| 1957 |
template <typename Container> |
| 1958 |
operator Matcher<Container>() const { |
| 1959 |
return Matcher<Container>(new Impl<const Container&>(size_matcher_)); |
| 1960 |
} |
| 1961 |
|
| 1962 |
template <typename Container> |
| 1963 |
class Impl : public MatcherInterface<Container> { |
| 1964 |
public: |
| 1965 |
using SizeType = decltype(std::declval<Container>().size()); |
| 1966 |
explicit Impl(const SizeMatcher& size_matcher) |
| 1967 |
: size_matcher_(MatcherCast<SizeType>(size_matcher)) {} |
| 1968 |
|
| 1969 |
void DescribeTo(::std::ostream* os) const override { |
| 1970 |
*os << "size "; |
| 1971 |
size_matcher_.DescribeTo(os); |
| 1972 |
} |
| 1973 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 1974 |
*os << "size "; |
| 1975 |
size_matcher_.DescribeNegationTo(os); |
| 1976 |
} |
| 1977 |
|
| 1978 |
bool MatchAndExplain(Container container, |
| 1979 |
MatchResultListener* listener) const override { |
| 1980 |
SizeType size = container.size(); |
| 1981 |
StringMatchResultListener size_listener; |
| 1982 |
const bool result = size_matcher_.MatchAndExplain(size, &size_listener); |
| 1983 |
*listener |
| 1984 |
<< "whose size " << size << (result ? " matches" : " doesn't match"); |
| 1985 |
PrintIfNotEmpty(size_listener.str(), listener->stream()); |
| 1986 |
return result; |
| 1987 |
} |
| 1988 |
|
| 1989 |
private: |
| 1990 |
const Matcher<SizeType> size_matcher_; |
| 1991 |
GTEST_DISALLOW_ASSIGN_(Impl); |
| 1992 |
}; |
| 1993 |
|
| 1994 |
private: |
| 1995 |
const SizeMatcher size_matcher_; |
| 1996 |
GTEST_DISALLOW_ASSIGN_(SizeIsMatcher); |
| 1997 |
}; |
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
template <typename DistanceMatcher> |
| 2002 |
class BeginEndDistanceIsMatcher { |
| 2003 |
public: |
| 2004 |
explicit BeginEndDistanceIsMatcher(const DistanceMatcher& distance_matcher) |
| 2005 |
: distance_matcher_(distance_matcher) {} |
| 2006 |
|
| 2007 |
template <typename Container> |
| 2008 |
operator Matcher<Container>() const { |
| 2009 |
return Matcher<Container>(new Impl<const Container&>(distance_matcher_)); |
| 2010 |
} |
| 2011 |
|
| 2012 |
template <typename Container> |
| 2013 |
class Impl : public MatcherInterface<Container> { |
| 2014 |
public: |
| 2015 |
typedef internal::StlContainerView< |
| 2016 |
GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView; |
| 2017 |
typedef typename std::iterator_traits< |
| 2018 |
typename ContainerView::type::const_iterator>::difference_type |
| 2019 |
DistanceType; |
| 2020 |
explicit Impl(const DistanceMatcher& distance_matcher) |
| 2021 |
: distance_matcher_(MatcherCast<DistanceType>(distance_matcher)) {} |
| 2022 |
|
| 2023 |
void DescribeTo(::std::ostream* os) const override { |
| 2024 |
*os << "distance between begin() and end() "; |
| 2025 |
distance_matcher_.DescribeTo(os); |
| 2026 |
} |
| 2027 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 2028 |
*os << "distance between begin() and end() "; |
| 2029 |
distance_matcher_.DescribeNegationTo(os); |
| 2030 |
} |
| 2031 |
|
| 2032 |
bool MatchAndExplain(Container container, |
| 2033 |
MatchResultListener* listener) const override { |
| 2034 |
using std::begin; |
| 2035 |
using std::end; |
| 2036 |
DistanceType distance = std::distance(begin(container), end(container)); |
| 2037 |
StringMatchResultListener distance_listener; |
| 2038 |
const bool result = |
| 2039 |
distance_matcher_.MatchAndExplain(distance, &distance_listener); |
| 2040 |
*listener << "whose distance between begin() and end() " << distance |
| 2041 |
<< (result ? " matches" : " doesn't match"); |
| 2042 |
PrintIfNotEmpty(distance_listener.str(), listener->stream()); |
| 2043 |
return result; |
| 2044 |
} |
| 2045 |
|
| 2046 |
private: |
| 2047 |
const Matcher<DistanceType> distance_matcher_; |
| 2048 |
GTEST_DISALLOW_ASSIGN_(Impl); |
| 2049 |
}; |
| 2050 |
|
| 2051 |
private: |
| 2052 |
const DistanceMatcher distance_matcher_; |
| 2053 |
GTEST_DISALLOW_ASSIGN_(BeginEndDistanceIsMatcher); |
| 2054 |
}; |
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
template <typename Container> |
| 2067 |
class ContainerEqMatcher { |
| 2068 |
public: |
| 2069 |
typedef internal::StlContainerView<Container> View; |
| 2070 |
typedef typename View::type StlContainer; |
| 2071 |
typedef typename View::const_reference StlContainerReference; |
| 2072 |
|
| 2073 |
static_assert(!std::is_const<Container>::value, |
| 2074 |
"Container type must not be const"); |
| 2075 |
static_assert(!std::is_reference<Container>::value, |
| 2076 |
"Container type must not be a reference"); |
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
explicit ContainerEqMatcher(const Container& expected) |
| 2081 |
: expected_(View::Copy(expected)) {} |
| 2082 |
|
| 2083 |
void DescribeTo(::std::ostream* os) const { |
| 2084 |
*os << "equals "; |
| 2085 |
UniversalPrint(expected_, os); |
| 2086 |
} |
| 2087 |
void DescribeNegationTo(::std::ostream* os) const { |
| 2088 |
*os << "does not equal "; |
| 2089 |
UniversalPrint(expected_, os); |
| 2090 |
} |
| 2091 |
|
| 2092 |
template <typename LhsContainer> |
| 2093 |
bool MatchAndExplain(const LhsContainer& lhs, |
| 2094 |
MatchResultListener* listener) const { |
| 2095 |
typedef internal::StlContainerView< |
| 2096 |
typename std::remove_const<LhsContainer>::type> |
| 2097 |
LhsView; |
| 2098 |
typedef typename LhsView::type LhsStlContainer; |
| 2099 |
StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); |
| 2100 |
if (lhs_stl_container == expected_) |
| 2101 |
return true; |
| 2102 |
|
| 2103 |
::std::ostream* const os = listener->stream(); |
| 2104 |
if (os != nullptr) { |
| 2105 |
|
| 2106 |
bool printed_header = false; |
| 2107 |
for (typename LhsStlContainer::const_iterator it = |
| 2108 |
lhs_stl_container.begin(); |
| 2109 |
it != lhs_stl_container.end(); ++it) { |
| 2110 |
if (internal::ArrayAwareFind(expected_.begin(), expected_.end(), *it) == |
| 2111 |
expected_.end()) { |
| 2112 |
if (printed_header) { |
| 2113 |
*os << ", "; |
| 2114 |
} else { |
| 2115 |
*os << "which has these unexpected elements: "; |
| 2116 |
printed_header = true; |
| 2117 |
} |
| 2118 |
UniversalPrint(*it, os); |
| 2119 |
} |
| 2120 |
} |
| 2121 |
|
| 2122 |
|
| 2123 |
bool printed_header2 = false; |
| 2124 |
for (typename StlContainer::const_iterator it = expected_.begin(); |
| 2125 |
it != expected_.end(); ++it) { |
| 2126 |
if (internal::ArrayAwareFind( |
| 2127 |
lhs_stl_container.begin(), lhs_stl_container.end(), *it) == |
| 2128 |
lhs_stl_container.end()) { |
| 2129 |
if (printed_header2) { |
| 2130 |
*os << ", "; |
| 2131 |
} else { |
| 2132 |
*os << (printed_header ? ",\nand" : "which") |
| 2133 |
<< " doesn't have these expected elements: "; |
| 2134 |
printed_header2 = true; |
| 2135 |
} |
| 2136 |
UniversalPrint(*it, os); |
| 2137 |
} |
| 2138 |
} |
| 2139 |
} |
| 2140 |
|
| 2141 |
return false; |
| 2142 |
} |
| 2143 |
|
| 2144 |
private: |
| 2145 |
const StlContainer expected_; |
| 2146 |
|
| 2147 |
GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher); |
| 2148 |
}; |
| 2149 |
|
| 2150 |
|
| 2151 |
struct LessComparator { |
| 2152 |
template <typename T, typename U> |
| 2153 |
bool operator()(const T& lhs, const U& rhs) const { return lhs < rhs; } |
| 2154 |
}; |
| 2155 |
|
| 2156 |
|
| 2157 |
template <typename Comparator, typename ContainerMatcher> |
| 2158 |
class WhenSortedByMatcher { |
| 2159 |
public: |
| 2160 |
WhenSortedByMatcher(const Comparator& comparator, |
| 2161 |
const ContainerMatcher& matcher) |
| 2162 |
: comparator_(comparator), matcher_(matcher) {} |
| 2163 |
|
| 2164 |
template <typename LhsContainer> |
| 2165 |
operator Matcher<LhsContainer>() const { |
| 2166 |
return MakeMatcher(new Impl<LhsContainer>(comparator_, matcher_)); |
| 2167 |
} |
| 2168 |
|
| 2169 |
template <typename LhsContainer> |
| 2170 |
class Impl : public MatcherInterface<LhsContainer> { |
| 2171 |
public: |
| 2172 |
typedef internal::StlContainerView< |
| 2173 |
GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView; |
| 2174 |
typedef typename LhsView::type LhsStlContainer; |
| 2175 |
typedef typename LhsView::const_reference LhsStlContainerReference; |
| 2176 |
|
| 2177 |
|
| 2178 |
typedef typename RemoveConstFromKey< |
| 2179 |
typename LhsStlContainer::value_type>::type LhsValue; |
| 2180 |
|
| 2181 |
Impl(const Comparator& comparator, const ContainerMatcher& matcher) |
| 2182 |
: comparator_(comparator), matcher_(matcher) {} |
| 2183 |
|
| 2184 |
void DescribeTo(::std::ostream* os) const override { |
| 2185 |
*os << "(when sorted) "; |
| 2186 |
matcher_.DescribeTo(os); |
| 2187 |
} |
| 2188 |
|
| 2189 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 2190 |
*os << "(when sorted) "; |
| 2191 |
matcher_.DescribeNegationTo(os); |
| 2192 |
} |
| 2193 |
|
| 2194 |
bool MatchAndExplain(LhsContainer lhs, |
| 2195 |
MatchResultListener* listener) const override { |
| 2196 |
LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); |
| 2197 |
::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(), |
| 2198 |
lhs_stl_container.end()); |
| 2199 |
::std::sort( |
| 2200 |
sorted_container.begin(), sorted_container.end(), comparator_); |
| 2201 |
|
| 2202 |
if (!listener->IsInterested()) { |
| 2203 |
|
| 2204 |
|
| 2205 |
return matcher_.Matches(sorted_container); |
| 2206 |
} |
| 2207 |
|
| 2208 |
*listener << "which is "; |
| 2209 |
UniversalPrint(sorted_container, listener->stream()); |
| 2210 |
*listener << " when sorted"; |
| 2211 |
|
| 2212 |
StringMatchResultListener inner_listener; |
| 2213 |
const bool match = matcher_.MatchAndExplain(sorted_container, |
| 2214 |
&inner_listener); |
| 2215 |
PrintIfNotEmpty(inner_listener.str(), listener->stream()); |
| 2216 |
return match; |
| 2217 |
} |
| 2218 |
|
| 2219 |
private: |
| 2220 |
const Comparator comparator_; |
| 2221 |
const Matcher<const ::std::vector<LhsValue>&> matcher_; |
| 2222 |
|
| 2223 |
GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl); |
| 2224 |
}; |
| 2225 |
|
| 2226 |
private: |
| 2227 |
const Comparator comparator_; |
| 2228 |
const ContainerMatcher matcher_; |
| 2229 |
|
| 2230 |
GTEST_DISALLOW_ASSIGN_(WhenSortedByMatcher); |
| 2231 |
}; |
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
template <typename TupleMatcher, typename RhsContainer> |
| 2238 |
class PointwiseMatcher { |
| 2239 |
GTEST_COMPILE_ASSERT_( |
| 2240 |
!IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>::value, |
| 2241 |
use_UnorderedPointwise_with_hash_tables); |
| 2242 |
|
| 2243 |
public: |
| 2244 |
typedef internal::StlContainerView<RhsContainer> RhsView; |
| 2245 |
typedef typename RhsView::type RhsStlContainer; |
| 2246 |
typedef typename RhsStlContainer::value_type RhsValue; |
| 2247 |
|
| 2248 |
static_assert(!std::is_const<RhsContainer>::value, |
| 2249 |
"RhsContainer type must not be const"); |
| 2250 |
static_assert(!std::is_reference<RhsContainer>::value, |
| 2251 |
"RhsContainer type must not be a reference"); |
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs) |
| 2256 |
: tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {} |
| 2257 |
|
| 2258 |
template <typename LhsContainer> |
| 2259 |
operator Matcher<LhsContainer>() const { |
| 2260 |
GTEST_COMPILE_ASSERT_( |
| 2261 |
!IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)>::value, |
| 2262 |
use_UnorderedPointwise_with_hash_tables); |
| 2263 |
|
| 2264 |
return Matcher<LhsContainer>( |
| 2265 |
new Impl<const LhsContainer&>(tuple_matcher_, rhs_)); |
| 2266 |
} |
| 2267 |
|
| 2268 |
template <typename LhsContainer> |
| 2269 |
class Impl : public MatcherInterface<LhsContainer> { |
| 2270 |
public: |
| 2271 |
typedef internal::StlContainerView< |
| 2272 |
GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView; |
| 2273 |
typedef typename LhsView::type LhsStlContainer; |
| 2274 |
typedef typename LhsView::const_reference LhsStlContainerReference; |
| 2275 |
typedef typename LhsStlContainer::value_type LhsValue; |
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
typedef ::std::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg; |
| 2281 |
|
| 2282 |
Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs) |
| 2283 |
|
| 2284 |
: mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)), |
| 2285 |
rhs_(rhs) {} |
| 2286 |
|
| 2287 |
void DescribeTo(::std::ostream* os) const override { |
| 2288 |
*os << "contains " << rhs_.size() |
| 2289 |
<< " values, where each value and its corresponding value in "; |
| 2290 |
UniversalPrinter<RhsStlContainer>::Print(rhs_, os); |
| 2291 |
*os << " "; |
| 2292 |
mono_tuple_matcher_.DescribeTo(os); |
| 2293 |
} |
| 2294 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 2295 |
*os << "doesn't contain exactly " << rhs_.size() |
| 2296 |
<< " values, or contains a value x at some index i" |
| 2297 |
<< " where x and the i-th value of "; |
| 2298 |
UniversalPrint(rhs_, os); |
| 2299 |
*os << " "; |
| 2300 |
mono_tuple_matcher_.DescribeNegationTo(os); |
| 2301 |
} |
| 2302 |
|
| 2303 |
bool MatchAndExplain(LhsContainer lhs, |
| 2304 |
MatchResultListener* listener) const override { |
| 2305 |
LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); |
| 2306 |
const size_t actual_size = lhs_stl_container.size(); |
| 2307 |
if (actual_size != rhs_.size()) { |
| 2308 |
*listener << "which contains " << actual_size << " values"; |
| 2309 |
return false; |
| 2310 |
} |
| 2311 |
|
| 2312 |
typename LhsStlContainer::const_iterator left = lhs_stl_container.begin(); |
| 2313 |
typename RhsStlContainer::const_iterator right = rhs_.begin(); |
| 2314 |
for (size_t i = 0; i != actual_size; ++i, ++left, ++right) { |
| 2315 |
if (listener->IsInterested()) { |
| 2316 |
StringMatchResultListener inner_listener; |
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
if (!mono_tuple_matcher_.MatchAndExplain( |
| 2321 |
InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left), |
| 2322 |
ImplicitCast_<const RhsValue&>(*right)), |
| 2323 |
&inner_listener)) { |
| 2324 |
*listener << "where the value pair ("; |
| 2325 |
UniversalPrint(*left, listener->stream()); |
| 2326 |
*listener << ", "; |
| 2327 |
UniversalPrint(*right, listener->stream()); |
| 2328 |
*listener << ") at index #" << i << " don't match"; |
| 2329 |
PrintIfNotEmpty(inner_listener.str(), listener->stream()); |
| 2330 |
return false; |
| 2331 |
} |
| 2332 |
} else { |
| 2333 |
if (!mono_tuple_matcher_.Matches( |
| 2334 |
InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left), |
| 2335 |
ImplicitCast_<const RhsValue&>(*right)))) |
| 2336 |
return false; |
| 2337 |
} |
| 2338 |
} |
| 2339 |
|
| 2340 |
return true; |
| 2341 |
} |
| 2342 |
|
| 2343 |
private: |
| 2344 |
const Matcher<InnerMatcherArg> mono_tuple_matcher_; |
| 2345 |
const RhsStlContainer rhs_; |
| 2346 |
|
| 2347 |
GTEST_DISALLOW_ASSIGN_(Impl); |
| 2348 |
}; |
| 2349 |
|
| 2350 |
private: |
| 2351 |
const TupleMatcher tuple_matcher_; |
| 2352 |
const RhsStlContainer rhs_; |
| 2353 |
|
| 2354 |
GTEST_DISALLOW_ASSIGN_(PointwiseMatcher); |
| 2355 |
}; |
| 2356 |
|
| 2357 |
|
| 2358 |
template <typename Container> |
| 2359 |
class QuantifierMatcherImpl : public MatcherInterface<Container> { |
| 2360 |
public: |
| 2361 |
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 2362 |
typedef StlContainerView<RawContainer> View; |
| 2363 |
typedef typename View::type StlContainer; |
| 2364 |
typedef typename View::const_reference StlContainerReference; |
| 2365 |
typedef typename StlContainer::value_type Element; |
| 2366 |
|
| 2367 |
template <typename InnerMatcher> |
| 2368 |
explicit QuantifierMatcherImpl(InnerMatcher inner_matcher) |
| 2369 |
: inner_matcher_( |
| 2370 |
testing::SafeMatcherCast<const Element&>(inner_matcher)) {} |
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
bool MatchAndExplainImpl(bool all_elements_should_match, |
| 2376 |
Container container, |
| 2377 |
MatchResultListener* listener) const { |
| 2378 |
StlContainerReference stl_container = View::ConstReference(container); |
| 2379 |
size_t i = 0; |
| 2380 |
for (typename StlContainer::const_iterator it = stl_container.begin(); |
| 2381 |
it != stl_container.end(); ++it, ++i) { |
| 2382 |
StringMatchResultListener inner_listener; |
| 2383 |
const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener); |
| 2384 |
|
| 2385 |
if (matches != all_elements_should_match) { |
| 2386 |
*listener << "whose element #" << i |
| 2387 |
<< (matches ? " matches" : " doesn't match"); |
| 2388 |
PrintIfNotEmpty(inner_listener.str(), listener->stream()); |
| 2389 |
return !all_elements_should_match; |
| 2390 |
} |
| 2391 |
} |
| 2392 |
return all_elements_should_match; |
| 2393 |
} |
| 2394 |
|
| 2395 |
protected: |
| 2396 |
const Matcher<const Element&> inner_matcher_; |
| 2397 |
|
| 2398 |
GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl); |
| 2399 |
}; |
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
template <typename Container> |
| 2404 |
class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> { |
| 2405 |
public: |
| 2406 |
template <typename InnerMatcher> |
| 2407 |
explicit ContainsMatcherImpl(InnerMatcher inner_matcher) |
| 2408 |
: QuantifierMatcherImpl<Container>(inner_matcher) {} |
| 2409 |
|
| 2410 |
|
| 2411 |
void DescribeTo(::std::ostream* os) const override { |
| 2412 |
*os << "contains at least one element that "; |
| 2413 |
this->inner_matcher_.DescribeTo(os); |
| 2414 |
} |
| 2415 |
|
| 2416 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 2417 |
*os << "doesn't contain any element that "; |
| 2418 |
this->inner_matcher_.DescribeTo(os); |
| 2419 |
} |
| 2420 |
|
| 2421 |
bool MatchAndExplain(Container container, |
| 2422 |
MatchResultListener* listener) const override { |
| 2423 |
return this->MatchAndExplainImpl(false, container, listener); |
| 2424 |
} |
| 2425 |
|
| 2426 |
private: |
| 2427 |
GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl); |
| 2428 |
}; |
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
template <typename Container> |
| 2433 |
class EachMatcherImpl : public QuantifierMatcherImpl<Container> { |
| 2434 |
public: |
| 2435 |
template <typename InnerMatcher> |
| 2436 |
explicit EachMatcherImpl(InnerMatcher inner_matcher) |
| 2437 |
: QuantifierMatcherImpl<Container>(inner_matcher) {} |
| 2438 |
|
| 2439 |
|
| 2440 |
void DescribeTo(::std::ostream* os) const override { |
| 2441 |
*os << "only contains elements that "; |
| 2442 |
this->inner_matcher_.DescribeTo(os); |
| 2443 |
} |
| 2444 |
|
| 2445 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 2446 |
*os << "contains some element that "; |
| 2447 |
this->inner_matcher_.DescribeNegationTo(os); |
| 2448 |
} |
| 2449 |
|
| 2450 |
bool MatchAndExplain(Container container, |
| 2451 |
MatchResultListener* listener) const override { |
| 2452 |
return this->MatchAndExplainImpl(true, container, listener); |
| 2453 |
} |
| 2454 |
|
| 2455 |
private: |
| 2456 |
GTEST_DISALLOW_ASSIGN_(EachMatcherImpl); |
| 2457 |
}; |
| 2458 |
|
| 2459 |
|
| 2460 |
template <typename M> |
| 2461 |
class ContainsMatcher { |
| 2462 |
public: |
| 2463 |
explicit ContainsMatcher(M m) : inner_matcher_(m) {} |
| 2464 |
|
| 2465 |
template <typename Container> |
| 2466 |
operator Matcher<Container>() const { |
| 2467 |
return Matcher<Container>( |
| 2468 |
new ContainsMatcherImpl<const Container&>(inner_matcher_)); |
| 2469 |
} |
| 2470 |
|
| 2471 |
private: |
| 2472 |
const M inner_matcher_; |
| 2473 |
|
| 2474 |
GTEST_DISALLOW_ASSIGN_(ContainsMatcher); |
| 2475 |
}; |
| 2476 |
|
| 2477 |
|
| 2478 |
template <typename M> |
| 2479 |
class EachMatcher { |
| 2480 |
public: |
| 2481 |
explicit EachMatcher(M m) : inner_matcher_(m) {} |
| 2482 |
|
| 2483 |
template <typename Container> |
| 2484 |
operator Matcher<Container>() const { |
| 2485 |
return Matcher<Container>( |
| 2486 |
new EachMatcherImpl<const Container&>(inner_matcher_)); |
| 2487 |
} |
| 2488 |
|
| 2489 |
private: |
| 2490 |
const M inner_matcher_; |
| 2491 |
|
| 2492 |
GTEST_DISALLOW_ASSIGN_(EachMatcher); |
| 2493 |
}; |
| 2494 |
|
| 2495 |
struct Rank1 {}; |
| 2496 |
struct Rank0 : Rank1 {}; |
| 2497 |
|
| 2498 |
namespace pair_getters { |
| 2499 |
using std::get; |
| 2500 |
template <typename T> |
| 2501 |
auto First(T& x, Rank1) -> decltype(get<0>(x)) { |
| 2502 |
return get<0>(x); |
| 2503 |
} |
| 2504 |
template <typename T> |
| 2505 |
auto First(T& x, Rank0) -> decltype((x.first)) { |
| 2506 |
return x.first; |
| 2507 |
} |
| 2508 |
|
| 2509 |
template <typename T> |
| 2510 |
auto Second(T& x, Rank1) -> decltype(get<1>(x)) { |
| 2511 |
return get<1>(x); |
| 2512 |
} |
| 2513 |
template <typename T> |
| 2514 |
auto Second(T& x, Rank0) -> decltype((x.second)) { |
| 2515 |
return x.second; |
| 2516 |
} |
| 2517 |
} |
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
template <typename PairType> |
| 2524 |
class KeyMatcherImpl : public MatcherInterface<PairType> { |
| 2525 |
public: |
| 2526 |
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType; |
| 2527 |
typedef typename RawPairType::first_type KeyType; |
| 2528 |
|
| 2529 |
template <typename InnerMatcher> |
| 2530 |
explicit KeyMatcherImpl(InnerMatcher inner_matcher) |
| 2531 |
: inner_matcher_( |
| 2532 |
testing::SafeMatcherCast<const KeyType&>(inner_matcher)) { |
| 2533 |
} |
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
bool MatchAndExplain(PairType key_value, |
| 2538 |
MatchResultListener* listener) const override { |
| 2539 |
StringMatchResultListener inner_listener; |
| 2540 |
const bool match = inner_matcher_.MatchAndExplain( |
| 2541 |
pair_getters::First(key_value, Rank0()), &inner_listener); |
| 2542 |
const std::string explanation = inner_listener.str(); |
| 2543 |
if (explanation != "") { |
| 2544 |
*listener << "whose first field is a value " << explanation; |
| 2545 |
} |
| 2546 |
return match; |
| 2547 |
} |
| 2548 |
|
| 2549 |
|
| 2550 |
void DescribeTo(::std::ostream* os) const override { |
| 2551 |
*os << "has a key that "; |
| 2552 |
inner_matcher_.DescribeTo(os); |
| 2553 |
} |
| 2554 |
|
| 2555 |
|
| 2556 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 2557 |
*os << "doesn't have a key that "; |
| 2558 |
inner_matcher_.DescribeTo(os); |
| 2559 |
} |
| 2560 |
|
| 2561 |
private: |
| 2562 |
const Matcher<const KeyType&> inner_matcher_; |
| 2563 |
|
| 2564 |
GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl); |
| 2565 |
}; |
| 2566 |
|
| 2567 |
|
| 2568 |
template <typename M> |
| 2569 |
class KeyMatcher { |
| 2570 |
public: |
| 2571 |
explicit KeyMatcher(M m) : matcher_for_key_(m) {} |
| 2572 |
|
| 2573 |
template <typename PairType> |
| 2574 |
operator Matcher<PairType>() const { |
| 2575 |
return Matcher<PairType>( |
| 2576 |
new KeyMatcherImpl<const PairType&>(matcher_for_key_)); |
| 2577 |
} |
| 2578 |
|
| 2579 |
private: |
| 2580 |
const M matcher_for_key_; |
| 2581 |
|
| 2582 |
GTEST_DISALLOW_ASSIGN_(KeyMatcher); |
| 2583 |
}; |
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
template <typename PairType> |
| 2588 |
class PairMatcherImpl : public MatcherInterface<PairType> { |
| 2589 |
public: |
| 2590 |
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType; |
| 2591 |
typedef typename RawPairType::first_type FirstType; |
| 2592 |
typedef typename RawPairType::second_type SecondType; |
| 2593 |
|
| 2594 |
template <typename FirstMatcher, typename SecondMatcher> |
| 2595 |
PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher) |
| 2596 |
: first_matcher_( |
| 2597 |
testing::SafeMatcherCast<const FirstType&>(first_matcher)), |
| 2598 |
second_matcher_( |
| 2599 |
testing::SafeMatcherCast<const SecondType&>(second_matcher)) { |
| 2600 |
} |
| 2601 |
|
| 2602 |
|
| 2603 |
void DescribeTo(::std::ostream* os) const override { |
| 2604 |
*os << "has a first field that "; |
| 2605 |
first_matcher_.DescribeTo(os); |
| 2606 |
*os << ", and has a second field that "; |
| 2607 |
second_matcher_.DescribeTo(os); |
| 2608 |
} |
| 2609 |
|
| 2610 |
|
| 2611 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 2612 |
*os << "has a first field that "; |
| 2613 |
first_matcher_.DescribeNegationTo(os); |
| 2614 |
*os << ", or has a second field that "; |
| 2615 |
second_matcher_.DescribeNegationTo(os); |
| 2616 |
} |
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
bool MatchAndExplain(PairType a_pair, |
| 2621 |
MatchResultListener* listener) const override { |
| 2622 |
if (!listener->IsInterested()) { |
| 2623 |
|
| 2624 |
|
| 2625 |
return first_matcher_.Matches(pair_getters::First(a_pair, Rank0())) && |
| 2626 |
second_matcher_.Matches(pair_getters::Second(a_pair, Rank0())); |
| 2627 |
} |
| 2628 |
StringMatchResultListener first_inner_listener; |
| 2629 |
if (!first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank0()), |
| 2630 |
&first_inner_listener)) { |
| 2631 |
*listener << "whose first field does not match"; |
| 2632 |
PrintIfNotEmpty(first_inner_listener.str(), listener->stream()); |
| 2633 |
return false; |
| 2634 |
} |
| 2635 |
StringMatchResultListener second_inner_listener; |
| 2636 |
if (!second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank0()), |
| 2637 |
&second_inner_listener)) { |
| 2638 |
*listener << "whose second field does not match"; |
| 2639 |
PrintIfNotEmpty(second_inner_listener.str(), listener->stream()); |
| 2640 |
return false; |
| 2641 |
} |
| 2642 |
ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(), |
| 2643 |
listener); |
| 2644 |
return true; |
| 2645 |
} |
| 2646 |
|
| 2647 |
private: |
| 2648 |
void ExplainSuccess(const std::string& first_explanation, |
| 2649 |
const std::string& second_explanation, |
| 2650 |
MatchResultListener* listener) const { |
| 2651 |
*listener << "whose both fields match"; |
| 2652 |
if (first_explanation != "") { |
| 2653 |
*listener << ", where the first field is a value " << first_explanation; |
| 2654 |
} |
| 2655 |
if (second_explanation != "") { |
| 2656 |
*listener << ", "; |
| 2657 |
if (first_explanation != "") { |
| 2658 |
*listener << "and "; |
| 2659 |
} else { |
| 2660 |
*listener << "where "; |
| 2661 |
} |
| 2662 |
*listener << "the second field is a value " << second_explanation; |
| 2663 |
} |
| 2664 |
} |
| 2665 |
|
| 2666 |
const Matcher<const FirstType&> first_matcher_; |
| 2667 |
const Matcher<const SecondType&> second_matcher_; |
| 2668 |
|
| 2669 |
GTEST_DISALLOW_ASSIGN_(PairMatcherImpl); |
| 2670 |
}; |
| 2671 |
|
| 2672 |
|
| 2673 |
template <typename FirstMatcher, typename SecondMatcher> |
| 2674 |
class PairMatcher { |
| 2675 |
public: |
| 2676 |
PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher) |
| 2677 |
: first_matcher_(first_matcher), second_matcher_(second_matcher) {} |
| 2678 |
|
| 2679 |
template <typename PairType> |
| 2680 |
operator Matcher<PairType> () const { |
| 2681 |
return Matcher<PairType>( |
| 2682 |
new PairMatcherImpl<const PairType&>(first_matcher_, second_matcher_)); |
| 2683 |
} |
| 2684 |
|
| 2685 |
private: |
| 2686 |
const FirstMatcher first_matcher_; |
| 2687 |
const SecondMatcher second_matcher_; |
| 2688 |
|
| 2689 |
GTEST_DISALLOW_ASSIGN_(PairMatcher); |
| 2690 |
}; |
| 2691 |
|
| 2692 |
|
| 2693 |
template <typename Container> |
| 2694 |
class ElementsAreMatcherImpl : public MatcherInterface<Container> { |
| 2695 |
public: |
| 2696 |
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 2697 |
typedef internal::StlContainerView<RawContainer> View; |
| 2698 |
typedef typename View::type StlContainer; |
| 2699 |
typedef typename View::const_reference StlContainerReference; |
| 2700 |
typedef typename StlContainer::value_type Element; |
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
template <typename InputIter> |
| 2705 |
ElementsAreMatcherImpl(InputIter first, InputIter last) { |
| 2706 |
while (first != last) { |
| 2707 |
matchers_.push_back(MatcherCast<const Element&>(*first++)); |
| 2708 |
} |
| 2709 |
} |
| 2710 |
|
| 2711 |
|
| 2712 |
void DescribeTo(::std::ostream* os) const override { |
| 2713 |
if (count() == 0) { |
| 2714 |
*os << "is empty"; |
| 2715 |
} else if (count() == 1) { |
| 2716 |
*os << "has 1 element that "; |
| 2717 |
matchers_[0].DescribeTo(os); |
| 2718 |
} else { |
| 2719 |
*os << "has " << Elements(count()) << " where\n"; |
| 2720 |
for (size_t i = 0; i != count(); ++i) { |
| 2721 |
*os << "element #" << i << " "; |
| 2722 |
matchers_[i].DescribeTo(os); |
| 2723 |
if (i + 1 < count()) { |
| 2724 |
*os << ",\n"; |
| 2725 |
} |
| 2726 |
} |
| 2727 |
} |
| 2728 |
} |
| 2729 |
|
| 2730 |
|
| 2731 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 2732 |
if (count() == 0) { |
| 2733 |
*os << "isn't empty"; |
| 2734 |
return; |
| 2735 |
} |
| 2736 |
|
| 2737 |
*os << "doesn't have " << Elements(count()) << ", or\n"; |
| 2738 |
for (size_t i = 0; i != count(); ++i) { |
| 2739 |
*os << "element #" << i << " "; |
| 2740 |
matchers_[i].DescribeNegationTo(os); |
| 2741 |
if (i + 1 < count()) { |
| 2742 |
*os << ", or\n"; |
| 2743 |
} |
| 2744 |
} |
| 2745 |
} |
| 2746 |
|
| 2747 |
bool MatchAndExplain(Container container, |
| 2748 |
MatchResultListener* listener) const override { |
| 2749 |
|
| 2750 |
|
| 2751 |
|
| 2752 |
const bool listener_interested = listener->IsInterested(); |
| 2753 |
|
| 2754 |
|
| 2755 |
::std::vector<std::string> explanations(count()); |
| 2756 |
StlContainerReference stl_container = View::ConstReference(container); |
| 2757 |
typename StlContainer::const_iterator it = stl_container.begin(); |
| 2758 |
size_t exam_pos = 0; |
| 2759 |
bool mismatch_found = false; |
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) { |
| 2765 |
bool match; |
| 2766 |
if (listener_interested) { |
| 2767 |
StringMatchResultListener s; |
| 2768 |
match = matchers_[exam_pos].MatchAndExplain(*it, &s); |
| 2769 |
explanations[exam_pos] = s.str(); |
| 2770 |
} else { |
| 2771 |
match = matchers_[exam_pos].Matches(*it); |
| 2772 |
} |
| 2773 |
|
| 2774 |
if (!match) { |
| 2775 |
mismatch_found = true; |
| 2776 |
break; |
| 2777 |
} |
| 2778 |
} |
| 2779 |
|
| 2780 |
|
| 2781 |
|
| 2782 |
|
| 2783 |
|
| 2784 |
size_t actual_count = exam_pos; |
| 2785 |
for (; it != stl_container.end(); ++it) { |
| 2786 |
++actual_count; |
| 2787 |
} |
| 2788 |
|
| 2789 |
if (actual_count != count()) { |
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
if (listener_interested && (actual_count != 0)) { |
| 2795 |
*listener << "which has " << Elements(actual_count); |
| 2796 |
} |
| 2797 |
return false; |
| 2798 |
} |
| 2799 |
|
| 2800 |
if (mismatch_found) { |
| 2801 |
|
| 2802 |
if (listener_interested) { |
| 2803 |
*listener << "whose element #" << exam_pos << " doesn't match"; |
| 2804 |
PrintIfNotEmpty(explanations[exam_pos], listener->stream()); |
| 2805 |
} |
| 2806 |
return false; |
| 2807 |
} |
| 2808 |
|
| 2809 |
|
| 2810 |
|
| 2811 |
if (listener_interested) { |
| 2812 |
bool reason_printed = false; |
| 2813 |
for (size_t i = 0; i != count(); ++i) { |
| 2814 |
const std::string& s = explanations[i]; |
| 2815 |
if (!s.empty()) { |
| 2816 |
if (reason_printed) { |
| 2817 |
*listener << ",\nand "; |
| 2818 |
} |
| 2819 |
*listener << "whose element #" << i << " matches, " << s; |
| 2820 |
reason_printed = true; |
| 2821 |
} |
| 2822 |
} |
| 2823 |
} |
| 2824 |
return true; |
| 2825 |
} |
| 2826 |
|
| 2827 |
private: |
| 2828 |
static Message Elements(size_t count) { |
| 2829 |
return Message() << count << (count == 1 ? " element" : " elements"); |
| 2830 |
} |
| 2831 |
|
| 2832 |
size_t count() const { return matchers_.size(); } |
| 2833 |
|
| 2834 |
::std::vector<Matcher<const Element&> > matchers_; |
| 2835 |
|
| 2836 |
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl); |
| 2837 |
}; |
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
class GTEST_API_ MatchMatrix { |
| 2844 |
public: |
| 2845 |
MatchMatrix(size_t num_elements, size_t num_matchers) |
| 2846 |
: num_elements_(num_elements), |
| 2847 |
num_matchers_(num_matchers), |
| 2848 |
matched_(num_elements_* num_matchers_, 0) { |
| 2849 |
} |
| 2850 |
|
| 2851 |
size_t LhsSize() const { return num_elements_; } |
| 2852 |
size_t RhsSize() const { return num_matchers_; } |
| 2853 |
bool HasEdge(size_t ilhs, size_t irhs) const { |
| 2854 |
return matched_[SpaceIndex(ilhs, irhs)] == 1; |
| 2855 |
} |
| 2856 |
void SetEdge(size_t ilhs, size_t irhs, bool b) { |
| 2857 |
matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0; |
| 2858 |
} |
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
bool NextGraph(); |
| 2864 |
|
| 2865 |
void Randomize(); |
| 2866 |
|
| 2867 |
std::string DebugString() const; |
| 2868 |
|
| 2869 |
private: |
| 2870 |
size_t SpaceIndex(size_t ilhs, size_t irhs) const { |
| 2871 |
return ilhs * num_matchers_ + irhs; |
| 2872 |
} |
| 2873 |
|
| 2874 |
size_t num_elements_; |
| 2875 |
size_t num_matchers_; |
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
::std::vector<char> matched_; |
| 2881 |
}; |
| 2882 |
|
| 2883 |
typedef ::std::pair<size_t, size_t> ElementMatcherPair; |
| 2884 |
typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs; |
| 2885 |
|
| 2886 |
|
| 2887 |
|
| 2888 |
GTEST_API_ ElementMatcherPairs |
| 2889 |
FindMaxBipartiteMatching(const MatchMatrix& g); |
| 2890 |
|
| 2891 |
struct UnorderedMatcherRequire { |
| 2892 |
enum Flags { |
| 2893 |
Superset = 1 << 0, |
| 2894 |
Subset = 1 << 1, |
| 2895 |
ExactMatch = Superset | Subset, |
| 2896 |
}; |
| 2897 |
}; |
| 2898 |
|
| 2899 |
|
| 2900 |
|
| 2901 |
|
| 2902 |
class GTEST_API_ UnorderedElementsAreMatcherImplBase { |
| 2903 |
protected: |
| 2904 |
explicit UnorderedElementsAreMatcherImplBase( |
| 2905 |
UnorderedMatcherRequire::Flags matcher_flags) |
| 2906 |
: match_flags_(matcher_flags) {} |
| 2907 |
|
| 2908 |
|
| 2909 |
|
| 2910 |
|
| 2911 |
typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec; |
| 2912 |
|
| 2913 |
|
| 2914 |
void DescribeToImpl(::std::ostream* os) const; |
| 2915 |
|
| 2916 |
|
| 2917 |
void DescribeNegationToImpl(::std::ostream* os) const; |
| 2918 |
|
| 2919 |
bool VerifyMatchMatrix(const ::std::vector<std::string>& element_printouts, |
| 2920 |
const MatchMatrix& matrix, |
| 2921 |
MatchResultListener* listener) const; |
| 2922 |
|
| 2923 |
bool FindPairing(const MatchMatrix& matrix, |
| 2924 |
MatchResultListener* listener) const; |
| 2925 |
|
| 2926 |
MatcherDescriberVec& matcher_describers() { |
| 2927 |
return matcher_describers_; |
| 2928 |
} |
| 2929 |
|
| 2930 |
static Message Elements(size_t n) { |
| 2931 |
return Message() << n << " element" << (n == 1 ? "" : "s"); |
| 2932 |
} |
| 2933 |
|
| 2934 |
UnorderedMatcherRequire::Flags match_flags() const { return match_flags_; } |
| 2935 |
|
| 2936 |
private: |
| 2937 |
UnorderedMatcherRequire::Flags match_flags_; |
| 2938 |
MatcherDescriberVec matcher_describers_; |
| 2939 |
|
| 2940 |
GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase); |
| 2941 |
}; |
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
template <typename Container> |
| 2946 |
class UnorderedElementsAreMatcherImpl |
| 2947 |
: public MatcherInterface<Container>, |
| 2948 |
public UnorderedElementsAreMatcherImplBase { |
| 2949 |
public: |
| 2950 |
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 2951 |
typedef internal::StlContainerView<RawContainer> View; |
| 2952 |
typedef typename View::type StlContainer; |
| 2953 |
typedef typename View::const_reference StlContainerReference; |
| 2954 |
typedef typename StlContainer::const_iterator StlContainerConstIterator; |
| 2955 |
typedef typename StlContainer::value_type Element; |
| 2956 |
|
| 2957 |
template <typename InputIter> |
| 2958 |
UnorderedElementsAreMatcherImpl(UnorderedMatcherRequire::Flags matcher_flags, |
| 2959 |
InputIter first, InputIter last) |
| 2960 |
: UnorderedElementsAreMatcherImplBase(matcher_flags) { |
| 2961 |
for (; first != last; ++first) { |
| 2962 |
matchers_.push_back(MatcherCast<const Element&>(*first)); |
| 2963 |
matcher_describers().push_back(matchers_.back().GetDescriber()); |
| 2964 |
} |
| 2965 |
} |
| 2966 |
|
| 2967 |
|
| 2968 |
void DescribeTo(::std::ostream* os) const override { |
| 2969 |
return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os); |
| 2970 |
} |
| 2971 |
|
| 2972 |
|
| 2973 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 2974 |
return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os); |
| 2975 |
} |
| 2976 |
|
| 2977 |
bool MatchAndExplain(Container container, |
| 2978 |
MatchResultListener* listener) const override { |
| 2979 |
StlContainerReference stl_container = View::ConstReference(container); |
| 2980 |
::std::vector<std::string> element_printouts; |
| 2981 |
MatchMatrix matrix = |
| 2982 |
AnalyzeElements(stl_container.begin(), stl_container.end(), |
| 2983 |
&element_printouts, listener); |
| 2984 |
|
| 2985 |
if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) { |
| 2986 |
return true; |
| 2987 |
} |
| 2988 |
|
| 2989 |
if (match_flags() == UnorderedMatcherRequire::ExactMatch) { |
| 2990 |
if (matrix.LhsSize() != matrix.RhsSize()) { |
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
|
| 2995 |
if (matrix.LhsSize() != 0 && listener->IsInterested()) { |
| 2996 |
*listener << "which has " << Elements(matrix.LhsSize()); |
| 2997 |
} |
| 2998 |
return false; |
| 2999 |
} |
| 3000 |
} |
| 3001 |
|
| 3002 |
return VerifyMatchMatrix(element_printouts, matrix, listener) && |
| 3003 |
FindPairing(matrix, listener); |
| 3004 |
} |
| 3005 |
|
| 3006 |
private: |
| 3007 |
template <typename ElementIter> |
| 3008 |
MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last, |
| 3009 |
::std::vector<std::string>* element_printouts, |
| 3010 |
MatchResultListener* listener) const { |
| 3011 |
element_printouts->clear(); |
| 3012 |
::std::vector<char> did_match; |
| 3013 |
size_t num_elements = 0; |
| 3014 |
for (; elem_first != elem_last; ++num_elements, ++elem_first) { |
| 3015 |
if (listener->IsInterested()) { |
| 3016 |
element_printouts->push_back(PrintToString(*elem_first)); |
| 3017 |
} |
| 3018 |
for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) { |
| 3019 |
did_match.push_back(Matches(matchers_[irhs])(*elem_first)); |
| 3020 |
} |
| 3021 |
} |
| 3022 |
|
| 3023 |
MatchMatrix matrix(num_elements, matchers_.size()); |
| 3024 |
::std::vector<char>::const_iterator did_match_iter = did_match.begin(); |
| 3025 |
for (size_t ilhs = 0; ilhs != num_elements; ++ilhs) { |
| 3026 |
for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) { |
| 3027 |
matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0); |
| 3028 |
} |
| 3029 |
} |
| 3030 |
return matrix; |
| 3031 |
} |
| 3032 |
|
| 3033 |
::std::vector<Matcher<const Element&> > matchers_; |
| 3034 |
|
| 3035 |
GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl); |
| 3036 |
}; |
| 3037 |
|
| 3038 |
|
| 3039 |
|
| 3040 |
template <typename Target> |
| 3041 |
struct CastAndAppendTransform { |
| 3042 |
template <typename Arg> |
| 3043 |
Matcher<Target> operator()(const Arg& a) const { |
| 3044 |
return MatcherCast<Target>(a); |
| 3045 |
} |
| 3046 |
}; |
| 3047 |
|
| 3048 |
|
| 3049 |
template <typename MatcherTuple> |
| 3050 |
class UnorderedElementsAreMatcher { |
| 3051 |
public: |
| 3052 |
explicit UnorderedElementsAreMatcher(const MatcherTuple& args) |
| 3053 |
: matchers_(args) {} |
| 3054 |
|
| 3055 |
template <typename Container> |
| 3056 |
operator Matcher<Container>() const { |
| 3057 |
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 3058 |
typedef typename internal::StlContainerView<RawContainer>::type View; |
| 3059 |
typedef typename View::value_type Element; |
| 3060 |
typedef ::std::vector<Matcher<const Element&> > MatcherVec; |
| 3061 |
MatcherVec matchers; |
| 3062 |
matchers.reserve(::std::tuple_size<MatcherTuple>::value); |
| 3063 |
TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_, |
| 3064 |
::std::back_inserter(matchers)); |
| 3065 |
return Matcher<Container>( |
| 3066 |
new UnorderedElementsAreMatcherImpl<const Container&>( |
| 3067 |
UnorderedMatcherRequire::ExactMatch, matchers.begin(), |
| 3068 |
matchers.end())); |
| 3069 |
} |
| 3070 |
|
| 3071 |
private: |
| 3072 |
const MatcherTuple matchers_; |
| 3073 |
GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcher); |
| 3074 |
}; |
| 3075 |
|
| 3076 |
|
| 3077 |
template <typename MatcherTuple> |
| 3078 |
class ElementsAreMatcher { |
| 3079 |
public: |
| 3080 |
explicit ElementsAreMatcher(const MatcherTuple& args) : matchers_(args) {} |
| 3081 |
|
| 3082 |
template <typename Container> |
| 3083 |
operator Matcher<Container>() const { |
| 3084 |
GTEST_COMPILE_ASSERT_( |
| 3085 |
!IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value || |
| 3086 |
::std::tuple_size<MatcherTuple>::value < 2, |
| 3087 |
use_UnorderedElementsAre_with_hash_tables); |
| 3088 |
|
| 3089 |
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; |
| 3090 |
typedef typename internal::StlContainerView<RawContainer>::type View; |
| 3091 |
typedef typename View::value_type Element; |
| 3092 |
typedef ::std::vector<Matcher<const Element&> > MatcherVec; |
| 3093 |
MatcherVec matchers; |
| 3094 |
matchers.reserve(::std::tuple_size<MatcherTuple>::value); |
| 3095 |
TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_, |
| 3096 |
::std::back_inserter(matchers)); |
| 3097 |
return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>( |
| 3098 |
matchers.begin(), matchers.end())); |
| 3099 |
} |
| 3100 |
|
| 3101 |
private: |
| 3102 |
const MatcherTuple matchers_; |
| 3103 |
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher); |
| 3104 |
}; |
| 3105 |
|
| 3106 |
|
| 3107 |
template <typename T> |
| 3108 |
class UnorderedElementsAreArrayMatcher { |
| 3109 |
public: |
| 3110 |
template <typename Iter> |
| 3111 |
UnorderedElementsAreArrayMatcher(UnorderedMatcherRequire::Flags match_flags, |
| 3112 |
Iter first, Iter last) |
| 3113 |
: match_flags_(match_flags), matchers_(first, last) {} |
| 3114 |
|
| 3115 |
template <typename Container> |
| 3116 |
operator Matcher<Container>() const { |
| 3117 |
return Matcher<Container>( |
| 3118 |
new UnorderedElementsAreMatcherImpl<const Container&>( |
| 3119 |
match_flags_, matchers_.begin(), matchers_.end())); |
| 3120 |
} |
| 3121 |
|
| 3122 |
private: |
| 3123 |
UnorderedMatcherRequire::Flags match_flags_; |
| 3124 |
::std::vector<T> matchers_; |
| 3125 |
|
| 3126 |
GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher); |
| 3127 |
}; |
| 3128 |
|
| 3129 |
|
| 3130 |
template <typename T> |
| 3131 |
class ElementsAreArrayMatcher { |
| 3132 |
public: |
| 3133 |
template <typename Iter> |
| 3134 |
ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {} |
| 3135 |
|
| 3136 |
template <typename Container> |
| 3137 |
operator Matcher<Container>() const { |
| 3138 |
GTEST_COMPILE_ASSERT_( |
| 3139 |
!IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value, |
| 3140 |
use_UnorderedElementsAreArray_with_hash_tables); |
| 3141 |
|
| 3142 |
return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>( |
| 3143 |
matchers_.begin(), matchers_.end())); |
| 3144 |
} |
| 3145 |
|
| 3146 |
private: |
| 3147 |
const ::std::vector<T> matchers_; |
| 3148 |
|
| 3149 |
GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher); |
| 3150 |
}; |
| 3151 |
|
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
|
| 3156 |
|
| 3157 |
|
| 3158 |
|
| 3159 |
|
| 3160 |
|
| 3161 |
template <typename Tuple2Matcher, typename Second> |
| 3162 |
class BoundSecondMatcher { |
| 3163 |
public: |
| 3164 |
BoundSecondMatcher(const Tuple2Matcher& tm, const Second& second) |
| 3165 |
: tuple2_matcher_(tm), second_value_(second) {} |
| 3166 |
|
| 3167 |
template <typename T> |
| 3168 |
operator Matcher<T>() const { |
| 3169 |
return MakeMatcher(new Impl<T>(tuple2_matcher_, second_value_)); |
| 3170 |
} |
| 3171 |
|
| 3172 |
|
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
void operator=(const BoundSecondMatcher& ) { |
| 3181 |
GTEST_LOG_(FATAL) << "BoundSecondMatcher should never be assigned."; |
| 3182 |
} |
| 3183 |
|
| 3184 |
private: |
| 3185 |
template <typename T> |
| 3186 |
class Impl : public MatcherInterface<T> { |
| 3187 |
public: |
| 3188 |
typedef ::std::tuple<T, Second> ArgTuple; |
| 3189 |
|
| 3190 |
Impl(const Tuple2Matcher& tm, const Second& second) |
| 3191 |
: mono_tuple2_matcher_(SafeMatcherCast<const ArgTuple&>(tm)), |
| 3192 |
second_value_(second) {} |
| 3193 |
|
| 3194 |
void DescribeTo(::std::ostream* os) const override { |
| 3195 |
*os << "and "; |
| 3196 |
UniversalPrint(second_value_, os); |
| 3197 |
*os << " "; |
| 3198 |
mono_tuple2_matcher_.DescribeTo(os); |
| 3199 |
} |
| 3200 |
|
| 3201 |
bool MatchAndExplain(T x, MatchResultListener* listener) const override { |
| 3202 |
return mono_tuple2_matcher_.MatchAndExplain(ArgTuple(x, second_value_), |
| 3203 |
listener); |
| 3204 |
} |
| 3205 |
|
| 3206 |
private: |
| 3207 |
const Matcher<const ArgTuple&> mono_tuple2_matcher_; |
| 3208 |
const Second second_value_; |
| 3209 |
|
| 3210 |
GTEST_DISALLOW_ASSIGN_(Impl); |
| 3211 |
}; |
| 3212 |
|
| 3213 |
const Tuple2Matcher tuple2_matcher_; |
| 3214 |
const Second second_value_; |
| 3215 |
}; |
| 3216 |
|
| 3217 |
|
| 3218 |
|
| 3219 |
|
| 3220 |
|
| 3221 |
template <typename Tuple2Matcher, typename Second> |
| 3222 |
BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond( |
| 3223 |
const Tuple2Matcher& tm, const Second& second) { |
| 3224 |
return BoundSecondMatcher<Tuple2Matcher, Second>(tm, second); |
| 3225 |
} |
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
GTEST_API_ std::string FormatMatcherDescription(bool negation, |
| 3233 |
const char* matcher_name, |
| 3234 |
const Strings& param_values); |
| 3235 |
|
| 3236 |
|
| 3237 |
template <typename ValueMatcher> |
| 3238 |
class OptionalMatcher { |
| 3239 |
public: |
| 3240 |
explicit OptionalMatcher(const ValueMatcher& value_matcher) |
| 3241 |
: value_matcher_(value_matcher) {} |
| 3242 |
|
| 3243 |
template <typename Optional> |
| 3244 |
operator Matcher<Optional>() const { |
| 3245 |
return Matcher<Optional>(new Impl<const Optional&>(value_matcher_)); |
| 3246 |
} |
| 3247 |
|
| 3248 |
template <typename Optional> |
| 3249 |
class Impl : public MatcherInterface<Optional> { |
| 3250 |
public: |
| 3251 |
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Optional) OptionalView; |
| 3252 |
typedef typename OptionalView::value_type ValueType; |
| 3253 |
explicit Impl(const ValueMatcher& value_matcher) |
| 3254 |
: value_matcher_(MatcherCast<ValueType>(value_matcher)) {} |
| 3255 |
|
| 3256 |
void DescribeTo(::std::ostream* os) const override { |
| 3257 |
*os << "value "; |
| 3258 |
value_matcher_.DescribeTo(os); |
| 3259 |
} |
| 3260 |
|
| 3261 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 3262 |
*os << "value "; |
| 3263 |
value_matcher_.DescribeNegationTo(os); |
| 3264 |
} |
| 3265 |
|
| 3266 |
bool MatchAndExplain(Optional optional, |
| 3267 |
MatchResultListener* listener) const override { |
| 3268 |
if (!optional) { |
| 3269 |
*listener << "which is not engaged"; |
| 3270 |
return false; |
| 3271 |
} |
| 3272 |
const ValueType& value = *optional; |
| 3273 |
StringMatchResultListener value_listener; |
| 3274 |
const bool match = value_matcher_.MatchAndExplain(value, &value_listener); |
| 3275 |
*listener << "whose value " << PrintToString(value) |
| 3276 |
<< (match ? " matches" : " doesn't match"); |
| 3277 |
PrintIfNotEmpty(value_listener.str(), listener->stream()); |
| 3278 |
return match; |
| 3279 |
} |
| 3280 |
|
| 3281 |
private: |
| 3282 |
const Matcher<ValueType> value_matcher_; |
| 3283 |
GTEST_DISALLOW_ASSIGN_(Impl); |
| 3284 |
}; |
| 3285 |
|
| 3286 |
private: |
| 3287 |
const ValueMatcher value_matcher_; |
| 3288 |
GTEST_DISALLOW_ASSIGN_(OptionalMatcher); |
| 3289 |
}; |
| 3290 |
|
| 3291 |
namespace variant_matcher { |
| 3292 |
|
| 3293 |
template <typename T> |
| 3294 |
void holds_alternative() {} |
| 3295 |
template <typename T> |
| 3296 |
void get() {} |
| 3297 |
|
| 3298 |
|
| 3299 |
template <typename T> |
| 3300 |
class VariantMatcher { |
| 3301 |
public: |
| 3302 |
explicit VariantMatcher(::testing::Matcher<const T&> matcher) |
| 3303 |
: matcher_(std::move(matcher)) {} |
| 3304 |
|
| 3305 |
template <typename Variant> |
| 3306 |
bool MatchAndExplain(const Variant& value, |
| 3307 |
::testing::MatchResultListener* listener) const { |
| 3308 |
using std::get; |
| 3309 |
if (!listener->IsInterested()) { |
| 3310 |
return holds_alternative<T>(value) && matcher_.Matches(get<T>(value)); |
| 3311 |
} |
| 3312 |
|
| 3313 |
if (!holds_alternative<T>(value)) { |
| 3314 |
*listener << "whose value is not of type '" << GetTypeName() << "'"; |
| 3315 |
return false; |
| 3316 |
} |
| 3317 |
|
| 3318 |
const T& elem = get<T>(value); |
| 3319 |
StringMatchResultListener elem_listener; |
| 3320 |
const bool match = matcher_.MatchAndExplain(elem, &elem_listener); |
| 3321 |
*listener << "whose value " << PrintToString(elem) |
| 3322 |
<< (match ? " matches" : " doesn't match"); |
| 3323 |
PrintIfNotEmpty(elem_listener.str(), listener->stream()); |
| 3324 |
return match; |
| 3325 |
} |
| 3326 |
|
| 3327 |
void DescribeTo(std::ostream* os) const { |
| 3328 |
*os << "is a variant<> with value of type '" << GetTypeName() |
| 3329 |
<< "' and the value "; |
| 3330 |
matcher_.DescribeTo(os); |
| 3331 |
} |
| 3332 |
|
| 3333 |
void DescribeNegationTo(std::ostream* os) const { |
| 3334 |
*os << "is a variant<> with value of type other than '" << GetTypeName() |
| 3335 |
<< "' or the value "; |
| 3336 |
matcher_.DescribeNegationTo(os); |
| 3337 |
} |
| 3338 |
|
| 3339 |
private: |
| 3340 |
static std::string GetTypeName() { |
| 3341 |
#if GTEST_HAS_RTTI |
| 3342 |
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_( |
| 3343 |
return internal::GetTypeName<T>()); |
| 3344 |
#endif |
| 3345 |
return "the element type"; |
| 3346 |
} |
| 3347 |
|
| 3348 |
const ::testing::Matcher<const T&> matcher_; |
| 3349 |
}; |
| 3350 |
|
| 3351 |
} |
| 3352 |
|
| 3353 |
namespace any_cast_matcher { |
| 3354 |
|
| 3355 |
|
| 3356 |
template <typename T> |
| 3357 |
void any_cast() {} |
| 3358 |
|
| 3359 |
|
| 3360 |
template <typename T> |
| 3361 |
class AnyCastMatcher { |
| 3362 |
public: |
| 3363 |
explicit AnyCastMatcher(const ::testing::Matcher<const T&>& matcher) |
| 3364 |
: matcher_(matcher) {} |
| 3365 |
|
| 3366 |
template <typename AnyType> |
| 3367 |
bool MatchAndExplain(const AnyType& value, |
| 3368 |
::testing::MatchResultListener* listener) const { |
| 3369 |
if (!listener->IsInterested()) { |
| 3370 |
const T* ptr = any_cast<T>(&value); |
| 3371 |
return ptr != nullptr && matcher_.Matches(*ptr); |
| 3372 |
} |
| 3373 |
|
| 3374 |
const T* elem = any_cast<T>(&value); |
| 3375 |
if (elem == nullptr) { |
| 3376 |
*listener << "whose value is not of type '" << GetTypeName() << "'"; |
| 3377 |
return false; |
| 3378 |
} |
| 3379 |
|
| 3380 |
StringMatchResultListener elem_listener; |
| 3381 |
const bool match = matcher_.MatchAndExplain(*elem, &elem_listener); |
| 3382 |
*listener << "whose value " << PrintToString(*elem) |
| 3383 |
<< (match ? " matches" : " doesn't match"); |
| 3384 |
PrintIfNotEmpty(elem_listener.str(), listener->stream()); |
| 3385 |
return match; |
| 3386 |
} |
| 3387 |
|
| 3388 |
void DescribeTo(std::ostream* os) const { |
| 3389 |
*os << "is an 'any' type with value of type '" << GetTypeName() |
| 3390 |
<< "' and the value "; |
| 3391 |
matcher_.DescribeTo(os); |
| 3392 |
} |
| 3393 |
|
| 3394 |
void DescribeNegationTo(std::ostream* os) const { |
| 3395 |
*os << "is an 'any' type with value of type other than '" << GetTypeName() |
| 3396 |
<< "' or the value "; |
| 3397 |
matcher_.DescribeNegationTo(os); |
| 3398 |
} |
| 3399 |
|
| 3400 |
private: |
| 3401 |
static std::string GetTypeName() { |
| 3402 |
#if GTEST_HAS_RTTI |
| 3403 |
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_( |
| 3404 |
return internal::GetTypeName<T>()); |
| 3405 |
#endif |
| 3406 |
return "the element type"; |
| 3407 |
} |
| 3408 |
|
| 3409 |
const ::testing::Matcher<const T&> matcher_; |
| 3410 |
}; |
| 3411 |
|
| 3412 |
} |
| 3413 |
|
| 3414 |
|
| 3415 |
template <class ArgsTuple, size_t... k> |
| 3416 |
class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> { |
| 3417 |
public: |
| 3418 |
using RawArgsTuple = typename std::decay<ArgsTuple>::type; |
| 3419 |
using SelectedArgs = |
| 3420 |
std::tuple<typename std::tuple_element<k, RawArgsTuple>::type...>; |
| 3421 |
using MonomorphicInnerMatcher = Matcher<const SelectedArgs&>; |
| 3422 |
|
| 3423 |
template <typename InnerMatcher> |
| 3424 |
explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) |
| 3425 |
: inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {} |
| 3426 |
|
| 3427 |
bool MatchAndExplain(ArgsTuple args, |
| 3428 |
MatchResultListener* listener) const override { |
| 3429 |
|
| 3430 |
(void)args; |
| 3431 |
const SelectedArgs& selected_args = |
| 3432 |
std::forward_as_tuple(std::get<k>(args)...); |
| 3433 |
if (!listener->IsInterested()) return inner_matcher_.Matches(selected_args); |
| 3434 |
|
| 3435 |
PrintIndices(listener->stream()); |
| 3436 |
*listener << "are " << PrintToString(selected_args); |
| 3437 |
|
| 3438 |
StringMatchResultListener inner_listener; |
| 3439 |
const bool match = |
| 3440 |
inner_matcher_.MatchAndExplain(selected_args, &inner_listener); |
| 3441 |
PrintIfNotEmpty(inner_listener.str(), listener->stream()); |
| 3442 |
return match; |
| 3443 |
} |
| 3444 |
|
| 3445 |
void DescribeTo(::std::ostream* os) const override { |
| 3446 |
*os << "are a tuple "; |
| 3447 |
PrintIndices(os); |
| 3448 |
inner_matcher_.DescribeTo(os); |
| 3449 |
} |
| 3450 |
|
| 3451 |
void DescribeNegationTo(::std::ostream* os) const override { |
| 3452 |
*os << "are a tuple "; |
| 3453 |
PrintIndices(os); |
| 3454 |
inner_matcher_.DescribeNegationTo(os); |
| 3455 |
} |
| 3456 |
|
| 3457 |
private: |
| 3458 |
|
| 3459 |
static void PrintIndices(::std::ostream* os) { |
| 3460 |
*os << "whose fields ("; |
| 3461 |
const char* sep = ""; |
| 3462 |
|
| 3463 |
(void)sep; |
| 3464 |
const char* dummy[] = {"", (*os << sep << "#" << k, sep = ", ")...}; |
| 3465 |
(void)dummy; |
| 3466 |
*os << ") "; |
| 3467 |
} |
| 3468 |
|
| 3469 |
MonomorphicInnerMatcher inner_matcher_; |
| 3470 |
}; |
| 3471 |
|
| 3472 |
template <class InnerMatcher, size_t... k> |
| 3473 |
class ArgsMatcher { |
| 3474 |
public: |
| 3475 |
explicit ArgsMatcher(InnerMatcher inner_matcher) |
| 3476 |
: inner_matcher_(std::move(inner_matcher)) {} |
| 3477 |
|
| 3478 |
template <typename ArgsTuple> |
| 3479 |
operator Matcher<ArgsTuple>() const { |
| 3480 |
return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k...>(inner_matcher_)); |
| 3481 |
} |
| 3482 |
|
| 3483 |
private: |
| 3484 |
InnerMatcher inner_matcher_; |
| 3485 |
}; |
| 3486 |
|
| 3487 |
} |
| 3488 |
|
| 3489 |
|
| 3490 |
|
| 3491 |
|
| 3492 |
|
| 3493 |
|
| 3494 |
|
| 3495 |
|
| 3496 |
|
| 3497 |
|
| 3498 |
|
| 3499 |
|
| 3500 |
|
| 3501 |
|
| 3502 |
|
| 3503 |
|
| 3504 |
template <typename Iter> |
| 3505 |
inline internal::ElementsAreArrayMatcher< |
| 3506 |
typename ::std::iterator_traits<Iter>::value_type> |
| 3507 |
ElementsAreArray(Iter first, Iter last) { |
| 3508 |
typedef typename ::std::iterator_traits<Iter>::value_type T; |
| 3509 |
return internal::ElementsAreArrayMatcher<T>(first, last); |
| 3510 |
} |
| 3511 |
|
| 3512 |
template <typename T> |
| 3513 |
inline internal::ElementsAreArrayMatcher<T> ElementsAreArray( |
| 3514 |
const T* pointer, size_t count) { |
| 3515 |
return ElementsAreArray(pointer, pointer + count); |
| 3516 |
} |
| 3517 |
|
| 3518 |
template <typename T, size_t N> |
| 3519 |
inline internal::ElementsAreArrayMatcher<T> ElementsAreArray( |
| 3520 |
const T (&array)[N]) { |
| 3521 |
return ElementsAreArray(array, N); |
| 3522 |
} |
| 3523 |
|
| 3524 |
template <typename Container> |
| 3525 |
inline internal::ElementsAreArrayMatcher<typename Container::value_type> |
| 3526 |
ElementsAreArray(const Container& container) { |
| 3527 |
return ElementsAreArray(container.begin(), container.end()); |
| 3528 |
} |
| 3529 |
|
| 3530 |
template <typename T> |
| 3531 |
inline internal::ElementsAreArrayMatcher<T> |
| 3532 |
ElementsAreArray(::std::initializer_list<T> xs) { |
| 3533 |
return ElementsAreArray(xs.begin(), xs.end()); |
| 3534 |
} |
| 3535 |
|
| 3536 |
|
| 3537 |
|
| 3538 |
|
| 3539 |
|
| 3540 |
|
| 3541 |
|
| 3542 |
|
| 3543 |
|
| 3544 |
|
| 3545 |
|
| 3546 |
|
| 3547 |
|
| 3548 |
|
| 3549 |
template <typename Iter> |
| 3550 |
inline internal::UnorderedElementsAreArrayMatcher< |
| 3551 |
typename ::std::iterator_traits<Iter>::value_type> |
| 3552 |
UnorderedElementsAreArray(Iter first, Iter last) { |
| 3553 |
typedef typename ::std::iterator_traits<Iter>::value_type T; |
| 3554 |
return internal::UnorderedElementsAreArrayMatcher<T>( |
| 3555 |
internal::UnorderedMatcherRequire::ExactMatch, first, last); |
| 3556 |
} |
| 3557 |
|
| 3558 |
template <typename T> |
| 3559 |
inline internal::UnorderedElementsAreArrayMatcher<T> |
| 3560 |
UnorderedElementsAreArray(const T* pointer, size_t count) { |
| 3561 |
return UnorderedElementsAreArray(pointer, pointer + count); |
| 3562 |
} |
| 3563 |
|
| 3564 |
template <typename T, size_t N> |
| 3565 |
inline internal::UnorderedElementsAreArrayMatcher<T> |
| 3566 |
UnorderedElementsAreArray(const T (&array)[N]) { |
| 3567 |
return UnorderedElementsAreArray(array, N); |
| 3568 |
} |
| 3569 |
|
| 3570 |
template <typename Container> |
| 3571 |
inline internal::UnorderedElementsAreArrayMatcher< |
| 3572 |
typename Container::value_type> |
| 3573 |
UnorderedElementsAreArray(const Container& container) { |
| 3574 |
return UnorderedElementsAreArray(container.begin(), container.end()); |
| 3575 |
} |
| 3576 |
|
| 3577 |
template <typename T> |
| 3578 |
inline internal::UnorderedElementsAreArrayMatcher<T> |
| 3579 |
UnorderedElementsAreArray(::std::initializer_list<T> xs) { |
| 3580 |
return UnorderedElementsAreArray(xs.begin(), xs.end()); |
| 3581 |
} |
| 3582 |
|
| 3583 |
|
| 3584 |
|
| 3585 |
|
| 3586 |
|
| 3587 |
|
| 3588 |
|
| 3589 |
|
| 3590 |
|
| 3591 |
|
| 3592 |
const internal::AnythingMatcher _ = {}; |
| 3593 |
|
| 3594 |
template <typename T> |
| 3595 |
inline Matcher<T> A() { |
| 3596 |
return Matcher<T>(new internal::AnyMatcherImpl<T>()); |
| 3597 |
} |
| 3598 |
|
| 3599 |
|
| 3600 |
template <typename T> |
| 3601 |
inline Matcher<T> An() { return A<T>(); } |
| 3602 |
|
| 3603 |
template <typename T, typename M> |
| 3604 |
Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl( |
| 3605 |
const M& value, std::false_type , |
| 3606 |
std::false_type ) { |
| 3607 |
return Eq(value); |
| 3608 |
} |
| 3609 |
|
| 3610 |
|
| 3611 |
inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() { |
| 3612 |
return MakePolymorphicMatcher(internal::IsNullMatcher()); |
| 3613 |
} |
| 3614 |
|
| 3615 |
|
| 3616 |
|
| 3617 |
|
| 3618 |
inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() { |
| 3619 |
return MakePolymorphicMatcher(internal::NotNullMatcher()); |
| 3620 |
} |
| 3621 |
|
| 3622 |
|
| 3623 |
|
| 3624 |
template <typename T> |
| 3625 |
inline internal::RefMatcher<T&> Ref(T& x) { |
| 3626 |
return internal::RefMatcher<T&>(x); |
| 3627 |
} |
| 3628 |
|
| 3629 |
|
| 3630 |
|
| 3631 |
inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) { |
| 3632 |
return internal::FloatingEqMatcher<double>(rhs, false); |
| 3633 |
} |
| 3634 |
|
| 3635 |
|
| 3636 |
|
| 3637 |
inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(double rhs) { |
| 3638 |
return internal::FloatingEqMatcher<double>(rhs, true); |
| 3639 |
} |
| 3640 |
|
| 3641 |
|
| 3642 |
|
| 3643 |
|
| 3644 |
inline internal::FloatingEqMatcher<double> DoubleNear( |
| 3645 |
double rhs, double max_abs_error) { |
| 3646 |
return internal::FloatingEqMatcher<double>(rhs, false, max_abs_error); |
| 3647 |
} |
| 3648 |
|
| 3649 |
|
| 3650 |
|
| 3651 |
|
| 3652 |
inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear( |
| 3653 |
double rhs, double max_abs_error) { |
| 3654 |
return internal::FloatingEqMatcher<double>(rhs, true, max_abs_error); |
| 3655 |
} |
| 3656 |
|
| 3657 |
|
| 3658 |
|
| 3659 |
inline internal::FloatingEqMatcher<float> FloatEq(float rhs) { |
| 3660 |
return internal::FloatingEqMatcher<float>(rhs, false); |
| 3661 |
} |
| 3662 |
|
| 3663 |
|
| 3664 |
|
| 3665 |
inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(float rhs) { |
| 3666 |
return internal::FloatingEqMatcher<float>(rhs, true); |
| 3667 |
} |
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
|
| 3672 |
inline internal::FloatingEqMatcher<float> FloatNear( |
| 3673 |
float rhs, float max_abs_error) { |
| 3674 |
return internal::FloatingEqMatcher<float>(rhs, false, max_abs_error); |
| 3675 |
} |
| 3676 |
|
| 3677 |
|
| 3678 |
|
| 3679 |
|
| 3680 |
inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear( |
| 3681 |
float rhs, float max_abs_error) { |
| 3682 |
return internal::FloatingEqMatcher<float>(rhs, true, max_abs_error); |
| 3683 |
} |
| 3684 |
|
| 3685 |
|
| 3686 |
|
| 3687 |
template <typename InnerMatcher> |
| 3688 |
inline internal::PointeeMatcher<InnerMatcher> Pointee( |
| 3689 |
const InnerMatcher& inner_matcher) { |
| 3690 |
return internal::PointeeMatcher<InnerMatcher>(inner_matcher); |
| 3691 |
} |
| 3692 |
|
| 3693 |
#if GTEST_HAS_RTTI |
| 3694 |
|
| 3695 |
|
| 3696 |
|
| 3697 |
|
| 3698 |
|
| 3699 |
|
| 3700 |
template <typename To> |
| 3701 |
inline PolymorphicMatcher<internal::WhenDynamicCastToMatcher<To> > |
| 3702 |
WhenDynamicCastTo(const Matcher<To>& inner_matcher) { |
| 3703 |
return MakePolymorphicMatcher( |
| 3704 |
internal::WhenDynamicCastToMatcher<To>(inner_matcher)); |
| 3705 |
} |
| 3706 |
#endif |
| 3707 |
|
| 3708 |
|
| 3709 |
|
| 3710 |
|
| 3711 |
|
| 3712 |
template <typename Class, typename FieldType, typename FieldMatcher> |
| 3713 |
inline PolymorphicMatcher< |
| 3714 |
internal::FieldMatcher<Class, FieldType> > Field( |
| 3715 |
FieldType Class::*field, const FieldMatcher& matcher) { |
| 3716 |
return MakePolymorphicMatcher( |
| 3717 |
internal::FieldMatcher<Class, FieldType>( |
| 3718 |
field, MatcherCast<const FieldType&>(matcher))); |
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
|
| 3723 |
} |
| 3724 |
|
| 3725 |
|
| 3726 |
|
| 3727 |
template <typename Class, typename FieldType, typename FieldMatcher> |
| 3728 |
inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType> > Field( |
| 3729 |
const std::string& field_name, FieldType Class::*field, |
| 3730 |
const FieldMatcher& matcher) { |
| 3731 |
return MakePolymorphicMatcher(internal::FieldMatcher<Class, FieldType>( |
| 3732 |
field_name, field, MatcherCast<const FieldType&>(matcher))); |
| 3733 |
} |
| 3734 |
|
| 3735 |
|
| 3736 |
|
| 3737 |
|
| 3738 |
|
| 3739 |
template <typename Class, typename PropertyType, typename PropertyMatcher> |
| 3740 |
inline PolymorphicMatcher<internal::PropertyMatcher< |
| 3741 |
Class, PropertyType, PropertyType (Class::*)() const> > |
| 3742 |
Property(PropertyType (Class::*property)() const, |
| 3743 |
const PropertyMatcher& matcher) { |
| 3744 |
return MakePolymorphicMatcher( |
| 3745 |
internal::PropertyMatcher<Class, PropertyType, |
| 3746 |
PropertyType (Class::*)() const>( |
| 3747 |
property, MatcherCast<const PropertyType&>(matcher))); |
| 3748 |
|
| 3749 |
|
| 3750 |
|
| 3751 |
|
| 3752 |
} |
| 3753 |
|
| 3754 |
|
| 3755 |
|
| 3756 |
template <typename Class, typename PropertyType, typename PropertyMatcher> |
| 3757 |
inline PolymorphicMatcher<internal::PropertyMatcher< |
| 3758 |
Class, PropertyType, PropertyType (Class::*)() const> > |
| 3759 |
Property(const std::string& property_name, |
| 3760 |
PropertyType (Class::*property)() const, |
| 3761 |
const PropertyMatcher& matcher) { |
| 3762 |
return MakePolymorphicMatcher( |
| 3763 |
internal::PropertyMatcher<Class, PropertyType, |
| 3764 |
PropertyType (Class::*)() const>( |
| 3765 |
property_name, property, MatcherCast<const PropertyType&>(matcher))); |
| 3766 |
} |
| 3767 |
|
| 3768 |
|
| 3769 |
template <typename Class, typename PropertyType, typename PropertyMatcher> |
| 3770 |
inline PolymorphicMatcher<internal::PropertyMatcher< |
| 3771 |
Class, PropertyType, PropertyType (Class::*)() const &> > |
| 3772 |
Property(PropertyType (Class::*property)() const &, |
| 3773 |
const PropertyMatcher& matcher) { |
| 3774 |
return MakePolymorphicMatcher( |
| 3775 |
internal::PropertyMatcher<Class, PropertyType, |
| 3776 |
PropertyType (Class::*)() const&>( |
| 3777 |
property, MatcherCast<const PropertyType&>(matcher))); |
| 3778 |
} |
| 3779 |
|
| 3780 |
|
| 3781 |
template <typename Class, typename PropertyType, typename PropertyMatcher> |
| 3782 |
inline PolymorphicMatcher<internal::PropertyMatcher< |
| 3783 |
Class, PropertyType, PropertyType (Class::*)() const &> > |
| 3784 |
Property(const std::string& property_name, |
| 3785 |
PropertyType (Class::*property)() const &, |
| 3786 |
const PropertyMatcher& matcher) { |
| 3787 |
return MakePolymorphicMatcher( |
| 3788 |
internal::PropertyMatcher<Class, PropertyType, |
| 3789 |
PropertyType (Class::*)() const&>( |
| 3790 |
property_name, property, MatcherCast<const PropertyType&>(matcher))); |
| 3791 |
} |
| 3792 |
|
| 3793 |
|
| 3794 |
|
| 3795 |
|
| 3796 |
|
| 3797 |
|
| 3798 |
|
| 3799 |
|
| 3800 |
|
| 3801 |
template <typename Callable, typename InnerMatcher> |
| 3802 |
internal::ResultOfMatcher<Callable, InnerMatcher> ResultOf( |
| 3803 |
Callable callable, InnerMatcher matcher) { |
| 3804 |
return internal::ResultOfMatcher<Callable, InnerMatcher>( |
| 3805 |
std::move(callable), std::move(matcher)); |
| 3806 |
} |
| 3807 |
|
| 3808 |
|
| 3809 |
|
| 3810 |
|
| 3811 |
inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrEq( |
| 3812 |
const std::string& str) { |
| 3813 |
return MakePolymorphicMatcher( |
| 3814 |
internal::StrEqualityMatcher<std::string>(str, true, true)); |
| 3815 |
} |
| 3816 |
|
| 3817 |
|
| 3818 |
inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrNe( |
| 3819 |
const std::string& str) { |
| 3820 |
return MakePolymorphicMatcher( |
| 3821 |
internal::StrEqualityMatcher<std::string>(str, false, true)); |
| 3822 |
} |
| 3823 |
|
| 3824 |
|
| 3825 |
inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseEq( |
| 3826 |
const std::string& str) { |
| 3827 |
return MakePolymorphicMatcher( |
| 3828 |
internal::StrEqualityMatcher<std::string>(str, true, false)); |
| 3829 |
} |
| 3830 |
|
| 3831 |
|
| 3832 |
inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseNe( |
| 3833 |
const std::string& str) { |
| 3834 |
return MakePolymorphicMatcher( |
| 3835 |
internal::StrEqualityMatcher<std::string>(str, false, false)); |
| 3836 |
} |
| 3837 |
|
| 3838 |
|
| 3839 |
|
| 3840 |
inline PolymorphicMatcher<internal::HasSubstrMatcher<std::string> > HasSubstr( |
| 3841 |
const std::string& substring) { |
| 3842 |
return MakePolymorphicMatcher( |
| 3843 |
internal::HasSubstrMatcher<std::string>(substring)); |
| 3844 |
} |
| 3845 |
|
| 3846 |
|
| 3847 |
inline PolymorphicMatcher<internal::StartsWithMatcher<std::string> > StartsWith( |
| 3848 |
const std::string& prefix) { |
| 3849 |
return MakePolymorphicMatcher( |
| 3850 |
internal::StartsWithMatcher<std::string>(prefix)); |
| 3851 |
} |
| 3852 |
|
| 3853 |
|
| 3854 |
inline PolymorphicMatcher<internal::EndsWithMatcher<std::string> > EndsWith( |
| 3855 |
const std::string& suffix) { |
| 3856 |
return MakePolymorphicMatcher(internal::EndsWithMatcher<std::string>(suffix)); |
| 3857 |
} |
| 3858 |
|
| 3859 |
#if GTEST_HAS_STD_WSTRING |
| 3860 |
|
| 3861 |
|
| 3862 |
|
| 3863 |
inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrEq( |
| 3864 |
const std::wstring& str) { |
| 3865 |
return MakePolymorphicMatcher( |
| 3866 |
internal::StrEqualityMatcher<std::wstring>(str, true, true)); |
| 3867 |
} |
| 3868 |
|
| 3869 |
|
| 3870 |
inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrNe( |
| 3871 |
const std::wstring& str) { |
| 3872 |
return MakePolymorphicMatcher( |
| 3873 |
internal::StrEqualityMatcher<std::wstring>(str, false, true)); |
| 3874 |
} |
| 3875 |
|
| 3876 |
|
| 3877 |
inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > |
| 3878 |
StrCaseEq(const std::wstring& str) { |
| 3879 |
return MakePolymorphicMatcher( |
| 3880 |
internal::StrEqualityMatcher<std::wstring>(str, true, false)); |
| 3881 |
} |
| 3882 |
|
| 3883 |
|
| 3884 |
inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > |
| 3885 |
StrCaseNe(const std::wstring& str) { |
| 3886 |
return MakePolymorphicMatcher( |
| 3887 |
internal::StrEqualityMatcher<std::wstring>(str, false, false)); |
| 3888 |
} |
| 3889 |
|
| 3890 |
|
| 3891 |
|
| 3892 |
inline PolymorphicMatcher<internal::HasSubstrMatcher<std::wstring> > HasSubstr( |
| 3893 |
const std::wstring& substring) { |
| 3894 |
return MakePolymorphicMatcher( |
| 3895 |
internal::HasSubstrMatcher<std::wstring>(substring)); |
| 3896 |
} |
| 3897 |
|
| 3898 |
|
| 3899 |
inline PolymorphicMatcher<internal::StartsWithMatcher<std::wstring> > |
| 3900 |
StartsWith(const std::wstring& prefix) { |
| 3901 |
return MakePolymorphicMatcher( |
| 3902 |
internal::StartsWithMatcher<std::wstring>(prefix)); |
| 3903 |
} |
| 3904 |
|
| 3905 |
|
| 3906 |
inline PolymorphicMatcher<internal::EndsWithMatcher<std::wstring> > EndsWith( |
| 3907 |
const std::wstring& suffix) { |
| 3908 |
return MakePolymorphicMatcher( |
| 3909 |
internal::EndsWithMatcher<std::wstring>(suffix)); |
| 3910 |
} |
| 3911 |
|
| 3912 |
#endif |
| 3913 |
|
| 3914 |
|
| 3915 |
|
| 3916 |
inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); } |
| 3917 |
|
| 3918 |
|
| 3919 |
|
| 3920 |
inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); } |
| 3921 |
|
| 3922 |
|
| 3923 |
|
| 3924 |
inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); } |
| 3925 |
|
| 3926 |
|
| 3927 |
|
| 3928 |
inline internal::Le2Matcher Le() { return internal::Le2Matcher(); } |
| 3929 |
|
| 3930 |
|
| 3931 |
|
| 3932 |
inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); } |
| 3933 |
|
| 3934 |
|
| 3935 |
|
| 3936 |
inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); } |
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
inline internal::FloatingEq2Matcher<float> FloatEq() { |
| 3941 |
return internal::FloatingEq2Matcher<float>(); |
| 3942 |
} |
| 3943 |
|
| 3944 |
|
| 3945 |
|
| 3946 |
inline internal::FloatingEq2Matcher<double> DoubleEq() { |
| 3947 |
return internal::FloatingEq2Matcher<double>(); |
| 3948 |
} |
| 3949 |
|
| 3950 |
|
| 3951 |
|
| 3952 |
inline internal::FloatingEq2Matcher<float> NanSensitiveFloatEq() { |
| 3953 |
return internal::FloatingEq2Matcher<float>(true); |
| 3954 |
} |
| 3955 |
|
| 3956 |
|
| 3957 |
|
| 3958 |
inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleEq() { |
| 3959 |
return internal::FloatingEq2Matcher<double>(true); |
| 3960 |
} |
| 3961 |
|
| 3962 |
|
| 3963 |
|
| 3964 |
inline internal::FloatingEq2Matcher<float> FloatNear(float max_abs_error) { |
| 3965 |
return internal::FloatingEq2Matcher<float>(max_abs_error); |
| 3966 |
} |
| 3967 |
|
| 3968 |
|
| 3969 |
|
| 3970 |
inline internal::FloatingEq2Matcher<double> DoubleNear(double max_abs_error) { |
| 3971 |
return internal::FloatingEq2Matcher<double>(max_abs_error); |
| 3972 |
} |
| 3973 |
|
| 3974 |
|
| 3975 |
|
| 3976 |
|
| 3977 |
inline internal::FloatingEq2Matcher<float> NanSensitiveFloatNear( |
| 3978 |
float max_abs_error) { |
| 3979 |
return internal::FloatingEq2Matcher<float>(max_abs_error, true); |
| 3980 |
} |
| 3981 |
|
| 3982 |
|
| 3983 |
|
| 3984 |
|
| 3985 |
inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleNear( |
| 3986 |
double max_abs_error) { |
| 3987 |
return internal::FloatingEq2Matcher<double>(max_abs_error, true); |
| 3988 |
} |
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
template <typename InnerMatcher> |
| 3993 |
inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) { |
| 3994 |
return internal::NotMatcher<InnerMatcher>(m); |
| 3995 |
} |
| 3996 |
|
| 3997 |
|
| 3998 |
|
| 3999 |
|
| 4000 |
template <typename Predicate> |
| 4001 |
inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> > |
| 4002 |
Truly(Predicate pred) { |
| 4003 |
return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred)); |
| 4004 |
} |
| 4005 |
|
| 4006 |
|
| 4007 |
|
| 4008 |
|
| 4009 |
|
| 4010 |
|
| 4011 |
|
| 4012 |
template <typename SizeMatcher> |
| 4013 |
inline internal::SizeIsMatcher<SizeMatcher> |
| 4014 |
SizeIs(const SizeMatcher& size_matcher) { |
| 4015 |
return internal::SizeIsMatcher<SizeMatcher>(size_matcher); |
| 4016 |
} |
| 4017 |
|
| 4018 |
|
| 4019 |
|
| 4020 |
|
| 4021 |
|
| 4022 |
|
| 4023 |
template <typename DistanceMatcher> |
| 4024 |
inline internal::BeginEndDistanceIsMatcher<DistanceMatcher> |
| 4025 |
BeginEndDistanceIs(const DistanceMatcher& distance_matcher) { |
| 4026 |
return internal::BeginEndDistanceIsMatcher<DistanceMatcher>(distance_matcher); |
| 4027 |
} |
| 4028 |
|
| 4029 |
|
| 4030 |
|
| 4031 |
|
| 4032 |
|
| 4033 |
template <typename Container> |
| 4034 |
inline PolymorphicMatcher<internal::ContainerEqMatcher< |
| 4035 |
typename std::remove_const<Container>::type>> |
| 4036 |
ContainerEq(const Container& rhs) { |
| 4037 |
|
| 4038 |
|
| 4039 |
typedef typename std::remove_const<Container>::type RawContainer; |
| 4040 |
return MakePolymorphicMatcher( |
| 4041 |
internal::ContainerEqMatcher<RawContainer>(rhs)); |
| 4042 |
} |
| 4043 |
|
| 4044 |
|
| 4045 |
|
| 4046 |
template <typename Comparator, typename ContainerMatcher> |
| 4047 |
inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher> |
| 4048 |
WhenSortedBy(const Comparator& comparator, |
| 4049 |
const ContainerMatcher& container_matcher) { |
| 4050 |
return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>( |
| 4051 |
comparator, container_matcher); |
| 4052 |
} |
| 4053 |
|
| 4054 |
|
| 4055 |
|
| 4056 |
template <typename ContainerMatcher> |
| 4057 |
inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher> |
| 4058 |
WhenSorted(const ContainerMatcher& container_matcher) { |
| 4059 |
return |
| 4060 |
internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>( |
| 4061 |
internal::LessComparator(), container_matcher); |
| 4062 |
} |
| 4063 |
|
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
|
| 4069 |
|
| 4070 |
template <typename TupleMatcher, typename Container> |
| 4071 |
inline internal::PointwiseMatcher<TupleMatcher, |
| 4072 |
typename std::remove_const<Container>::type> |
| 4073 |
Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) { |
| 4074 |
|
| 4075 |
|
| 4076 |
|
| 4077 |
typedef typename std::remove_const<Container>::type RawContainer; |
| 4078 |
return internal::PointwiseMatcher<TupleMatcher, RawContainer>( |
| 4079 |
tuple_matcher, rhs); |
| 4080 |
} |
| 4081 |
|
| 4082 |
|
| 4083 |
|
| 4084 |
template <typename TupleMatcher, typename T> |
| 4085 |
inline internal::PointwiseMatcher<TupleMatcher, std::vector<T> > Pointwise( |
| 4086 |
const TupleMatcher& tuple_matcher, std::initializer_list<T> rhs) { |
| 4087 |
return Pointwise(tuple_matcher, std::vector<T>(rhs)); |
| 4088 |
} |
| 4089 |
|
| 4090 |
|
| 4091 |
|
| 4092 |
|
| 4093 |
|
| 4094 |
|
| 4095 |
|
| 4096 |
|
| 4097 |
|
| 4098 |
|
| 4099 |
|
| 4100 |
|
| 4101 |
|
| 4102 |
template <typename Tuple2Matcher, typename RhsContainer> |
| 4103 |
inline internal::UnorderedElementsAreArrayMatcher< |
| 4104 |
typename internal::BoundSecondMatcher< |
| 4105 |
Tuple2Matcher, |
| 4106 |
typename internal::StlContainerView< |
| 4107 |
typename std::remove_const<RhsContainer>::type>::type::value_type>> |
| 4108 |
UnorderedPointwise(const Tuple2Matcher& tuple2_matcher, |
| 4109 |
const RhsContainer& rhs_container) { |
| 4110 |
|
| 4111 |
|
| 4112 |
|
| 4113 |
typedef typename std::remove_const<RhsContainer>::type RawRhsContainer; |
| 4114 |
|
| 4115 |
|
| 4116 |
|
| 4117 |
typedef typename internal::StlContainerView<RawRhsContainer> RhsView; |
| 4118 |
typedef typename RhsView::type RhsStlContainer; |
| 4119 |
typedef typename RhsStlContainer::value_type Second; |
| 4120 |
const RhsStlContainer& rhs_stl_container = |
| 4121 |
RhsView::ConstReference(rhs_container); |
| 4122 |
|
| 4123 |
|
| 4124 |
::std::vector<internal::BoundSecondMatcher<Tuple2Matcher, Second> > matchers; |
| 4125 |
for (typename RhsStlContainer::const_iterator it = rhs_stl_container.begin(); |
| 4126 |
it != rhs_stl_container.end(); ++it) { |
| 4127 |
matchers.push_back( |
| 4128 |
internal::MatcherBindSecond(tuple2_matcher, *it)); |
| 4129 |
} |
| 4130 |
|
| 4131 |
|
| 4132 |
return UnorderedElementsAreArray(matchers); |
| 4133 |
} |
| 4134 |
|
| 4135 |
|
| 4136 |
|
| 4137 |
template <typename Tuple2Matcher, typename T> |
| 4138 |
inline internal::UnorderedElementsAreArrayMatcher< |
| 4139 |
typename internal::BoundSecondMatcher<Tuple2Matcher, T> > |
| 4140 |
UnorderedPointwise(const Tuple2Matcher& tuple2_matcher, |
| 4141 |
std::initializer_list<T> rhs) { |
| 4142 |
return UnorderedPointwise(tuple2_matcher, std::vector<T>(rhs)); |
| 4143 |
} |
| 4144 |
|
| 4145 |
|
| 4146 |
|
| 4147 |
|
| 4148 |
|
| 4149 |
|
| 4150 |
|
| 4151 |
|
| 4152 |
|
| 4153 |
|
| 4154 |
|
| 4155 |
|
| 4156 |
|
| 4157 |
|
| 4158 |
|
| 4159 |
|
| 4160 |
|
| 4161 |
|
| 4162 |
|
| 4163 |
|
| 4164 |
template <typename M> |
| 4165 |
inline internal::ContainsMatcher<M> Contains(M matcher) { |
| 4166 |
return internal::ContainsMatcher<M>(matcher); |
| 4167 |
} |
| 4168 |
|
| 4169 |
|
| 4170 |
|
| 4171 |
|
| 4172 |
|
| 4173 |
|
| 4174 |
|
| 4175 |
|
| 4176 |
|
| 4177 |
|
| 4178 |
|
| 4179 |
|
| 4180 |
|
| 4181 |
|
| 4182 |
|
| 4183 |
|
| 4184 |
|
| 4185 |
|
| 4186 |
|
| 4187 |
|
| 4188 |
|
| 4189 |
|
| 4190 |
|
| 4191 |
|
| 4192 |
|
| 4193 |
|
| 4194 |
|
| 4195 |
|
| 4196 |
template <typename Iter> |
| 4197 |
inline internal::UnorderedElementsAreArrayMatcher< |
| 4198 |
typename ::std::iterator_traits<Iter>::value_type> |
| 4199 |
IsSupersetOf(Iter first, Iter last) { |
| 4200 |
typedef typename ::std::iterator_traits<Iter>::value_type T; |
| 4201 |
return internal::UnorderedElementsAreArrayMatcher<T>( |
| 4202 |
internal::UnorderedMatcherRequire::Superset, first, last); |
| 4203 |
} |
| 4204 |
|
| 4205 |
template <typename T> |
| 4206 |
inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf( |
| 4207 |
const T* pointer, size_t count) { |
| 4208 |
return IsSupersetOf(pointer, pointer + count); |
| 4209 |
} |
| 4210 |
|
| 4211 |
template <typename T, size_t N> |
| 4212 |
inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf( |
| 4213 |
const T (&array)[N]) { |
| 4214 |
return IsSupersetOf(array, N); |
| 4215 |
} |
| 4216 |
|
| 4217 |
template <typename Container> |
| 4218 |
inline internal::UnorderedElementsAreArrayMatcher< |
| 4219 |
typename Container::value_type> |
| 4220 |
IsSupersetOf(const Container& container) { |
| 4221 |
return IsSupersetOf(container.begin(), container.end()); |
| 4222 |
} |
| 4223 |
|
| 4224 |
template <typename T> |
| 4225 |
inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf( |
| 4226 |
::std::initializer_list<T> xs) { |
| 4227 |
return IsSupersetOf(xs.begin(), xs.end()); |
| 4228 |
} |
| 4229 |
|
| 4230 |
|
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
|
| 4236 |
|
| 4237 |
|
| 4238 |
|
| 4239 |
|
| 4240 |
|
| 4241 |
|
| 4242 |
|
| 4243 |
|
| 4244 |
|
| 4245 |
|
| 4246 |
|
| 4247 |
|
| 4248 |
|
| 4249 |
|
| 4250 |
|
| 4251 |
|
| 4252 |
|
| 4253 |
template <typename Iter> |
| 4254 |
inline internal::UnorderedElementsAreArrayMatcher< |
| 4255 |
typename ::std::iterator_traits<Iter>::value_type> |
| 4256 |
IsSubsetOf(Iter first, Iter last) { |
| 4257 |
typedef typename ::std::iterator_traits<Iter>::value_type T; |
| 4258 |
return internal::UnorderedElementsAreArrayMatcher<T>( |
| 4259 |
internal::UnorderedMatcherRequire::Subset, first, last); |
| 4260 |
} |
| 4261 |
|
| 4262 |
template <typename T> |
| 4263 |
inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf( |
| 4264 |
const T* pointer, size_t count) { |
| 4265 |
return IsSubsetOf(pointer, pointer + count); |
| 4266 |
} |
| 4267 |
|
| 4268 |
template <typename T, size_t N> |
| 4269 |
inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf( |
| 4270 |
const T (&array)[N]) { |
| 4271 |
return IsSubsetOf(array, N); |
| 4272 |
} |
| 4273 |
|
| 4274 |
template <typename Container> |
| 4275 |
inline internal::UnorderedElementsAreArrayMatcher< |
| 4276 |
typename Container::value_type> |
| 4277 |
IsSubsetOf(const Container& container) { |
| 4278 |
return IsSubsetOf(container.begin(), container.end()); |
| 4279 |
} |
| 4280 |
|
| 4281 |
template <typename T> |
| 4282 |
inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf( |
| 4283 |
::std::initializer_list<T> xs) { |
| 4284 |
return IsSubsetOf(xs.begin(), xs.end()); |
| 4285 |
} |
| 4286 |
|
| 4287 |
|
| 4288 |
|
| 4289 |
|
| 4290 |
|
| 4291 |
|
| 4292 |
|
| 4293 |
|
| 4294 |
|
| 4295 |
|
| 4296 |
|
| 4297 |
|
| 4298 |
|
| 4299 |
|
| 4300 |
|
| 4301 |
|
| 4302 |
|
| 4303 |
|
| 4304 |
|
| 4305 |
|
| 4306 |
|
| 4307 |
|
| 4308 |
|
| 4309 |
|
| 4310 |
|
| 4311 |
|
| 4312 |
|
| 4313 |
|
| 4314 |
template <typename M> |
| 4315 |
inline internal::EachMatcher<M> Each(M matcher) { |
| 4316 |
return internal::EachMatcher<M>(matcher); |
| 4317 |
} |
| 4318 |
|
| 4319 |
|
| 4320 |
|
| 4321 |
|
| 4322 |
template <typename M> |
| 4323 |
inline internal::KeyMatcher<M> Key(M inner_matcher) { |
| 4324 |
return internal::KeyMatcher<M>(inner_matcher); |
| 4325 |
} |
| 4326 |
|
| 4327 |
|
| 4328 |
|
| 4329 |
|
| 4330 |
|
| 4331 |
|
| 4332 |
template <typename FirstMatcher, typename SecondMatcher> |
| 4333 |
inline internal::PairMatcher<FirstMatcher, SecondMatcher> |
| 4334 |
Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) { |
| 4335 |
return internal::PairMatcher<FirstMatcher, SecondMatcher>( |
| 4336 |
first_matcher, second_matcher); |
| 4337 |
} |
| 4338 |
|
| 4339 |
|
| 4340 |
|
| 4341 |
template <typename M> |
| 4342 |
inline internal::MatcherAsPredicate<M> Matches(M matcher) { |
| 4343 |
return internal::MatcherAsPredicate<M>(matcher); |
| 4344 |
} |
| 4345 |
|
| 4346 |
|
| 4347 |
template <typename T, typename M> |
| 4348 |
inline bool Value(const T& value, M matcher) { |
| 4349 |
return testing::Matches(matcher)(value); |
| 4350 |
} |
| 4351 |
|
| 4352 |
|
| 4353 |
|
| 4354 |
template <typename T, typename M> |
| 4355 |
inline bool ExplainMatchResult( |
| 4356 |
M matcher, const T& value, MatchResultListener* listener) { |
| 4357 |
return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener); |
| 4358 |
} |
| 4359 |
|
| 4360 |
|
| 4361 |
|
| 4362 |
|
| 4363 |
|
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
|
| 4370 |
template <typename T, typename M> |
| 4371 |
std::string DescribeMatcher(const M& matcher, bool negation = false) { |
| 4372 |
::std::stringstream ss; |
| 4373 |
Matcher<T> monomorphic_matcher = SafeMatcherCast<T>(matcher); |
| 4374 |
if (negation) { |
| 4375 |
monomorphic_matcher.DescribeNegationTo(&ss); |
| 4376 |
} else { |
| 4377 |
monomorphic_matcher.DescribeTo(&ss); |
| 4378 |
} |
| 4379 |
return ss.str(); |
| 4380 |
} |
| 4381 |
|
| 4382 |
template <typename... Args> |
| 4383 |
internal::ElementsAreMatcher< |
| 4384 |
std::tuple<typename std::decay<const Args&>::type...>> |
| 4385 |
ElementsAre(const Args&... matchers) { |
| 4386 |
return internal::ElementsAreMatcher< |
| 4387 |
std::tuple<typename std::decay<const Args&>::type...>>( |
| 4388 |
std::make_tuple(matchers...)); |
| 4389 |
} |
| 4390 |
|
| 4391 |
template <typename... Args> |
| 4392 |
internal::UnorderedElementsAreMatcher< |
| 4393 |
std::tuple<typename std::decay<const Args&>::type...>> |
| 4394 |
UnorderedElementsAre(const Args&... matchers) { |
| 4395 |
return internal::UnorderedElementsAreMatcher< |
| 4396 |
std::tuple<typename std::decay<const Args&>::type...>>( |
| 4397 |
std::make_tuple(matchers...)); |
| 4398 |
} |
| 4399 |
|
| 4400 |
|
| 4401 |
template <typename... Args> |
| 4402 |
internal::AllOfMatcher<typename std::decay<const Args&>::type...> AllOf( |
| 4403 |
const Args&... matchers) { |
| 4404 |
return internal::AllOfMatcher<typename std::decay<const Args&>::type...>( |
| 4405 |
matchers...); |
| 4406 |
} |
| 4407 |
|
| 4408 |
template <typename... Args> |
| 4409 |
internal::AnyOfMatcher<typename std::decay<const Args&>::type...> AnyOf( |
| 4410 |
const Args&... matchers) { |
| 4411 |
return internal::AnyOfMatcher<typename std::decay<const Args&>::type...>( |
| 4412 |
matchers...); |
| 4413 |
} |
| 4414 |
|
| 4415 |
|
| 4416 |
|
| 4417 |
|
| 4418 |
|
| 4419 |
|
| 4420 |
|
| 4421 |
|
| 4422 |
|
| 4423 |
|
| 4424 |
|
| 4425 |
|
| 4426 |
|
| 4427 |
|
| 4428 |
|
| 4429 |
|
| 4430 |
|
| 4431 |
|
| 4432 |
|
| 4433 |
|
| 4434 |
|
| 4435 |
|
| 4436 |
|
| 4437 |
template <typename Iter> |
| 4438 |
inline internal::AnyOfArrayMatcher< |
| 4439 |
typename ::std::iterator_traits<Iter>::value_type> |
| 4440 |
AnyOfArray(Iter first, Iter last) { |
| 4441 |
return internal::AnyOfArrayMatcher< |
| 4442 |
typename ::std::iterator_traits<Iter>::value_type>(first, last); |
| 4443 |
} |
| 4444 |
|
| 4445 |
template <typename Iter> |
| 4446 |
inline internal::AllOfArrayMatcher< |
| 4447 |
typename ::std::iterator_traits<Iter>::value_type> |
| 4448 |
AllOfArray(Iter first, Iter last) { |
| 4449 |
return internal::AllOfArrayMatcher< |
| 4450 |
typename ::std::iterator_traits<Iter>::value_type>(first, last); |
| 4451 |
} |
| 4452 |
|
| 4453 |
template <typename T> |
| 4454 |
inline internal::AnyOfArrayMatcher<T> AnyOfArray(const T* ptr, size_t count) { |
| 4455 |
return AnyOfArray(ptr, ptr + count); |
| 4456 |
} |
| 4457 |
|
| 4458 |
template <typename T> |
| 4459 |
inline internal::AllOfArrayMatcher<T> AllOfArray(const T* ptr, size_t count) { |
| 4460 |
return AllOfArray(ptr, ptr + count); |
| 4461 |
} |
| 4462 |
|
| 4463 |
template <typename T, size_t N> |
| 4464 |
inline internal::AnyOfArrayMatcher<T> AnyOfArray(const T (&array)[N]) { |
| 4465 |
return AnyOfArray(array, N); |
| 4466 |
} |
| 4467 |
|
| 4468 |
template <typename T, size_t N> |
| 4469 |
inline internal::AllOfArrayMatcher<T> AllOfArray(const T (&array)[N]) { |
| 4470 |
return AllOfArray(array, N); |
| 4471 |
} |
| 4472 |
|
| 4473 |
template <typename Container> |
| 4474 |
inline internal::AnyOfArrayMatcher<typename Container::value_type> AnyOfArray( |
| 4475 |
const Container& container) { |
| 4476 |
return AnyOfArray(container.begin(), container.end()); |
| 4477 |
} |
| 4478 |
|
| 4479 |
template <typename Container> |
| 4480 |
inline internal::AllOfArrayMatcher<typename Container::value_type> AllOfArray( |
| 4481 |
const Container& container) { |
| 4482 |
return AllOfArray(container.begin(), container.end()); |
| 4483 |
} |
| 4484 |
|
| 4485 |
template <typename T> |
| 4486 |
inline internal::AnyOfArrayMatcher<T> AnyOfArray( |
| 4487 |
::std::initializer_list<T> xs) { |
| 4488 |
return AnyOfArray(xs.begin(), xs.end()); |
| 4489 |
} |
| 4490 |
|
| 4491 |
template <typename T> |
| 4492 |
inline internal::AllOfArrayMatcher<T> AllOfArray( |
| 4493 |
::std::initializer_list<T> xs) { |
| 4494 |
return AllOfArray(xs.begin(), xs.end()); |
| 4495 |
} |
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
|
| 4500 |
template <size_t... k, typename InnerMatcher> |
| 4501 |
internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...> Args( |
| 4502 |
InnerMatcher&& matcher) { |
| 4503 |
return internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...>( |
| 4504 |
std::forward<InnerMatcher>(matcher)); |
| 4505 |
} |
| 4506 |
|
| 4507 |
|
| 4508 |
|
| 4509 |
|
| 4510 |
|
| 4511 |
|
| 4512 |
|
| 4513 |
|
| 4514 |
template <typename InnerMatcher> |
| 4515 |
inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; } |
| 4516 |
|
| 4517 |
|
| 4518 |
|
| 4519 |
|
| 4520 |
|
| 4521 |
|
| 4522 |
|
| 4523 |
|
| 4524 |
|
| 4525 |
template <typename ValueMatcher> |
| 4526 |
inline internal::OptionalMatcher<ValueMatcher> Optional( |
| 4527 |
const ValueMatcher& value_matcher) { |
| 4528 |
return internal::OptionalMatcher<ValueMatcher>(value_matcher); |
| 4529 |
} |
| 4530 |
|
| 4531 |
|
| 4532 |
template <typename T> |
| 4533 |
PolymorphicMatcher<internal::any_cast_matcher::AnyCastMatcher<T> > AnyWith( |
| 4534 |
const Matcher<const T&>& matcher) { |
| 4535 |
return MakePolymorphicMatcher( |
| 4536 |
internal::any_cast_matcher::AnyCastMatcher<T>(matcher)); |
| 4537 |
} |
| 4538 |
|
| 4539 |
|
| 4540 |
|
| 4541 |
|
| 4542 |
|
| 4543 |
template <typename T> |
| 4544 |
PolymorphicMatcher<internal::variant_matcher::VariantMatcher<T> > VariantWith( |
| 4545 |
const Matcher<const T&>& matcher) { |
| 4546 |
return MakePolymorphicMatcher( |
| 4547 |
internal::variant_matcher::VariantMatcher<T>(matcher)); |
| 4548 |
} |
| 4549 |
|
| 4550 |
|
| 4551 |
|
| 4552 |
|
| 4553 |
|
| 4554 |
#define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\ |
| 4555 |
::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) |
| 4556 |
#define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\ |
| 4557 |
::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) |
| 4558 |
|
| 4559 |
} |
| 4560 |
|
| 4561 |
GTEST_DISABLE_MSC_WARNINGS_POP_() |
| 4562 |
|
| 4563 |
|
| 4564 |
|
| 4565 |
|
| 4566 |
#include "gmock/internal/custom/gmock-matchers.h" |
| 4567 |
|
| 4568 |
#endif |