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
b7c56832
Commit
b7c56832
authored
Mar 22, 2018
by
Gennadiy Civil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merging, gmock -1
parent
4e89c76d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
60 deletions
+120
-60
gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+45
-24
gmock-matchers.cc
googlemock/src/gmock-matchers.cc
+42
-35
gmock-internal-utils_test.cc
googlemock/test/gmock-internal-utils_test.cc
+28
-0
gmock_output_test_.cc
googlemock/test/gmock_output_test_.cc
+5
-1
No files found.
googlemock/include/gmock/gmock-matchers.h
View file @
b7c56832
...
@@ -323,7 +323,13 @@ class Matcher : public internal::MatcherBase<T> {
...
@@ -323,7 +323,13 @@ class Matcher : public internal::MatcherBase<T> {
explicit
Matcher
()
{}
// NOLINT
explicit
Matcher
()
{}
// NOLINT
// Constructs a matcher from its implementation.
// Constructs a matcher from its implementation.
explicit
Matcher
(
const
MatcherInterface
<
T
>*
impl
)
explicit
Matcher
(
const
MatcherInterface
<
GTEST_REFERENCE_TO_CONST_
(
T
)
>*
impl
)
:
internal
::
MatcherBase
<
T
>
(
impl
)
{}
template
<
typename
U
>
explicit
Matcher
(
const
MatcherInterface
<
U
>*
impl
,
typename
internal
::
EnableIf
<!
internal
::
IsSame
<
U
,
GTEST_REFERENCE_TO_CONST_
(
U
)
>::
value
>::
type
*
=
NULL
)
:
internal
::
MatcherBase
<
T
>
(
impl
)
{}
:
internal
::
MatcherBase
<
T
>
(
impl
)
{}
// Implicit constructor here allows people to write
// Implicit constructor here allows people to write
...
@@ -332,64 +338,79 @@ class Matcher : public internal::MatcherBase<T> {
...
@@ -332,64 +338,79 @@ class Matcher : public internal::MatcherBase<T> {
};
};
// The following two specializations allow the user to write str
// The following two specializations allow the user to write str
// instead of Eq(str) and "foo" instead of Eq("foo") when a string
// instead of Eq(str) and "foo" instead of Eq("foo") when a st
d::st
ring
// matcher is expected.
// matcher is expected.
template
<>
template
<>
class
GTEST_API_
Matcher
<
const
internal
::
string
&>
class
GTEST_API_
Matcher
<
const
std
::
string
&>
:
public
internal
::
MatcherBase
<
const
internal
::
string
&>
{
:
public
internal
::
MatcherBase
<
const
std
::
string
&>
{
public
:
public
:
Matcher
()
{}
Matcher
()
{}
explicit
Matcher
(
const
MatcherInterface
<
const
internal
::
string
&>*
impl
)
explicit
Matcher
(
const
MatcherInterface
<
const
std
::
string
&>*
impl
)
:
internal
::
MatcherBase
<
const
internal
::
string
&>
(
impl
)
{}
:
internal
::
MatcherBase
<
const
std
::
string
&>
(
impl
)
{}
// Allows the user to write str instead of Eq(str) sometimes, where
// Allows the user to write str instead of Eq(str) sometimes, where
// str is a string object.
// str is a std::string object.
Matcher
(
const
internal
::
string
&
s
);
// NOLINT
Matcher
(
const
std
::
string
&
s
);
// NOLINT
#if GTEST_HAS_GLOBAL_STRING
// Allows the user to write str instead of Eq(str) sometimes, where
// str is a ::string object.
Matcher
(
const
::
string
&
s
);
// NOLINT
#endif // GTEST_HAS_GLOBAL_STRING
// Allows the user to write "foo" instead of Eq("foo") sometimes.
// Allows the user to write "foo" instead of Eq("foo") sometimes.
Matcher
(
const
char
*
s
);
// NOLINT
Matcher
(
const
char
*
s
);
// NOLINT
};
};
template
<>
template
<>
class
GTEST_API_
Matcher
<
internal
::
string
>
class
GTEST_API_
Matcher
<
std
::
string
>
:
public
internal
::
MatcherBase
<
internal
::
string
>
{
:
public
internal
::
MatcherBase
<
std
::
string
>
{
public
:
public
:
Matcher
()
{}
Matcher
()
{}
explicit
Matcher
(
const
MatcherInterface
<
internal
::
string
>*
impl
)
explicit
Matcher
(
const
MatcherInterface
<
std
::
string
>*
impl
)
:
internal
::
MatcherBase
<
internal
::
string
>
(
impl
)
{}
:
internal
::
MatcherBase
<
std
::
string
>
(
impl
)
{}
// Allows the user to write str instead of Eq(str) sometimes, where
// Allows the user to write str instead of Eq(str) sometimes, where
// str is a string object.
// str is a string object.
Matcher
(
const
internal
::
string
&
s
);
// NOLINT
Matcher
(
const
std
::
string
&
s
);
// NOLINT
#if GTEST_HAS_GLOBAL_STRING
// Allows the user to write str instead of Eq(str) sometimes, where
// str is a ::string object.
Matcher
(
const
::
string
&
s
);
// NOLINT
#endif // GTEST_HAS_GLOBAL_STRING
// Allows the user to write "foo" instead of Eq("foo") sometimes.
// Allows the user to write "foo" instead of Eq("foo") sometimes.
Matcher
(
const
char
*
s
);
// NOLINT
Matcher
(
const
char
*
s
);
// NOLINT
};
};
#if GTEST_HAS_
STRING_PIECE_
#if GTEST_HAS_
GLOBAL_STRING
// The following two specializations allow the user to write str
// The following two specializations allow the user to write str
// instead of Eq(str) and "foo" instead of Eq("foo") when a
StringPiece
// instead of Eq(str) and "foo" instead of Eq("foo") when a
::string
// matcher is expected.
// matcher is expected.
template
<>
template
<>
class
GTEST_API_
Matcher
<
const
StringPiece
&>
class
GTEST_API_
Matcher
<
const
::
string
&>
:
public
internal
::
MatcherBase
<
const
StringPiece
&>
{
:
public
internal
::
MatcherBase
<
const
::
string
&>
{
public
:
public
:
Matcher
()
{}
Matcher
()
{}
explicit
Matcher
(
const
MatcherInterface
<
const
StringPiece
&>*
impl
)
explicit
Matcher
(
const
MatcherInterface
<
const
::
string
&>*
impl
)
:
internal
::
MatcherBase
<
const
StringPiece
&>
(
impl
)
{}
:
internal
::
MatcherBase
<
const
::
string
&>
(
impl
)
{}
// Allows the user to write str instead of Eq(str) sometimes, where
// Allows the user to write str instead of Eq(str) sometimes, where
// str is a string object.
// str is a std::string object.
Matcher
(
const
internal
::
string
&
s
);
// NOLINT
Matcher
(
const
std
::
string
&
s
);
// NOLINT
// Allows the user to write str instead of Eq(str) sometimes, where
// str is a ::string object.
Matcher
(
const
::
string
&
s
);
// NOLINT
// Allows the user to write "foo" instead of Eq("foo") sometimes.
// Allows the user to write "foo" instead of Eq("foo") sometimes.
Matcher
(
const
char
*
s
);
// NOLINT
Matcher
(
const
char
*
s
);
// NOLINT
};
// Allows the user to pass StringPieces directly.
Matcher
(
StringPiece
s
);
// NOLINT
};
};
template
<>
template
<>
...
@@ -1340,7 +1361,7 @@ class MatchesRegexMatcher {
...
@@ -1340,7 +1361,7 @@ class MatchesRegexMatcher {
// Matches anything that can convert to std::string.
// Matches anything that can convert to std::string.
//
//
// This is a template, not just a plain function with const std::string&,
// This is a template, not just a plain function with const std::string&,
// because
StringPiece
has some interfering non-explicit constructors.
// because
absl::string_view
has some interfering non-explicit constructors.
template
<
class
MatcheeStringType
>
template
<
class
MatcheeStringType
>
bool
MatchAndExplain
(
const
MatcheeStringType
&
s
,
bool
MatchAndExplain
(
const
MatcheeStringType
&
s
,
MatchResultListener
*
/* listener */
)
const
{
MatchResultListener
*
/* listener */
)
const
{
...
...
googlemock/src/gmock-matchers.cc
View file @
b7c56832
...
@@ -44,60 +44,67 @@
...
@@ -44,60 +44,67 @@
namespace
testing
{
namespace
testing
{
// Constructs a matcher that matches a const string& whose value is
// Constructs a matcher that matches a const st
d::st
ring& whose value is
// equal to s.
// equal to s.
Matcher
<
const
internal
::
string
&>::
Matcher
(
const
internal
::
string
&
s
)
{
Matcher
<
const
std
::
string
&>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
*
this
=
Eq
(
s
);
#if GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a const std::string& whose value is
// equal to s.
Matcher
<
const
std
::
string
&>::
Matcher
(
const
::
string
&
s
)
{
*
this
=
Eq
(
static_cast
<
std
::
string
>
(
s
));
}
}
#endif // GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a const string& whose value is
// Constructs a matcher that matches a const st
d::st
ring& whose value is
// equal to s.
// equal to s.
Matcher
<
const
internal
::
string
&>::
Matcher
(
const
char
*
s
)
{
Matcher
<
const
std
::
string
&>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
internal
::
string
(
s
));
*
this
=
Eq
(
std
::
string
(
s
));
}
}
// Constructs a matcher that matches a string whose value is equal to s.
// Constructs a matcher that matches a std::string whose value is equal to
Matcher
<
internal
::
string
>::
Matcher
(
const
internal
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
// s.
Matcher
<
std
::
string
>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
// Constructs a matcher that matches a string whose value is equal to s.
#if GTEST_HAS_GLOBAL_STRING
Matcher
<
internal
::
string
>::
Matcher
(
const
char
*
s
)
{
// Constructs a matcher that matches a std::string whose value is equal to
*
this
=
Eq
(
internal
::
string
(
s
));
// s.
Matcher
<
std
::
string
>::
Matcher
(
const
::
string
&
s
)
{
*
this
=
Eq
(
static_cast
<
std
::
string
>
(
s
));
}
}
#endif // GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a std::string whose value is equal to
// s.
Matcher
<
std
::
string
>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
}
#if GTEST_HAS_
STRING_PIECE_
#if GTEST_HAS_
GLOBAL_STRING
// Constructs a matcher that matches a const
StringPiece
& whose value is
// Constructs a matcher that matches a const
::string
& whose value is
// equal to s.
// equal to s.
Matcher
<
const
StringPiece
&>::
Matcher
(
const
internal
::
string
&
s
)
{
Matcher
<
const
::
string
&>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
);
*
this
=
Eq
(
s
tatic_cast
<::
string
>
(
s
)
);
}
}
// Constructs a matcher that matches a const
StringPiece
& whose value is
// Constructs a matcher that matches a const
::string
& whose value is
// equal to s.
// equal to s.
Matcher
<
const
StringPiece
&>::
Matcher
(
const
char
*
s
)
{
Matcher
<
const
::
string
&>::
Matcher
(
const
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
*
this
=
Eq
(
internal
::
string
(
s
));
}
// Constructs a matcher that matches a const
StringPiece
& whose value is
// Constructs a matcher that matches a const
::string
& whose value is
// equal to s.
// equal to s.
Matcher
<
const
StringPiece
&>::
Matcher
(
StringPiece
s
)
{
Matcher
<
const
::
string
&>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
::
string
(
s
));
}
*
this
=
Eq
(
s
.
ToString
());
}
// Constructs a matcher that matches a
StringPiece
whose value is equal to s.
// Constructs a matcher that matches a
::string
whose value is equal to s.
Matcher
<
StringPiece
>::
Matcher
(
const
internal
::
string
&
s
)
{
Matcher
<
::
string
>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
);
*
this
=
Eq
(
s
tatic_cast
<::
string
>
(
s
)
);
}
}
// Constructs a matcher that matches a StringPiece whose value is equal to s.
// Constructs a matcher that matches a ::string whose value is equal to s.
Matcher
<
StringPiece
>::
Matcher
(
const
char
*
s
)
{
Matcher
<::
string
>::
Matcher
(
const
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
*
this
=
Eq
(
internal
::
string
(
s
));
}
// Constructs a matcher that matches a string whose value is equal to s.
Matcher
<::
string
>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
::
string
(
s
));
}
#endif // GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a StringPiece whose value is equal to s.
Matcher
<
StringPiece
>::
Matcher
(
StringPiece
s
)
{
*
this
=
Eq
(
s
.
ToString
());
}
#endif // GTEST_HAS_STRING_PIECE_
namespace
internal
{
namespace
internal
{
...
...
googlemock/test/gmock-internal-utils_test.cc
View file @
b7c56832
...
@@ -44,7 +44,15 @@
...
@@ -44,7 +44,15 @@
#include "gmock/internal/gmock-port.h"
#include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest-spi.h"
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in
// their code.
#define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h"
#include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_
#if GTEST_OS_CYGWIN
#if GTEST_OS_CYGWIN
# include <sys/types.h> // For ssize_t. NOLINT
# include <sys/types.h> // For ssize_t. NOLINT
...
@@ -61,6 +69,26 @@ namespace internal {
...
@@ -61,6 +69,26 @@ namespace internal {
namespace
{
namespace
{
TEST
(
JoinAsTupleTest
,
JoinsEmptyTuple
)
{
EXPECT_EQ
(
""
,
JoinAsTuple
(
Strings
()));
}
TEST
(
JoinAsTupleTest
,
JoinsOneTuple
)
{
const
char
*
fields
[]
=
{
"1"
};
EXPECT_EQ
(
"1"
,
JoinAsTuple
(
Strings
(
fields
,
fields
+
1
)));
}
TEST
(
JoinAsTupleTest
,
JoinsTwoTuple
)
{
const
char
*
fields
[]
=
{
"1"
,
"a"
};
EXPECT_EQ
(
"(1, a)"
,
JoinAsTuple
(
Strings
(
fields
,
fields
+
2
)));
}
TEST
(
JoinAsTupleTest
,
JoinsTenTuple
)
{
const
char
*
fields
[]
=
{
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"10"
};
EXPECT_EQ
(
"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)"
,
JoinAsTuple
(
Strings
(
fields
,
fields
+
10
)));
}
TEST
(
ConvertIdentifierNameToWordsTest
,
WorksWhenNameContainsNoWord
)
{
TEST
(
ConvertIdentifierNameToWordsTest
,
WorksWhenNameContainsNoWord
)
{
EXPECT_EQ
(
""
,
ConvertIdentifierNameToWords
(
""
));
EXPECT_EQ
(
""
,
ConvertIdentifierNameToWords
(
""
));
EXPECT_EQ
(
""
,
ConvertIdentifierNameToWords
(
"_"
));
EXPECT_EQ
(
""
,
ConvertIdentifierNameToWords
(
"_"
));
...
...
googlemock/test/gmock_output_test_.cc
View file @
b7c56832
...
@@ -47,6 +47,7 @@ using testing::NaggyMock;
...
@@ -47,6 +47,7 @@ using testing::NaggyMock;
using
testing
::
Ref
;
using
testing
::
Ref
;
using
testing
::
Return
;
using
testing
::
Return
;
using
testing
::
Sequence
;
using
testing
::
Sequence
;
using
testing
::
Value
;
class
MockFoo
{
class
MockFoo
{
public
:
public
:
...
@@ -268,6 +269,10 @@ TEST_F(GMockOutputTest, CatchesLeakedMocks) {
...
@@ -268,6 +269,10 @@ TEST_F(GMockOutputTest, CatchesLeakedMocks) {
// Both foo1 and foo2 are deliberately leaked.
// Both foo1 and foo2 are deliberately leaked.
}
}
MATCHER_P2
(
IsPair
,
first
,
second
,
""
)
{
return
Value
(
arg
.
first
,
first
)
&&
Value
(
arg
.
second
,
second
);
}
void
TestCatchesLeakedMocksInAdHocTests
()
{
void
TestCatchesLeakedMocksInAdHocTests
()
{
MockFoo
*
foo
=
new
MockFoo
;
MockFoo
*
foo
=
new
MockFoo
;
...
@@ -280,7 +285,6 @@ void TestCatchesLeakedMocksInAdHocTests() {
...
@@ -280,7 +285,6 @@ void TestCatchesLeakedMocksInAdHocTests() {
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleMock
(
&
argc
,
argv
);
testing
::
InitGoogleMock
(
&
argc
,
argv
);
// Ensures that the tests pass no matter what value of
// Ensures that the tests pass no matter what value of
// --gmock_catch_leaked_mocks and --gmock_verbose the user specifies.
// --gmock_catch_leaked_mocks and --gmock_verbose the user specifies.
testing
::
GMOCK_FLAG
(
catch_leaked_mocks
)
=
true
;
testing
::
GMOCK_FLAG
(
catch_leaked_mocks
)
=
true
;
...
...
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