Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
79b83505
Commit
79b83505
authored
Nov 18, 2009
by
vladlosev
Browse files
Updates IsNull and NotNull matchers to work with smart pointers.
parent
a63be0bd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
6 deletions
+43
-6
include/gmock/gmock-matchers.h
include/gmock/gmock-matchers.h
+6
-6
test/gmock-matchers_test.cc
test/gmock-matchers_test.cc
+37
-0
No files found.
include/gmock/gmock-matchers.h
View file @
79b83505
...
@@ -633,12 +633,12 @@ GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ne, !=, "not equal to");
...
@@ -633,12 +633,12 @@ GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ne, !=, "not equal to");
#undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_
#undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_
// Implements the polymorphic IsNull() matcher, which matches any
// Implements the polymorphic IsNull() matcher, which matches any
raw or smart
// pointer that is NULL.
// pointer that is NULL.
class
IsNullMatcher
{
class
IsNullMatcher
{
public:
public:
template
<
typename
T
>
template
<
typename
Pointer
>
bool
Matches
(
T
*
p
)
const
{
return
p
==
NULL
;
}
bool
Matches
(
const
Pointer
&
p
)
const
{
return
GetRawPointer
(
p
)
==
NULL
;
}
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"is NULL"
;
}
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"is NULL"
;
}
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
...
@@ -646,12 +646,12 @@ class IsNullMatcher {
...
@@ -646,12 +646,12 @@ class IsNullMatcher {
}
}
};
};
// Implements the polymorphic NotNull() matcher, which matches any
// Implements the polymorphic NotNull() matcher, which matches any
raw or smart
// pointer that is not NULL.
// pointer that is not NULL.
class
NotNullMatcher
{
class
NotNullMatcher
{
public:
public:
template
<
typename
T
>
template
<
typename
Pointer
>
bool
Matches
(
T
*
p
)
const
{
return
p
!=
NULL
;
}
bool
Matches
(
const
Pointer
&
p
)
const
{
return
GetRawPointer
(
p
)
!=
NULL
;
}
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"is not NULL"
;
}
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"is not NULL"
;
}
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
...
...
test/gmock-matchers_test.cc
View file @
79b83505
...
@@ -121,6 +121,7 @@ using testing::internal::ValidateMatcherDescription;
...
@@ -121,6 +121,7 @@ using testing::internal::ValidateMatcherDescription;
using
testing
::
internal
::
kInvalidInterpolation
;
using
testing
::
internal
::
kInvalidInterpolation
;
using
testing
::
internal
::
kPercentInterpolation
;
using
testing
::
internal
::
kPercentInterpolation
;
using
testing
::
internal
::
kTupleInterpolation
;
using
testing
::
internal
::
kTupleInterpolation
;
using
testing
::
internal
::
linked_ptr
;
using
testing
::
internal
::
string
;
using
testing
::
internal
::
string
;
#ifdef GMOCK_HAS_REGEX
#ifdef GMOCK_HAS_REGEX
...
@@ -715,6 +716,24 @@ TEST(IsNullTest, MatchesNullPointer) {
...
@@ -715,6 +716,24 @@ TEST(IsNullTest, MatchesNullPointer) {
#endif
#endif
}
}
TEST
(
IsNullTest
,
LinkedPtr
)
{
const
Matcher
<
linked_ptr
<
int
>
>
m
=
IsNull
();
const
linked_ptr
<
int
>
null_p
;
const
linked_ptr
<
int
>
non_null_p
(
new
int
);
EXPECT_TRUE
(
m
.
Matches
(
null_p
));
EXPECT_FALSE
(
m
.
Matches
(
non_null_p
));
}
TEST
(
IsNullTest
,
ReferenceToConstLinkedPtr
)
{
const
Matcher
<
const
linked_ptr
<
double
>&>
m
=
IsNull
();
const
linked_ptr
<
double
>
null_p
;
const
linked_ptr
<
double
>
non_null_p
(
new
double
);
EXPECT_TRUE
(
m
.
Matches
(
null_p
));
EXPECT_FALSE
(
m
.
Matches
(
non_null_p
));
}
// Tests that IsNull() describes itself properly.
// Tests that IsNull() describes itself properly.
TEST
(
IsNullTest
,
CanDescribeSelf
)
{
TEST
(
IsNullTest
,
CanDescribeSelf
)
{
Matcher
<
int
*>
m
=
IsNull
();
Matcher
<
int
*>
m
=
IsNull
();
...
@@ -736,6 +755,24 @@ TEST(NotNullTest, MatchesNonNullPointer) {
...
@@ -736,6 +755,24 @@ TEST(NotNullTest, MatchesNonNullPointer) {
EXPECT_TRUE
(
m2
.
Matches
(
"hi"
));
EXPECT_TRUE
(
m2
.
Matches
(
"hi"
));
}
}
TEST
(
NotNullTest
,
LinkedPtr
)
{
const
Matcher
<
linked_ptr
<
int
>
>
m
=
NotNull
();
const
linked_ptr
<
int
>
null_p
;
const
linked_ptr
<
int
>
non_null_p
(
new
int
);
EXPECT_FALSE
(
m
.
Matches
(
null_p
));
EXPECT_TRUE
(
m
.
Matches
(
non_null_p
));
}
TEST
(
NotNullTest
,
ReferenceToConstLinkedPtr
)
{
const
Matcher
<
const
linked_ptr
<
double
>&>
m
=
NotNull
();
const
linked_ptr
<
double
>
null_p
;
const
linked_ptr
<
double
>
non_null_p
(
new
double
);
EXPECT_FALSE
(
m
.
Matches
(
null_p
));
EXPECT_TRUE
(
m
.
Matches
(
non_null_p
));
}
// Tests that NotNull() describes itself properly.
// Tests that NotNull() describes itself properly.
TEST
(
NotNullTest
,
CanDescribeSelf
)
{
TEST
(
NotNullTest
,
CanDescribeSelf
)
{
Matcher
<
int
*>
m
=
NotNull
();
Matcher
<
int
*>
m
=
NotNull
();
...
...
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