aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorkosak <kosak@google.com>2013-12-03 01:43:07 +0000
committerkosak <kosak@google.com>2013-12-03 01:43:07 +0000
commit5f2a6ca4fd5e1ab6330be758ea88bfe778af2b77 (patch)
tree9cc89e97215c60ce4954cd5c7982d6a9fd0af29d /test
parent88080ee943b2b769557488e9c60850da96ab839e (diff)
downloadgoogletest-5f2a6ca4fd5e1ab6330be758ea88bfe778af2b77.tar.gz
googletest-5f2a6ca4fd5e1ab6330be758ea88bfe778af2b77.tar.bz2
googletest-5f2a6ca4fd5e1ab6330be758ea88bfe778af2b77.zip
Don't copy the argument in SafeMatcherCast because it's not safe.
Diffstat (limited to 'test')
-rw-r--r--test/gmock-matchers_test.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc
index 4ce1e4a5..5de45c78 100644
--- a/test/gmock-matchers_test.cc
+++ b/test/gmock-matchers_test.cc
@@ -636,6 +636,22 @@ TEST(MatcherCastTest, FromConvertibleFromAny) {
EXPECT_FALSE(m.Matches(ConvertibleFromAny(2)));
}
+struct IntReferenceWrapper {
+ IntReferenceWrapper(const int& a_value) : value(&a_value) {}
+ const int* value;
+};
+
+bool operator==(const IntReferenceWrapper& a, const IntReferenceWrapper& b) {
+ return a.value == b.value;
+}
+
+TEST(MatcherCastTest, ValueIsNotCopied) {
+ int n = 42;
+ Matcher<IntReferenceWrapper> m = MatcherCast<IntReferenceWrapper>(n);
+ // Verify that the matcher holds a reference to n, not to its temporary copy.
+ EXPECT_TRUE(m.Matches(n));
+}
+
class Base {};
class Derived : public Base {};
@@ -724,6 +740,13 @@ TEST(SafeMatcherCastTest, FromConvertibleFromAny) {
EXPECT_FALSE(m.Matches(ConvertibleFromAny(2)));
}
+TEST(SafeMatcherCastTest, ValueIsNotCopied) {
+ int n = 42;
+ Matcher<IntReferenceWrapper> m = SafeMatcherCast<IntReferenceWrapper>(n);
+ // Verify that the matcher holds a reference to n, not to its temporary copy.
+ EXPECT_TRUE(m.Matches(n));
+}
+
// Tests that A<T>() matches any value of type T.
TEST(ATest, MatchesAnyValue) {
// Tests a matcher for a value type.