Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
34b034c2
Commit
34b034c2
authored
Mar 05, 2010
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds a free function MatchAndExplain().
parent
5905ba00
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
gmock-matchers.h
include/gmock/gmock-matchers.h
+8
-0
gmock-matchers_test.cc
test/gmock-matchers_test.cc
+26
-2
No files found.
include/gmock/gmock-matchers.h
View file @
34b034c2
...
@@ -2850,6 +2850,14 @@ inline bool Value(const T& value, M matcher) {
...
@@ -2850,6 +2850,14 @@ inline bool Value(const T& value, M matcher) {
return
testing
::
Matches
(
matcher
)(
value
);
return
testing
::
Matches
(
matcher
)(
value
);
}
}
// Matches the value against the given matcher and explains the match
// result to listener.
template
<
typename
T
,
typename
M
>
inline
bool
MatchAndExplain
(
M
matcher
,
const
T
&
value
,
MatchResultListener
*
listener
)
{
return
SafeMatcherCast
<
const
T
&>
(
matcher
).
MatchAndExplain
(
value
,
listener
);
}
// AllArgs(m) is a synonym of m. This is useful in
// AllArgs(m) is a synonym of m. This is useful in
//
//
// EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
// EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
...
...
test/gmock-matchers_test.cc
View file @
34b034c2
...
@@ -88,6 +88,7 @@ using testing::Matcher;
...
@@ -88,6 +88,7 @@ using testing::Matcher;
using
testing
::
MatcherCast
;
using
testing
::
MatcherCast
;
using
testing
::
MatcherInterface
;
using
testing
::
MatcherInterface
;
using
testing
::
Matches
;
using
testing
::
Matches
;
using
testing
::
MatchAndExplain
;
using
testing
::
MatchResultListener
;
using
testing
::
MatchResultListener
;
using
testing
::
NanSensitiveDoubleEq
;
using
testing
::
NanSensitiveDoubleEq
;
using
testing
::
NanSensitiveFloatEq
;
using
testing
::
NanSensitiveFloatEq
;
...
@@ -118,6 +119,7 @@ using testing::internal::JoinAsTuple;
...
@@ -118,6 +119,7 @@ using testing::internal::JoinAsTuple;
using
testing
::
internal
::
SkipPrefix
;
using
testing
::
internal
::
SkipPrefix
;
using
testing
::
internal
::
String
;
using
testing
::
internal
::
String
;
using
testing
::
internal
::
Strings
;
using
testing
::
internal
::
Strings
;
using
testing
::
internal
::
StringMatchResultListener
;
using
testing
::
internal
::
ValidateMatcherDescription
;
using
testing
::
internal
::
ValidateMatcherDescription
;
using
testing
::
internal
::
kInvalidInterpolation
;
using
testing
::
internal
::
kInvalidInterpolation
;
using
testing
::
internal
::
kPercentInterpolation
;
using
testing
::
internal
::
kPercentInterpolation
;
...
@@ -287,11 +289,11 @@ TEST(MatcherTest, CanDescribeItself) {
...
@@ -287,11 +289,11 @@ TEST(MatcherTest, CanDescribeItself) {
// Tests Matcher<T>::MatchAndExplain().
// Tests Matcher<T>::MatchAndExplain().
TEST
(
MatcherTest
,
MatchAndExplain
)
{
TEST
(
MatcherTest
,
MatchAndExplain
)
{
Matcher
<
int
>
m
=
GreaterThan
(
0
);
Matcher
<
int
>
m
=
GreaterThan
(
0
);
::
testing
::
internal
::
StringMatchResultListener
listener1
;
StringMatchResultListener
listener1
;
EXPECT_TRUE
(
m
.
MatchAndExplain
(
42
,
&
listener1
));
EXPECT_TRUE
(
m
.
MatchAndExplain
(
42
,
&
listener1
));
EXPECT_EQ
(
"is 42 more than 0"
,
listener1
.
str
());
EXPECT_EQ
(
"is 42 more than 0"
,
listener1
.
str
());
::
testing
::
internal
::
StringMatchResultListener
listener2
;
StringMatchResultListener
listener2
;
EXPECT_FALSE
(
m
.
MatchAndExplain
(
-
9
,
&
listener2
));
EXPECT_FALSE
(
m
.
MatchAndExplain
(
-
9
,
&
listener2
));
EXPECT_EQ
(
"is 9 less than 0"
,
listener2
.
str
());
EXPECT_EQ
(
"is 9 less than 0"
,
listener2
.
str
());
}
}
...
@@ -2047,6 +2049,28 @@ TEST(ValueTest, WorksWithMonomorphicMatcher) {
...
@@ -2047,6 +2049,28 @@ TEST(ValueTest, WorksWithMonomorphicMatcher) {
EXPECT_FALSE
(
Value
(
1
,
ref_n
));
EXPECT_FALSE
(
Value
(
1
,
ref_n
));
}
}
TEST
(
MatchAndExplainTest
,
WorksWithPolymorphicMatcher
)
{
StringMatchResultListener
listener1
;
EXPECT_TRUE
(
MatchAndExplain
(
PolymorphicIsEven
(),
42
,
&
listener1
));
EXPECT_EQ
(
"% 2 == 0"
,
listener1
.
str
());
StringMatchResultListener
listener2
;
EXPECT_FALSE
(
MatchAndExplain
(
Ge
(
42
),
1.5
,
&
listener2
));
EXPECT_EQ
(
""
,
listener2
.
str
());
}
TEST
(
MatchAndExplainTest
,
WorksWithMonomorphicMatcher
)
{
const
Matcher
<
int
>
is_even
=
PolymorphicIsEven
();
StringMatchResultListener
listener1
;
EXPECT_TRUE
(
MatchAndExplain
(
is_even
,
42
,
&
listener1
));
EXPECT_EQ
(
"% 2 == 0"
,
listener1
.
str
());
const
Matcher
<
const
double
&>
is_zero
=
Eq
(
0
);
StringMatchResultListener
listener2
;
EXPECT_FALSE
(
MatchAndExplain
(
is_zero
,
1.5
,
&
listener2
));
EXPECT_EQ
(
""
,
listener2
.
str
());
}
TEST
(
AllArgsTest
,
WorksForTuple
)
{
TEST
(
AllArgsTest
,
WorksForTuple
)
{
EXPECT_THAT
(
make_tuple
(
1
,
2L
),
AllArgs
(
Lt
()));
EXPECT_THAT
(
make_tuple
(
1
,
2L
),
AllArgs
(
Lt
()));
EXPECT_THAT
(
make_tuple
(
2L
,
1
),
Not
(
AllArgs
(
Lt
())));
EXPECT_THAT
(
make_tuple
(
2L
,
1
),
Not
(
AllArgs
(
Lt
())));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment