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
08cb06b1
Unverified
Commit
08cb06b1
authored
Apr 18, 2018
by
dnsunderland
Committed by
GitHub
Apr 18, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into parameterless
parents
f437f8ca
4bd8c463
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
121 additions
and
20 deletions
+121
-20
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-matchers.h
googlemock/include/gmock/gmock-matchers.h
+19
-2
gmock-generated-matchers_test.cc
googlemock/test/gmock-generated-matchers_test.cc
+59
-4
gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+27
-0
No files found.
googlemock/include/gmock/gmock-generated-matchers.h
View file @
08cb06b1
This diff is collapsed.
Click to expand it.
googlemock/include/gmock/gmock-generated-matchers.h.pump
View file @
08cb06b1
...
...
@@ -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 [" +
// st
d::st
ring(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/include/gmock/gmock-matchers.h
View file @
08cb06b1
...
...
@@ -5202,15 +5202,32 @@ std::string DescribeMatcher(const M& matcher, bool negation = false) {
// Define variadic matcher versions. They are overloaded in
// gmock-generated-matchers.h for the cases supported by pre C++11 compilers.
template
<
typename
...
Args
>
in
line
in
ternal
::
AllOfMatcher
<
Args
...
>
AllOf
(
const
Args
&
...
matchers
)
{
internal
::
AllOfMatcher
<
Args
...
>
AllOf
(
const
Args
&
...
matchers
)
{
return
internal
::
AllOfMatcher
<
Args
...
>
(
matchers
...);
}
template
<
typename
...
Args
>
in
line
in
ternal
::
AnyOfMatcher
<
Args
...
>
AnyOf
(
const
Args
&
...
matchers
)
{
internal
::
AnyOfMatcher
<
Args
...
>
AnyOf
(
const
Args
&
...
matchers
)
{
return
internal
::
AnyOfMatcher
<
Args
...
>
(
matchers
...);
}
template
<
typename
...
Args
>
internal
::
ElementsAreMatcher
<
tuple
<
typename
std
::
decay
<
const
Args
&>::
type
...
>>
ElementsAre
(
const
Args
&
...
matchers
)
{
return
internal
::
ElementsAreMatcher
<
tuple
<
typename
std
::
decay
<
const
Args
&>::
type
...
>>
(
make_tuple
(
matchers
...));
}
template
<
typename
...
Args
>
internal
::
UnorderedElementsAreMatcher
<
tuple
<
typename
std
::
decay
<
const
Args
&>::
type
...
>>
UnorderedElementsAre
(
const
Args
&
...
matchers
)
{
return
internal
::
UnorderedElementsAreMatcher
<
tuple
<
typename
std
::
decay
<
const
Args
&>::
type
...
>>
(
make_tuple
(
matchers
...));
}
#endif // GTEST_LANG_CXX11
// AllArgs(m) is a synonym of m. This is useful in
...
...
googlemock/test/gmock-generated-matchers_test.cc
View file @
08cb06b1
...
...
@@ -31,10 +31,19 @@
//
// This file tests the built-in matchers generated by a script.
// Silence warning C4244: 'initializing': conversion from 'int' to 'short',
// possible loss of data and C4100, unreferenced local parameter
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable:4244)
# pragma warning(disable:4100)
#endif
#include "gmock/gmock-generated-matchers.h"
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
...
...
@@ -57,6 +66,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 +131,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 +139,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 +170,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 +1294,48 @@ 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
#ifdef _MSC_VER
# pragma warning(pop)
#endif
googlemock/test/gmock-matchers_test.cc
View file @
08cb06b1
...
...
@@ -2742,6 +2742,33 @@ TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) {
41
,
42
,
43
,
44
,
45
,
46
,
47
,
48
,
49
,
50
));
}
// Tests the variadic version of the ElementsAreMatcher
TEST
(
ElementsAreTest
,
HugeMatcher
)
{
vector
<
int
>
test_vector
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
};
EXPECT_THAT
(
test_vector
,
ElementsAre
(
Eq
(
1
),
Eq
(
2
),
Lt
(
13
),
Eq
(
4
),
Eq
(
5
),
Eq
(
6
),
Eq
(
7
),
Eq
(
8
),
Eq
(
9
),
Eq
(
10
),
Gt
(
1
),
Eq
(
12
)));
}
// Tests the variadic version of the UnorderedElementsAreMatcher
TEST
(
ElementsAreTest
,
HugeMatcherStr
)
{
vector
<
string
>
test_vector
{
"literal_string"
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
};
EXPECT_THAT
(
test_vector
,
UnorderedElementsAre
(
"literal_string"
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
));
}
// Tests the variadic version of the UnorderedElementsAreMatcher
TEST
(
ElementsAreTest
,
HugeMatcherUnordered
)
{
vector
<
int
>
test_vector
{
2
,
1
,
8
,
5
,
4
,
6
,
7
,
3
,
9
,
12
,
11
,
10
};
EXPECT_THAT
(
test_vector
,
UnorderedElementsAre
(
Eq
(
2
),
Eq
(
1
),
Gt
(
7
),
Eq
(
5
),
Eq
(
4
),
Eq
(
6
),
Eq
(
7
),
Eq
(
3
),
Eq
(
9
),
Eq
(
12
),
Eq
(
11
),
Ne
(
122
)));
}
#endif // GTEST_LANG_CXX11
// Tests that AnyOf(m1, ..., mn) describes itself properly.
...
...
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