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
8d3dc0cd
Commit
8d3dc0cd
authored
Apr 14, 2011
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplifies TrulyMatcher and adds a test for it
parent
8d7c5ad6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
9 deletions
+32
-9
gmock-matchers.h
include/gmock/gmock-matchers.h
+9
-9
gmock-matchers_test.cc
test/gmock-matchers_test.cc
+23
-0
No files found.
include/gmock/gmock-matchers.h
View file @
8d3dc0cd
...
@@ -1392,15 +1392,15 @@ class TrulyMatcher {
...
@@ -1392,15 +1392,15 @@ class TrulyMatcher {
template
<
typename
T
>
template
<
typename
T
>
bool
MatchAndExplain
(
T
&
x
,
// NOLINT
bool
MatchAndExplain
(
T
&
x
,
// NOLINT
MatchResultListener
*
/* listener */
)
const
{
MatchResultListener
*
/* listener */
)
const
{
#ifdef _MSC_VER
// Without the if-statement, MSVC sometimes warns about converting
//
MSVC warns about converting a value in
to bool (warning 4800).
//
a value
to bool (warning 4800).
# pragma warning(push) // Saves the current warning state.
//
# pragma warning(disable:4800) // Temporarily disables warning 4800.
// We cannot write 'return !!predicate_(x);' as that doesn't work
#endif
// when predicate_(x) returns a class convertible to bool but
return
predicate_
(
x
);
// having no operator!().
#ifdef _MSC_VER
if
(
predicate_
(
x
))
# pragma warning(pop) // Restores the warning state.
return
true
;
#endif
return
false
;
}
}
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
...
...
test/gmock-matchers_test.cc
View file @
8d3dc0cd
...
@@ -2256,6 +2256,29 @@ TEST(TrulyTest, CanBeUsedWithFunctor) {
...
@@ -2256,6 +2256,29 @@ TEST(TrulyTest, CanBeUsedWithFunctor) {
EXPECT_FALSE
(
m
.
Matches
(
4
));
EXPECT_FALSE
(
m
.
Matches
(
4
));
}
}
// A class that can be implicitly converted to bool.
class
ConvertibleToBool
{
public
:
explicit
ConvertibleToBool
(
int
number
)
:
number_
(
number
)
{}
operator
bool
()
const
{
return
number_
!=
0
;
}
private
:
int
number_
;
};
ConvertibleToBool
IsNotZero
(
int
number
)
{
return
ConvertibleToBool
(
number
);
}
// Tests that the predicate used in Truly() may return a class that's
// implicitly convertible to bool, even when the class has no
// operator!().
TEST
(
TrulyTest
,
PredicateCanReturnAClassConvertibleToBool
)
{
Matcher
<
int
>
m
=
Truly
(
IsNotZero
);
EXPECT_TRUE
(
m
.
Matches
(
1
));
EXPECT_FALSE
(
m
.
Matches
(
0
));
}
// Tests that Truly(predicate) can describe itself properly.
// Tests that Truly(predicate) can describe itself properly.
TEST
(
TrulyTest
,
CanDescribeSelf
)
{
TEST
(
TrulyTest
,
CanDescribeSelf
)
{
Matcher
<
double
>
m
=
Truly
(
IsPositive
);
Matcher
<
double
>
m
=
Truly
(
IsPositive
);
...
...
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