Googletest export

Introduce a new `Address` matcher to gmock.

PiperOrigin-RevId: 346344591
This commit is contained in:
Abseil Team
2020-12-08 12:37:32 -05:00
committed by Andy Getz
parent 8779937dd0
commit e5644f5f12
3 changed files with 92 additions and 0 deletions

View File

@@ -3787,6 +3787,46 @@ TEST(PointerTest, SmartPointerToConst) {
EXPECT_FALSE(m.Matches(p));
}
TEST(AddressTest, NonConst) {
int n = 1;
const Matcher<int> m = Address(Eq(&n));
EXPECT_TRUE(m.Matches(n));
int other = 5;
EXPECT_FALSE(m.Matches(other));
int& n_ref = n;
EXPECT_TRUE(m.Matches(n_ref));
}
TEST(AddressTest, Const) {
const int n = 1;
const Matcher<int> m = Address(Eq(&n));
EXPECT_TRUE(m.Matches(n));
int other = 5;
EXPECT_FALSE(m.Matches(other));
}
TEST(AddressTest, MatcherDoesntCopy) {
std::unique_ptr<int> n(new int(1));
const Matcher<std::unique_ptr<int>> m = Address(Eq(&n));
EXPECT_TRUE(m.Matches(n));
}
TEST(AddressTest, Describe) {
Matcher<int> matcher = Address(_);
EXPECT_EQ("has address that is anything", Describe(matcher));
EXPECT_EQ("does not have address that is anything",
DescribeNegation(matcher));
}
MATCHER_P(FieldIIs, inner_matcher, "") {
return ExplainMatchResult(inner_matcher, arg.i, result_listener);
}