summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkosak@google.com <kosak@google.com@8415998a-534a-0410-bf83-d39667b30386>2015-01-08 03:03:09 +0000
committerkosak@google.com <kosak@google.com@8415998a-534a-0410-bf83-d39667b30386>2015-01-08 03:03:09 +0000
commitf58eeabbfa2315313c822b9170217f8716ccd5c5 (patch)
treecaeeb19d2e1a04c16c23f0f46211a092c948f77f
parent3e00742ca740d5a29d65a2d9bc4ec7fd9911c875 (diff)
downloadgooglemock-f58eeabbfa2315313c822b9170217f8716ccd5c5.tar.gz
Make ReturnNull() support unique_ptr and shared_ptr.
git-svn-id: http://googlemock.googlecode.com/svn/trunk@504 8415998a-534a-0410-bf83-d39667b30386
-rw-r--r--include/gmock/gmock-actions.h8
-rw-r--r--test/gmock-actions_test.cc12
2 files changed, 19 insertions, 1 deletions
diff --git a/include/gmock/gmock-actions.h b/include/gmock/gmock-actions.h
index f92e479..46b7bf9 100644
--- a/include/gmock/gmock-actions.h
+++ b/include/gmock/gmock-actions.h
@@ -583,12 +583,18 @@ class ReturnAction {
// Implements the ReturnNull() action.
class ReturnNullAction {
public:
- // Allows ReturnNull() to be used in any pointer-returning function.
+ // Allows ReturnNull() to be used in any pointer-returning function. In C++11
+ // this is enforced by returning nullptr, and in non-C++11 by asserting a
+ // pointer type on compile time.
template <typename Result, typename ArgumentTuple>
static Result Perform(const ArgumentTuple&) {
+#if GTEST_LANG_CXX11
+ return nullptr;
+#else
GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value,
ReturnNull_can_be_used_to_return_a_pointer_only);
return NULL;
+#endif // GTEST_LANG_CXX11
}
};
diff --git a/test/gmock-actions_test.cc b/test/gmock-actions_test.cc
index 8089a81..a055194 100644
--- a/test/gmock-actions_test.cc
+++ b/test/gmock-actions_test.cc
@@ -604,6 +604,18 @@ TEST(ReturnNullTest, WorksInPointerReturningFunction) {
EXPECT_TRUE(a2.Perform(make_tuple(true)) == NULL);
}
+#if GTEST_HAS_STD_UNIQUE_PTR_
+// Tests that ReturnNull() returns NULL for shared_ptr and unique_ptr returning
+// functions.
+TEST(ReturnNullTest, WorksInSmartPointerReturningFunction) {
+ const Action<std::unique_ptr<const int>()> a1 = ReturnNull();
+ EXPECT_TRUE(a1.Perform(make_tuple()) == nullptr);
+
+ const Action<std::shared_ptr<int>(std::string)> a2 = ReturnNull();
+ EXPECT_TRUE(a2.Perform(make_tuple("foo")) == nullptr);
+}
+#endif // GTEST_HAS_STD_UNIQUE_PTR_
+
// Tests that ReturnRef(v) works for reference types.
TEST(ReturnRefTest, WorksForReference) {
const int n = 0;