Electroneum
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::MatcherDescriberInterface
virtual ~MatcherDescriberInterface ()

Detailed Description

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

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

Member Typedef Documentation

◆ Element

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

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

◆ StlContainer

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

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

◆ StlContainerReference

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

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

◆ View

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

Definition at line 3111 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 3119 of file gmock-matchers.h.

3119 {
3120 while (first != last) {
3121 matchers_.push_back(MatcherCast<const Element&>(*first++));
3122 }
3123 }
Here is the call graph for this function:

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 3145 of file gmock-matchers.h.

3145 {
3146 if (count() == 0) {
3147 *os << "isn't empty";
3148 return;
3149 }
3150
3151 *os << "doesn't have " << Elements(count()) << ", or\n";
3152 for (size_t i = 0; i != count(); ++i) {
3153 *os << "element #" << i << " ";
3154 matchers_[i].DescribeNegationTo(os);
3155 if (i + 1 < count()) {
3156 *os << ", or\n";
3157 }
3158 }
3159 }
virtual void DescribeNegationTo(::std::ostream *os) const

◆ DescribeTo()

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

Implements testing::MatcherDescriberInterface.

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

3126 {
3127 if (count() == 0) {
3128 *os << "is empty";
3129 } else if (count() == 1) {
3130 *os << "has 1 element that ";
3131 matchers_[0].DescribeTo(os);
3132 } else {
3133 *os << "has " << Elements(count()) << " where\n";
3134 for (size_t i = 0; i != count(); ++i) {
3135 *os << "element #" << i << " ";
3136 matchers_[i].DescribeTo(os);
3137 if (i + 1 < count()) {
3138 *os << ",\n";
3139 }
3140 }
3141 }
3142 }
virtual void DescribeTo(::std::ostream *os) const

◆ 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 3161 of file gmock-matchers.h.

3162 {
3163 // To work with stream-like "containers", we must only walk
3164 // through the elements in one pass.
3165
3166 const bool listener_interested = listener->IsInterested();
3167
3168 // explanations[i] is the explanation of the element at index i.
3172 size_t exam_pos = 0;
3173 bool mismatch_found = false; // Have we found a mismatched element yet?
3174
3175 // Go through the elements and matchers in pairs, until we reach
3176 // the end of either the elements or the matchers, or until we find a
3177 // mismatch.
3178 for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
3179 bool match; // Does the current element match the current matcher?
3180 if (listener_interested) {
3182 match = matchers_[exam_pos].MatchAndExplain(*it, &s);
3183 explanations[exam_pos] = s.str();
3184 } else {
3185 match = matchers_[exam_pos].Matches(*it);
3186 }
3187
3188 if (!match) {
3189 mismatch_found = true;
3190 break;
3191 }
3192 }
3193 // If mismatch_found is true, 'exam_pos' is the index of the mismatch.
3194
3195 // Find how many elements the actual container has. We avoid
3196 // calling size() s.t. this code works for stream-like "containers"
3197 // that don't define size().
3198 size_t actual_count = exam_pos;
3199 for (; it != stl_container.end(); ++it) {
3200 ++actual_count;
3201 }
3202
3203 if (actual_count != count()) {
3204 // The element count doesn't match. If the container is empty,
3205 // there's no need to explain anything as Google Mock already
3206 // prints the empty container. Otherwise we just need to show
3207 // how many elements there actually are.
3208 if (listener_interested && (actual_count != 0)) {
3209 *listener << "which has " << Elements(actual_count);
3210 }
3211 return false;
3212 }
3213
3214 if (mismatch_found) {
3215 // The element count matches, but the exam_pos-th element doesn't match.
3216 if (listener_interested) {
3217 *listener << "whose element #" << exam_pos << " doesn't match";
3219 }
3220 return false;
3221 }
3222
3223 // Every element matches its expectation. We need to explain why
3224 // (the obvious ones can be skipped).
3225 if (listener_interested) {
3226 bool reason_printed = false;
3227 for (size_t i = 0; i != count(); ++i) {
3228 const internal::string& s = explanations[i];
3229 if (!s.empty()) {
3230 if (reason_printed) {
3231 *listener << ",\nand ";
3232 }
3233 *listener << "whose element #" << i << " matches, " << s;
3234 reason_printed = true;
3235 }
3236 }
3237 }
3238 return true;
3239 }
virtual bool MatchAndExplain(Container container, MatchResultListener *listener) const
static const_reference ConstReference(const RawContainer &container)
void PrintIfNotEmpty(const internal::string &explanation, ::std::ostream *os)
Here is the call graph for this function:

The documentation for this class was generated from the following file:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/external/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-matchers.h