Allows Field() and Property() to work when the matcher argument is a pointer passed by reference.

This commit is contained in:
zhanyong.wan
2010-01-13 05:15:07 +00:00
parent e122e457a6
commit 6953a725fc
2 changed files with 29 additions and 3 deletions

View File

@@ -2648,6 +2648,16 @@ TEST(FieldForPointerTest, WorksForPointerToNonConst) {
EXPECT_FALSE(m.Matches(&a));
}
// Tests that Field() works when the argument is a reference to a const pointer.
TEST(FieldForPointerTest, WorksForReferenceToConstPointer) {
Matcher<AStruct* const&> m = Field(&AStruct::x, Ge(0));
AStruct a;
EXPECT_TRUE(m.Matches(&a));
a.x = -1;
EXPECT_FALSE(m.Matches(&a));
}
// Tests that Field() does not match the NULL pointer.
TEST(FieldForPointerTest, DoesNotMatchNull) {
Matcher<const AStruct*> m = Field(&AStruct::x, _);
@@ -2846,6 +2856,19 @@ TEST(PropertyForPointerTest, WorksForPointerToNonConst) {
EXPECT_FALSE(m.Matches(&a));
}
// Tests that Property() works when the argument is a reference to a
// const pointer.
TEST(PropertyForPointerTest, WorksForReferenceToConstPointer) {
Matcher<AClass* const&> m = Property(&AClass::s, StartsWith("hi"));
AClass a;
a.set_s("hill");
EXPECT_TRUE(m.Matches(&a));
a.set_s("hole");
EXPECT_FALSE(m.Matches(&a));
}
// Tests that Property() does not match the NULL pointer.
TEST(PropertyForPointerTest, WorksForReferenceToNonConstProperty) {
Matcher<const AClass*> m = Property(&AClass::x, _);