merging gmock-matchers.h 2

This commit is contained in:
Gennadiy Civil 2018-03-26 10:16:59 -04:00
parent 8ea10d3878
commit 23187058e7

View File

@ -2862,6 +2862,10 @@ class WhenSortedByMatcher {
// container and the RHS container respectively. // container and the RHS container respectively.
template <typename TupleMatcher, typename RhsContainer> template <typename TupleMatcher, typename RhsContainer>
class PointwiseMatcher { class PointwiseMatcher {
GTEST_COMPILE_ASSERT_(
!IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>::value,
use_UnorderedPointwise_with_hash_tables);
public: public:
typedef internal::StlContainerView<RhsContainer> RhsView; typedef internal::StlContainerView<RhsContainer> RhsView;
typedef typename RhsView::type RhsStlContainer; typedef typename RhsView::type RhsStlContainer;
@ -2879,6 +2883,10 @@ class PointwiseMatcher {
template <typename LhsContainer> template <typename LhsContainer>
operator Matcher<LhsContainer>() const { operator Matcher<LhsContainer>() const {
GTEST_COMPILE_ASSERT_(
!IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)>::value,
use_UnorderedPointwise_with_hash_tables);
return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_)); return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_));
} }
@ -2929,12 +2937,15 @@ class PointwiseMatcher {
typename LhsStlContainer::const_iterator left = lhs_stl_container.begin(); typename LhsStlContainer::const_iterator left = lhs_stl_container.begin();
typename RhsStlContainer::const_iterator right = rhs_.begin(); typename RhsStlContainer::const_iterator right = rhs_.begin();
for (size_t i = 0; i != actual_size; ++i, ++left, ++right) { for (size_t i = 0; i != actual_size; ++i, ++left, ++right) {
const InnerMatcherArg value_pair(*left, *right);
if (listener->IsInterested()) { if (listener->IsInterested()) {
StringMatchResultListener inner_listener; StringMatchResultListener inner_listener;
// Create InnerMatcherArg as a temporarily object to avoid it outlives
// *left and *right. Dereference or the conversion to `const T&` may
// return temp objects, e.g for vector<bool>.
if (!mono_tuple_matcher_.MatchAndExplain( if (!mono_tuple_matcher_.MatchAndExplain(
value_pair, &inner_listener)) { InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
ImplicitCast_<const RhsValue&>(*right)),
&inner_listener)) {
*listener << "where the value pair ("; *listener << "where the value pair (";
UniversalPrint(*left, listener->stream()); UniversalPrint(*left, listener->stream());
*listener << ", "; *listener << ", ";
@ -2944,7 +2955,9 @@ class PointwiseMatcher {
return false; return false;
} }
} else { } else {
if (!mono_tuple_matcher_.Matches(value_pair)) if (!mono_tuple_matcher_.Matches(
InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
ImplicitCast_<const RhsValue&>(*right))))
return false; return false;
} }
} }
@ -3166,8 +3179,8 @@ class KeyMatcherImpl : public MatcherInterface<PairType> {
virtual bool MatchAndExplain(PairType key_value, virtual bool MatchAndExplain(PairType key_value,
MatchResultListener* listener) const { MatchResultListener* listener) const {
StringMatchResultListener inner_listener; StringMatchResultListener inner_listener;
const bool match = inner_matcher_.MatchAndExplain(key_value.first, const bool match = inner_matcher_.MatchAndExplain(
&inner_listener); pair_getters::First(key_value, Rank0()), &inner_listener);
const std::string explanation = inner_listener.str(); const std::string explanation = inner_listener.str();
if (explanation != "") { if (explanation != "") {
*listener << "whose first field is a value " << explanation; *listener << "whose first field is a value " << explanation;
@ -3708,6 +3721,11 @@ class ElementsAreMatcher {
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
GTEST_COMPILE_ASSERT_(
!IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value ||
::testing::tuple_size<MatcherTuple>::value < 2,
use_UnorderedElementsAre_with_hash_tables);
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type View; typedef typename internal::StlContainerView<RawContainer>::type View;
typedef typename View::value_type Element; typedef typename View::value_type Element;
@ -3756,6 +3774,10 @@ class ElementsAreArrayMatcher {
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
GTEST_COMPILE_ASSERT_(
!IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value,
use_UnorderedElementsAreArray_with_hash_tables);
return MakeMatcher(new ElementsAreMatcherImpl<Container>( return MakeMatcher(new ElementsAreMatcherImpl<Container>(
matchers_.begin(), matchers_.end())); matchers_.begin(), matchers_.end()));
} }
@ -3953,7 +3975,7 @@ class VariantMatcher {
} }
private: private:
static string GetTypeName() { static std::string GetTypeName() {
#if GTEST_HAS_RTTI #if GTEST_HAS_RTTI
return internal::GetTypeName<T>(); return internal::GetTypeName<T>();
#endif #endif
@ -4351,6 +4373,21 @@ Property(PropertyType (Class::*property)() const,
// to compile where bar() returns an int32 and m is a matcher for int64. // to compile where bar() returns an int32 and m is a matcher for int64.
} }
// Same as Property() above, but also takes the name of the property to provide
// better error messages.
template <typename Class, typename PropertyType, typename PropertyMatcher>
inline PolymorphicMatcher<internal::PropertyMatcher<
Class, PropertyType, PropertyType (Class::*)() const> >
Property(const std::string& property_name,
PropertyType (Class::*property)() const,
const PropertyMatcher& matcher) {
return MakePolymorphicMatcher(
internal::PropertyMatcher<Class, PropertyType,
PropertyType (Class::*)() const>(
property_name, property,
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
}
#if GTEST_LANG_CXX11 #if GTEST_LANG_CXX11
// The same as above but for reference-qualified member functions. // The same as above but for reference-qualified member functions.
template <typename Class, typename PropertyType, typename PropertyMatcher> template <typename Class, typename PropertyType, typename PropertyMatcher>