aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock/test
diff options
context:
space:
mode:
Diffstat (limited to 'googlemock/test')
-rw-r--r--googlemock/test/BUILD.bazel52
-rw-r--r--googlemock/test/gmock-matchers_test.cc20
-rw-r--r--googlemock/test/gmock-nice-strict_test.cc23
3 files changed, 95 insertions, 0 deletions
diff --git a/googlemock/test/BUILD.bazel b/googlemock/test/BUILD.bazel
new file mode 100644
index 00000000..6e67f187
--- /dev/null
+++ b/googlemock/test/BUILD.bazel
@@ -0,0 +1,52 @@
+# Copyright 2017 Google Inc.
+# All Rights Reserved.
+#
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Author: misterg@google.com (Gennadiy Civil)
+#
+# Bazel Build for Google C++ Testing Framework(Google Test)-googlemock
+
+""" gmock own tests """
+
+cc_test(
+ name = "gmock_all_test",
+ size = "small",
+ srcs = glob(
+ include = [
+ "gmock-*.cc",
+ ],
+ ),
+ linkopts = select({
+ "//:win": [],
+ "//conditions:default": [
+ "-pthread",
+ ],
+ }),
+ deps = ["//:gtest"],
+)
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;