Merge branch 'master' into bazel
This commit is contained in:
commit
79cdf971fb
|
@ -2232,7 +2232,10 @@ class FieldMatcher {
|
||||||
|
|
||||||
// Implements the Property() matcher for matching a property
|
// Implements the Property() matcher for matching a property
|
||||||
// (i.e. return value of a getter method) of an object.
|
// (i.e. return value of a getter method) of an object.
|
||||||
template <typename Class, typename PropertyType>
|
//
|
||||||
|
// Property is a const-qualified member function of Class returning
|
||||||
|
// PropertyType.
|
||||||
|
template <typename Class, typename PropertyType, typename Property>
|
||||||
class PropertyMatcher {
|
class PropertyMatcher {
|
||||||
public:
|
public:
|
||||||
// The property may have a reference type, so 'const PropertyType&'
|
// The property may have a reference type, so 'const PropertyType&'
|
||||||
|
@ -2241,8 +2244,7 @@ class PropertyMatcher {
|
||||||
// PropertyType being a reference or not.
|
// PropertyType being a reference or not.
|
||||||
typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty;
|
typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty;
|
||||||
|
|
||||||
PropertyMatcher(PropertyType (Class::*property)() const,
|
PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher)
|
||||||
const Matcher<RefToConstProperty>& matcher)
|
|
||||||
: property_(property), matcher_(matcher) {}
|
: property_(property), matcher_(matcher) {}
|
||||||
|
|
||||||
void DescribeTo(::std::ostream* os) const {
|
void DescribeTo(::std::ostream* os) const {
|
||||||
|
@ -2295,7 +2297,7 @@ class PropertyMatcher {
|
||||||
return MatchAndExplainImpl(false_type(), *p, listener);
|
return MatchAndExplainImpl(false_type(), *p, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyType (Class::*property_)() const;
|
Property property_;
|
||||||
const Matcher<RefToConstProperty> matcher_;
|
const Matcher<RefToConstProperty> matcher_;
|
||||||
|
|
||||||
GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
|
GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
|
||||||
|
@ -3908,11 +3910,13 @@ inline PolymorphicMatcher<
|
||||||
// Property(&Foo::str, StartsWith("hi"))
|
// Property(&Foo::str, StartsWith("hi"))
|
||||||
// matches a Foo object x iff x.str() starts with "hi".
|
// matches a Foo object x iff x.str() starts with "hi".
|
||||||
template <typename Class, typename PropertyType, typename PropertyMatcher>
|
template <typename Class, typename PropertyType, typename PropertyMatcher>
|
||||||
inline PolymorphicMatcher<
|
inline PolymorphicMatcher<internal::PropertyMatcher<
|
||||||
internal::PropertyMatcher<Class, PropertyType> > Property(
|
Class, PropertyType, PropertyType (Class::*)() const> >
|
||||||
PropertyType (Class::*property)() const, const PropertyMatcher& matcher) {
|
Property(PropertyType (Class::*property)() const,
|
||||||
|
const PropertyMatcher& matcher) {
|
||||||
return MakePolymorphicMatcher(
|
return MakePolymorphicMatcher(
|
||||||
internal::PropertyMatcher<Class, PropertyType>(
|
internal::PropertyMatcher<Class, PropertyType,
|
||||||
|
PropertyType (Class::*)() const>(
|
||||||
property,
|
property,
|
||||||
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
|
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
|
||||||
// The call to MatcherCast() is required for supporting inner
|
// The call to MatcherCast() is required for supporting inner
|
||||||
|
@ -3921,6 +3925,21 @@ inline PolymorphicMatcher<
|
||||||
// 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.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GTEST_LANG_CXX11
|
||||||
|
// The same as above but for reference-qualified member functions.
|
||||||
|
template <typename Class, typename PropertyType, typename PropertyMatcher>
|
||||||
|
inline PolymorphicMatcher<internal::PropertyMatcher<
|
||||||
|
Class, PropertyType, PropertyType (Class::*)() const &> >
|
||||||
|
Property(PropertyType (Class::*property)() const &,
|
||||||
|
const PropertyMatcher& matcher) {
|
||||||
|
return MakePolymorphicMatcher(
|
||||||
|
internal::PropertyMatcher<Class, PropertyType,
|
||||||
|
PropertyType (Class::*)() const &>(
|
||||||
|
property,
|
||||||
|
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Creates a matcher that matches an object iff the result of applying
|
// Creates a matcher that matches an object iff the result of applying
|
||||||
// a callable to x matches 'matcher'.
|
// a callable to x matches 'matcher'.
|
||||||
// For example,
|
// For example,
|
||||||
|
|
|
@ -364,7 +364,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
|
||||||
|
|
||||||
if (!need_to_report_uninteresting_call) {
|
if (!need_to_report_uninteresting_call) {
|
||||||
// Perform the action without printing the call information.
|
// Perform the action without printing the call information.
|
||||||
return this->UntypedPerformDefaultAction(untyped_args, "");
|
return this->UntypedPerformDefaultAction(untyped_args, "Function call: " + std::string(Name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warns about the uninteresting call.
|
// Warns about the uninteresting call.
|
||||||
|
|
|
@ -3588,10 +3588,15 @@ class AClass {
|
||||||
// A getter that returns a reference to const.
|
// A getter that returns a reference to const.
|
||||||
const std::string& s() const { return s_; }
|
const std::string& s() const { return s_; }
|
||||||
|
|
||||||
|
#if GTEST_LANG_CXX11
|
||||||
|
const std::string& s_ref() const & { return s_; }
|
||||||
|
#endif
|
||||||
|
|
||||||
void set_s(const std::string& new_s) { s_ = new_s; }
|
void set_s(const std::string& new_s) { s_ = new_s; }
|
||||||
|
|
||||||
// A getter that returns a reference to non-const.
|
// A getter that returns a reference to non-const.
|
||||||
double& x() const { return x_; }
|
double& x() const { return x_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int n_;
|
int n_;
|
||||||
std::string s_;
|
std::string s_;
|
||||||
|
@ -3635,6 +3640,21 @@ TEST(PropertyTest, WorksForReferenceToConstProperty) {
|
||||||
EXPECT_FALSE(m.Matches(a));
|
EXPECT_FALSE(m.Matches(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GTEST_LANG_CXX11
|
||||||
|
// Tests that Property(&Foo::property, ...) works when property() is
|
||||||
|
// ref-qualified.
|
||||||
|
TEST(PropertyTest, WorksForRefQualifiedProperty) {
|
||||||
|
Matcher<const AClass&> m = Property(&AClass::s_ref, StartsWith("hi"));
|
||||||
|
|
||||||
|
AClass a;
|
||||||
|
a.set_s("hill");
|
||||||
|
EXPECT_TRUE(m.Matches(a));
|
||||||
|
|
||||||
|
a.set_s("hole");
|
||||||
|
EXPECT_FALSE(m.Matches(a));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Tests that Property(&Foo::property, ...) works when property()
|
// Tests that Property(&Foo::property, ...) works when property()
|
||||||
// returns a reference to non-const.
|
// returns a reference to non-const.
|
||||||
TEST(PropertyTest, WorksForReferenceToNonConstProperty) {
|
TEST(PropertyTest, WorksForReferenceToNonConstProperty) {
|
||||||
|
|
|
@ -62,6 +62,12 @@ using testing::internal::CaptureStdout;
|
||||||
using testing::internal::GetCapturedStdout;
|
using testing::internal::GetCapturedStdout;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Class without default constructor.
|
||||||
|
class NotDefaultConstructible {
|
||||||
|
public:
|
||||||
|
explicit NotDefaultConstructible(int) {}
|
||||||
|
};
|
||||||
|
|
||||||
// Defines some mock classes needed by the tests.
|
// Defines some mock classes needed by the tests.
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
|
@ -79,6 +85,7 @@ class MockFoo : public Foo {
|
||||||
|
|
||||||
MOCK_METHOD0(DoThis, void());
|
MOCK_METHOD0(DoThis, void());
|
||||||
MOCK_METHOD1(DoThat, int(bool flag));
|
MOCK_METHOD1(DoThat, int(bool flag));
|
||||||
|
MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
|
||||||
|
@ -207,6 +214,22 @@ TEST(NiceMockTest, AllowsExpectedCall) {
|
||||||
nice_foo.DoThis();
|
nice_foo.DoThis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests that an unexpected call on a nice mock which returns a not-default-constructible
|
||||||
|
// type throws an exception and the exception contains the method's name.
|
||||||
|
TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) {
|
||||||
|
NiceMock<MockFoo> nice_foo;
|
||||||
|
#if GTEST_HAS_EXCEPTIONS
|
||||||
|
try {
|
||||||
|
nice_foo.ReturnNonDefaultConstructible();
|
||||||
|
FAIL();
|
||||||
|
} catch (const std::runtime_error& ex) {
|
||||||
|
EXPECT_THAT(ex.what(), HasSubstr("ReturnNonDefaultConstructible"));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
EXPECT_DEATH_IF_SUPPORTED({ nice_foo.ReturnNonDefaultConstructible(); }, "");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Tests that an unexpected call on a nice mock fails.
|
// Tests that an unexpected call on a nice mock fails.
|
||||||
TEST(NiceMockTest, UnexpectedCallFails) {
|
TEST(NiceMockTest, UnexpectedCallFails) {
|
||||||
NiceMock<MockFoo> nice_foo;
|
NiceMock<MockFoo> nice_foo;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user