Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
bd2a1aed
Commit
bd2a1aed
authored
Apr 16, 2018
by
Gennadiy Civil
Browse files
merging gmock generated matchers
parent
1f605414
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
414 additions
and
268 deletions
+414
-268
googlemock/include/gmock/gmock-generated-matchers.h
googlemock/include/gmock/gmock-generated-matchers.h
+351
-250
googlemock/include/gmock/gmock-generated-matchers.h.pump
googlemock/include/gmock/gmock-generated-matchers.h.pump
+16
-14
googlemock/test/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, [[
// 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.
//
// If you have >$n elements, consider UnorderedElementsAreArray() or
// UnorderedPointwise() instead.
$
range
i
0.
.
n
$
for
i
[[
...
...
@@ -479,7 +482,7 @@ $$ // show up in the generated code.
// using testing::PrintToString;
//
// MATCHER_P2(InClosedRange, low, hi,
// string(negation ? "is not" : "is") + " in range [" +
//
std::
string(negation ? "is not" : "is") + " in range [" +
// PrintToString(low) + ", " + PrintToString(hi) + "]") {
// return low <= arg && arg <= hi;
// }
...
...
@@ -604,32 +607,34 @@ $var template = [[$if i==0 [[]] $else [[
]]]]
$
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_inits
=
[[
$
if
i
==
0
[[]]
$
else
[[
:
$
for
j
,
[[
p
$
j
(
gmock_p
$
j
)]]]]]]
$
var
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
(
::
testing
::
internal
::
move
(
gmock_p
$
j
)
)
]]]]]]
$
var
params
=
[[
$
for
j
,
[[
p
$
j
]]]]
$
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_field_decls
=
[[
$
for
j
[[
p
$
j
##
_type
p
$
j
;
\
p
$
j
##
_type
const
p
$
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
class
$
class_name
{
\
public
:
\
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
:
\
[[
$
if
i
==
1
[[
explicit
]]]]
gmock_Impl
(
$
impl_ctor_param_list
)
\
$
impl_inits
{}
\
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
{
\
*
gmock_os
<<
FormatDescription
(
false
);
\
}
\
...
...
@@ -637,17 +642,15 @@ $var param_field_decls2 = [[$for j
*
gmock_os
<<
FormatDescription
(
true
);
\
}
\$
param_field_decls
private:
\
::
testing
::
internal
::
string
FormatDescription
(
bool
negation
)
const
{
\
const
::
testing
::
internal
::
string
gmock_description
=
(
description
);
\
if
(
!
gmock_description
.
empty
())
{
\
::
std
::
string
FormatDescription
(
bool
negation
)
const
{
\
::
std
::
string
gmock_description
=
(
description
);
\
if
(
!
gmock_description
.
empty
())
\
return
gmock_description
;
\
}
\
return
::
testing
::
internal
::
FormatMatcherDescription
(
\
negation
,
#
name
,
\
::
testing
::
internal
::
UniversalTersePrintTupleFieldsToStrings
(
\
::
testing
::
tuple
<
$
for
j
,
[[
p
$
j
##
_type
]]
>
(
$
for
j
,
[[
p
$
j
]])));
\
}
\
GTEST_DISALLOW_ASSIGN_
(
gmock_Impl
);
\
};
\
template
<
typename
arg_type
>
\
operator
::
testing
::
Matcher
<
arg_type
>
()
const
{
\
...
...
@@ -657,14 +660,13 @@ $var param_field_decls2 = [[$for j
[[
$
if
i
==
1
[[
explicit
]]]]
$
class_name
(
$
ctor_param_list
)
$
inits
{
\
}
\$
param_field_decls2
private:
\
GTEST_DISALLOW_ASSIGN_
(
$
class_name
);
\
};
\$
template
inline
$
class_name
$
param_types
name
(
$
param_types_and_names
)
{
\
return
$
class_name
$
param_types
(
$
params
);
\
}\$
template
template
<
typename
arg_type
>
\
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_
)
\
const
]]
...
...
googlemock/test/gmock-generated-matchers_test.cc
View file @
bd2a1aed
...
...
@@ -35,6 +35,7 @@
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
...
...
@@ -57,6 +58,8 @@ using testing::get;
using
testing
::
make_tuple
;
using
testing
::
tuple
;
using
testing
::
_
;
using
testing
::
AllOf
;
using
testing
::
AnyOf
;
using
testing
::
Args
;
using
testing
::
Contains
;
using
testing
::
ElementsAre
;
...
...
@@ -120,7 +123,7 @@ TEST(ArgsTest, AcceptsOneTemplateArg) {
}
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
<
1
,
2
>
(
Lt
())));
...
...
@@ -128,13 +131,13 @@ TEST(ArgsTest, AcceptsTwoTemplateArgs) {
}
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
,
Not
(
Args
<
1
,
1
>
(
Ne
())));
}
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
,
Not
(
Args
<
2
,
1
>
(
Lt
())));
}
...
...
@@ -159,7 +162,7 @@ TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) {
}
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
<
0
,
1
,
3
>
(
Args
<
0
,
2
>
(
Lt
()))));
}
...
...
@@ -1283,4 +1286,44 @@ TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
# pragma warning(pop)
#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
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