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
572e261b
Commit
572e261b
authored
Jan 31, 2020
by
Abseil Team
Committed by
Andy Getz
Feb 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
Fix use of reserved names. Minimize code duplication needed for explict-vs-nonexplicit constructor. PiperOrigin-RevId: 292555014
parent
7bc671b8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
54 deletions
+48
-54
gmock-generated-matchers.h
googlemock/include/gmock/gmock-generated-matchers.h
+11
-33
gmock-generated-matchers.h.pump
googlemock/include/gmock/gmock-generated-matchers.h.pump
+1
-2
gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+9
-19
gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+27
-0
No files found.
googlemock/include/gmock/gmock-generated-matchers.h
View file @
572e261b
...
@@ -50,10 +50,8 @@
...
@@ -50,10 +50,8 @@
#define GMOCK_INTERNAL_MATCHER(name, description)\
#define GMOCK_INTERNAL_MATCHER(name, description)\
class name##Matcher : public \
class name##Matcher : public \
::testing::internal::MatcherBaseImpl<name##Matcher> {\
::testing::internal::MatcherBaseImpl<name##Matcher> {\
using __internal_base_type = \
::testing::internal::MatcherBaseImpl<name##Matcher>;\
public:\
public:\
using
__internal_base_type::__internal_base_type
;\
using
name##Matcher::MatcherBaseImpl::MatcherBaseImpl
;\
template <typename arg_type>\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
...
@@ -95,10 +93,8 @@
...
@@ -95,10 +93,8 @@
template <typename p0##_type>\
template <typename p0##_type>\
class name##MatcherP : public \
class name##MatcherP : public \
::testing::internal::MatcherBaseImpl<name##MatcherP<p0##_type>> {\
::testing::internal::MatcherBaseImpl<name##MatcherP<p0##_type>> {\
using __internal_base_type = \
::testing::internal::MatcherBaseImpl<name##MatcherP>;\
public:\
public:\
using
__internal_base_type::__internal_base_type
;\
using
name##MatcherP::MatcherBaseImpl::MatcherBaseImpl
;\
template <typename arg_type>\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
...
@@ -144,10 +140,8 @@
...
@@ -144,10 +140,8 @@
class name##MatcherP2 : public \
class name##MatcherP2 : public \
::testing::internal::MatcherBaseImpl<name##MatcherP2<p0##_type, \
::testing::internal::MatcherBaseImpl<name##MatcherP2<p0##_type, \
p1##_type>> {\
p1##_type>> {\
using __internal_base_type = \
::testing::internal::MatcherBaseImpl<name##MatcherP2>;\
public:\
public:\
using
__internal_base_type::__internal_base_type
;\
using
name##MatcherP2::MatcherBaseImpl::MatcherBaseImpl
;\
template <typename arg_type>\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
...
@@ -196,10 +190,8 @@
...
@@ -196,10 +190,8 @@
class name##MatcherP3 : public \
class name##MatcherP3 : public \
::testing::internal::MatcherBaseImpl<name##MatcherP3<p0##_type, \
::testing::internal::MatcherBaseImpl<name##MatcherP3<p0##_type, \
p1##_type, p2##_type>> {\
p1##_type, p2##_type>> {\
using __internal_base_type = \
::testing::internal::MatcherBaseImpl<name##MatcherP3>;\
public:\
public:\
using
__internal_base_type::__internal_base_type
;\
using
name##MatcherP3::MatcherBaseImpl::MatcherBaseImpl
;\
template <typename arg_type>\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
...
@@ -251,10 +243,8 @@
...
@@ -251,10 +243,8 @@
class name##MatcherP4 : public \
class name##MatcherP4 : public \
::testing::internal::MatcherBaseImpl<name##MatcherP4<p0##_type, \
::testing::internal::MatcherBaseImpl<name##MatcherP4<p0##_type, \
p1##_type, p2##_type, p3##_type>> {\
p1##_type, p2##_type, p3##_type>> {\
using __internal_base_type = \
::testing::internal::MatcherBaseImpl<name##MatcherP4>;\
public:\
public:\
using
__internal_base_type::__internal_base_type
;\
using
name##MatcherP4::MatcherBaseImpl::MatcherBaseImpl
;\
template <typename arg_type>\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
...
@@ -313,10 +303,8 @@
...
@@ -313,10 +303,8 @@
class name##MatcherP5 : public \
class name##MatcherP5 : public \
::testing::internal::MatcherBaseImpl<name##MatcherP5<p0##_type, \
::testing::internal::MatcherBaseImpl<name##MatcherP5<p0##_type, \
p1##_type, p2##_type, p3##_type, p4##_type>> {\
p1##_type, p2##_type, p3##_type, p4##_type>> {\
using __internal_base_type = \
::testing::internal::MatcherBaseImpl<name##MatcherP5>;\
public:\
public:\
using
__internal_base_type::__internal_base_type
;\
using
name##MatcherP5::MatcherBaseImpl::MatcherBaseImpl
;\
template <typename arg_type>\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
...
@@ -377,10 +365,8 @@
...
@@ -377,10 +365,8 @@
class name##MatcherP6 : public \
class name##MatcherP6 : public \
::testing::internal::MatcherBaseImpl<name##MatcherP6<p0##_type, \
::testing::internal::MatcherBaseImpl<name##MatcherP6<p0##_type, \
p1##_type, p2##_type, p3##_type, p4##_type, p5##_type>> {\
p1##_type, p2##_type, p3##_type, p4##_type, p5##_type>> {\
using __internal_base_type = \
::testing::internal::MatcherBaseImpl<name##MatcherP6>;\
public:\
public:\
using
__internal_base_type::__internal_base_type
;\
using
name##MatcherP6::MatcherBaseImpl::MatcherBaseImpl
;\
template <typename arg_type>\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
...
@@ -444,10 +430,8 @@
...
@@ -444,10 +430,8 @@
class name##MatcherP7 : public \
class name##MatcherP7 : public \
::testing::internal::MatcherBaseImpl<name##MatcherP7<p0##_type, \
::testing::internal::MatcherBaseImpl<name##MatcherP7<p0##_type, \
p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type>> {\
p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type>> {\
using __internal_base_type = \
::testing::internal::MatcherBaseImpl<name##MatcherP7>;\
public:\
public:\
using
__internal_base_type::__internal_base_type
;\
using
name##MatcherP7::MatcherBaseImpl::MatcherBaseImpl
;\
template <typename arg_type>\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
...
@@ -519,10 +503,8 @@
...
@@ -519,10 +503,8 @@
::testing::internal::MatcherBaseImpl<name##MatcherP8<p0##_type, \
::testing::internal::MatcherBaseImpl<name##MatcherP8<p0##_type, \
p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type, \
p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type, \
p7##_type>> {\
p7##_type>> {\
using __internal_base_type = \
::testing::internal::MatcherBaseImpl<name##MatcherP8>;\
public:\
public:\
using
__internal_base_type::__internal_base_type
;\
using
name##MatcherP8::MatcherBaseImpl::MatcherBaseImpl
;\
template <typename arg_type>\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
...
@@ -597,10 +579,8 @@
...
@@ -597,10 +579,8 @@
::testing::internal::MatcherBaseImpl<name##MatcherP9<p0##_type, \
::testing::internal::MatcherBaseImpl<name##MatcherP9<p0##_type, \
p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type, \
p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type, \
p7##_type, p8##_type>> {\
p7##_type, p8##_type>> {\
using __internal_base_type = \
::testing::internal::MatcherBaseImpl<name##MatcherP9>;\
public:\
public:\
using
__internal_base_type::__internal_base_type
;\
using
name##MatcherP9::MatcherBaseImpl::MatcherBaseImpl
;\
template <typename arg_type>\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
...
@@ -679,10 +659,8 @@
...
@@ -679,10 +659,8 @@
::testing::internal::MatcherBaseImpl<name##MatcherP10<p0##_type, \
::testing::internal::MatcherBaseImpl<name##MatcherP10<p0##_type, \
p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type, \
p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type, \
p7##_type, p8##_type, p9##_type>> {\
p7##_type, p8##_type, p9##_type>> {\
using __internal_base_type = \
::testing::internal::MatcherBaseImpl<name##MatcherP10>;\
public:\
public:\
using
__internal_base_type::__internal_base_type
;\
using
name##MatcherP10::MatcherBaseImpl::MatcherBaseImpl
;\
template <typename arg_type>\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
...
...
googlemock/include/gmock/gmock-generated-matchers.h.pump
View file @
572e261b
...
@@ -80,9 +80,8 @@ $var param_field_decls2 = [[$for j
...
@@ -80,9 +80,8 @@ $var param_field_decls2 = [[$for j
#define $macro_name(name, description$for j [[, p$j]])\$template
#define $macro_name(name, description$for j [[, p$j]])\$template
class
$
class_name
:
public
::
testing
::
internal
::
MatcherBaseImpl
<
$
class_name
$
param_types
>
{
\
class
$
class_name
:
public
::
testing
::
internal
::
MatcherBaseImpl
<
$
class_name
$
param_types
>
{
\
using
__internal_base_type
=
::
testing
::
internal
::
MatcherBaseImpl
<
$
class_name
>
;
\
public
:
\
public
:
\
using
__internal_base_type
::
__internal_base_type
;
\
using
$
class_name
::
MatcherBaseImpl
::
MatcherBaseImpl
;
\
template
<
typename
arg_type
>
\
template
<
typename
arg_type
>
\
class
gmock_Impl
:
public
::
testing
::
MatcherInterface
<
\
class
gmock_Impl
:
public
::
testing
::
MatcherInterface
<
\
GTEST_REFERENCE_TO_CONST_
(
arg_type
)
>
{
\
GTEST_REFERENCE_TO_CONST_
(
arg_type
)
>
{
\
...
...
googlemock/include/gmock/gmock-matchers.h
View file @
572e261b
...
@@ -462,28 +462,18 @@ class MatcherBaseImpl {
...
@@ -462,28 +462,18 @@ class MatcherBaseImpl {
}
}
};
};
// Template specialization for Matcher with 1 parameter.
// Template specialization for Matcher with parameters.
template
<
template
<
typename
...
>
class
Derived
,
typename
T
>
class
MatcherBaseImpl
<
Derived
<
T
>>
{
public
:
explicit
MatcherBaseImpl
(
T
param
)
:
param_
(
std
::
move
(
param
))
{}
template
<
typename
F
>
operator
::
testing
::
Matcher
<
F
>
()
const
{
// NOLINT(runtime/explicit)
return
::
testing
::
Matcher
<
F
>
(
new
typename
Derived
<
T
>::
template
gmock_Impl
<
F
>
(
param_
));
}
private
:
const
T
param_
;
};
// Template specialization for Matcher with multiple parameters.
template
<
template
<
typename
...
>
class
Derived
,
typename
...
Ts
>
template
<
template
<
typename
...
>
class
Derived
,
typename
...
Ts
>
class
MatcherBaseImpl
<
Derived
<
Ts
...
>>
{
class
MatcherBaseImpl
<
Derived
<
Ts
...
>>
{
public
:
public
:
MatcherBaseImpl
(
Ts
...
params
)
// Mark the constructor explicit for single argument T to avoid implicit
:
params_
(
std
::
move
(
params
)...)
{}
// NOLINT(runtime/explicit)
// conversions.
template
<
typename
E
=
std
::
enable_if
<
sizeof
...(
Ts
)
==
1
>
,
typename
E
::
type
*
=
nullptr
>
explicit
MatcherBaseImpl
(
Ts
...
params
)
:
params_
(
std
::
move
(
params
)...)
{}
template
<
typename
E
=
std
::
enable_if
<
sizeof
...(
Ts
)
!=
1
>
,
typename
=
typename
E
::
type
>
MatcherBaseImpl
(
Ts
...
params
)
:
params_
(
std
::
move
(
params
)...)
{}
// NOLINT
template
<
typename
F
>
template
<
typename
F
>
operator
::
testing
::
Matcher
<
F
>
()
const
{
// NOLINT(runtime/explicit)
operator
::
testing
::
Matcher
<
F
>
()
const
{
// NOLINT(runtime/explicit)
...
...
googlemock/test/gmock-matchers_test.cc
View file @
572e261b
...
@@ -2875,6 +2875,33 @@ TEST(ExplainMatchResultTest, WorksWithMonomorphicMatcher) {
...
@@ -2875,6 +2875,33 @@ TEST(ExplainMatchResultTest, WorksWithMonomorphicMatcher) {
EXPECT_EQ
(
""
,
listener2
.
str
());
EXPECT_EQ
(
""
,
listener2
.
str
());
}
}
MATCHER
(
ConstructNoArg
,
""
)
{
return
true
;
}
MATCHER_P
(
Construct1Arg
,
arg1
,
""
)
{
return
true
;
}
MATCHER_P2
(
Construct2Args
,
arg1
,
arg2
,
""
)
{
return
true
;
}
TEST
(
MatcherConstruct
,
ExplicitVsImplicit
)
{
{
// No arg constructor can be constructed with empty brace.
ConstructNoArgMatcher
m
=
{};
(
void
)
m
;
// And with no args
ConstructNoArgMatcher
m2
;
(
void
)
m2
;
}
{
// The one arg constructor has an explicit constructor.
// This is to prevent the implicit conversion.
using
M
=
Construct1ArgMatcherP
<
int
>
;
EXPECT_TRUE
((
std
::
is_constructible
<
M
,
int
>::
value
));
EXPECT_FALSE
((
std
::
is_convertible
<
int
,
M
>::
value
));
}
{
// Multiple arg matchers can be constructed with an implicit construction.
Construct2ArgsMatcherP2
<
int
,
double
>
m
=
{
1
,
2.2
};
(
void
)
m
;
}
}
MATCHER_P
(
Really
,
inner_matcher
,
""
)
{
MATCHER_P
(
Really
,
inner_matcher
,
""
)
{
return
ExplainMatchResult
(
inner_matcher
,
arg
,
result_listener
);
return
ExplainMatchResult
(
inner_matcher
,
arg
,
result_listener
);
}
}
...
...
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