Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
testing::internal::ElementsAreMatcherImpl< Container > Class Template Reference

#include <gmock-matchers.h>

Inheritance diagram for testing::internal::ElementsAreMatcherImpl< Container >:
Collaboration diagram for testing::internal::ElementsAreMatcherImpl< Container >:

Public Types

typedef internal::StlContainerView< RawContainer > View
 
typedef View::type StlContainer
 
typedef View::const_reference StlContainerReference
 
typedef StlContainer::value_type Element
 

Public Member Functions

typedef GTEST_REMOVE_REFERENCE_AND_CONST_ (Container) RawContainer
 
template<typename InputIter >
 ElementsAreMatcherImpl (InputIter first, InputIter last)
 
virtual void DescribeTo (::std::ostream *os) const
 
virtual void DescribeNegationTo (::std::ostream *os) const
 
virtual bool MatchAndExplain (Container container, MatchResultListener *listener) const
 
- Public Member Functions inherited from testing::MatcherInterface< Container >
- Public Member Functions inherited from testing::MatcherDescriberInterface
virtual ~MatcherDescriberInterface ()
 

Detailed Description

template<typename Container>
class testing::internal::ElementsAreMatcherImpl< Container >

Definition at line 3460 of file gmock-matchers.h.

Member Typedef Documentation

◆ Element

template<typename Container >
StlContainer::value_type testing::internal::ElementsAreMatcherImpl< Container >::Element

Definition at line 3466 of file gmock-matchers.h.

◆ StlContainer

template<typename Container >
View::type testing::internal::ElementsAreMatcherImpl< Container >::StlContainer

Definition at line 3464 of file gmock-matchers.h.

◆ StlContainerReference

template<typename Container >
View::const_reference testing::internal::ElementsAreMatcherImpl< Container >::StlContainerReference

Definition at line 3465 of file gmock-matchers.h.

◆ View

template<typename Container >
internal::StlContainerView<RawContainer> testing::internal::ElementsAreMatcherImpl< Container >::View

Definition at line 3463 of file gmock-matchers.h.

Constructor & Destructor Documentation

◆ ElementsAreMatcherImpl()

template<typename Container >
template<typename InputIter >
testing::internal::ElementsAreMatcherImpl< Container >::ElementsAreMatcherImpl ( InputIter first,
InputIter last )
inline

Definition at line 3471 of file gmock-matchers.h.

3471 {
3472 while (first != last) {
3473 matchers_.push_back(MatcherCast<const Element&>(*first++));
3474 }
3475 }

Member Function Documentation

◆ DescribeNegationTo()

template<typename Container >
virtual void testing::internal::ElementsAreMatcherImpl< Container >::DescribeNegationTo ( ::std::ostream * os) const
inlinevirtual

Reimplemented from testing::MatcherDescriberInterface.

Definition at line 3497 of file gmock-matchers.h.

3497 {
3498 if (count() == 0) {
3499 *os << "isn't empty";
3500 return;
3501 }
3502
3503 *os << "doesn't have " << Elements(count()) << ", or\n";
3504 for (size_t i = 0; i != count(); ++i) {
3505 *os << "element #" << i << " ";
3506 matchers_[i].DescribeNegationTo(os);
3507 if (i + 1 < count()) {
3508 *os << ", or\n";
3509 }
3510 }
3511 }
os_t os

◆ DescribeTo()

template<typename Container >
virtual void testing::internal::ElementsAreMatcherImpl< Container >::DescribeTo ( ::std::ostream * os) const
inlinevirtual

Implements testing::MatcherDescriberInterface.

Definition at line 3478 of file gmock-matchers.h.

3478 {
3479 if (count() == 0) {
3480 *os << "is empty";
3481 } else if (count() == 1) {
3482 *os << "has 1 element that ";
3483 matchers_[0].DescribeTo(os);
3484 } else {
3485 *os << "has " << Elements(count()) << " where\n";
3486 for (size_t i = 0; i != count(); ++i) {
3487 *os << "element #" << i << " ";
3488 matchers_[i].DescribeTo(os);
3489 if (i + 1 < count()) {
3490 *os << ",\n";
3491 }
3492 }
3493 }
3494 }

◆ GTEST_REMOVE_REFERENCE_AND_CONST_()

template<typename Container >
typedef testing::internal::ElementsAreMatcherImpl< Container >::GTEST_REMOVE_REFERENCE_AND_CONST_ ( Container )

◆ MatchAndExplain()

template<typename Container >
virtual bool testing::internal::ElementsAreMatcherImpl< Container >::MatchAndExplain ( Container container,
MatchResultListener * listener ) const
inlinevirtual

Implements testing::MatcherInterface< Container >.

Definition at line 3513 of file gmock-matchers.h.

3514 {
3515 // To work with stream-like "containers", we must only walk
3516 // through the elements in one pass.
3517
3518 const bool listener_interested = listener->IsInterested();
3519
3520 // explanations[i] is the explanation of the element at index i.
3521 ::std::vector<std::string> explanations(count());
3522 StlContainerReference stl_container = View::ConstReference(container);
3523 typename StlContainer::const_iterator it = stl_container.begin();
3524 size_t exam_pos = 0;
3525 bool mismatch_found = false; // Have we found a mismatched element yet?
3526
3527 // Go through the elements and matchers in pairs, until we reach
3528 // the end of either the elements or the matchers, or until we find a
3529 // mismatch.
3530 for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
3531 bool match; // Does the current element match the current matcher?
3532 if (listener_interested) {
3533 StringMatchResultListener s;
3534 match = matchers_[exam_pos].MatchAndExplain(*it, &s);
3535 explanations[exam_pos] = s.str();
3536 } else {
3537 match = matchers_[exam_pos].Matches(*it);
3538 }
3539
3540 if (!match) {
3541 mismatch_found = true;
3542 break;
3543 }
3544 }
3545 // If mismatch_found is true, 'exam_pos' is the index of the mismatch.
3546
3547 // Find how many elements the actual container has. We avoid
3548 // calling size() s.t. this code works for stream-like "containers"
3549 // that don't define size().
3550 size_t actual_count = exam_pos;
3551 for (; it != stl_container.end(); ++it) {
3552 ++actual_count;
3553 }
3554
3555 if (actual_count != count()) {
3556 // The element count doesn't match. If the container is empty,
3557 // there's no need to explain anything as Google Mock already
3558 // prints the empty container. Otherwise we just need to show
3559 // how many elements there actually are.
3560 if (listener_interested && (actual_count != 0)) {
3561 *listener << "which has " << Elements(actual_count);
3562 }
3563 return false;
3564 }
3565
3566 if (mismatch_found) {
3567 // The element count matches, but the exam_pos-th element doesn't match.
3568 if (listener_interested) {
3569 *listener << "whose element #" << exam_pos << " doesn't match";
3570 PrintIfNotEmpty(explanations[exam_pos], listener->stream());
3571 }
3572 return false;
3573 }
3574
3575 // Every element matches its expectation. We need to explain why
3576 // (the obvious ones can be skipped).
3577 if (listener_interested) {
3578 bool reason_printed = false;
3579 for (size_t i = 0; i != count(); ++i) {
3580 const std::string& s = explanations[i];
3581 if (!s.empty()) {
3582 if (reason_printed) {
3583 *listener << ",\nand ";
3584 }
3585 *listener << "whose element #" << i << " matches, " << s;
3586 reason_printed = true;
3587 }
3588 }
3589 }
3590 return true;
3591 }
static const_reference ConstReference(const RawContainer &container)
void PrintIfNotEmpty(const std::string &explanation, ::std::ostream *os)
char * s
Here is the call graph for this function:

The documentation for this class was generated from the following file: