summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkosak@google.com <kosak@google.com@8415998a-534a-0410-bf83-d39667b30386>2015-04-28 22:36:31 +0000
committerkosak@google.com <kosak@google.com@8415998a-534a-0410-bf83-d39667b30386>2015-04-28 22:36:31 +0000
commit8c791542b10da35a1b439e999786c4b006943ce5 (patch)
tree24c9b7b5a78b756ceb6bca09336124c403a03703
parent595e1ae06f27440309e48f678dab5537ebcaf930 (diff)
downloadgooglemock-8c791542b10da35a1b439e999786c4b006943ce5.tar.gz
Change IsNull and NotNull to use ==/!= nullptr in C++11.
Also update gmock_doctor due to Clang wording change. git-svn-id: http://googlemock.googlecode.com/svn/trunk@518 8415998a-534a-0410-bf83-d39667b30386
-rw-r--r--include/gmock/gmock-matchers.h8
-rwxr-xr-xscripts/gmock_doctor.py2
-rw-r--r--test/gmock-matchers_test.cc18
3 files changed, 27 insertions, 1 deletions
diff --git a/include/gmock/gmock-matchers.h b/include/gmock/gmock-matchers.h
index 6450f9b..822337b 100644
--- a/include/gmock/gmock-matchers.h
+++ b/include/gmock/gmock-matchers.h
@@ -979,7 +979,11 @@ class IsNullMatcher {
template <typename Pointer>
bool MatchAndExplain(const Pointer& p,
MatchResultListener* /* listener */) const {
+#if GTEST_LANG_CXX11
+ return p == nullptr;
+#else // GTEST_LANG_CXX11
return GetRawPointer(p) == NULL;
+#endif // GTEST_LANG_CXX11
}
void DescribeTo(::std::ostream* os) const { *os << "is NULL"; }
@@ -995,7 +999,11 @@ class NotNullMatcher {
template <typename Pointer>
bool MatchAndExplain(const Pointer& p,
MatchResultListener* /* listener */) const {
+#if GTEST_LANG_CXX11
+ return p != nullptr;
+#else // GTEST_LANG_CXX11
return GetRawPointer(p) != NULL;
+#endif // GTEST_LANG_CXX11
}
void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; }
diff --git a/scripts/gmock_doctor.py b/scripts/gmock_doctor.py
index e6e6a52..c6a8a90 100755
--- a/scripts/gmock_doctor.py
+++ b/scripts/gmock_doctor.py
@@ -362,7 +362,7 @@ def _MockObjectPointerDiagnoser(msg):
r'which is of non-class type \'(.*::)*(?P<class_name>.+)\*\'')
clang_regex = (_CLANG_FILE_LINE_RE + r'error: member reference type '
r'\'(?P<class_name>.*?) *\' is a pointer; '
- r'maybe you meant to use \'->\'\?')
+ r'(did you mean|maybe you meant) to use \'->\'\?')
diagnosis = """
The first argument to ON_CALL() and EXPECT_CALL() must be a mock *object*,
not a *pointer* to it. Please write '*(%(mock_object)s)' instead of
diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc
index be2e900..494c85f 100644
--- a/test/gmock-matchers_test.cc
+++ b/test/gmock-matchers_test.cc
@@ -1025,6 +1025,15 @@ TEST(IsNullTest, ReferenceToConstLinkedPtr) {
EXPECT_FALSE(m.Matches(non_null_p));
}
+#if GTEST_LANG_CXX11
+TEST(IsNullTest, StdFunction) {
+ const Matcher<std::function<void()>> m = IsNull();
+
+ EXPECT_TRUE(m.Matches(std::function<void()>()));
+ EXPECT_FALSE(m.Matches([]{}));
+}
+#endif // GTEST_LANG_CXX11
+
TEST(IsNullTest, ReferenceToConstScopedPtr) {
const Matcher<const scoped_ptr<double>&> m = IsNull();
const scoped_ptr<double> null_p;
@@ -1073,6 +1082,15 @@ TEST(NotNullTest, ReferenceToConstLinkedPtr) {
EXPECT_TRUE(m.Matches(non_null_p));
}
+#if GTEST_LANG_CXX11
+TEST(NotNullTest, StdFunction) {
+ const Matcher<std::function<void()>> m = NotNull();
+
+ EXPECT_TRUE(m.Matches([]{}));
+ EXPECT_FALSE(m.Matches(std::function<void()>()));
+}
+#endif // GTEST_LANG_CXX11
+
TEST(NotNullTest, ReferenceToConstScopedPtr) {
const Matcher<const scoped_ptr<double>&> m = NotNull();
const scoped_ptr<double> null_p;