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
bd2a1aed
Commit
bd2a1aed
authored
Apr 16, 2018
by
Gennadiy Civil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merging gmock generated matchers
parent
1f605414
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
18 deletions
+63
-18
gmock-generated-matchers.h
googlemock/include/gmock/gmock-generated-matchers.h
+0
-0
gmock-generated-matchers.h.pump
googlemock/include/gmock/gmock-generated-matchers.h.pump
+16
-14
gmock-generated-matchers_test.cc
googlemock/test/gmock-generated-matchers_test.cc
+47
-4
No files found.
googlemock/include/gmock/gmock-generated-matchers.h
View file @
bd2a1aed
This diff is collapsed.
Click to expand it.
googlemock/include/gmock/gmock-generated-matchers.h.pump
View file @
bd2a1aed
...
@@ -303,6 +303,9 @@ $for j, [[
...
@@ -303,6 +303,9 @@ $for j, [[
// UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
// UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
// that matches n elements in any order. We support up to n=$n arguments.
// that matches n elements in any order. We support up to n=$n arguments.
//
// If you have >$n elements, consider UnorderedElementsAreArray() or
// UnorderedPointwise() instead.
$
range
i
0.
.
n
$
range
i
0.
.
n
$
for
i
[[
$
for
i
[[
...
@@ -479,7 +482,7 @@ $$ // show up in the generated code.
...
@@ -479,7 +482,7 @@ $$ // show up in the generated code.
// using testing::PrintToString;
// using testing::PrintToString;
//
//
// MATCHER_P2(InClosedRange, low, hi,
// MATCHER_P2(InClosedRange, low, hi,
// string(negation ? "is not" : "is") + " in range [" +
// st
d::st
ring(negation ? "is not" : "is") + " in range [" +
// PrintToString(low) + ", " + PrintToString(hi) + "]") {
// PrintToString(low) + ", " + PrintToString(hi) + "]") {
// return low <= arg && arg <= hi;
// return low <= arg && arg <= hi;
// }
// }
...
@@ -604,32 +607,34 @@ $var template = [[$if i==0 [[]] $else [[
...
@@ -604,32 +607,34 @@ $var template = [[$if i==0 [[]] $else [[
]]]]
]]]]
$
var
ctor_param_list
=
[[
$
for
j
,
[[
p
$
j
##
_type
gmock_p
$
j
]]]]
$
var
ctor_param_list
=
[[
$
for
j
,
[[
p
$
j
##
_type
gmock_p
$
j
]]]]
$
var
impl_ctor_param_list
=
[[
$
for
j
,
[[
p
$
j
##
_type
gmock_p
$
j
]]]]
$
var
impl_ctor_param_list
=
[[
$
for
j
,
[[
p
$
j
##
_type
gmock_p
$
j
]]]]
$
var
impl_inits
=
[[
$
if
i
==
0
[[]]
$
else
[[
:
$
for
j
,
[[
p
$
j
(
gmock_p
$
j
)]]]]]]
$
var
impl_inits
=
[[
$
if
i
==
0
[[]]
$
else
[[
:
$
for
j
,
[[
p
$
j
(
::
testing
::
internal
::
move
(
gmock_p
$
j
)
)]]]]]]
$
var
inits
=
[[
$
if
i
==
0
[[]]
$
else
[[
:
$
for
j
,
[[
p
$
j
(
gmock_p
$
j
)]]]]]]
$
var
inits
=
[[
$
if
i
==
0
[[]]
$
else
[[
:
$
for
j
,
[[
p
$
j
(
::
testing
::
internal
::
move
(
gmock_p
$
j
)
)]]]]]]
$
var
params
=
[[
$
for
j
,
[[
p
$
j
]]]]
$
var
params
=
[[
$
for
j
,
[[
p
$
j
]]]]
$
var
param_types
=
[[
$
if
i
==
0
[[]]
$
else
[[
<
$
for
j
,
[[
p
$
j
##
_type
]]
>
]]]]
$
var
param_types
=
[[
$
if
i
==
0
[[]]
$
else
[[
<
$
for
j
,
[[
p
$
j
##
_type
]]
>
]]]]
$
var
param_types_and_names
=
[[
$
for
j
,
[[
p
$
j
##
_type
p
$
j
]]]]
$
var
param_types_and_names
=
[[
$
for
j
,
[[
p
$
j
##
_type
p
$
j
]]]]
$
var
param_field_decls
=
[[
$
for
j
$
var
param_field_decls
=
[[
$
for
j
[[
[[
p
$
j
##
_type
p
$
j
;
\
p
$
j
##
_type
const
p
$
j
;
\
]]]]
]]]]
$
var
param_field_decls2
=
[[
$
for
j
$
var
param_field_decls2
=
[[
$
for
j
[[
[[
p
$
j
##
_type
p
$
j
;
\
p
$
j
##
_type
const
p
$
j
;
\
]]]]
]]]]
#define $macro_name(name$for j [[, p$j]], description)\$template
#define $macro_name(name$for j [[, p$j]], description)\$template
class
$
class_name
{
\
class
$
class_name
{
\
public
:
\
public
:
\
template
<
typename
arg_type
>
\
template
<
typename
arg_type
>
\
class
gmock_Impl
:
public
::
testing
::
MatcherInterface
<
arg_type
>
{
\
class
gmock_Impl
:
public
::
testing
::
MatcherInterface
<
\
GTEST_REFERENCE_TO_CONST_
(
arg_type
)
>
{
\
public
:
\
public
:
\
[[
$
if
i
==
1
[[
explicit
]]]]
gmock_Impl
(
$
impl_ctor_param_list
)
\
[[
$
if
i
==
1
[[
explicit
]]]]
gmock_Impl
(
$
impl_ctor_param_list
)
\
$
impl_inits
{}
\
$
impl_inits
{}
\
virtual
bool
MatchAndExplain
(
\
virtual
bool
MatchAndExplain
(
\
arg_type
arg
,
::
testing
::
MatchResultListener
*
result_listener
)
const
;
\
GTEST_REFERENCE_TO_CONST_
(
arg_type
)
arg
,
\
::
testing
::
MatchResultListener
*
result_listener
)
const
;
\
virtual
void
DescribeTo
(
::
std
::
ostream
*
gmock_os
)
const
{
\
virtual
void
DescribeTo
(
::
std
::
ostream
*
gmock_os
)
const
{
\
*
gmock_os
<<
FormatDescription
(
false
);
\
*
gmock_os
<<
FormatDescription
(
false
);
\
}
\
}
\
...
@@ -637,17 +642,15 @@ $var param_field_decls2 = [[$for j
...
@@ -637,17 +642,15 @@ $var param_field_decls2 = [[$for j
*
gmock_os
<<
FormatDescription
(
true
);
\
*
gmock_os
<<
FormatDescription
(
true
);
\
}
\$
param_field_decls
}
\$
param_field_decls
private
:
\
private
:
\
::
testing
::
internal
::
string
FormatDescription
(
bool
negation
)
const
{
\
::
std
::
string
FormatDescription
(
bool
negation
)
const
{
\
const
::
testing
::
internal
::
string
gmock_description
=
(
description
);
\
::
std
::
string
gmock_description
=
(
description
);
\
if
(
!
gmock_description
.
empty
())
{
\
if
(
!
gmock_description
.
empty
())
\
return
gmock_description
;
\
return
gmock_description
;
\
}
\
return
::
testing
::
internal
::
FormatMatcherDescription
(
\
return
::
testing
::
internal
::
FormatMatcherDescription
(
\
negation
,
#
name
,
\
negation
,
#
name
,
\
::
testing
::
internal
::
UniversalTersePrintTupleFieldsToStrings
(
\
::
testing
::
internal
::
UniversalTersePrintTupleFieldsToStrings
(
\
::
testing
::
tuple
<
$
for
j
,
[[
p
$
j
##
_type
]]
>
(
$
for
j
,
[[
p
$
j
]])));
\
::
testing
::
tuple
<
$
for
j
,
[[
p
$
j
##
_type
]]
>
(
$
for
j
,
[[
p
$
j
]])));
\
}
\
}
\
GTEST_DISALLOW_ASSIGN_
(
gmock_Impl
);
\
};
\
};
\
template
<
typename
arg_type
>
\
template
<
typename
arg_type
>
\
operator
::
testing
::
Matcher
<
arg_type
>
()
const
{
\
operator
::
testing
::
Matcher
<
arg_type
>
()
const
{
\
...
@@ -657,14 +660,13 @@ $var param_field_decls2 = [[$for j
...
@@ -657,14 +660,13 @@ $var param_field_decls2 = [[$for j
[[
$
if
i
==
1
[[
explicit
]]]]
$
class_name
(
$
ctor_param_list
)
$
inits
{
\
[[
$
if
i
==
1
[[
explicit
]]]]
$
class_name
(
$
ctor_param_list
)
$
inits
{
\
}
\$
param_field_decls2
}
\$
param_field_decls2
private
:
\
private
:
\
GTEST_DISALLOW_ASSIGN_
(
$
class_name
);
\
};
\$
template
};
\$
template
inline
$
class_name
$
param_types
name
(
$
param_types_and_names
)
{
\
inline
$
class_name
$
param_types
name
(
$
param_types_and_names
)
{
\
return
$
class_name
$
param_types
(
$
params
);
\
return
$
class_name
$
param_types
(
$
params
);
\
}
\$
template
}
\$
template
template
<
typename
arg_type
>
\
template
<
typename
arg_type
>
\
bool
$
class_name
$
param_types
::
gmock_Impl
<
arg_type
>::
MatchAndExplain
(
\
bool
$
class_name
$
param_types
::
gmock_Impl
<
arg_type
>::
MatchAndExplain
(
\
arg_type
arg
,
\
GTEST_REFERENCE_TO_CONST_
(
arg_type
)
arg
,
\
::
testing
::
MatchResultListener
*
result_listener
GTEST_ATTRIBUTE_UNUSED_
)
\
::
testing
::
MatchResultListener
*
result_listener
GTEST_ATTRIBUTE_UNUSED_
)
\
const
const
]]
]]
...
...
googlemock/test/gmock-generated-matchers_test.cc
View file @
bd2a1aed
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#include <list>
#include <list>
#include <map>
#include <map>
#include <memory>
#include <set>
#include <set>
#include <sstream>
#include <sstream>
#include <string>
#include <string>
...
@@ -57,6 +58,8 @@ using testing::get;
...
@@ -57,6 +58,8 @@ using testing::get;
using
testing
::
make_tuple
;
using
testing
::
make_tuple
;
using
testing
::
tuple
;
using
testing
::
tuple
;
using
testing
::
_
;
using
testing
::
_
;
using
testing
::
AllOf
;
using
testing
::
AnyOf
;
using
testing
::
Args
;
using
testing
::
Args
;
using
testing
::
Contains
;
using
testing
::
Contains
;
using
testing
::
ElementsAre
;
using
testing
::
ElementsAre
;
...
@@ -120,7 +123,7 @@ TEST(ArgsTest, AcceptsOneTemplateArg) {
...
@@ -120,7 +123,7 @@ TEST(ArgsTest, AcceptsOneTemplateArg) {
}
}
TEST
(
ArgsTest
,
AcceptsTwoTemplateArgs
)
{
TEST
(
ArgsTest
,
AcceptsTwoTemplateArgs
)
{
const
tuple
<
short
,
int
,
long
>
t
(
static_cast
<
short
>
(
4
)
,
5
,
6L
);
// NOLINT
const
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
0
,
1
>
(
Lt
())));
EXPECT_THAT
(
t
,
(
Args
<
0
,
1
>
(
Lt
())));
EXPECT_THAT
(
t
,
(
Args
<
1
,
2
>
(
Lt
())));
EXPECT_THAT
(
t
,
(
Args
<
1
,
2
>
(
Lt
())));
...
@@ -128,13 +131,13 @@ TEST(ArgsTest, AcceptsTwoTemplateArgs) {
...
@@ -128,13 +131,13 @@ TEST(ArgsTest, AcceptsTwoTemplateArgs) {
}
}
TEST
(
ArgsTest
,
AcceptsRepeatedTemplateArgs
)
{
TEST
(
ArgsTest
,
AcceptsRepeatedTemplateArgs
)
{
const
tuple
<
short
,
int
,
long
>
t
(
static_cast
<
short
>
(
4
)
,
5
,
6L
);
// NOLINT
const
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
0
,
0
>
(
Eq
())));
EXPECT_THAT
(
t
,
(
Args
<
0
,
0
>
(
Eq
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
1
,
1
>
(
Ne
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
1
,
1
>
(
Ne
())));
}
}
TEST
(
ArgsTest
,
AcceptsDecreasingTemplateArgs
)
{
TEST
(
ArgsTest
,
AcceptsDecreasingTemplateArgs
)
{
const
tuple
<
short
,
int
,
long
>
t
(
static_cast
<
short
>
(
4
)
,
5
,
6L
);
// NOLINT
const
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
2
,
0
>
(
Gt
())));
EXPECT_THAT
(
t
,
(
Args
<
2
,
0
>
(
Gt
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
2
,
1
>
(
Lt
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
2
,
1
>
(
Lt
())));
}
}
...
@@ -159,7 +162,7 @@ TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) {
...
@@ -159,7 +162,7 @@ TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) {
}
}
TEST
(
ArgsTest
,
CanBeNested
)
{
TEST
(
ArgsTest
,
CanBeNested
)
{
const
tuple
<
short
,
int
,
long
,
int
>
t
(
static_cast
<
short
>
(
4
)
,
5
,
6L
,
6
);
// NOLINT
const
tuple
<
short
,
int
,
long
,
int
>
t
(
4
,
5
,
6L
,
6
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
1
,
2
,
3
>
(
Args
<
1
,
2
>
(
Eq
()))));
EXPECT_THAT
(
t
,
(
Args
<
1
,
2
,
3
>
(
Args
<
1
,
2
>
(
Eq
()))));
EXPECT_THAT
(
t
,
(
Args
<
0
,
1
,
3
>
(
Args
<
0
,
2
>
(
Lt
()))));
EXPECT_THAT
(
t
,
(
Args
<
0
,
1
,
3
>
(
Args
<
0
,
2
>
(
Lt
()))));
}
}
...
@@ -1283,4 +1286,44 @@ TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
...
@@ -1283,4 +1286,44 @@ TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
# pragma warning(pop)
# pragma warning(pop)
#endif
#endif
#if GTEST_LANG_CXX11
TEST
(
AllOfTest
,
WorksOnMoveOnlyType
)
{
std
::
unique_ptr
<
int
>
p
(
new
int
(
3
));
EXPECT_THAT
(
p
,
AllOf
(
Pointee
(
Eq
(
3
)),
Pointee
(
Gt
(
0
)),
Pointee
(
Lt
(
5
))));
EXPECT_THAT
(
p
,
Not
(
AllOf
(
Pointee
(
Eq
(
3
)),
Pointee
(
Gt
(
0
)),
Pointee
(
Lt
(
3
)))));
}
TEST
(
AnyOfTest
,
WorksOnMoveOnlyType
)
{
std
::
unique_ptr
<
int
>
p
(
new
int
(
3
));
EXPECT_THAT
(
p
,
AnyOf
(
Pointee
(
Eq
(
5
)),
Pointee
(
Lt
(
0
)),
Pointee
(
Lt
(
5
))));
EXPECT_THAT
(
p
,
Not
(
AnyOf
(
Pointee
(
Eq
(
5
)),
Pointee
(
Lt
(
0
)),
Pointee
(
Gt
(
5
)))));
}
MATCHER
(
IsNotNull
,
""
)
{
return
arg
!=
nullptr
;
}
// Verifies that a matcher defined using MATCHER() can work on
// move-only types.
TEST
(
MatcherMacroTest
,
WorksOnMoveOnlyType
)
{
std
::
unique_ptr
<
int
>
p
(
new
int
(
3
));
EXPECT_THAT
(
p
,
IsNotNull
());
EXPECT_THAT
(
std
::
unique_ptr
<
int
>
(),
Not
(
IsNotNull
()));
}
MATCHER_P
(
UniquePointee
,
pointee
,
""
)
{
return
*
arg
==
pointee
;
}
// Verifies that a matcher defined using MATCHER_P*() can work on
// move-only types.
TEST
(
MatcherPMacroTest
,
WorksOnMoveOnlyType
)
{
std
::
unique_ptr
<
int
>
p
(
new
int
(
3
));
EXPECT_THAT
(
p
,
UniquePointee
(
3
));
EXPECT_THAT
(
p
,
Not
(
UniquePointee
(
2
)));
}
#endif // GTEST_LASNG_CXX11
}
// namespace
}
// namespace
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