diff options
author | Gennadiy Civil <gennadiycivil@users.noreply.github.com> | 2017-08-22 23:20:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-22 23:20:53 -0400 |
commit | 79cdf971fbf8f1efb1573df97bcc6f5e8ef3215a (patch) | |
tree | 17c4a91302a4e58a11042726ef622b9430d1ff56 /googlemock/test | |
parent | f52c95dae48bc954efb3d98692a394948d5fe49e (diff) | |
parent | 863e02644b57cebe2bb3ee87bffee17127fc02d7 (diff) | |
download | googletest-79cdf971fbf8f1efb1573df97bcc6f5e8ef3215a.tar.gz googletest-79cdf971fbf8f1efb1573df97bcc6f5e8ef3215a.tar.bz2 googletest-79cdf971fbf8f1efb1573df97bcc6f5e8ef3215a.zip |
Merge branch 'master' into bazel
Diffstat (limited to 'googlemock/test')
-rw-r--r-- | googlemock/test/gmock-matchers_test.cc | 20 | ||||
-rw-r--r-- | googlemock/test/gmock-nice-strict_test.cc | 23 |
2 files changed, 43 insertions, 0 deletions
diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index f5ab7c81..fc867487 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -3588,10 +3588,15 @@ class AClass { // A getter that returns a reference to const. 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; } // A getter that returns a reference to non-const. double& x() const { return x_; } + private: int n_; std::string s_; @@ -3635,6 +3640,21 @@ TEST(PropertyTest, WorksForReferenceToConstProperty) { 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() // returns a reference to non-const. TEST(PropertyTest, WorksForReferenceToNonConstProperty) { diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 5d6ccc4f..0eac6439 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -62,6 +62,12 @@ using testing::internal::CaptureStdout; using testing::internal::GetCapturedStdout; #endif +// Class without default constructor. +class NotDefaultConstructible { + public: + explicit NotDefaultConstructible(int) {} +}; + // Defines some mock classes needed by the tests. class Foo { @@ -79,6 +85,7 @@ class MockFoo : public Foo { MOCK_METHOD0(DoThis, void()); MOCK_METHOD1(DoThat, int(bool flag)); + MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible()); private: GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo); @@ -207,6 +214,22 @@ TEST(NiceMockTest, AllowsExpectedCall) { 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. TEST(NiceMockTest, UnexpectedCallFails) { NiceMock<MockFoo> nice_foo; |