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
7cc548dc
Commit
7cc548dc
authored
May 16, 2017
by
Billy Donahue
Committed by
GitHub
May 16, 2017
Browse files
Merge pull request #1089 from nico/stdstring
Use std::string and ::string explicitly in gtest and gmock code.
parents
078d5d93
09fd5b3e
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
425 additions
and
421 deletions
+425
-421
googlemock/include/gmock/gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+58
-60
googlemock/include/gmock/gmock-spec-builders.h
googlemock/include/gmock/gmock-spec-builders.h
+28
-25
googlemock/include/gmock/internal/gmock-internal-utils.h
googlemock/include/gmock/internal/gmock-internal-utils.h
+4
-5
googlemock/src/gmock-cardinalities.cc
googlemock/src/gmock-cardinalities.cc
+1
-1
googlemock/src/gmock-internal-utils.cc
googlemock/src/gmock-internal-utils.cc
+2
-3
googlemock/src/gmock-matchers.cc
googlemock/src/gmock-matchers.cc
+4
-5
googlemock/src/gmock-spec-builders.cc
googlemock/src/gmock-spec-builders.cc
+4
-5
googlemock/test/gmock-generated-actions_test.cc
googlemock/test/gmock-generated-actions_test.cc
+57
-57
googlemock/test/gmock-generated-function-mockers_test.cc
googlemock/test/gmock-generated-function-mockers_test.cc
+20
-18
googlemock/test/gmock-generated-matchers_test.cc
googlemock/test/gmock-generated-matchers_test.cc
+36
-36
googlemock/test/gmock-internal-utils_test.cc
googlemock/test/gmock-internal-utils_test.cc
+12
-13
googlemock/test/gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+84
-78
googlemock/test/gmock-more-actions_test.cc
googlemock/test/gmock-more-actions_test.cc
+77
-74
googlemock/test/gmock-nice-strict_test.cc
googlemock/test/gmock-nice-strict_test.cc
+13
-14
googlemock/test/gmock-spec-builders_test.cc
googlemock/test/gmock-spec-builders_test.cc
+5
-6
googlemock/test/gmock_stress_test.cc
googlemock/test/gmock_stress_test.cc
+1
-1
googletest/include/gtest/gtest-printers.h
googletest/include/gtest/gtest-printers.h
+5
-5
googletest/include/gtest/gtest-spi.h
googletest/include/gtest/gtest-spi.h
+2
-3
googletest/include/gtest/internal/gtest-internal.h
googletest/include/gtest/internal/gtest-internal.h
+3
-2
googletest/include/gtest/internal/gtest-param-util.h
googletest/include/gtest/internal/gtest-param-util.h
+9
-10
No files found.
googlemock/include/gmock/gmock-matchers.h
View file @
7cc548dc
...
@@ -186,7 +186,7 @@ class StringMatchResultListener : public MatchResultListener {
...
@@ -186,7 +186,7 @@ class StringMatchResultListener : public MatchResultListener {
StringMatchResultListener
()
:
MatchResultListener
(
&
ss_
)
{}
StringMatchResultListener
()
:
MatchResultListener
(
&
ss_
)
{}
// Returns the explanation accumulated so far.
// Returns the explanation accumulated so far.
internal
::
string
str
()
const
{
return
ss_
.
str
();
}
std
::
string
str
()
const
{
return
ss_
.
str
();
}
// Clears the explanation accumulated so far.
// Clears the explanation accumulated so far.
void
Clear
()
{
ss_
.
str
(
""
);
}
void
Clear
()
{
ss_
.
str
(
""
);
}
...
@@ -675,7 +675,7 @@ Matcher<T> A();
...
@@ -675,7 +675,7 @@ Matcher<T> A();
namespace
internal
{
namespace
internal
{
// If the explanation is not empty, prints it to the ostream.
// If the explanation is not empty, prints it to the ostream.
inline
void
PrintIfNotEmpty
(
const
internal
::
string
&
explanation
,
inline
void
PrintIfNotEmpty
(
const
std
::
string
&
explanation
,
::
std
::
ostream
*
os
)
{
::
std
::
ostream
*
os
)
{
if
(
explanation
!=
""
&&
os
!=
NULL
)
{
if
(
explanation
!=
""
&&
os
!=
NULL
)
{
*
os
<<
", "
<<
explanation
;
*
os
<<
", "
<<
explanation
;
...
@@ -685,11 +685,11 @@ inline void PrintIfNotEmpty(const internal::string& explanation,
...
@@ -685,11 +685,11 @@ inline void PrintIfNotEmpty(const internal::string& explanation,
// Returns true if the given type name is easy to read by a human.
// Returns true if the given type name is easy to read by a human.
// This is used to decide whether printing the type of a value might
// This is used to decide whether printing the type of a value might
// be helpful.
// be helpful.
inline
bool
IsReadableTypeName
(
const
string
&
type_name
)
{
inline
bool
IsReadableTypeName
(
const
std
::
string
&
type_name
)
{
// We consider a type name readable if it's short or doesn't contain
// We consider a type name readable if it's short or doesn't contain
// a template or function type.
// a template or function type.
return
(
type_name
.
length
()
<=
20
||
return
(
type_name
.
length
()
<=
20
||
type_name
.
find_first_of
(
"<("
)
==
string
::
npos
);
type_name
.
find_first_of
(
"<("
)
==
std
::
string
::
npos
);
}
}
// Matches the value against the given matcher, prints the value and explains
// Matches the value against the given matcher, prints the value and explains
...
@@ -711,7 +711,7 @@ bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
...
@@ -711,7 +711,7 @@ bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
UniversalPrint
(
value
,
listener
->
stream
());
UniversalPrint
(
value
,
listener
->
stream
());
#if GTEST_HAS_RTTI
#if GTEST_HAS_RTTI
const
string
&
type_name
=
GetTypeName
<
Value
>
();
const
std
::
string
&
type_name
=
GetTypeName
<
Value
>
();
if
(
IsReadableTypeName
(
type_name
))
if
(
IsReadableTypeName
(
type_name
))
*
listener
->
stream
()
<<
" (of type "
<<
type_name
<<
")"
;
*
listener
->
stream
()
<<
" (of type "
<<
type_name
<<
")"
;
#endif
#endif
...
@@ -1335,17 +1335,17 @@ class MatchesRegexMatcher {
...
@@ -1335,17 +1335,17 @@ class MatchesRegexMatcher {
// wchar_t*
// wchar_t*
template
<
typename
CharType
>
template
<
typename
CharType
>
bool
MatchAndExplain
(
CharType
*
s
,
MatchResultListener
*
listener
)
const
{
bool
MatchAndExplain
(
CharType
*
s
,
MatchResultListener
*
listener
)
const
{
return
s
!=
NULL
&&
MatchAndExplain
(
internal
::
string
(
s
),
listener
);
return
s
!=
NULL
&&
MatchAndExplain
(
std
::
string
(
s
),
listener
);
}
}
// Matches anything that can convert to
internal
::string.
// Matches anything that can convert to
std
::string.
//
//
// This is a template, not just a plain function with const
internal
::string&,
// This is a template, not just a plain function with const
std
::string&,
// because StringPiece has some interfering non-explicit constructors.
// because StringPiece 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
{
const
internal
::
string
&
s2
(
s
);
const
std
::
string
&
s2
(
s
);
return
full_match_
?
RE
:
:
FullMatch
(
s2
,
*
regex_
)
:
return
full_match_
?
RE
:
:
FullMatch
(
s2
,
*
regex_
)
:
RE
::
PartialMatch
(
s2
,
*
regex_
);
RE
::
PartialMatch
(
s2
,
*
regex_
);
}
}
...
@@ -1353,13 +1353,13 @@ class MatchesRegexMatcher {
...
@@ -1353,13 +1353,13 @@ class MatchesRegexMatcher {
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
(
full_match_
?
"matches"
:
"contains"
)
*
os
<<
(
full_match_
?
"matches"
:
"contains"
)
<<
" regular expression "
;
<<
" regular expression "
;
UniversalPrinter
<
internal
::
string
>::
Print
(
regex_
->
pattern
(),
os
);
UniversalPrinter
<
std
::
string
>::
Print
(
regex_
->
pattern
(),
os
);
}
}
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"doesn't "
<<
(
full_match_
?
"match"
:
"contain"
)
*
os
<<
"doesn't "
<<
(
full_match_
?
"match"
:
"contain"
)
<<
" regular expression "
;
<<
" regular expression "
;
UniversalPrinter
<
internal
::
string
>::
Print
(
regex_
->
pattern
(),
os
);
UniversalPrinter
<
std
::
string
>::
Print
(
regex_
->
pattern
(),
os
);
}
}
private:
private:
...
@@ -1526,8 +1526,8 @@ class BothOfMatcherImpl : public MatcherInterface<T> {
...
@@ -1526,8 +1526,8 @@ class BothOfMatcherImpl : public MatcherInterface<T> {
}
}
// Otherwise we need to explain why *both* of them match.
// Otherwise we need to explain why *both* of them match.
const
internal
::
string
s1
=
listener1
.
str
();
const
std
::
string
s1
=
listener1
.
str
();
const
internal
::
string
s2
=
listener2
.
str
();
const
std
::
string
s2
=
listener2
.
str
();
if
(
s1
==
""
)
{
if
(
s1
==
""
)
{
*
listener
<<
s2
;
*
listener
<<
s2
;
...
@@ -1698,8 +1698,8 @@ class EitherOfMatcherImpl : public MatcherInterface<T> {
...
@@ -1698,8 +1698,8 @@ class EitherOfMatcherImpl : public MatcherInterface<T> {
}
}
// Otherwise we need to explain why *both* of them fail.
// Otherwise we need to explain why *both* of them fail.
const
internal
::
string
s1
=
listener1
.
str
();
const
std
::
string
s1
=
listener1
.
str
();
const
internal
::
string
s2
=
listener2
.
str
();
const
std
::
string
s2
=
listener2
.
str
();
if
(
s1
==
""
)
{
if
(
s1
==
""
)
{
*
listener
<<
s2
;
*
listener
<<
s2
;
...
@@ -2123,7 +2123,7 @@ class WhenDynamicCastToMatcherBase {
...
@@ -2123,7 +2123,7 @@ class WhenDynamicCastToMatcherBase {
protected:
protected:
const
Matcher
<
To
>
matcher_
;
const
Matcher
<
To
>
matcher_
;
static
string
GetToName
()
{
static
std
::
string
GetToName
()
{
#if GTEST_HAS_RTTI
#if GTEST_HAS_RTTI
return
GetTypeName
<
To
>
();
return
GetTypeName
<
To
>
();
#else // GTEST_HAS_RTTI
#else // GTEST_HAS_RTTI
...
@@ -2953,7 +2953,7 @@ class KeyMatcherImpl : public MatcherInterface<PairType> {
...
@@ -2953,7 +2953,7 @@ class KeyMatcherImpl : public MatcherInterface<PairType> {
StringMatchResultListener
inner_listener
;
StringMatchResultListener
inner_listener
;
const
bool
match
=
inner_matcher_
.
MatchAndExplain
(
key_value
.
first
,
const
bool
match
=
inner_matcher_
.
MatchAndExplain
(
key_value
.
first
,
&
inner_listener
);
&
inner_listener
);
const
internal
::
string
explanation
=
inner_listener
.
str
();
const
std
::
string
explanation
=
inner_listener
.
str
();
if
(
explanation
!=
""
)
{
if
(
explanation
!=
""
)
{
*
listener
<<
"whose first field is a value "
<<
explanation
;
*
listener
<<
"whose first field is a value "
<<
explanation
;
}
}
...
@@ -3058,8 +3058,8 @@ class PairMatcherImpl : public MatcherInterface<PairType> {
...
@@ -3058,8 +3058,8 @@ class PairMatcherImpl : public MatcherInterface<PairType> {
}
}
private:
private:
void
ExplainSuccess
(
const
internal
::
string
&
first_explanation
,
void
ExplainSuccess
(
const
std
::
string
&
first_explanation
,
const
internal
::
string
&
second_explanation
,
const
std
::
string
&
second_explanation
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
*
listener
<<
"whose both fields match"
;
*
listener
<<
"whose both fields match"
;
if
(
first_explanation
!=
""
)
{
if
(
first_explanation
!=
""
)
{
...
@@ -3166,7 +3166,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
...
@@ -3166,7 +3166,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
const
bool
listener_interested
=
listener
->
IsInterested
();
const
bool
listener_interested
=
listener
->
IsInterested
();
// explanations[i] is the explanation of the element at index i.
// explanations[i] is the explanation of the element at index i.
::
std
::
vector
<
internal
::
string
>
explanations
(
count
());
::
std
::
vector
<
std
::
string
>
explanations
(
count
());
StlContainerReference
stl_container
=
View
::
ConstReference
(
container
);
StlContainerReference
stl_container
=
View
::
ConstReference
(
container
);
typename
StlContainer
::
const_iterator
it
=
stl_container
.
begin
();
typename
StlContainer
::
const_iterator
it
=
stl_container
.
begin
();
size_t
exam_pos
=
0
;
size_t
exam_pos
=
0
;
...
@@ -3225,7 +3225,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
...
@@ -3225,7 +3225,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
if
(
listener_interested
)
{
if
(
listener_interested
)
{
bool
reason_printed
=
false
;
bool
reason_printed
=
false
;
for
(
size_t
i
=
0
;
i
!=
count
();
++
i
)
{
for
(
size_t
i
=
0
;
i
!=
count
();
++
i
)
{
const
internal
::
string
&
s
=
explanations
[
i
];
const
std
::
string
&
s
=
explanations
[
i
];
if
(
!
s
.
empty
())
{
if
(
!
s
.
empty
())
{
if
(
reason_printed
)
{
if
(
reason_printed
)
{
*
listener
<<
",
\n
and "
;
*
listener
<<
",
\n
and "
;
...
@@ -3278,7 +3278,7 @@ class GTEST_API_ MatchMatrix {
...
@@ -3278,7 +3278,7 @@ class GTEST_API_ MatchMatrix {
void
Randomize
();
void
Randomize
();
string
DebugString
()
const
;
std
::
string
DebugString
()
const
;
private:
private:
size_t
SpaceIndex
(
size_t
ilhs
,
size_t
irhs
)
const
{
size_t
SpaceIndex
(
size_t
ilhs
,
size_t
irhs
)
const
{
...
@@ -3322,9 +3322,8 @@ class GTEST_API_ UnorderedElementsAreMatcherImplBase {
...
@@ -3322,9 +3322,8 @@ class GTEST_API_ UnorderedElementsAreMatcherImplBase {
void
DescribeNegationToImpl
(
::
std
::
ostream
*
os
)
const
;
void
DescribeNegationToImpl
(
::
std
::
ostream
*
os
)
const
;
bool
VerifyAllElementsAndMatchersAreMatched
(
bool
VerifyAllElementsAndMatchersAreMatched
(
const
::
std
::
vector
<
string
>&
element_printouts
,
const
::
std
::
vector
<
std
::
string
>&
element_printouts
,
const
MatchMatrix
&
matrix
,
const
MatchMatrix
&
matrix
,
MatchResultListener
*
listener
)
const
;
MatchResultListener
*
listener
)
const
;
MatcherDescriberVec
&
matcher_describers
()
{
MatcherDescriberVec
&
matcher_describers
()
{
return
matcher_describers_
;
return
matcher_describers_
;
...
@@ -3376,7 +3375,7 @@ class UnorderedElementsAreMatcherImpl
...
@@ -3376,7 +3375,7 @@ class UnorderedElementsAreMatcherImpl
virtual
bool
MatchAndExplain
(
Container
container
,
virtual
bool
MatchAndExplain
(
Container
container
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
StlContainerReference
stl_container
=
View
::
ConstReference
(
container
);
StlContainerReference
stl_container
=
View
::
ConstReference
(
container
);
::
std
::
vector
<
string
>
element_printouts
;
::
std
::
vector
<
std
::
string
>
element_printouts
;
MatchMatrix
matrix
=
AnalyzeElements
(
stl_container
.
begin
(),
MatchMatrix
matrix
=
AnalyzeElements
(
stl_container
.
begin
(),
stl_container
.
end
(),
stl_container
.
end
(),
&
element_printouts
,
&
element_printouts
,
...
@@ -3407,7 +3406,7 @@ class UnorderedElementsAreMatcherImpl
...
@@ -3407,7 +3406,7 @@ class UnorderedElementsAreMatcherImpl
template
<
typename
ElementIter
>
template
<
typename
ElementIter
>
MatchMatrix
AnalyzeElements
(
ElementIter
elem_first
,
ElementIter
elem_last
,
MatchMatrix
AnalyzeElements
(
ElementIter
elem_first
,
ElementIter
elem_last
,
::
std
::
vector
<
string
>*
element_printouts
,
::
std
::
vector
<
std
::
string
>*
element_printouts
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
element_printouts
->
clear
();
element_printouts
->
clear
();
::
std
::
vector
<
char
>
did_match
;
::
std
::
vector
<
char
>
did_match
;
...
@@ -3619,9 +3618,9 @@ BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond(
...
@@ -3619,9 +3618,9 @@ BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond(
// 'negation' is false; otherwise returns the description of the
// 'negation' is false; otherwise returns the description of the
// negation of the matcher. 'param_values' contains a list of strings
// negation of the matcher. 'param_values' contains a list of strings
// that are the print-out of the matcher's parameters.
// that are the print-out of the matcher's parameters.
GTEST_API_
string
FormatMatcherDescription
(
bool
negation
,
GTEST_API_
std
::
string
FormatMatcherDescription
(
bool
negation
,
const
char
*
matcher_name
,
const
char
*
matcher_name
,
const
Strings
&
param_values
);
const
Strings
&
param_values
);
}
// namespace internal
}
// namespace internal
...
@@ -3951,53 +3950,52 @@ internal::ResultOfMatcher<Callable> ResultOf(
...
@@ -3951,53 +3950,52 @@ internal::ResultOfMatcher<Callable> ResultOf(
// String matchers.
// String matchers.
// Matches a string equal to str.
// Matches a string equal to str.
inline
PolymorphicMatcher
<
internal
::
StrEqualityMatcher
<
internal
::
string
>
>
inline
PolymorphicMatcher
<
internal
::
StrEqualityMatcher
<
std
::
string
>
>
StrEq
(
StrEq
(
const
internal
::
string
&
str
)
{
const
std
::
string
&
str
)
{
return
MakePolymorphicMatcher
(
internal
::
StrEqualityMatcher
<
internal
::
string
>
(
return
MakePolymorphicMatcher
(
str
,
true
,
true
));
internal
::
StrEqualityMatcher
<
std
::
string
>
(
str
,
true
,
true
));
}
}
// Matches a string not equal to str.
// Matches a string not equal to str.
inline
PolymorphicMatcher
<
internal
::
StrEqualityMatcher
<
internal
::
string
>
>
inline
PolymorphicMatcher
<
internal
::
StrEqualityMatcher
<
std
::
string
>
>
StrNe
(
StrNe
(
const
internal
::
string
&
str
)
{
const
std
::
string
&
str
)
{
return
MakePolymorphicMatcher
(
internal
::
StrEqualityMatcher
<
internal
::
string
>
(
return
MakePolymorphicMatcher
(
str
,
false
,
true
));
internal
::
StrEqualityMatcher
<
std
::
string
>
(
str
,
false
,
true
));
}
}
// Matches a string equal to str, ignoring case.
// Matches a string equal to str, ignoring case.
inline
PolymorphicMatcher
<
internal
::
StrEqualityMatcher
<
internal
::
string
>
>
inline
PolymorphicMatcher
<
internal
::
StrEqualityMatcher
<
std
::
string
>
>
StrCaseEq
(
StrCaseEq
(
const
internal
::
string
&
str
)
{
const
std
::
string
&
str
)
{
return
MakePolymorphicMatcher
(
internal
::
StrEqualityMatcher
<
internal
::
string
>
(
return
MakePolymorphicMatcher
(
str
,
true
,
false
));
internal
::
StrEqualityMatcher
<
std
::
string
>
(
str
,
true
,
false
));
}
}
// Matches a string not equal to str, ignoring case.
// Matches a string not equal to str, ignoring case.
inline
PolymorphicMatcher
<
internal
::
StrEqualityMatcher
<
internal
::
string
>
>
inline
PolymorphicMatcher
<
internal
::
StrEqualityMatcher
<
std
::
string
>
>
StrCaseNe
(
StrCaseNe
(
const
internal
::
string
&
str
)
{
const
std
::
string
&
str
)
{
return
MakePolymorphicMatcher
(
internal
::
StrEqualityMatcher
<
internal
::
string
>
(
return
MakePolymorphicMatcher
(
str
,
false
,
false
));
internal
::
StrEqualityMatcher
<
std
::
string
>
(
str
,
false
,
false
));
}
}
// Creates a matcher that matches any string, std::string, or C string
// Creates a matcher that matches any string, std::string, or C string
// that contains the given substring.
// that contains the given substring.
inline
PolymorphicMatcher
<
internal
::
HasSubstrMatcher
<
internal
::
string
>
>
inline
PolymorphicMatcher
<
internal
::
HasSubstrMatcher
<
std
::
string
>
>
HasSubstr
(
HasSubstr
(
const
internal
::
string
&
substring
)
{
const
std
::
string
&
substring
)
{
return
MakePolymorphicMatcher
(
internal
::
HasSubstrMatcher
<
internal
::
string
>
(
return
MakePolymorphicMatcher
(
substring
));
internal
::
HasSubstrMatcher
<
std
::
string
>
(
substring
));
}
}
// Matches a string that starts with 'prefix' (case-sensitive).
// Matches a string that starts with 'prefix' (case-sensitive).
inline
PolymorphicMatcher
<
internal
::
StartsWithMatcher
<
internal
::
string
>
>
inline
PolymorphicMatcher
<
internal
::
StartsWithMatcher
<
std
::
string
>
>
StartsWith
(
StartsWith
(
const
internal
::
string
&
prefix
)
{
const
std
::
string
&
prefix
)
{
return
MakePolymorphicMatcher
(
internal
::
StartsWithMatcher
<
internal
::
string
>
(
return
MakePolymorphicMatcher
(
prefix
));
internal
::
StartsWithMatcher
<
std
::
string
>
(
prefix
));
}
}
// Matches a string that ends with 'suffix' (case-sensitive).
// Matches a string that ends with 'suffix' (case-sensitive).
inline
PolymorphicMatcher
<
internal
::
EndsWithMatcher
<
internal
::
string
>
>
inline
PolymorphicMatcher
<
internal
::
EndsWithMatcher
<
std
::
string
>
>
EndsWith
(
EndsWith
(
const
internal
::
string
&
suffix
)
{
const
std
::
string
&
suffix
)
{
return
MakePolymorphicMatcher
(
internal
::
EndsWithMatcher
<
internal
::
string
>
(
return
MakePolymorphicMatcher
(
internal
::
EndsWithMatcher
<
std
::
string
>
(
suffix
));
suffix
));
}
}
// Matches a string that fully matches regular expression 'regex'.
// Matches a string that fully matches regular expression 'regex'.
...
@@ -4007,7 +4005,7 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
...
@@ -4007,7 +4005,7 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
return
MakePolymorphicMatcher
(
internal
::
MatchesRegexMatcher
(
regex
,
true
));
return
MakePolymorphicMatcher
(
internal
::
MatchesRegexMatcher
(
regex
,
true
));
}
}
inline
PolymorphicMatcher
<
internal
::
MatchesRegexMatcher
>
MatchesRegex
(
inline
PolymorphicMatcher
<
internal
::
MatchesRegexMatcher
>
MatchesRegex
(
const
internal
::
string
&
regex
)
{
const
std
::
string
&
regex
)
{
return
MatchesRegex
(
new
internal
::
RE
(
regex
));
return
MatchesRegex
(
new
internal
::
RE
(
regex
));
}
}
...
@@ -4018,7 +4016,7 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
...
@@ -4018,7 +4016,7 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
return
MakePolymorphicMatcher
(
internal
::
MatchesRegexMatcher
(
regex
,
false
));
return
MakePolymorphicMatcher
(
internal
::
MatchesRegexMatcher
(
regex
,
false
));
}
}
inline
PolymorphicMatcher
<
internal
::
MatchesRegexMatcher
>
ContainsRegex
(
inline
PolymorphicMatcher
<
internal
::
MatchesRegexMatcher
>
ContainsRegex
(
const
internal
::
string
&
regex
)
{
const
std
::
string
&
regex
)
{
return
ContainsRegex
(
new
internal
::
RE
(
regex
));
return
ContainsRegex
(
new
internal
::
RE
(
regex
));
}
}
...
...
googlemock/include/gmock/gmock-spec-builders.h
View file @
7cc548dc
...
@@ -148,8 +148,7 @@ class GTEST_API_ UntypedFunctionMockerBase {
...
@@ -148,8 +148,7 @@ class GTEST_API_ UntypedFunctionMockerBase {
// action fails.
// action fails.
// L = *
// L = *
virtual
UntypedActionResultHolderBase
*
UntypedPerformDefaultAction
(
virtual
UntypedActionResultHolderBase
*
UntypedPerformDefaultAction
(
const
void
*
untyped_args
,
const
void
*
untyped_args
,
const
std
::
string
&
call_description
)
const
=
0
;
const
string
&
call_description
)
const
=
0
;
// Performs the given action with the given arguments and returns
// Performs the given action with the given arguments and returns
// the action's result.
// the action's result.
...
@@ -263,12 +262,14 @@ class UntypedOnCallSpecBase {
...
@@ -263,12 +262,14 @@ class UntypedOnCallSpecBase {
};
};
// Asserts that the ON_CALL() statement has a certain property.
// Asserts that the ON_CALL() statement has a certain property.
void
AssertSpecProperty
(
bool
property
,
const
string
&
failure_message
)
const
{
void
AssertSpecProperty
(
bool
property
,
const
std
::
string
&
failure_message
)
const
{
Assert
(
property
,
file_
,
line_
,
failure_message
);
Assert
(
property
,
file_
,
line_
,
failure_message
);
}
}
// Expects that the ON_CALL() statement has a certain property.
// Expects that the ON_CALL() statement has a certain property.
void
ExpectSpecProperty
(
bool
property
,
const
string
&
failure_message
)
const
{
void
ExpectSpecProperty
(
bool
property
,
const
std
::
string
&
failure_message
)
const
{
Expect
(
property
,
file_
,
line_
,
failure_message
);
Expect
(
property
,
file_
,
line_
,
failure_message
);
}
}
...
@@ -690,7 +691,7 @@ GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
...
@@ -690,7 +691,7 @@ GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
class
GTEST_API_
ExpectationBase
{
class
GTEST_API_
ExpectationBase
{
public:
public:
// source_text is the EXPECT_CALL(...) source that created this Expectation.
// source_text is the EXPECT_CALL(...) source that created this Expectation.
ExpectationBase
(
const
char
*
file
,
int
line
,
const
string
&
source_text
);
ExpectationBase
(
const
char
*
file
,
int
line
,
const
std
::
string
&
source_text
);
virtual
~
ExpectationBase
();
virtual
~
ExpectationBase
();
...
@@ -738,12 +739,14 @@ class GTEST_API_ ExpectationBase {
...
@@ -738,12 +739,14 @@ class GTEST_API_ ExpectationBase {
virtual
Expectation
GetHandle
()
=
0
;
virtual
Expectation
GetHandle
()
=
0
;
// Asserts that the EXPECT_CALL() statement has the given property.
// Asserts that the EXPECT_CALL() statement has the given property.
void
AssertSpecProperty
(
bool
property
,
const
string
&
failure_message
)
const
{
void
AssertSpecProperty
(
bool
property
,
const
std
::
string
&
failure_message
)
const
{
Assert
(
property
,
file_
,
line_
,
failure_message
);
Assert
(
property
,
file_
,
line_
,
failure_message
);
}
}
// Expects that the EXPECT_CALL() statement has the given property.
// Expects that the EXPECT_CALL() statement has the given property.
void
ExpectSpecProperty
(
bool
property
,
const
string
&
failure_message
)
const
{
void
ExpectSpecProperty
(
bool
property
,
const
std
::
string
&
failure_message
)
const
{
Expect
(
property
,
file_
,
line_
,
failure_message
);
Expect
(
property
,
file_
,
line_
,
failure_message
);
}
}
...
@@ -845,7 +848,7 @@ class GTEST_API_ ExpectationBase {
...
@@ -845,7 +848,7 @@ class GTEST_API_ ExpectationBase {
// an EXPECT_CALL() statement finishes.
// an EXPECT_CALL() statement finishes.
const
char
*
file_
;
// The file that contains the expectation.
const
char
*
file_
;
// The file that contains the expectation.
int
line_
;
// The line number of the expectation.
int
line_
;
// The line number of the expectation.
const
string
source_text_
;
// The EXPECT_CALL(...) source text.
const
std
::
string
source_text_
;
// The EXPECT_CALL(...) source text.
// True iff the cardinality is specified explicitly.
// True iff the cardinality is specified explicitly.
bool
cardinality_specified_
;
bool
cardinality_specified_
;
Cardinality
cardinality_
;
// The cardinality of the expectation.
Cardinality
cardinality_
;
// The cardinality of the expectation.
...
@@ -880,8 +883,8 @@ class TypedExpectation : public ExpectationBase {
...
@@ -880,8 +883,8 @@ class TypedExpectation : public ExpectationBase {
typedef
typename
Function
<
F
>::
ArgumentMatcherTuple
ArgumentMatcherTuple
;
typedef
typename
Function
<
F
>::
ArgumentMatcherTuple
ArgumentMatcherTuple
;
typedef
typename
Function
<
F
>::
Result
Result
;
typedef
typename
Function
<
F
>::
Result
Result
;
TypedExpectation
(
FunctionMockerBase
<
F
>*
owner
,
TypedExpectation
(
FunctionMockerBase
<
F
>*
owner
,
const
char
*
a_file
,
int
a_line
,
const
char
*
a_file
,
int
a_line
,
const
string
&
a_source_text
,
const
std
::
string
&
a_source_text
,
const
ArgumentMatcherTuple
&
m
)
const
ArgumentMatcherTuple
&
m
)
:
ExpectationBase
(
a_file
,
a_line
,
a_source_text
),
:
ExpectationBase
(
a_file
,
a_line
,
a_source_text
),
owner_
(
owner
),
owner_
(
owner
),
...
@@ -1240,7 +1243,7 @@ class TypedExpectation : public ExpectationBase {
...
@@ -1240,7 +1243,7 @@ class TypedExpectation : public ExpectationBase {
// Logs a message including file and line number information.
// Logs a message including file and line number information.
GTEST_API_
void
LogWithLocation
(
testing
::
internal
::
LogSeverity
severity
,
GTEST_API_
void
LogWithLocation
(
testing
::
internal
::
LogSeverity
severity
,
const
char
*
file
,
int
line
,
const
char
*
file
,
int
line
,
const
string
&
message
);
const
std
::
string
&
message
);
template
<
typename
F
>
template
<
typename
F
>
class
MockSpec
{
class
MockSpec
{
...
@@ -1259,7 +1262,7 @@ class MockSpec {
...
@@ -1259,7 +1262,7 @@ class MockSpec {
internal
::
OnCallSpec
<
F
>&
InternalDefaultActionSetAt
(
internal
::
OnCallSpec
<
F
>&
InternalDefaultActionSetAt
(
const
char
*
file
,
int
line
,
const
char
*
obj
,
const
char
*
call
)
{
const
char
*
file
,
int
line
,
const
char
*
obj
,
const
char
*
call
)
{
LogWithLocation
(
internal
::
kInfo
,
file
,
line
,
LogWithLocation
(
internal
::
kInfo
,
file
,
line
,
string
(
"ON_CALL("
)
+
obj
+
", "
+
call
+
") invoked"
);
std
::
string
(
"ON_CALL("
)
+
obj
+
", "
+
call
+
") invoked"
);
return
function_mocker_
->
AddNewOnCallSpec
(
file
,
line
,
matchers_
);
return
function_mocker_
->
AddNewOnCallSpec
(
file
,
line
,
matchers_
);
}
}
...
@@ -1267,7 +1270,8 @@ class MockSpec {
...
@@ -1267,7 +1270,8 @@ class MockSpec {
// the newly created spec.
// the newly created spec.
internal
::
TypedExpectation
<
F
>&
InternalExpectedAt
(
internal
::
TypedExpectation
<
F
>&
InternalExpectedAt
(
const
char
*
file
,
int
line
,
const
char
*
obj
,
const
char
*
call
)
{
const
char
*
file
,
int
line
,
const
char
*
obj
,
const
char
*
call
)
{
const
string
source_text
(
string
(
"EXPECT_CALL("
)
+
obj
+
", "
+
call
+
")"
);
const
std
::
string
source_text
(
std
::
string
(
"EXPECT_CALL("
)
+
obj
+
", "
+
call
+
")"
);
LogWithLocation
(
internal
::
kInfo
,
file
,
line
,
source_text
+
" invoked"
);
LogWithLocation
(
internal
::
kInfo
,
file
,
line
,
source_text
+
" invoked"
);
return
function_mocker_
->
AddNewExpectation
(
return
function_mocker_
->
AddNewExpectation
(
file
,
line
,
source_text
,
matchers_
);
file
,
line
,
source_text
,
matchers_
);
...
@@ -1389,7 +1393,7 @@ class ActionResultHolder : public UntypedActionResultHolderBase {
...
@@ -1389,7 +1393,7 @@ class ActionResultHolder : public UntypedActionResultHolderBase {
static
ActionResultHolder
*
PerformDefaultAction
(
static
ActionResultHolder
*
PerformDefaultAction
(
const
FunctionMockerBase
<
F
>*
func_mocker
,
const
FunctionMockerBase
<
F
>*
func_mocker
,
const
typename
Function
<
F
>::
ArgumentTuple
&
args
,
const
typename
Function
<
F
>::
ArgumentTuple
&
args
,
const
string
&
call_description
)
{
const
std
::
string
&
call_description
)
{
return
new
ActionResultHolder
(
Wrapper
(
return
new
ActionResultHolder
(
Wrapper
(
func_mocker
->
PerformDefaultAction
(
args
,
call_description
)));
func_mocker
->
PerformDefaultAction
(
args
,
call_description
)));
}
}
...
@@ -1429,7 +1433,7 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
...
@@ -1429,7 +1433,7 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
static
ActionResultHolder
*
PerformDefaultAction
(
static
ActionResultHolder
*
PerformDefaultAction
(
const
FunctionMockerBase
<
F
>*
func_mocker
,
const
FunctionMockerBase
<
F
>*
func_mocker
,
const
typename
Function
<
F
>::
ArgumentTuple
&
args
,
const
typename
Function
<
F
>::
ArgumentTuple
&
args
,
const
string
&
call_description
)
{
const
std
::
string
&
call_description
)
{
func_mocker
->
PerformDefaultAction
(
args
,
call_description
);
func_mocker
->
PerformDefaultAction
(
args
,
call_description
);
return
new
ActionResultHolder
;
return
new
ActionResultHolder
;
}
}
...
@@ -1496,13 +1500,14 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
...
@@ -1496,13 +1500,14 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// without locking.
// without locking.
// L = *
// L = *
Result
PerformDefaultAction
(
const
ArgumentTuple
&
args
,
Result
PerformDefaultAction
(
const
ArgumentTuple
&
args
,
const
string
&
call_description
)
const
{
const
std
::
string
&
call_description
)
const
{
const
OnCallSpec
<
F
>*
const
spec
=
const
OnCallSpec
<
F
>*
const
spec
=
this
->
FindOnCallSpec
(
args
);
this
->
FindOnCallSpec
(
args
);
if
(
spec
!=
NULL
)
{
if
(
spec
!=
NULL
)
{
return
spec
->
GetAction
().
Perform
(
args
);
return
spec
->
GetAction
().
Perform
(
args
);
}
}
const
string
message
=
call_description
+
const
std
::
string
message
=
call_description
+
"
\n
The mock function has no default action "
"
\n
The mock function has no default action "
"set, and its return type has no default value set."
;
"set, and its return type has no default value set."
;
#if GTEST_HAS_EXCEPTIONS
#if GTEST_HAS_EXCEPTIONS
...
@@ -1522,7 +1527,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
...
@@ -1522,7 +1527,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// L = *
// L = *
virtual
UntypedActionResultHolderBase
*
UntypedPerformDefaultAction
(
virtual
UntypedActionResultHolderBase
*
UntypedPerformDefaultAction
(
const
void
*
untyped_args
,
// must point to an ArgumentTuple
const
void
*
untyped_args
,
// must point to an ArgumentTuple
const
string
&
call_description
)
const
{
const
std
::
string
&
call_description
)
const
{
const
ArgumentTuple
&
args
=
const
ArgumentTuple
&
args
=
*
static_cast
<
const
ArgumentTuple
*>
(
untyped_args
);
*
static_cast
<
const
ArgumentTuple
*>
(
untyped_args
);
return
ResultHolder
::
PerformDefaultAction
(
this
,
args
,
call_description
);
return
ResultHolder
::
PerformDefaultAction
(
this
,
args
,
call_description
);
...
@@ -1598,12 +1603,10 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
...
@@ -1598,12 +1603,10 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
}
}
// Adds and returns an expectation spec for this mock function.
// Adds and returns an expectation spec for this mock function.
TypedExpectation
<
F
>&
AddNewExpectation
(
TypedExpectation
<
F
>&
AddNewExpectation
(
const
char
*
file
,
int
line
,
const
char
*
file
,
const
std
::
string
&
source_text
,
int
line
,
const
ArgumentMatcherTuple
&
m
)
const
string
&
source_text
,
GTEST_LOCK_EXCLUDED_
(
g_gmock_mutex
)
{
const
ArgumentMatcherTuple
&
m
)
GTEST_LOCK_EXCLUDED_
(
g_gmock_mutex
)
{
Mock
::
RegisterUseByOnCallOrExpectCall
(
MockObject
(),
file
,
line
);
Mock
::
RegisterUseByOnCallOrExpectCall
(
MockObject
(),
file
,
line
);
TypedExpectation
<
F
>*
const
expectation
=
TypedExpectation
<
F
>*
const
expectation
=
new
TypedExpectation
<
F
>
(
this
,
file
,
line
,
source_text
,
m
);
new
TypedExpectation
<
F
>
(
this
,
file
,
line
,
source_text
,
m
);
...
@@ -1796,7 +1799,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
...
@@ -1796,7 +1799,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// Reports an uninteresting call (whose description is in msg) in the
// Reports an uninteresting call (whose description is in msg) in the
// manner specified by 'reaction'.
// manner specified by 'reaction'.
void
ReportUninterestingCall
(
CallReaction
reaction
,
const
string
&
msg
);
void
ReportUninterestingCall
(
CallReaction
reaction
,
const
std
::
string
&
msg
);
}
// namespace internal
}
// namespace internal
...
...
googlemock/include/gmock/internal/gmock-internal-utils.h
View file @
7cc548dc
...
@@ -267,7 +267,7 @@ class FailureReporterInterface {
...
@@ -267,7 +267,7 @@ class FailureReporterInterface {
// Reports a failure that occurred at the given source file location.
// Reports a failure that occurred at the given source file location.
virtual
void
ReportFailure
(
FailureType
type
,
const
char
*
file
,
int
line
,
virtual
void
ReportFailure
(
FailureType
type
,
const
char
*
file
,
int
line
,
const
string
&
message
)
=
0
;
const
std
::
string
&
message
)
=
0
;
};
};
// Returns the failure reporter used by Google Mock.
// Returns the failure reporter used by Google Mock.
...
@@ -279,7 +279,7 @@ GTEST_API_ FailureReporterInterface* GetFailureReporter();
...
@@ -279,7 +279,7 @@ GTEST_API_ FailureReporterInterface* GetFailureReporter();
// inline this function to prevent it from showing up in the stack
// inline this function to prevent it from showing up in the stack
// trace.
// trace.
inline
void
Assert
(
bool
condition
,
const
char
*
file
,
int
line
,
inline
void
Assert
(
bool
condition
,
const
char
*
file
,
int
line
,
const
string
&
msg
)
{
const
std
::
string
&
msg
)
{
if
(
!
condition
)
{
if
(
!
condition
)
{
GetFailureReporter
()
->
ReportFailure
(
FailureReporterInterface
::
kFatal
,
GetFailureReporter
()
->
ReportFailure
(
FailureReporterInterface
::
kFatal
,
file
,
line
,
msg
);
file
,
line
,
msg
);
...
@@ -292,7 +292,7 @@ inline void Assert(bool condition, const char* file, int line) {
...
@@ -292,7 +292,7 @@ inline void Assert(bool condition, const char* file, int line) {
// Verifies that condition is true; generates a non-fatal failure if
// Verifies that condition is true; generates a non-fatal failure if
// condition is false.
// condition is false.
inline
void
Expect
(
bool
condition
,
const
char
*
file
,
int
line
,
inline
void
Expect
(
bool
condition
,
const
char
*
file
,
int
line
,
const
string
&
msg
)
{
const
std
::
string
&
msg
)
{
if
(
!
condition
)
{
if
(
!
condition
)
{
GetFailureReporter
()
->
ReportFailure
(
FailureReporterInterface
::
kNonfatal
,
GetFailureReporter
()
->
ReportFailure
(
FailureReporterInterface
::
kNonfatal
,
file
,
line
,
msg
);
file
,
line
,
msg
);
...
@@ -328,8 +328,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity);
...
@@ -328,8 +328,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity);
// stack_frames_to_skip is treated as 0, since we don't know which
// stack_frames_to_skip is treated as 0, since we don't know which
// function calls will be inlined by the compiler and need to be
// function calls will be inlined by the compiler and need to be
// conservative.
// conservative.
GTEST_API_
void
Log
(
LogSeverity
severity
,
GTEST_API_
void
Log
(
LogSeverity
severity
,
const
std
::
string
&
message
,
const
string
&
message
,
int
stack_frames_to_skip
);
int
stack_frames_to_skip
);
// TODO(wan@google.com): group all type utilities together.
// TODO(wan@google.com): group all type utilities together.
...
...
googlemock/src/gmock-cardinalities.cc
View file @
7cc548dc
...
@@ -92,7 +92,7 @@ class BetweenCardinalityImpl : public CardinalityInterface {
...
@@ -92,7 +92,7 @@ class BetweenCardinalityImpl : public CardinalityInterface {
};
};
// Formats "n times" in a human-friendly way.
// Formats "n times" in a human-friendly way.
inline
internal
::
string
FormatTimes
(
int
n
)
{
inline
std
::
string
FormatTimes
(
int
n
)
{
if
(
n
==
1
)
{
if
(
n
==
1
)
{
return
"once"
;
return
"once"
;
}
else
if
(
n
==
2
)
{
}
else
if
(
n
==
2
)
{
...
...
googlemock/src/gmock-internal-utils.cc
View file @
7cc548dc
...
@@ -76,7 +76,7 @@ GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name) {
...
@@ -76,7 +76,7 @@ GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name) {
class
GoogleTestFailureReporter
:
public
FailureReporterInterface
{
class
GoogleTestFailureReporter
:
public
FailureReporterInterface
{
public:
public:
virtual
void
ReportFailure
(
FailureType
type
,
const
char
*
file
,
int
line
,
virtual
void
ReportFailure
(
FailureType
type
,
const
char
*
file
,
int
line
,
const
string
&
message
)
{
const
std
::
string
&
message
)
{
AssertHelper
(
type
==
kFatal
?
AssertHelper
(
type
==
kFatal
?
TestPartResult
::
kFatalFailure
:
TestPartResult
::
kFatalFailure
:
TestPartResult
::
kNonFatalFailure
,
TestPartResult
::
kNonFatalFailure
,
...
@@ -128,8 +128,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity) {
...
@@ -128,8 +128,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity) {
// stack_frames_to_skip is treated as 0, since we don't know which
// stack_frames_to_skip is treated as 0, since we don't know which
// function calls will be inlined by the compiler and need to be
// function calls will be inlined by the compiler and need to be
// conservative.
// conservative.
GTEST_API_
void
Log
(
LogSeverity
severity
,
GTEST_API_
void
Log
(
LogSeverity
severity
,
const
std
::
string
&
message
,
const
string
&
message
,
int
stack_frames_to_skip
)
{
int
stack_frames_to_skip
)
{
if
(
!
LogIsVisible
(
severity
))
if
(
!
LogIsVisible
(
severity
))
return
;
return
;
...
...
googlemock/src/gmock-matchers.cc
View file @
7cc548dc
...
@@ -379,7 +379,7 @@ void MatchMatrix::Randomize() {
...
@@ -379,7 +379,7 @@ void MatchMatrix::Randomize() {
}
}
}
}
string
MatchMatrix
::
DebugString
()
const
{
std
::
string
MatchMatrix
::
DebugString
()
const
{
::
std
::
stringstream
ss
;
::
std
::
stringstream
ss
;
const
char
*
sep
=
""
;
const
char
*
sep
=
""
;
for
(
size_t
i
=
0
;
i
<
LhsSize
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
LhsSize
();
++
i
)
{
...
@@ -441,10 +441,9 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
...
@@ -441,10 +441,9 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
// Returns false, writing an explanation to 'listener', if and only
// Returns false, writing an explanation to 'listener', if and only
// if the success criteria are not met.
// if the success criteria are not met.
bool
UnorderedElementsAreMatcherImplBase
::
bool
UnorderedElementsAreMatcherImplBase
::
VerifyAllElementsAndMatchersAreMatched
(
VerifyAllElementsAndMatchersAreMatched
(
const
::
std
::
vector
<
string
>&
element_printouts
,
const
::
std
::
vector
<
std
::
string
>&
element_printouts
,
const
MatchMatrix
&
matrix
,
const
MatchMatrix
&
matrix
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
bool
result
=
true
;
bool
result
=
true
;
::
std
::
vector
<
char
>
element_matched
(
matrix
.
LhsSize
(),
0
);
::
std
::
vector
<
char
>
element_matched
(
matrix
.
LhsSize
(),
0
);
::
std
::
vector
<
char
>
matcher_matched
(
matrix
.
RhsSize
(),
0
);
::
std
::
vector
<
char
>
matcher_matched
(
matrix
.
RhsSize
(),
0
);
...
...
googlemock/src/gmock-spec-builders.cc
View file @
7cc548dc
...
@@ -58,16 +58,15 @@ GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_gmock_mutex);
...
@@ -58,16 +58,15 @@ GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_gmock_mutex);
// Logs a message including file and line number information.
// Logs a message including file and line number information.
GTEST_API_
void
LogWithLocation
(
testing
::
internal
::
LogSeverity
severity
,
GTEST_API_
void
LogWithLocation
(
testing
::
internal
::
LogSeverity
severity
,
const
char
*
file
,
int
line
,
const
char
*
file
,
int
line
,
const
string
&
message
)
{
const
std
::
string
&
message
)
{
::
std
::
ostringstream
s
;
::
std
::
ostringstream
s
;
s
<<
file
<<
":"
<<
line
<<
": "
<<
message
<<
::
std
::
endl
;
s
<<
file
<<
":"
<<
line
<<
": "
<<
message
<<
::
std
::
endl
;
Log
(
severity
,
s
.
str
(),
0
);
Log
(
severity
,
s
.
str
(),
0
);
}
}
// Constructs an ExpectationBase object.
// Constructs an ExpectationBase object.
ExpectationBase
::
ExpectationBase
(
const
char
*
a_file
,
ExpectationBase
::
ExpectationBase
(
const
char
*
a_file
,
int
a_line
,
int
a_line
,
const
std
::
string
&
a_source_text
)
const
string
&
a_source_text
)
:
file_
(
a_file
),
:
file_
(
a_file
),
line_
(
a_line
),
line_
(
a_line
),
source_text_
(
a_source_text
),
source_text_
(
a_source_text
),
...
@@ -244,7 +243,7 @@ GTEST_API_ ThreadLocal<Sequence*> g_gmock_implicit_sequence;
...
@@ -244,7 +243,7 @@ GTEST_API_ ThreadLocal<Sequence*> g_gmock_implicit_sequence;
// Reports an uninteresting call (whose description is in msg) in the
// Reports an uninteresting call (whose description is in msg) in the
// manner specified by 'reaction'.
// manner specified by 'reaction'.
void
ReportUninterestingCall
(
CallReaction
reaction
,
const
string
&
msg
)
{
void
ReportUninterestingCall
(
CallReaction
reaction
,
const
std
::
string
&
msg
)
{
// Include a stack trace only if --gmock_verbose=info is specified.
// Include a stack trace only if --gmock_verbose=info is specified.
const
int
stack_frames_to_skip
=
const
int
stack_frames_to_skip
=
GMOCK_FLAG
(
verbose
)
==
kInfoVerbosity
?
3
:
-
1
;
GMOCK_FLAG
(
verbose
)
==
kInfoVerbosity
?
3
:
-
1
;
...
...
googlemock/test/gmock-generated-actions_test.cc
View file @
7cc548dc
...
@@ -81,12 +81,12 @@ bool Unary(int x) { return x < 0; }
...
@@ -81,12 +81,12 @@ bool Unary(int x) { return x < 0; }
const
char
*
Plus1
(
const
char
*
s
)
{
return
s
+
1
;
}
const
char
*
Plus1
(
const
char
*
s
)
{
return
s
+
1
;
}
bool
ByConstRef
(
const
string
&
s
)
{
return
s
==
"Hi"
;
}
bool
ByConstRef
(
const
std
::
string
&
s
)
{
return
s
==
"Hi"
;
}
const
double
g_double
=
0
;
const
double
g_double
=
0
;
bool
ReferencesGlobalDouble
(
const
double
&
x
)
{
return
&
x
==
&
g_double
;
}
bool
ReferencesGlobalDouble
(
const
double
&
x
)
{
return
&
x
==
&
g_double
;
}
string
ByNonConstRef
(
string
&
s
)
{
return
s
+=
"+"
;
}
// NOLINT
std
::
string
ByNonConstRef
(
std
::
string
&
s
)
{
return
s
+=
"+"
;
}
// NOLINT
struct
UnaryFunctor
{
struct
UnaryFunctor
{
int
operator
()(
bool
x
)
{
return
x
?
1
:
-
1
;
}
int
operator
()(
bool
x
)
{
return
x
?
1
:
-
1
;
}
...
@@ -102,9 +102,9 @@ void VoidTernary(int, char, bool) { g_done = true; }
...
@@ -102,9 +102,9 @@ void VoidTernary(int, char, bool) { g_done = true; }
int
SumOf4
(
int
a
,
int
b
,
int
c
,
int
d
)
{
return
a
+
b
+
c
+
d
;
}
int
SumOf4
(
int
a
,
int
b
,
int
c
,
int
d
)
{
return
a
+
b
+
c
+
d
;
}
string
Concat4
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat4
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
)
{
const
char
*
s4
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
;
}
}
int
SumOf5
(
int
a
,
int
b
,
int
c
,
int
d
,
int
e
)
{
return
a
+
b
+
c
+
d
+
e
;
}
int
SumOf5
(
int
a
,
int
b
,
int
c
,
int
d
,
int
e
)
{
return
a
+
b
+
c
+
d
+
e
;
}
...
@@ -115,9 +115,9 @@ struct SumOf5Functor {
...
@@ -115,9 +115,9 @@ struct SumOf5Functor {
}
}
};
};
string
Concat5
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat5
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
)
{
const
char
*
s4
,
const
char
*
s5
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
;
}
}
int
SumOf6
(
int
a
,
int
b
,
int
c
,
int
d
,
int
e
,
int
f
)
{
int
SumOf6
(
int
a
,
int
b
,
int
c
,
int
d
,
int
e
,
int
f
)
{
...
@@ -130,34 +130,34 @@ struct SumOf6Functor {
...
@@ -130,34 +130,34 @@ struct SumOf6Functor {
}
}
};
};
string
Concat6
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat6
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
)
{
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
;
}
}
string
Concat7
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat7
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
)
{
const
char
*
s7
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
;
}
}
string
Concat8
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat8
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
)
{
const
char
*
s7
,
const
char
*
s8
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
;
}
}
string
Concat9
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat9
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
)
{
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
;
}
}
string
Concat10
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat10
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
,
const
char
*
s10
)
{
const
char
*
s10
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
+
s10
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
+
s10
;
}
}
// A helper that turns the type of a C-string literal from const
// A helper that turns the type of a C-string literal from const
...
@@ -208,38 +208,37 @@ TEST(InvokeArgumentTest, Functor6) {
...
@@ -208,38 +208,37 @@ TEST(InvokeArgumentTest, Functor6) {
// Tests using InvokeArgument with a 7-ary function.
// Tests using InvokeArgument with a 7-ary function.
TEST
(
InvokeArgumentTest
,
Function7
)
{
TEST
(
InvokeArgumentTest
,
Function7
)
{
Action
<
st
ring
(
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
st
d
::
string
(
std
::
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
const
char
*
))
>
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
);
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
);
EXPECT_EQ
(
"1234567"
,
a
.
Perform
(
make_tuple
(
&
Concat7
)));
EXPECT_EQ
(
"1234567"
,
a
.
Perform
(
make_tuple
(
&
Concat7
)));
}
}
// Tests using InvokeArgument with a 8-ary function.
// Tests using InvokeArgument with a 8-ary function.
TEST
(
InvokeArgumentTest
,
Function8
)
{
TEST
(
InvokeArgumentTest
,
Function8
)
{
Action
<
st
ring
(
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
st
d
::
string
(
std
::
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
const
char
*
,
const
char
*
))
>
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
);
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
);
EXPECT_EQ
(
"12345678"
,
a
.
Perform
(
make_tuple
(
&
Concat8
)));
EXPECT_EQ
(
"12345678"
,
a
.
Perform
(
make_tuple
(
&
Concat8
)));
}
}
// Tests using InvokeArgument with a 9-ary function.
// Tests using InvokeArgument with a 9-ary function.
TEST
(
InvokeArgumentTest
,
Function9
)
{
TEST
(
InvokeArgumentTest
,
Function9
)
{
Action
<
st
ring
(
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
st
d
::
string
(
std
::
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
const
char
*
,
const
char
*
,
const
char
*
))
>
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
);
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
);
EXPECT_EQ
(
"123456789"
,
a
.
Perform
(
make_tuple
(
&
Concat9
)));
EXPECT_EQ
(
"123456789"
,
a
.
Perform
(
make_tuple
(
&
Concat9
)));
}
}
// Tests using InvokeArgument with a 10-ary function.
// Tests using InvokeArgument with a 10-ary function.
TEST
(
InvokeArgumentTest
,
Function10
)
{
TEST
(
InvokeArgumentTest
,
Function10
)
{
Action
<
string
(
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
std
::
string
(
std
::
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
const
char
*
))
>
a
=
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"0"
);
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"0"
);
EXPECT_EQ
(
"1234567890"
,
a
.
Perform
(
make_tuple
(
&
Concat10
)));
EXPECT_EQ
(
"1234567890"
,
a
.
Perform
(
make_tuple
(
&
Concat10
)));
}
}
...
@@ -260,8 +259,8 @@ TEST(InvokeArgumentTest, FunctionWithCStringLiteral) {
...
@@ -260,8 +259,8 @@ TEST(InvokeArgumentTest, FunctionWithCStringLiteral) {
// Tests using InvokeArgument with a function that takes a const reference.
// Tests using InvokeArgument with a function that takes a const reference.
TEST
(
InvokeArgumentTest
,
ByConstReferenceFunction
)
{
TEST
(
InvokeArgumentTest
,
ByConstReferenceFunction
)
{
Action
<
bool
(
bool
(
*
function
)(
const
string
&
s
))
>
a
=
// NOLINT
Action
<
bool
(
bool
(
*
function
)(
const
std
::
string
&
s
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
string
(
"Hi"
));
InvokeArgument
<
0
>
(
std
::
string
(
"Hi"
));
// When action 'a' is constructed, it makes a copy of the temporary
// When action 'a' is constructed, it makes a copy of the temporary
// string object passed to it, so it's OK to use 'a' later, when the
// string object passed to it, so it's OK to use 'a' later, when the
// temporary object has already died.
// temporary object has already died.
...
@@ -305,17 +304,18 @@ TEST(WithArgsTest, ThreeArgs) {
...
@@ -305,17 +304,18 @@ TEST(WithArgsTest, ThreeArgs) {
// Tests using WithArgs with an action that takes 4 arguments.
// Tests using WithArgs with an action that takes 4 arguments.
TEST
(
WithArgsTest
,
FourArgs
)
{
TEST
(
WithArgsTest
,
FourArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
double
,
const
char
*
,
const
char
*
)
>
a
=
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
double
,
const
char
*
,
WithArgs
<
4
,
3
,
1
,
0
>
(
Invoke
(
Concat4
));
const
char
*
)
>
a
=
WithArgs
<
4
,
3
,
1
,
0
>
(
Invoke
(
Concat4
));
EXPECT_EQ
(
"4310"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
2.5
,
EXPECT_EQ
(
"4310"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
2.5
,
CharPtr
(
"3"
),
CharPtr
(
"4"
))));
CharPtr
(
"3"
),
CharPtr
(
"4"
))));
}
}
// Tests using WithArgs with an action that takes 5 arguments.
// Tests using WithArgs with an action that takes 5 arguments.
TEST
(
WithArgsTest
,
FiveArgs
)
{
TEST
(
WithArgsTest
,
FiveArgs
)
{
Action
<
st
ring
(
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
st
d
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
const
char
*
)
>
WithArgs
<
4
,
3
,
2
,
1
,
0
>
(
Invoke
(
Concat5
));
a
=
WithArgs
<
4
,
3
,
2
,
1
,
0
>
(
Invoke
(
Concat5
));
EXPECT_EQ
(
"43210"
,
EXPECT_EQ
(
"43210"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
))));
CharPtr
(
"3"
),
CharPtr
(
"4"
))));
...
@@ -323,7 +323,7 @@ TEST(WithArgsTest, FiveArgs) {
...
@@ -323,7 +323,7 @@ TEST(WithArgsTest, FiveArgs) {
// Tests using WithArgs with an action that takes 6 arguments.
// Tests using WithArgs with an action that takes 6 arguments.
TEST
(
WithArgsTest
,
SixArgs
)
{
TEST
(
WithArgsTest
,
SixArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
2
,
1
,
0
>
(
Invoke
(
Concat6
));
WithArgs
<
0
,
1
,
2
,
2
,
1
,
0
>
(
Invoke
(
Concat6
));
EXPECT_EQ
(
"012210"
,
EXPECT_EQ
(
"012210"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
))));
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
))));
...
@@ -331,7 +331,7 @@ TEST(WithArgsTest, SixArgs) {
...
@@ -331,7 +331,7 @@ TEST(WithArgsTest, SixArgs) {
// Tests using WithArgs with an action that takes 7 arguments.
// Tests using WithArgs with an action that takes 7 arguments.
TEST
(
WithArgsTest
,
SevenArgs
)
{
TEST
(
WithArgsTest
,
SevenArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
2
,
1
,
0
>
(
Invoke
(
Concat7
));
WithArgs
<
0
,
1
,
2
,
3
,
2
,
1
,
0
>
(
Invoke
(
Concat7
));
EXPECT_EQ
(
"0123210"
,
EXPECT_EQ
(
"0123210"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
...
@@ -340,7 +340,7 @@ TEST(WithArgsTest, SevenArgs) {
...
@@ -340,7 +340,7 @@ TEST(WithArgsTest, SevenArgs) {
// Tests using WithArgs with an action that takes 8 arguments.
// Tests using WithArgs with an action that takes 8 arguments.
TEST
(
WithArgsTest
,
EightArgs
)
{
TEST
(
WithArgsTest
,
EightArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
0
,
1
,
2
,
3
>
(
Invoke
(
Concat8
));
WithArgs
<
0
,
1
,
2
,
3
,
0
,
1
,
2
,
3
>
(
Invoke
(
Concat8
));
EXPECT_EQ
(
"01230123"
,
EXPECT_EQ
(
"01230123"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
...
@@ -349,7 +349,7 @@ TEST(WithArgsTest, EightArgs) {
...
@@ -349,7 +349,7 @@ TEST(WithArgsTest, EightArgs) {
// Tests using WithArgs with an action that takes 9 arguments.
// Tests using WithArgs with an action that takes 9 arguments.
TEST
(
WithArgsTest
,
NineArgs
)
{
TEST
(
WithArgsTest
,
NineArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
1
,
2
,
3
,
2
,
3
>
(
Invoke
(
Concat9
));
WithArgs
<
0
,
1
,
2
,
3
,
1
,
2
,
3
,
2
,
3
>
(
Invoke
(
Concat9
));
EXPECT_EQ
(
"012312323"
,
EXPECT_EQ
(
"012312323"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
...
@@ -358,7 +358,7 @@ TEST(WithArgsTest, NineArgs) {
...
@@ -358,7 +358,7 @@ TEST(WithArgsTest, NineArgs) {
// Tests using WithArgs with an action that takes 10 arguments.
// Tests using WithArgs with an action that takes 10 arguments.
TEST
(
WithArgsTest
,
TenArgs
)
{
TEST
(
WithArgsTest
,
TenArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
2
,
1
,
0
,
1
,
2
,
3
>
(
Invoke
(
Concat10
));
WithArgs
<
0
,
1
,
2
,
3
,
2
,
1
,
0
,
1
,
2
,
3
>
(
Invoke
(
Concat10
));
EXPECT_EQ
(
"0123210123"
,
EXPECT_EQ
(
"0123210123"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
...
...
googlemock/test/gmock-generated-function-mockers_test.cc
View file @
7cc548dc
...
@@ -57,7 +57,6 @@
...
@@ -57,7 +57,6 @@
namespace
testing
{
namespace
testing
{
namespace
gmock_generated_function_mockers_test
{
namespace
gmock_generated_function_mockers_test
{
using
testing
::
internal
::
string
;
using
testing
::
_
;
using
testing
::
_
;
using
testing
::
A
;
using
testing
::
A
;
using
testing
::
An
;
using
testing
::
An
;
...
@@ -82,11 +81,11 @@ class FooInterface {
...
@@ -82,11 +81,11 @@ class FooInterface {
virtual
bool
Unary
(
int
x
)
=
0
;
virtual
bool
Unary
(
int
x
)
=
0
;
virtual
long
Binary
(
short
x
,
int
y
)
=
0
;
// NOLINT
virtual
long
Binary
(
short
x
,
int
y
)
=
0
;
// NOLINT
virtual
int
Decimal
(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
// NOLINT
virtual
int
Decimal
(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
// NOLINT
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
string
&
k
)
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
=
0
;
const
std
::
string
&
k
)
=
0
;
virtual
bool
TakesNonConstReference
(
int
&
n
)
=
0
;
// NOLINT
virtual
bool
TakesNonConstReference
(
int
&
n
)
=
0
;
// NOLINT
virtual
string
TakesConstReference
(
const
int
&
n
)
=
0
;
virtual
std
::
string
TakesConstReference
(
const
int
&
n
)
=
0
;
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
virtual
bool
TakesConst
(
const
int
x
)
=
0
;
virtual
bool
TakesConst
(
const
int
x
)
=
0
;
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
...
@@ -101,13 +100,14 @@ class FooInterface {
...
@@ -101,13 +100,14 @@ class FooInterface {
virtual
char
OverloadedOnConstness
()
const
=
0
;
virtual
char
OverloadedOnConstness
()
const
=
0
;
virtual
int
TypeWithHole
(
int
(
*
func
)())
=
0
;
virtual
int
TypeWithHole
(
int
(
*
func
)())
=
0
;
virtual
int
TypeWithComma
(
const
std
::
map
<
int
,
string
>&
a_map
)
=
0
;
virtual
int
TypeWithComma
(
const
std
::
map
<
int
,
std
::
string
>&
a_map
)
=
0
;
#if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
STDMETHOD_
(
int
,
CTNullary
)()
=
0
;
STDMETHOD_
(
int
,
CTNullary
)()
=
0
;
STDMETHOD_
(
bool
,
CTUnary
)(
int
x
)
=
0
;
STDMETHOD_
(
bool
,
CTUnary
)(
int
x
)
=
0
;
STDMETHOD_
(
int
,
CTDecimal
)(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
// NOLINT
STDMETHOD_
(
int
,
CTDecimal
)
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
string
&
k
)
=
0
;
(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
// NOLINT
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
std
::
string
&
k
)
=
0
;
STDMETHOD_
(
char
,
CTConst
)(
int
x
)
const
=
0
;
STDMETHOD_
(
char
,
CTConst
)(
int
x
)
const
=
0
;
#endif // GTEST_OS_WINDOWS
#endif // GTEST_OS_WINDOWS
};
};
...
@@ -133,19 +133,19 @@ class MockFoo : public FooInterface {
...
@@ -133,19 +133,19 @@ class MockFoo : public FooInterface {
MOCK_METHOD1
(
Unary
,
bool
(
int
));
// NOLINT
MOCK_METHOD1
(
Unary
,
bool
(
int
));
// NOLINT
MOCK_METHOD2
(
Binary
,
long
(
short
,
int
));
// NOLINT
MOCK_METHOD2
(
Binary
,
long
(
short
,
int
));
// NOLINT
MOCK_METHOD10
(
Decimal
,
int
(
bool
,
char
,
short
,
int
,
long
,
float
,
// NOLINT
MOCK_METHOD10
(
Decimal
,
int
(
bool
,
char
,
short
,
int
,
long
,
float
,
// NOLINT
double
,
unsigned
,
char
*
,
const
string
&
str
));
double
,
unsigned
,
char
*
,
const
std
::
string
&
str
));
MOCK_METHOD1
(
TakesNonConstReference
,
bool
(
int
&
));
// NOLINT
MOCK_METHOD1
(
TakesNonConstReference
,
bool
(
int
&
));
// NOLINT
MOCK_METHOD1
(
TakesConstReference
,
string
(
const
int
&
));
MOCK_METHOD1
(
TakesConstReference
,
std
::
string
(
const
int
&
));
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
MOCK_METHOD1
(
TakesConst
,
bool
(
const
int
));
// NOLINT
MOCK_METHOD1
(
TakesConst
,
bool
(
const
int
));
// NOLINT
#endif
#endif
// Tests that the function return type can contain unprotected comma.
// Tests that the function return type can contain unprotected comma.
MOCK_METHOD0
(
ReturnTypeWithComma
,
std
::
map
<
int
,
string
>
());
MOCK_METHOD0
(
ReturnTypeWithComma
,
std
::
map
<
int
,
std
::
string
>
());
MOCK_CONST_METHOD1
(
ReturnTypeWithComma
,
MOCK_CONST_METHOD1
(
ReturnTypeWithComma
,
std
::
map
<
int
,
string
>
(
int
));
// NOLINT
std
::
map
<
int
,
std
::
string
>
(
int
));
// NOLINT
MOCK_METHOD0
(
OverloadedOnArgumentNumber
,
int
());
// NOLINT
MOCK_METHOD0
(
OverloadedOnArgumentNumber
,
int
());
// NOLINT
MOCK_METHOD1
(
OverloadedOnArgumentNumber
,
int
(
int
));
// NOLINT
MOCK_METHOD1
(
OverloadedOnArgumentNumber
,
int
(
int
));
// NOLINT
...
@@ -157,19 +157,21 @@ class MockFoo : public FooInterface {
...
@@ -157,19 +157,21 @@ class MockFoo : public FooInterface {
MOCK_CONST_METHOD0
(
OverloadedOnConstness
,
char
());
// NOLINT
MOCK_CONST_METHOD0
(
OverloadedOnConstness
,
char
());
// NOLINT
MOCK_METHOD1
(
TypeWithHole
,
int
(
int
(
*
)()));
// NOLINT
MOCK_METHOD1
(
TypeWithHole
,
int
(
int
(
*
)()));
// NOLINT
MOCK_METHOD1
(
TypeWithComma
,
int
(
const
std
::
map
<
int
,
string
>&
));
// NOLINT
MOCK_METHOD1
(
TypeWithComma
,
int
(
const
std
::
map
<
int
,
std
::
string
>&
));
// NOLINT
#if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
MOCK_METHOD0_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTNullary
,
int
());
MOCK_METHOD0_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTNullary
,
int
());
MOCK_METHOD1_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTUnary
,
bool
(
int
));
MOCK_METHOD1_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTUnary
,
bool
(
int
));
MOCK_METHOD10_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTDecimal
,
int
(
bool
b
,
char
c
,
MOCK_METHOD10_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTDecimal
,
short
d
,
int
e
,
long
f
,
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
int
(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
const
string
&
k
));
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
std
::
string
&
k
));
MOCK_CONST_METHOD1_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTConst
,
char
(
int
));
MOCK_CONST_METHOD1_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTConst
,
char
(
int
));
// Tests that the function return type can contain unprotected comma.
// Tests that the function return type can contain unprotected comma.
MOCK_METHOD0_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTReturnTypeWithComma
,
MOCK_METHOD0_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTReturnTypeWithComma
,
std
::
map
<
int
,
string
>
());
std
::
map
<
int
,
std
::
string
>
());
#endif // GTEST_OS_WINDOWS
#endif // GTEST_OS_WINDOWS
private:
private:
...
@@ -291,7 +293,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) {
...
@@ -291,7 +293,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) {
}
}
TEST_F
(
FunctionMockerTest
,
MocksReturnTypeWithComma
)
{
TEST_F
(
FunctionMockerTest
,
MocksReturnTypeWithComma
)
{
const
std
::
map
<
int
,
string
>
a_map
;
const
std
::
map
<
int
,
std
::
string
>
a_map
;
EXPECT_CALL
(
mock_foo_
,
ReturnTypeWithComma
())
EXPECT_CALL
(
mock_foo_
,
ReturnTypeWithComma
())
.
WillOnce
(
Return
(
a_map
));
.
WillOnce
(
Return
(
a_map
));
EXPECT_CALL
(
mock_foo_
,
ReturnTypeWithComma
(
42
))
EXPECT_CALL
(
mock_foo_
,
ReturnTypeWithComma
(
42
))
...
@@ -341,7 +343,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
...
@@ -341,7 +343,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
}
}
TEST_F
(
FunctionMockerTest
,
MocksReturnTypeWithCommaAndCallType
)
{
TEST_F
(
FunctionMockerTest
,
MocksReturnTypeWithCommaAndCallType
)
{
const
std
::
map
<
int
,
string
>
a_map
;
const
std
::
map
<
int
,
std
::
string
>
a_map
;
EXPECT_CALL
(
mock_foo_
,
CTReturnTypeWithComma
())
EXPECT_CALL
(
mock_foo_
,
CTReturnTypeWithComma
())
.
WillOnce
(
Return
(
a_map
));
.
WillOnce
(
Return
(
a_map
));
...
...
googlemock/test/gmock-generated-matchers_test.cc
View file @
7cc548dc
...
@@ -79,11 +79,10 @@ using testing::StaticAssertTypeEq;
...
@@ -79,11 +79,10 @@ using testing::StaticAssertTypeEq;
using
testing
::
StrEq
;
using
testing
::
StrEq
;
using
testing
::
Value
;
using
testing
::
Value
;
using
testing
::
internal
::
ElementsAreArrayMatcher
;
using
testing
::
internal
::
ElementsAreArrayMatcher
;
using
testing
::
internal
::
string
;
// Returns the description of the given matcher.
// Returns the description of the given matcher.
template
<
typename
T
>
template
<
typename
T
>
string
Describe
(
const
Matcher
<
T
>&
m
)
{
std
::
string
Describe
(
const
Matcher
<
T
>&
m
)
{
stringstream
ss
;
stringstream
ss
;
m
.
DescribeTo
(
&
ss
);
m
.
DescribeTo
(
&
ss
);
return
ss
.
str
();
return
ss
.
str
();
...
@@ -91,7 +90,7 @@ string Describe(const Matcher<T>& m) {
...
@@ -91,7 +90,7 @@ string Describe(const Matcher<T>& m) {
// Returns the description of the negation of the given matcher.
// Returns the description of the negation of the given matcher.
template
<
typename
T
>
template
<
typename
T
>
string
DescribeNegation
(
const
Matcher
<
T
>&
m
)
{
std
::
string
DescribeNegation
(
const
Matcher
<
T
>&
m
)
{
stringstream
ss
;
stringstream
ss
;
m
.
DescribeNegationTo
(
&
ss
);
m
.
DescribeNegationTo
(
&
ss
);
return
ss
.
str
();
return
ss
.
str
();
...
@@ -99,7 +98,7 @@ string DescribeNegation(const Matcher<T>& m) {
...
@@ -99,7 +98,7 @@ string DescribeNegation(const Matcher<T>& m) {
// Returns the reason why x matches, or doesn't match, m.
// Returns the reason why x matches, or doesn't match, m.
template
<
typename
MatcherType
,
typename
Value
>
template
<
typename
MatcherType
,
typename
Value
>
string
Explain
(
const
MatcherType
&
m
,
const
Value
&
x
)
{
std
::
string
Explain
(
const
MatcherType
&
m
,
const
Value
&
x
)
{
stringstream
ss
;
stringstream
ss
;
m
.
ExplainMatchResultTo
(
x
,
&
ss
);
m
.
ExplainMatchResultTo
(
x
,
&
ss
);
return
ss
.
str
();
return
ss
.
str
();
...
@@ -296,7 +295,7 @@ TEST(ElementsAreTest, CanDescribeExpectingOneElement) {
...
@@ -296,7 +295,7 @@ TEST(ElementsAreTest, CanDescribeExpectingOneElement) {
}
}
TEST
(
ElementsAreTest
,
CanDescribeExpectingManyElements
)
{
TEST
(
ElementsAreTest
,
CanDescribeExpectingManyElements
)
{
Matcher
<
list
<
string
>
>
m
=
ElementsAre
(
StrEq
(
"one"
),
"two"
);
Matcher
<
list
<
std
::
string
>
>
m
=
ElementsAre
(
StrEq
(
"one"
),
"two"
);
EXPECT_EQ
(
"has 2 elements where
\n
"
EXPECT_EQ
(
"has 2 elements where
\n
"
"element #0 is equal to
\"
one
\"
,
\n
"
"element #0 is equal to
\"
one
\"
,
\n
"
"element #1 is equal to
\"
two
\"
"
,
Describe
(
m
));
"element #1 is equal to
\"
two
\"
"
,
Describe
(
m
));
...
@@ -314,7 +313,7 @@ TEST(ElementsAreTest, CanDescribeNegationOfExpectingOneElment) {
...
@@ -314,7 +313,7 @@ TEST(ElementsAreTest, CanDescribeNegationOfExpectingOneElment) {
}
}
TEST
(
ElementsAreTest
,
CanDescribeNegationOfExpectingManyElements
)
{
TEST
(
ElementsAreTest
,
CanDescribeNegationOfExpectingManyElements
)
{
Matcher
<
const
list
<
string
>&
>
m
=
ElementsAre
(
"one"
,
"two"
);
Matcher
<
const
list
<
std
::
string
>&>
m
=
ElementsAre
(
"one"
,
"two"
);
EXPECT_EQ
(
"doesn't have 2 elements, or
\n
"
EXPECT_EQ
(
"doesn't have 2 elements, or
\n
"
"element #0 isn't equal to
\"
one
\"
, or
\n
"
"element #0 isn't equal to
\"
one
\"
, or
\n
"
"element #1 isn't equal to
\"
two
\"
"
,
DescribeNegation
(
m
));
"element #1 isn't equal to
\"
two
\"
"
,
DescribeNegation
(
m
));
...
@@ -365,21 +364,21 @@ TEST(ElementsAreTest, CanExplainMismatchRightSize) {
...
@@ -365,21 +364,21 @@ TEST(ElementsAreTest, CanExplainMismatchRightSize) {
}
}
TEST
(
ElementsAreTest
,
MatchesOneElementVector
)
{
TEST
(
ElementsAreTest
,
MatchesOneElementVector
)
{
vector
<
string
>
test_vector
;
vector
<
std
::
string
>
test_vector
;
test_vector
.
push_back
(
"test string"
);
test_vector
.
push_back
(
"test string"
);
EXPECT_THAT
(
test_vector
,
ElementsAre
(
StrEq
(
"test string"
)));
EXPECT_THAT
(
test_vector
,
ElementsAre
(
StrEq
(
"test string"
)));
}
}
TEST
(
ElementsAreTest
,
MatchesOneElementList
)
{
TEST
(
ElementsAreTest
,
MatchesOneElementList
)
{
list
<
string
>
test_list
;
list
<
std
::
string
>
test_list
;
test_list
.
push_back
(
"test string"
);
test_list
.
push_back
(
"test string"
);
EXPECT_THAT
(
test_list
,
ElementsAre
(
"test string"
));
EXPECT_THAT
(
test_list
,
ElementsAre
(
"test string"
));
}
}
TEST
(
ElementsAreTest
,
MatchesThreeElementVector
)
{
TEST
(
ElementsAreTest
,
MatchesThreeElementVector
)
{
vector
<
string
>
test_vector
;
vector
<
std
::
string
>
test_vector
;
test_vector
.
push_back
(
"one"
);
test_vector
.
push_back
(
"one"
);
test_vector
.
push_back
(
"two"
);
test_vector
.
push_back
(
"two"
);
test_vector
.
push_back
(
"three"
);
test_vector
.
push_back
(
"three"
);
...
@@ -428,30 +427,30 @@ TEST(ElementsAreTest, MatchesTenElementVector) {
...
@@ -428,30 +427,30 @@ TEST(ElementsAreTest, MatchesTenElementVector) {
}
}
TEST
(
ElementsAreTest
,
DoesNotMatchWrongSize
)
{
TEST
(
ElementsAreTest
,
DoesNotMatchWrongSize
)
{
vector
<
string
>
test_vector
;
vector
<
std
::
string
>
test_vector
;
test_vector
.
push_back
(
"test string"
);
test_vector
.
push_back
(
"test string"
);
test_vector
.
push_back
(
"test string"
);
test_vector
.
push_back
(
"test string"
);
Matcher
<
vector
<
string
>
>
m
=
ElementsAre
(
StrEq
(
"test string"
));
Matcher
<
vector
<
std
::
string
>
>
m
=
ElementsAre
(
StrEq
(
"test string"
));
EXPECT_FALSE
(
m
.
Matches
(
test_vector
));
EXPECT_FALSE
(
m
.
Matches
(
test_vector
));
}
}
TEST
(
ElementsAreTest
,
DoesNotMatchWrongValue
)
{
TEST
(
ElementsAreTest
,
DoesNotMatchWrongValue
)
{
vector
<
string
>
test_vector
;
vector
<
std
::
string
>
test_vector
;
test_vector
.
push_back
(
"other string"
);
test_vector
.
push_back
(
"other string"
);
Matcher
<
vector
<
string
>
>
m
=
ElementsAre
(
StrEq
(
"test string"
));
Matcher
<
vector
<
std
::
string
>
>
m
=
ElementsAre
(
StrEq
(
"test string"
));
EXPECT_FALSE
(
m
.
Matches
(
test_vector
));
EXPECT_FALSE
(
m
.
Matches
(
test_vector
));
}
}
TEST
(
ElementsAreTest
,
DoesNotMatchWrongOrder
)
{
TEST
(
ElementsAreTest
,
DoesNotMatchWrongOrder
)
{
vector
<
string
>
test_vector
;
vector
<
std
::
string
>
test_vector
;
test_vector
.
push_back
(
"one"
);
test_vector
.
push_back
(
"one"
);
test_vector
.
push_back
(
"three"
);
test_vector
.
push_back
(
"three"
);
test_vector
.
push_back
(
"two"
);
test_vector
.
push_back
(
"two"
);
Matcher
<
vector
<
string
>
>
m
=
ElementsAre
(
Matcher
<
vector
<
std
::
string
>
>
m
=
StrEq
(
"one"
),
StrEq
(
"two"
),
StrEq
(
"three"
));
ElementsAre
(
StrEq
(
"one"
),
StrEq
(
"two"
),
StrEq
(
"three"
));
EXPECT_FALSE
(
m
.
Matches
(
test_vector
));
EXPECT_FALSE
(
m
.
Matches
(
test_vector
));
}
}
...
@@ -527,7 +526,7 @@ TEST(ElementsAreTest, WorksWithTwoDimensionalNativeArray) {
...
@@ -527,7 +526,7 @@ TEST(ElementsAreTest, WorksWithTwoDimensionalNativeArray) {
}
}
TEST
(
ElementsAreTest
,
AcceptsStringLiteral
)
{
TEST
(
ElementsAreTest
,
AcceptsStringLiteral
)
{
string
array
[]
=
{
"hi"
,
"one"
,
"two"
};
std
::
string
array
[]
=
{
"hi"
,
"one"
,
"two"
};
EXPECT_THAT
(
array
,
ElementsAre
(
"hi"
,
"one"
,
"two"
));
EXPECT_THAT
(
array
,
ElementsAre
(
"hi"
,
"one"
,
"two"
));
EXPECT_THAT
(
array
,
Not
(
ElementsAre
(
"hi"
,
"one"
,
"too"
)));
EXPECT_THAT
(
array
,
Not
(
ElementsAre
(
"hi"
,
"one"
,
"too"
)));
}
}
...
@@ -546,10 +545,10 @@ TEST(ElementsAreTest, AcceptsArrayWithUnknownSize) {
...
@@ -546,10 +545,10 @@ TEST(ElementsAreTest, AcceptsArrayWithUnknownSize) {
// The size of kHi is not known in this test, but ElementsAre() should
// The size of kHi is not known in this test, but ElementsAre() should
// still accept it.
// still accept it.
string
array1
[]
=
{
"hi"
};
std
::
string
array1
[]
=
{
"hi"
};
EXPECT_THAT
(
array1
,
ElementsAre
(
kHi
));
EXPECT_THAT
(
array1
,
ElementsAre
(
kHi
));
string
array2
[]
=
{
"ho"
};
std
::
string
array2
[]
=
{
"ho"
};
EXPECT_THAT
(
array2
,
Not
(
ElementsAre
(
kHi
)));
EXPECT_THAT
(
array2
,
Not
(
ElementsAre
(
kHi
)));
}
}
...
@@ -589,7 +588,7 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
...
@@ -589,7 +588,7 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
TEST
(
ElementsAreArrayTest
,
CanBeCreatedWithArraySize
)
{
TEST
(
ElementsAreArrayTest
,
CanBeCreatedWithArraySize
)
{
const
char
*
a
[]
=
{
"one"
,
"two"
,
"three"
};
const
char
*
a
[]
=
{
"one"
,
"two"
,
"three"
};
vector
<
string
>
test_vector
(
a
,
a
+
GTEST_ARRAY_SIZE_
(
a
));
vector
<
std
::
string
>
test_vector
(
a
,
a
+
GTEST_ARRAY_SIZE_
(
a
));
EXPECT_THAT
(
test_vector
,
ElementsAreArray
(
a
,
GTEST_ARRAY_SIZE_
(
a
)));
EXPECT_THAT
(
test_vector
,
ElementsAreArray
(
a
,
GTEST_ARRAY_SIZE_
(
a
)));
const
char
**
p
=
a
;
const
char
**
p
=
a
;
...
@@ -600,7 +599,7 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) {
...
@@ -600,7 +599,7 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) {
TEST
(
ElementsAreArrayTest
,
CanBeCreatedWithoutArraySize
)
{
TEST
(
ElementsAreArrayTest
,
CanBeCreatedWithoutArraySize
)
{
const
char
*
a
[]
=
{
"one"
,
"two"
,
"three"
};
const
char
*
a
[]
=
{
"one"
,
"two"
,
"three"
};
vector
<
string
>
test_vector
(
a
,
a
+
GTEST_ARRAY_SIZE_
(
a
));
vector
<
std
::
string
>
test_vector
(
a
,
a
+
GTEST_ARRAY_SIZE_
(
a
));
EXPECT_THAT
(
test_vector
,
ElementsAreArray
(
a
));
EXPECT_THAT
(
test_vector
,
ElementsAreArray
(
a
));
test_vector
[
0
]
=
"1"
;
test_vector
[
0
]
=
"1"
;
...
@@ -608,10 +607,10 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) {
...
@@ -608,10 +607,10 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) {
}
}
TEST
(
ElementsAreArrayTest
,
CanBeCreatedWithMatcherArray
)
{
TEST
(
ElementsAreArrayTest
,
CanBeCreatedWithMatcherArray
)
{
const
Matcher
<
string
>
kMatcherArray
[]
=
const
Matcher
<
std
::
string
>
kMatcherArray
[]
=
{
StrEq
(
"one"
),
StrEq
(
"two"
),
{
StrEq
(
"one"
),
StrEq
(
"two"
),
StrEq
(
"three"
)
};
StrEq
(
"three"
)};
vector
<
string
>
test_vector
;
vector
<
std
::
string
>
test_vector
;
test_vector
.
push_back
(
"one"
);
test_vector
.
push_back
(
"one"
);
test_vector
.
push_back
(
"two"
);
test_vector
.
push_back
(
"two"
);
test_vector
.
push_back
(
"three"
);
test_vector
.
push_back
(
"three"
);
...
@@ -640,7 +639,7 @@ TEST(ElementsAreArrayTest, TakesInitializerList) {
...
@@ -640,7 +639,7 @@ TEST(ElementsAreArrayTest, TakesInitializerList) {
}
}
TEST
(
ElementsAreArrayTest
,
TakesInitializerListOfCStrings
)
{
TEST
(
ElementsAreArrayTest
,
TakesInitializerListOfCStrings
)
{
const
string
a
[
5
]
=
{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
};
const
std
::
string
a
[
5
]
=
{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
};
EXPECT_THAT
(
a
,
ElementsAreArray
({
"a"
,
"b"
,
"c"
,
"d"
,
"e"
}));
EXPECT_THAT
(
a
,
ElementsAreArray
({
"a"
,
"b"
,
"c"
,
"d"
,
"e"
}));
EXPECT_THAT
(
a
,
Not
(
ElementsAreArray
({
"a"
,
"b"
,
"c"
,
"e"
,
"d"
})));
EXPECT_THAT
(
a
,
Not
(
ElementsAreArray
({
"a"
,
"b"
,
"c"
,
"e"
,
"d"
})));
EXPECT_THAT
(
a
,
Not
(
ElementsAreArray
({
"a"
,
"b"
,
"c"
,
"d"
,
"ef"
})));
EXPECT_THAT
(
a
,
Not
(
ElementsAreArray
({
"a"
,
"b"
,
"c"
,
"d"
,
"ef"
})));
...
@@ -751,9 +750,9 @@ MATCHER(IsEven2, negation ? "is odd" : "is even") {
...
@@ -751,9 +750,9 @@ MATCHER(IsEven2, negation ? "is odd" : "is even") {
// This also tests that the description string can reference matcher
// This also tests that the description string can reference matcher
// parameters.
// parameters.
MATCHER_P2
(
EqSumOf
,
x
,
y
,
MATCHER_P2
(
EqSumOf
,
x
,
y
,
std
::
string
(
negation
?
"doesn't equal"
:
"equals"
)
+
string
(
negation
?
"doesn't equal"
:
"equals"
)
+
" the sum of
"
+
" the sum of "
+
PrintToString
(
x
)
+
" and
"
+
PrintToString
(
x
)
+
" and "
+
PrintToString
(
y
))
{
PrintToString
(
y
))
{
if
(
arg
==
(
x
+
y
))
{
if
(
arg
==
(
x
+
y
))
{
*
result_listener
<<
"OK"
;
*
result_listener
<<
"OK"
;
return
true
;
return
true
;
...
@@ -1117,12 +1116,12 @@ TEST(ContainsTest, ListMatchesWhenElementIsInContainer) {
...
@@ -1117,12 +1116,12 @@ TEST(ContainsTest, ListMatchesWhenElementIsInContainer) {
EXPECT_THAT
(
some_list
,
Contains
(
Gt
(
2.5
)));
EXPECT_THAT
(
some_list
,
Contains
(
Gt
(
2.5
)));
EXPECT_THAT
(
some_list
,
Contains
(
Eq
(
2.0
f
)));
EXPECT_THAT
(
some_list
,
Contains
(
Eq
(
2.0
f
)));
list
<
string
>
another_list
;
list
<
std
::
string
>
another_list
;
another_list
.
push_back
(
"fee"
);
another_list
.
push_back
(
"fee"
);
another_list
.
push_back
(
"fie"
);
another_list
.
push_back
(
"fie"
);
another_list
.
push_back
(
"foe"
);
another_list
.
push_back
(
"foe"
);
another_list
.
push_back
(
"fum"
);
another_list
.
push_back
(
"fum"
);
EXPECT_THAT
(
another_list
,
Contains
(
string
(
"fee"
)));
EXPECT_THAT
(
another_list
,
Contains
(
std
::
string
(
"fee"
)));
}
}
TEST
(
ContainsTest
,
ListDoesNotMatchWhenElementIsNotInContainer
)
{
TEST
(
ContainsTest
,
ListDoesNotMatchWhenElementIsNotInContainer
)
{
...
@@ -1146,7 +1145,7 @@ TEST(ContainsTest, SetMatchesWhenElementIsInContainer) {
...
@@ -1146,7 +1145,7 @@ TEST(ContainsTest, SetMatchesWhenElementIsInContainer) {
another_set
.
insert
(
"fie"
);
another_set
.
insert
(
"fie"
);
another_set
.
insert
(
"foe"
);
another_set
.
insert
(
"foe"
);
another_set
.
insert
(
"fum"
);
another_set
.
insert
(
"fum"
);
EXPECT_THAT
(
another_set
,
Contains
(
Eq
(
string
(
"fum"
))));
EXPECT_THAT
(
another_set
,
Contains
(
Eq
(
std
::
string
(
"fum"
))));
}
}
TEST
(
ContainsTest
,
SetDoesNotMatchWhenElementIsNotInContainer
)
{
TEST
(
ContainsTest
,
SetDoesNotMatchWhenElementIsNotInContainer
)
{
...
@@ -1157,7 +1156,7 @@ TEST(ContainsTest, SetDoesNotMatchWhenElementIsNotInContainer) {
...
@@ -1157,7 +1156,7 @@ TEST(ContainsTest, SetDoesNotMatchWhenElementIsNotInContainer) {
set
<
const
char
*>
c_string_set
;
set
<
const
char
*>
c_string_set
;
c_string_set
.
insert
(
"hello"
);
c_string_set
.
insert
(
"hello"
);
EXPECT_THAT
(
c_string_set
,
Not
(
Contains
(
string
(
"hello"
).
c_str
())));
EXPECT_THAT
(
c_string_set
,
Not
(
Contains
(
std
::
string
(
"hello"
).
c_str
())));
}
}
TEST
(
ContainsTest
,
ExplainsMatchResultCorrectly
)
{
TEST
(
ContainsTest
,
ExplainsMatchResultCorrectly
)
{
...
@@ -1189,13 +1188,14 @@ TEST(ContainsTest, MapMatchesWhenElementIsInContainer) {
...
@@ -1189,13 +1188,14 @@ TEST(ContainsTest, MapMatchesWhenElementIsInContainer) {
my_map
[
bar
]
=
2
;
my_map
[
bar
]
=
2
;
EXPECT_THAT
(
my_map
,
Contains
(
pair
<
const
char
*
const
,
int
>
(
bar
,
2
)));
EXPECT_THAT
(
my_map
,
Contains
(
pair
<
const
char
*
const
,
int
>
(
bar
,
2
)));
map
<
string
,
int
>
another_map
;
map
<
std
::
string
,
int
>
another_map
;
another_map
[
"fee"
]
=
1
;
another_map
[
"fee"
]
=
1
;
another_map
[
"fie"
]
=
2
;
another_map
[
"fie"
]
=
2
;
another_map
[
"foe"
]
=
3
;
another_map
[
"foe"
]
=
3
;
another_map
[
"fum"
]
=
4
;
another_map
[
"fum"
]
=
4
;
EXPECT_THAT
(
another_map
,
Contains
(
pair
<
const
string
,
int
>
(
string
(
"fee"
),
1
)));
EXPECT_THAT
(
another_map
,
EXPECT_THAT
(
another_map
,
Contains
(
pair
<
const
string
,
int
>
(
"fie"
,
2
)));
Contains
(
pair
<
const
std
::
string
,
int
>
(
std
::
string
(
"fee"
),
1
)));
EXPECT_THAT
(
another_map
,
Contains
(
pair
<
const
std
::
string
,
int
>
(
"fie"
,
2
)));
}
}
TEST
(
ContainsTest
,
MapDoesNotMatchWhenElementIsNotInContainer
)
{
TEST
(
ContainsTest
,
MapDoesNotMatchWhenElementIsNotInContainer
)
{
...
@@ -1207,7 +1207,7 @@ TEST(ContainsTest, MapDoesNotMatchWhenElementIsNotInContainer) {
...
@@ -1207,7 +1207,7 @@ TEST(ContainsTest, MapDoesNotMatchWhenElementIsNotInContainer) {
TEST
(
ContainsTest
,
ArrayMatchesWhenElementIsInContainer
)
{
TEST
(
ContainsTest
,
ArrayMatchesWhenElementIsInContainer
)
{
const
char
*
string_array
[]
=
{
"fee"
,
"fie"
,
"foe"
,
"fum"
};
const
char
*
string_array
[]
=
{
"fee"
,
"fie"
,
"foe"
,
"fum"
};
EXPECT_THAT
(
string_array
,
Contains
(
Eq
(
string
(
"fum"
))));
EXPECT_THAT
(
string_array
,
Contains
(
Eq
(
std
::
string
(
"fum"
))));
}
}
TEST
(
ContainsTest
,
ArrayDoesNotMatchWhenElementIsNotInContainer
)
{
TEST
(
ContainsTest
,
ArrayDoesNotMatchWhenElementIsNotInContainer
)
{
...
...
googlemock/test/gmock-internal-utils_test.cc
View file @
7cc548dc
...
@@ -319,11 +319,10 @@ TEST(TupleMatchesTest, WorksForSize2) {
...
@@ -319,11 +319,10 @@ TEST(TupleMatchesTest, WorksForSize2) {
TEST
(
TupleMatchesTest
,
WorksForSize5
)
{
TEST
(
TupleMatchesTest
,
WorksForSize5
)
{
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
long
>
,
// NOLINT
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
long
>
,
// NOLINT
Matcher
<
string
>
>
Matcher
<
std
::
string
>
>
matchers
(
Eq
(
1
),
Eq
(
'a'
),
Eq
(
true
),
Eq
(
2L
),
Eq
(
"hi"
));
matchers
(
Eq
(
1
),
Eq
(
'a'
),
Eq
(
true
),
Eq
(
2L
),
Eq
(
"hi"
));
tuple
<
int
,
char
,
bool
,
long
,
string
>
// NOLINT
tuple
<
int
,
char
,
bool
,
long
,
std
::
string
>
// NOLINT
values1
(
1
,
'a'
,
true
,
2L
,
"hi"
),
values1
(
1
,
'a'
,
true
,
2L
,
"hi"
),
values2
(
1
,
'a'
,
true
,
2L
,
"hello"
),
values2
(
1
,
'a'
,
true
,
2L
,
"hello"
),
values3
(
2
,
'a'
,
true
,
2L
,
"hi"
);
values3
(
2
,
'a'
,
true
,
2L
,
"hi"
);
EXPECT_TRUE
(
TupleMatches
(
matchers
,
values1
));
EXPECT_TRUE
(
TupleMatches
(
matchers
,
values1
));
...
@@ -375,7 +374,7 @@ class LogIsVisibleTest : public ::testing::Test {
...
@@ -375,7 +374,7 @@ class LogIsVisibleTest : public ::testing::Test {
virtual
void
TearDown
()
{
GMOCK_FLAG
(
verbose
)
=
original_verbose_
;
}
virtual
void
TearDown
()
{
GMOCK_FLAG
(
verbose
)
=
original_verbose_
;
}
string
original_verbose_
;
std
::
string
original_verbose_
;
};
};
TEST_F
(
LogIsVisibleTest
,
AlwaysReturnsTrueIfVerbosityIsInfo
)
{
TEST_F
(
LogIsVisibleTest
,
AlwaysReturnsTrueIfVerbosityIsInfo
)
{
...
@@ -402,9 +401,9 @@ TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
...
@@ -402,9 +401,9 @@ TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
// Verifies that Log() behaves correctly for the given verbosity level
// Verifies that Log() behaves correctly for the given verbosity level
// and log severity.
// and log severity.
void
TestLogWithSeverity
(
const
string
&
verbosity
,
LogSeverity
severity
,
void
TestLogWithSeverity
(
const
std
::
string
&
verbosity
,
LogSeverity
severity
,
bool
should_print
)
{
bool
should_print
)
{
const
string
old_flag
=
GMOCK_FLAG
(
verbose
);
const
std
::
string
old_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
verbosity
;
GMOCK_FLAG
(
verbose
)
=
verbosity
;
CaptureStdout
();
CaptureStdout
();
Log
(
severity
,
"Test log.
\n
"
,
0
);
Log
(
severity
,
"Test log.
\n
"
,
0
);
...
@@ -423,7 +422,7 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
...
@@ -423,7 +422,7 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
// Tests that when the stack_frames_to_skip parameter is negative,
// Tests that when the stack_frames_to_skip parameter is negative,
// Log() doesn't include the stack trace in the output.
// Log() doesn't include the stack trace in the output.
TEST
(
LogTest
,
NoStackTraceWhenStackFramesToSkipIsNegative
)
{
TEST
(
LogTest
,
NoStackTraceWhenStackFramesToSkipIsNegative
)
{
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
const
std
::
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
kInfoVerbosity
;
GMOCK_FLAG
(
verbose
)
=
kInfoVerbosity
;
CaptureStdout
();
CaptureStdout
();
Log
(
kInfo
,
"Test log.
\n
"
,
-
1
);
Log
(
kInfo
,
"Test log.
\n
"
,
-
1
);
...
@@ -432,7 +431,7 @@ TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
...
@@ -432,7 +431,7 @@ TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
}
}
struct
MockStackTraceGetter
:
testing
::
internal
::
OsStackTraceGetterInterface
{
struct
MockStackTraceGetter
:
testing
::
internal
::
OsStackTraceGetterInterface
{
virtual
string
CurrentStackTrace
(
int
max_depth
,
int
skip_count
)
{
virtual
std
::
string
CurrentStackTrace
(
int
max_depth
,
int
skip_count
)
{
return
(
testing
::
Message
()
<<
max_depth
<<
"::"
<<
skip_count
<<
"
\n
"
)
return
(
testing
::
Message
()
<<
max_depth
<<
"::"
<<
skip_count
<<
"
\n
"
)
.
GetString
();
.
GetString
();
}
}
...
@@ -447,11 +446,11 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
...
@@ -447,11 +446,11 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
CaptureStdout
();
CaptureStdout
();
Log
(
kWarning
,
"Test log.
\n
"
,
100
);
Log
(
kWarning
,
"Test log.
\n
"
,
100
);
const
string
log
=
GetCapturedStdout
();
const
std
::
string
log
=
GetCapturedStdout
();
string
expected_trace
=
std
::
string
expected_trace
=
(
testing
::
Message
()
<<
GTEST_FLAG
(
stack_trace_depth
)
<<
"::"
).
GetString
();
(
testing
::
Message
()
<<
GTEST_FLAG
(
stack_trace_depth
)
<<
"::"
).
GetString
();
string
expected_message
=
std
::
string
expected_message
=
"
\n
GMOCK WARNING:
\n
"
"
\n
GMOCK WARNING:
\n
"
"Test log.
\n
"
"Test log.
\n
"
"Stack trace:
\n
"
+
"Stack trace:
\n
"
+
...
@@ -547,7 +546,7 @@ TEST(TypeTraitsTest, remove_reference) {
...
@@ -547,7 +546,7 @@ TEST(TypeTraitsTest, remove_reference) {
// Verifies that Log() behaves correctly for the given verbosity level
// Verifies that Log() behaves correctly for the given verbosity level
// and log severity.
// and log severity.
std
::
string
GrabOutput
(
void
(
*
logger
)(),
const
char
*
verbosity
)
{
std
::
string
GrabOutput
(
void
(
*
logger
)(),
const
char
*
verbosity
)
{
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
const
std
::
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
verbosity
;
GMOCK_FLAG
(
verbose
)
=
verbosity
;
CaptureStdout
();
CaptureStdout
();
logger
();
logger
();
...
...
googlemock/test/gmock-matchers_test.cc
View file @
7cc548dc
...
@@ -189,7 +189,7 @@ Matcher<int> GreaterThan(int n) {
...
@@ -189,7 +189,7 @@ Matcher<int> GreaterThan(int n) {
return
MakeMatcher
(
new
GreaterThanMatcher
(
n
));
return
MakeMatcher
(
new
GreaterThanMatcher
(
n
));
}
}
string
OfType
(
const
string
&
type_name
)
{
std
::
string
OfType
(
const
std
::
string
&
type_name
)
{
#if GTEST_HAS_RTTI
#if GTEST_HAS_RTTI
return
" (of type "
+
type_name
+
")"
;
return
" (of type "
+
type_name
+
")"
;
#else
#else
...
@@ -199,7 +199,7 @@ string OfType(const string& type_name) {
...
@@ -199,7 +199,7 @@ string OfType(const string& type_name) {
// Returns the description of the given matcher.
// Returns the description of the given matcher.
template
<
typename
T
>
template
<
typename
T
>
string
Describe
(
const
Matcher
<
T
>&
m
)
{
std
::
string
Describe
(
const
Matcher
<
T
>&
m
)
{
stringstream
ss
;
stringstream
ss
;
m
.
DescribeTo
(
&
ss
);
m
.
DescribeTo
(
&
ss
);
return
ss
.
str
();
return
ss
.
str
();
...
@@ -207,7 +207,7 @@ string Describe(const Matcher<T>& m) {
...
@@ -207,7 +207,7 @@ string Describe(const Matcher<T>& m) {
// Returns the description of the negation of the given matcher.
// Returns the description of the negation of the given matcher.
template
<
typename
T
>
template
<
typename
T
>
string
DescribeNegation
(
const
Matcher
<
T
>&
m
)
{
std
::
string
DescribeNegation
(
const
Matcher
<
T
>&
m
)
{
stringstream
ss
;
stringstream
ss
;
m
.
DescribeNegationTo
(
&
ss
);
m
.
DescribeNegationTo
(
&
ss
);
return
ss
.
str
();
return
ss
.
str
();
...
@@ -215,7 +215,7 @@ string DescribeNegation(const Matcher<T>& m) {
...
@@ -215,7 +215,7 @@ string DescribeNegation(const Matcher<T>& m) {
// Returns the reason why x matches, or doesn't match, m.
// Returns the reason why x matches, or doesn't match, m.
template
<
typename
MatcherType
,
typename
Value
>
template
<
typename
MatcherType
,
typename
Value
>
string
Explain
(
const
MatcherType
&
m
,
const
Value
&
x
)
{
std
::
string
Explain
(
const
MatcherType
&
m
,
const
Value
&
x
)
{
StringMatchResultListener
listener
;
StringMatchResultListener
listener
;
ExplainMatchResult
(
m
,
x
,
&
listener
);
ExplainMatchResult
(
m
,
x
,
&
listener
);
return
listener
.
str
();
return
listener
.
str
();
...
@@ -973,7 +973,7 @@ TEST(LeTest, CanDescribeSelf) {
...
@@ -973,7 +973,7 @@ TEST(LeTest, CanDescribeSelf) {
// Tests that Lt(v) matches anything < v.
// Tests that Lt(v) matches anything < v.
TEST
(
LtTest
,
ImplementsLessThan
)
{
TEST
(
LtTest
,
ImplementsLessThan
)
{
Matcher
<
const
string
&>
m1
=
Lt
(
"Hello"
);
Matcher
<
const
std
::
string
&>
m1
=
Lt
(
"Hello"
);
EXPECT_TRUE
(
m1
.
Matches
(
"Abc"
));
EXPECT_TRUE
(
m1
.
Matches
(
"Abc"
));
EXPECT_FALSE
(
m1
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m1
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m1
.
Matches
(
"Hello, world!"
));
EXPECT_FALSE
(
m1
.
Matches
(
"Hello, world!"
));
...
@@ -1125,7 +1125,7 @@ TEST(RefTest, CanDescribeSelf) {
...
@@ -1125,7 +1125,7 @@ TEST(RefTest, CanDescribeSelf) {
Matcher
<
int
&>
m
=
Ref
(
n
);
Matcher
<
int
&>
m
=
Ref
(
n
);
stringstream
ss
;
stringstream
ss
;
ss
<<
"references the variable @"
<<
&
n
<<
" 5"
;
ss
<<
"references the variable @"
<<
&
n
<<
" 5"
;
EXPECT_EQ
(
string
(
ss
.
str
()
)
,
Describe
(
m
));
EXPECT_EQ
(
ss
.
str
(),
Describe
(
m
));
}
}
// Test that Ref(non_const_varialbe) can be used as a matcher for a
// Test that Ref(non_const_varialbe) can be used as a matcher for a
...
@@ -1169,27 +1169,27 @@ TEST(RefTest, ExplainsResult) {
...
@@ -1169,27 +1169,27 @@ TEST(RefTest, ExplainsResult) {
// Tests string comparison matchers.
// Tests string comparison matchers.
TEST
(
StrEqTest
,
MatchesEqualString
)
{
TEST
(
StrEqTest
,
MatchesEqualString
)
{
Matcher
<
const
char
*>
m
=
StrEq
(
string
(
"Hello"
));
Matcher
<
const
char
*>
m
=
StrEq
(
std
::
string
(
"Hello"
));
EXPECT_TRUE
(
m
.
Matches
(
"Hello"
));
EXPECT_TRUE
(
m
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m
.
Matches
(
"hello"
));
EXPECT_FALSE
(
m
.
Matches
(
"hello"
));
EXPECT_FALSE
(
m
.
Matches
(
NULL
));
EXPECT_FALSE
(
m
.
Matches
(
NULL
));
Matcher
<
const
string
&>
m2
=
StrEq
(
"Hello"
);
Matcher
<
const
std
::
string
&>
m2
=
StrEq
(
"Hello"
);
EXPECT_TRUE
(
m2
.
Matches
(
"Hello"
));
EXPECT_TRUE
(
m2
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hi"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hi"
));
}
}
TEST
(
StrEqTest
,
CanDescribeSelf
)
{
TEST
(
StrEqTest
,
CanDescribeSelf
)
{
Matcher
<
string
>
m
=
StrEq
(
"Hi-
\'\"
?
\\\a\b\f\n\r\t\v\xD3
"
);
Matcher
<
std
::
string
>
m
=
StrEq
(
"Hi-
\'\"
?
\\\a\b\f\n\r\t\v\xD3
"
);
EXPECT_EQ
(
"is equal to
\"
Hi-
\'\\\"
?
\\\\\\
a
\\
b
\\
f
\\
n
\\
r
\\
t
\\
v
\\
xD3
\"
"
,
EXPECT_EQ
(
"is equal to
\"
Hi-
\'\\\"
?
\\\\\\
a
\\
b
\\
f
\\
n
\\
r
\\
t
\\
v
\\
xD3
\"
"
,
Describe
(
m
));
Describe
(
m
));
string
str
(
"01204500800"
);
std
::
string
str
(
"01204500800"
);
str
[
3
]
=
'\0'
;
str
[
3
]
=
'\0'
;
Matcher
<
string
>
m2
=
StrEq
(
str
);
Matcher
<
std
::
string
>
m2
=
StrEq
(
str
);
EXPECT_EQ
(
"is equal to
\"
012
\\
04500800
\"
"
,
Describe
(
m2
));
EXPECT_EQ
(
"is equal to
\"
012
\\
04500800
\"
"
,
Describe
(
m2
));
str
[
0
]
=
str
[
6
]
=
str
[
7
]
=
str
[
9
]
=
str
[
10
]
=
'\0'
;
str
[
0
]
=
str
[
6
]
=
str
[
7
]
=
str
[
9
]
=
str
[
10
]
=
'\0'
;
Matcher
<
string
>
m3
=
StrEq
(
str
);
Matcher
<
std
::
string
>
m3
=
StrEq
(
str
);
EXPECT_EQ
(
"is equal to
\"\\
012
\\
045
\\
0
\\
08
\\
0
\\
0
\"
"
,
Describe
(
m3
));
EXPECT_EQ
(
"is equal to
\"\\
012
\\
045
\\
0
\\
08
\\
0
\\
0
\"
"
,
Describe
(
m3
));
}
}
...
@@ -1199,7 +1199,7 @@ TEST(StrNeTest, MatchesUnequalString) {
...
@@ -1199,7 +1199,7 @@ TEST(StrNeTest, MatchesUnequalString) {
EXPECT_TRUE
(
m
.
Matches
(
NULL
));
EXPECT_TRUE
(
m
.
Matches
(
NULL
));
EXPECT_FALSE
(
m
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m
.
Matches
(
"Hello"
));
Matcher
<
string
>
m2
=
StrNe
(
string
(
"Hello"
));
Matcher
<
std
::
string
>
m2
=
StrNe
(
std
::
string
(
"Hello"
));
EXPECT_TRUE
(
m2
.
Matches
(
"hello"
));
EXPECT_TRUE
(
m2
.
Matches
(
"hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hello"
));
}
}
...
@@ -1222,32 +1222,32 @@ TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
...
@@ -1222,32 +1222,32 @@ TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
}
}
TEST
(
StrCaseEqTest
,
MatchesEqualStringWith0IgnoringCase
)
{
TEST
(
StrCaseEqTest
,
MatchesEqualStringWith0IgnoringCase
)
{
string
str1
(
"oabocdooeoo"
);
std
::
string
str1
(
"oabocdooeoo"
);
string
str2
(
"OABOCDOOEOO"
);
std
::
string
str2
(
"OABOCDOOEOO"
);
Matcher
<
const
string
&>
m0
=
StrCaseEq
(
str1
);
Matcher
<
const
std
::
string
&>
m0
=
StrCaseEq
(
str1
);
EXPECT_FALSE
(
m0
.
Matches
(
str2
+
string
(
1
,
'\0'
)));
EXPECT_FALSE
(
m0
.
Matches
(
str2
+
std
::
string
(
1
,
'\0'
)));
str1
[
3
]
=
str2
[
3
]
=
'\0'
;
str1
[
3
]
=
str2
[
3
]
=
'\0'
;
Matcher
<
const
string
&>
m1
=
StrCaseEq
(
str1
);
Matcher
<
const
std
::
string
&>
m1
=
StrCaseEq
(
str1
);
EXPECT_TRUE
(
m1
.
Matches
(
str2
));
EXPECT_TRUE
(
m1
.
Matches
(
str2
));
str1
[
0
]
=
str1
[
6
]
=
str1
[
7
]
=
str1
[
10
]
=
'\0'
;
str1
[
0
]
=
str1
[
6
]
=
str1
[
7
]
=
str1
[
10
]
=
'\0'
;
str2
[
0
]
=
str2
[
6
]
=
str2
[
7
]
=
str2
[
10
]
=
'\0'
;
str2
[
0
]
=
str2
[
6
]
=
str2
[
7
]
=
str2
[
10
]
=
'\0'
;
Matcher
<
const
string
&>
m2
=
StrCaseEq
(
str1
);
Matcher
<
const
std
::
string
&>
m2
=
StrCaseEq
(
str1
);
str1
[
9
]
=
str2
[
9
]
=
'\0'
;
str1
[
9
]
=
str2
[
9
]
=
'\0'
;
EXPECT_FALSE
(
m2
.
Matches
(
str2
));
EXPECT_FALSE
(
m2
.
Matches
(
str2
));
Matcher
<
const
string
&>
m3
=
StrCaseEq
(
str1
);
Matcher
<
const
std
::
string
&>
m3
=
StrCaseEq
(
str1
);
EXPECT_TRUE
(
m3
.
Matches
(
str2
));
EXPECT_TRUE
(
m3
.
Matches
(
str2
));
EXPECT_FALSE
(
m3
.
Matches
(
str2
+
"x"
));
EXPECT_FALSE
(
m3
.
Matches
(
str2
+
"x"
));
str2
.
append
(
1
,
'\0'
);
str2
.
append
(
1
,
'\0'
);
EXPECT_FALSE
(
m3
.
Matches
(
str2
));
EXPECT_FALSE
(
m3
.
Matches
(
str2
));
EXPECT_FALSE
(
m3
.
Matches
(
string
(
str2
,
0
,
9
)));
EXPECT_FALSE
(
m3
.
Matches
(
std
::
string
(
str2
,
0
,
9
)));
}
}
TEST
(
StrCaseEqTest
,
CanDescribeSelf
)
{
TEST
(
StrCaseEqTest
,
CanDescribeSelf
)
{
Matcher
<
string
>
m
=
StrCaseEq
(
"Hi"
);
Matcher
<
std
::
string
>
m
=
StrCaseEq
(
"Hi"
);
EXPECT_EQ
(
"is equal to (ignoring case)
\"
Hi
\"
"
,
Describe
(
m
));
EXPECT_EQ
(
"is equal to (ignoring case)
\"
Hi
\"
"
,
Describe
(
m
));
}
}
...
@@ -1258,7 +1258,7 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) {
...
@@ -1258,7 +1258,7 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) {
EXPECT_FALSE
(
m
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m
.
Matches
(
"hello"
));
EXPECT_FALSE
(
m
.
Matches
(
"hello"
));
Matcher
<
string
>
m2
=
StrCaseNe
(
string
(
"Hello"
));
Matcher
<
std
::
string
>
m2
=
StrCaseNe
(
std
::
string
(
"Hello"
));
EXPECT_TRUE
(
m2
.
Matches
(
""
));
EXPECT_TRUE
(
m2
.
Matches
(
""
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hello"
));
}
}
...
@@ -1270,9 +1270,9 @@ TEST(StrCaseNeTest, CanDescribeSelf) {
...
@@ -1270,9 +1270,9 @@ TEST(StrCaseNeTest, CanDescribeSelf) {
// Tests that HasSubstr() works for matching string-typed values.
// Tests that HasSubstr() works for matching string-typed values.
TEST
(
HasSubstrTest
,
WorksForStringClasses
)
{
TEST
(
HasSubstrTest
,
WorksForStringClasses
)
{
const
Matcher
<
string
>
m1
=
HasSubstr
(
"foo"
);
const
Matcher
<
std
::
string
>
m1
=
HasSubstr
(
"foo"
);
EXPECT_TRUE
(
m1
.
Matches
(
string
(
"I love food."
)));
EXPECT_TRUE
(
m1
.
Matches
(
std
::
string
(
"I love food."
)));
EXPECT_FALSE
(
m1
.
Matches
(
string
(
"tofo"
)));
EXPECT_FALSE
(
m1
.
Matches
(
std
::
string
(
"tofo"
)));
const
Matcher
<
const
std
::
string
&>
m2
=
HasSubstr
(
"foo"
);
const
Matcher
<
const
std
::
string
&>
m2
=
HasSubstr
(
"foo"
);
EXPECT_TRUE
(
m2
.
Matches
(
std
::
string
(
"I love food."
)));
EXPECT_TRUE
(
m2
.
Matches
(
std
::
string
(
"I love food."
)));
...
@@ -1294,7 +1294,7 @@ TEST(HasSubstrTest, WorksForCStrings) {
...
@@ -1294,7 +1294,7 @@ TEST(HasSubstrTest, WorksForCStrings) {
// Tests that HasSubstr(s) describes itself properly.
// Tests that HasSubstr(s) describes itself properly.
TEST
(
HasSubstrTest
,
CanDescribeSelf
)
{
TEST
(
HasSubstrTest
,
CanDescribeSelf
)
{
Matcher
<
string
>
m
=
HasSubstr
(
"foo
\n\"
"
);
Matcher
<
std
::
string
>
m
=
HasSubstr
(
"foo
\n\"
"
);
EXPECT_EQ
(
"has substring
\"
foo
\\
n
\\\"\"
"
,
Describe
(
m
));
EXPECT_EQ
(
"has substring
\"
foo
\\
n
\\\"\"
"
,
Describe
(
m
));
}
}
...
@@ -1460,12 +1460,12 @@ TEST(PairTest, InsideContainsUsingMap) {
...
@@ -1460,12 +1460,12 @@ TEST(PairTest, InsideContainsUsingMap) {
// Tests StartsWith(s).
// Tests StartsWith(s).
TEST
(
StartsWithTest
,
MatchesStringWithGivenPrefix
)
{
TEST
(
StartsWithTest
,
MatchesStringWithGivenPrefix
)
{
const
Matcher
<
const
char
*>
m1
=
StartsWith
(
string
(
""
));
const
Matcher
<
const
char
*>
m1
=
StartsWith
(
std
::
string
(
""
));
EXPECT_TRUE
(
m1
.
Matches
(
"Hi"
));
EXPECT_TRUE
(
m1
.
Matches
(
"Hi"
));
EXPECT_TRUE
(
m1
.
Matches
(
""
));
EXPECT_TRUE
(
m1
.
Matches
(
""
));
EXPECT_FALSE
(
m1
.
Matches
(
NULL
));
EXPECT_FALSE
(
m1
.
Matches
(
NULL
));
const
Matcher
<
const
string
&>
m2
=
StartsWith
(
"Hi"
);
const
Matcher
<
const
std
::
string
&>
m2
=
StartsWith
(
"Hi"
);
EXPECT_TRUE
(
m2
.
Matches
(
"Hi"
));
EXPECT_TRUE
(
m2
.
Matches
(
"Hi"
));
EXPECT_TRUE
(
m2
.
Matches
(
"Hi Hi!"
));
EXPECT_TRUE
(
m2
.
Matches
(
"Hi Hi!"
));
EXPECT_TRUE
(
m2
.
Matches
(
"High"
));
EXPECT_TRUE
(
m2
.
Matches
(
"High"
));
...
@@ -1507,14 +1507,14 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) {
...
@@ -1507,14 +1507,14 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) {
EXPECT_TRUE
(
m1
.
Matches
(
"abcz"
));
EXPECT_TRUE
(
m1
.
Matches
(
"abcz"
));
EXPECT_FALSE
(
m1
.
Matches
(
NULL
));
EXPECT_FALSE
(
m1
.
Matches
(
NULL
));
const
Matcher
<
const
string
&>
m2
=
MatchesRegex
(
new
RE
(
"a.*z"
));
const
Matcher
<
const
std
::
string
&>
m2
=
MatchesRegex
(
new
RE
(
"a.*z"
));
EXPECT_TRUE
(
m2
.
Matches
(
"azbz"
));
EXPECT_TRUE
(
m2
.
Matches
(
"azbz"
));
EXPECT_FALSE
(
m2
.
Matches
(
"az1"
));
EXPECT_FALSE
(
m2
.
Matches
(
"az1"
));
EXPECT_FALSE
(
m2
.
Matches
(
"1az"
));
EXPECT_FALSE
(
m2
.
Matches
(
"1az"
));
}
}
TEST
(
MatchesRegexTest
,
CanDescribeSelf
)
{
TEST
(
MatchesRegexTest
,
CanDescribeSelf
)
{
Matcher
<
const
std
::
string
>
m1
=
MatchesRegex
(
string
(
"Hi.*"
));
Matcher
<
const
std
::
string
>
m1
=
MatchesRegex
(
std
::
string
(
"Hi.*"
));
EXPECT_EQ
(
"matches regular expression
\"
Hi.*
\"
"
,
Describe
(
m1
));
EXPECT_EQ
(
"matches regular expression
\"
Hi.*
\"
"
,
Describe
(
m1
));
Matcher
<
const
char
*>
m2
=
MatchesRegex
(
new
RE
(
"a.*"
));
Matcher
<
const
char
*>
m2
=
MatchesRegex
(
new
RE
(
"a.*"
));
...
@@ -1524,12 +1524,12 @@ TEST(MatchesRegexTest, CanDescribeSelf) {
...
@@ -1524,12 +1524,12 @@ TEST(MatchesRegexTest, CanDescribeSelf) {
// Tests ContainsRegex().
// Tests ContainsRegex().
TEST
(
ContainsRegexTest
,
MatchesStringContainingGivenRegex
)
{
TEST
(
ContainsRegexTest
,
MatchesStringContainingGivenRegex
)
{
const
Matcher
<
const
char
*>
m1
=
ContainsRegex
(
string
(
"a.*z"
));
const
Matcher
<
const
char
*>
m1
=
ContainsRegex
(
std
::
string
(
"a.*z"
));
EXPECT_TRUE
(
m1
.
Matches
(
"az"
));
EXPECT_TRUE
(
m1
.
Matches
(
"az"
));
EXPECT_TRUE
(
m1
.
Matches
(
"0abcz1"
));
EXPECT_TRUE
(
m1
.
Matches
(
"0abcz1"
));
EXPECT_FALSE
(
m1
.
Matches
(
NULL
));
EXPECT_FALSE
(
m1
.
Matches
(
NULL
));
const
Matcher
<
const
string
&>
m2
=
ContainsRegex
(
new
RE
(
"a.*z"
));
const
Matcher
<
const
std
::
string
&>
m2
=
ContainsRegex
(
new
RE
(
"a.*z"
));
EXPECT_TRUE
(
m2
.
Matches
(
"azbz"
));
EXPECT_TRUE
(
m2
.
Matches
(
"azbz"
));
EXPECT_TRUE
(
m2
.
Matches
(
"az1"
));
EXPECT_TRUE
(
m2
.
Matches
(
"az1"
));
EXPECT_FALSE
(
m2
.
Matches
(
"1a"
));
EXPECT_FALSE
(
m2
.
Matches
(
"1a"
));
...
@@ -2685,9 +2685,9 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
...
@@ -2685,9 +2685,9 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
Matcher
<
const
char
*>
starts_with_he
=
StartsWith
(
"he"
);
Matcher
<
const
char
*>
starts_with_he
=
StartsWith
(
"he"
);
ASSERT_THAT
(
"hello"
,
starts_with_he
);
ASSERT_THAT
(
"hello"
,
starts_with_he
);
Matcher
<
const
string
&>
ends_with_ok
=
EndsWith
(
"ok"
);
Matcher
<
const
std
::
string
&>
ends_with_ok
=
EndsWith
(
"ok"
);
ASSERT_THAT
(
"book"
,
ends_with_ok
);
ASSERT_THAT
(
"book"
,
ends_with_ok
);
const
string
bad
=
"bad"
;
const
std
::
string
bad
=
"bad"
;
EXPECT_NONFATAL_FAILURE
(
EXPECT_THAT
(
bad
,
ends_with_ok
),
EXPECT_NONFATAL_FAILURE
(
EXPECT_THAT
(
bad
,
ends_with_ok
),
"Value of: bad
\n
"
"Value of: bad
\n
"
"Expected: ends with
\"
ok
\"\n
"
"Expected: ends with
\"
ok
\"\n
"
...
@@ -3099,7 +3099,8 @@ TEST_F(DoubleNearTest, ExplainsResultWhenMatchFails) {
...
@@ -3099,7 +3099,8 @@ TEST_F(DoubleNearTest, ExplainsResultWhenMatchFails) {
EXPECT_EQ
(
"which is 0.2 from 2"
,
Explain
(
DoubleNear
(
2.0
,
0.1
),
2.2
));
EXPECT_EQ
(
"which is 0.2 from 2"
,
Explain
(
DoubleNear
(
2.0
,
0.1
),
2.2
));
EXPECT_EQ
(
"which is -0.3 from 2"
,
Explain
(
DoubleNear
(
2.0
,
0.1
),
1.7
));
EXPECT_EQ
(
"which is -0.3 from 2"
,
Explain
(
DoubleNear
(
2.0
,
0.1
),
1.7
));
const
string
explanation
=
Explain
(
DoubleNear
(
2.1
,
1e-10
),
2.1
+
1.2e-10
);
const
std
::
string
explanation
=
Explain
(
DoubleNear
(
2.1
,
1e-10
),
2.1
+
1.2e-10
);
// Different C++ implementations may print floating-point numbers
// Different C++ implementations may print floating-point numbers
// slightly differently.
// slightly differently.
EXPECT_TRUE
(
explanation
==
"which is 1.2e-10 from 2.1"
||
// GCC
EXPECT_TRUE
(
explanation
==
"which is 1.2e-10 from 2.1"
||
// GCC
...
@@ -3337,9 +3338,9 @@ TEST(PointeeTest, CanDescribeSelf) {
...
@@ -3337,9 +3338,9 @@ TEST(PointeeTest, CanDescribeSelf) {
}
}
TEST
(
PointeeTest
,
CanExplainMatchResult
)
{
TEST
(
PointeeTest
,
CanExplainMatchResult
)
{
const
Matcher
<
const
string
*>
m
=
Pointee
(
StartsWith
(
"Hi"
));
const
Matcher
<
const
std
::
string
*>
m
=
Pointee
(
StartsWith
(
"Hi"
));
EXPECT_EQ
(
""
,
Explain
(
m
,
static_cast
<
const
string
*>
(
NULL
)));
EXPECT_EQ
(
""
,
Explain
(
m
,
static_cast
<
const
std
::
string
*>
(
NULL
)));
const
Matcher
<
long
*>
m2
=
Pointee
(
GreaterThan
(
1
));
// NOLINT
const
Matcher
<
long
*>
m2
=
Pointee
(
GreaterThan
(
1
));
// NOLINT
long
n
=
3
;
// NOLINT
long
n
=
3
;
// NOLINT
...
@@ -3585,15 +3586,15 @@ class AClass {
...
@@ -3585,15 +3586,15 @@ class AClass {
void
set_n
(
int
new_n
)
{
n_
=
new_n
;
}
void
set_n
(
int
new_n
)
{
n_
=
new_n
;
}
// A getter that returns a reference to const.
// A getter that returns a reference to const.
const
string
&
s
()
const
{
return
s_
;
}
const
std
::
string
&
s
()
const
{
return
s_
;
}
void
set_s
(
const
string
&
new_s
)
{
s_
=
new_s
;
}
void
set_s
(
const
std
::
string
&
new_s
)
{
s_
=
new_s
;
}
// A getter that returns a reference to non-const.
// A getter that returns a reference to non-const.
double
&
x
()
const
{
return
x_
;
}
double
&
x
()
const
{
return
x_
;
}
private:
private:
int
n_
;
int
n_
;
string
s_
;
std
::
string
s_
;
static
double
x_
;
static
double
x_
;
};
};
...
@@ -3799,10 +3800,12 @@ TEST(PropertyForPointerTest, CanExplainMatchResult) {
...
@@ -3799,10 +3800,12 @@ TEST(PropertyForPointerTest, CanExplainMatchResult) {
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
// function pointer.
// function pointer.
string
IntToStringFunction
(
int
input
)
{
return
input
==
1
?
"foo"
:
"bar"
;
}
std
::
string
IntToStringFunction
(
int
input
)
{
return
input
==
1
?
"foo"
:
"bar"
;
}
TEST
(
ResultOfTest
,
WorksForFunctionPointers
)
{
TEST
(
ResultOfTest
,
WorksForFunctionPointers
)
{
Matcher
<
int
>
matcher
=
ResultOf
(
&
IntToStringFunction
,
Eq
(
string
(
"foo"
)));
Matcher
<
int
>
matcher
=
ResultOf
(
&
IntToStringFunction
,
Eq
(
std
::
string
(
"foo"
)));
EXPECT_TRUE
(
matcher
.
Matches
(
1
));
EXPECT_TRUE
(
matcher
.
Matches
(
1
));
EXPECT_FALSE
(
matcher
.
Matches
(
2
));
EXPECT_FALSE
(
matcher
.
Matches
(
2
));
...
@@ -3868,12 +3871,12 @@ TEST(ResultOfTest, WorksForReferenceToNonConstResults) {
...
@@ -3868,12 +3871,12 @@ TEST(ResultOfTest, WorksForReferenceToNonConstResults) {
// Tests that ResultOf(f, ...) compiles and works as expected when f(x)
// Tests that ResultOf(f, ...) compiles and works as expected when f(x)
// returns a reference to const.
// returns a reference to const.
const
string
&
StringFunction
(
const
string
&
input
)
{
return
input
;
}
const
std
::
string
&
StringFunction
(
const
std
::
string
&
input
)
{
return
input
;
}
TEST
(
ResultOfTest
,
WorksForReferenceToConstResults
)
{
TEST
(
ResultOfTest
,
WorksForReferenceToConstResults
)
{
string
s
=
"foo"
;
std
::
string
s
=
"foo"
;
string
s2
=
s
;
std
::
string
s2
=
s
;
Matcher
<
const
string
&>
matcher
=
ResultOf
(
&
StringFunction
,
Ref
(
s
));
Matcher
<
const
std
::
string
&>
matcher
=
ResultOf
(
&
StringFunction
,
Ref
(
s
));
EXPECT_TRUE
(
matcher
.
Matches
(
s
));
EXPECT_TRUE
(
matcher
.
Matches
(
s
));
EXPECT_FALSE
(
matcher
.
Matches
(
s2
));
EXPECT_FALSE
(
matcher
.
Matches
(
s2
));
...
@@ -3893,8 +3896,9 @@ TEST(ResultOfTest, WorksForCompatibleMatcherTypes) {
...
@@ -3893,8 +3896,9 @@ TEST(ResultOfTest, WorksForCompatibleMatcherTypes) {
// a NULL function pointer.
// a NULL function pointer.
TEST
(
ResultOfDeathTest
,
DiesOnNullFunctionPointers
)
{
TEST
(
ResultOfDeathTest
,
DiesOnNullFunctionPointers
)
{
EXPECT_DEATH_IF_SUPPORTED
(
EXPECT_DEATH_IF_SUPPORTED
(
ResultOf
(
static_cast
<
string
(
*
)(
int
dummy
)
>
(
NULL
),
Eq
(
string
(
"foo"
))),
ResultOf
(
static_cast
<
std
::
string
(
*
)(
int
dummy
)
>
(
NULL
),
"NULL function pointer is passed into ResultOf
\\
(
\\
)
\\
."
);
Eq
(
std
::
string
(
"foo"
))),
"NULL function pointer is passed into ResultOf
\\
(
\\
)
\\
."
);
}
}
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
...
@@ -3907,14 +3911,14 @@ TEST(ResultOfTest, WorksForFunctionReferences) {
...
@@ -3907,14 +3911,14 @@ TEST(ResultOfTest, WorksForFunctionReferences) {
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
// function object.
// function object.
struct
Functor
:
public
::
std
::
unary_function
<
int
,
string
>
{
struct
Functor
:
public
::
std
::
unary_function
<
int
,
std
::
string
>
{
result_type
operator
()(
argument_type
input
)
const
{
result_type
operator
()(
argument_type
input
)
const
{
return
IntToStringFunction
(
input
);
return
IntToStringFunction
(
input
);
}
}
};
};
TEST
(
ResultOfTest
,
WorksForFunctors
)
{
TEST
(
ResultOfTest
,
WorksForFunctors
)
{
Matcher
<
int
>
matcher
=
ResultOf
(
Functor
(),
Eq
(
string
(
"foo"
)));
Matcher
<
int
>
matcher
=
ResultOf
(
Functor
(),
Eq
(
std
::
string
(
"foo"
)));
EXPECT_TRUE
(
matcher
.
Matches
(
1
));
EXPECT_TRUE
(
matcher
.
Matches
(
1
));
EXPECT_FALSE
(
matcher
.
Matches
(
2
));
EXPECT_FALSE
(
matcher
.
Matches
(
2
));
...
@@ -4080,11 +4084,11 @@ TEST(IsEmptyTest, ImplementsIsEmpty) {
...
@@ -4080,11 +4084,11 @@ TEST(IsEmptyTest, ImplementsIsEmpty) {
}
}
TEST
(
IsEmptyTest
,
WorksWithString
)
{
TEST
(
IsEmptyTest
,
WorksWithString
)
{
string
text
;
std
::
string
text
;
EXPECT_THAT
(
text
,
IsEmpty
());
EXPECT_THAT
(
text
,
IsEmpty
());
text
=
"foo"
;
text
=
"foo"
;
EXPECT_THAT
(
text
,
Not
(
IsEmpty
()));
EXPECT_THAT
(
text
,
Not
(
IsEmpty
()));
text
=
string
(
"
\0
"
,
1
);
text
=
std
::
string
(
"
\0
"
,
1
);
EXPECT_THAT
(
text
,
Not
(
IsEmpty
()));
EXPECT_THAT
(
text
,
Not
(
IsEmpty
()));
}
}
...
@@ -4115,7 +4119,7 @@ TEST(SizeIsTest, ImplementsSizeIs) {
...
@@ -4115,7 +4119,7 @@ TEST(SizeIsTest, ImplementsSizeIs) {
}
}
TEST
(
SizeIsTest
,
WorksWithMap
)
{
TEST
(
SizeIsTest
,
WorksWithMap
)
{
map
<
string
,
int
>
container
;
map
<
std
::
string
,
int
>
container
;
EXPECT_THAT
(
container
,
SizeIs
(
0
));
EXPECT_THAT
(
container
,
SizeIs
(
0
));
EXPECT_THAT
(
container
,
Not
(
SizeIs
(
1
)));
EXPECT_THAT
(
container
,
Not
(
SizeIs
(
1
)));
container
.
insert
(
make_pair
(
"foo"
,
1
));
container
.
insert
(
make_pair
(
"foo"
,
1
));
...
@@ -4380,13 +4384,13 @@ TEST(WhenSortedByTest, WorksForNonEmptyContainer) {
...
@@ -4380,13 +4384,13 @@ TEST(WhenSortedByTest, WorksForNonEmptyContainer) {
}
}
TEST
(
WhenSortedByTest
,
WorksForNonVectorContainer
)
{
TEST
(
WhenSortedByTest
,
WorksForNonVectorContainer
)
{
list
<
string
>
words
;
list
<
std
::
string
>
words
;
words
.
push_back
(
"say"
);
words
.
push_back
(
"say"
);
words
.
push_back
(
"hello"
);
words
.
push_back
(
"hello"
);
words
.
push_back
(
"world"
);
words
.
push_back
(
"world"
);
EXPECT_THAT
(
words
,
WhenSortedBy
(
less
<
string
>
(),
EXPECT_THAT
(
words
,
WhenSortedBy
(
less
<
std
::
string
>
(),
ElementsAre
(
"hello"
,
"say"
,
"world"
)));
ElementsAre
(
"hello"
,
"say"
,
"world"
)));
EXPECT_THAT
(
words
,
Not
(
WhenSortedBy
(
less
<
string
>
(),
EXPECT_THAT
(
words
,
Not
(
WhenSortedBy
(
less
<
std
::
string
>
(),
ElementsAre
(
"say"
,
"hello"
,
"world"
))));
ElementsAre
(
"say"
,
"hello"
,
"world"
))));
}
}
...
@@ -4429,7 +4433,7 @@ TEST(WhenSortedTest, WorksForEmptyContainer) {
...
@@ -4429,7 +4433,7 @@ TEST(WhenSortedTest, WorksForEmptyContainer) {
}
}
TEST
(
WhenSortedTest
,
WorksForNonEmptyContainer
)
{
TEST
(
WhenSortedTest
,
WorksForNonEmptyContainer
)
{
list
<
string
>
words
;
list
<
std
::
string
>
words
;
words
.
push_back
(
"3"
);
words
.
push_back
(
"3"
);
words
.
push_back
(
"1"
);
words
.
push_back
(
"1"
);
words
.
push_back
(
"2"
);
words
.
push_back
(
"2"
);
...
@@ -4439,14 +4443,16 @@ TEST(WhenSortedTest, WorksForNonEmptyContainer) {
...
@@ -4439,14 +4443,16 @@ TEST(WhenSortedTest, WorksForNonEmptyContainer) {
}
}
TEST
(
WhenSortedTest
,
WorksForMapTypes
)
{
TEST
(
WhenSortedTest
,
WorksForMapTypes
)
{
map
<
string
,
int
>
word_counts
;
map
<
std
::
string
,
int
>
word_counts
;
word_counts
[
"and"
]
=
1
;
word_counts
[
"and"
]
=
1
;
word_counts
[
"the"
]
=
1
;
word_counts
[
"the"
]
=
1
;
word_counts
[
"buffalo"
]
=
2
;
word_counts
[
"buffalo"
]
=
2
;
EXPECT_THAT
(
word_counts
,
WhenSorted
(
ElementsAre
(
EXPECT_THAT
(
word_counts
,
Pair
(
"and"
,
1
),
Pair
(
"buffalo"
,
2
),
Pair
(
"the"
,
1
))));
WhenSorted
(
ElementsAre
(
Pair
(
"and"
,
1
),
Pair
(
"buffalo"
,
2
),
EXPECT_THAT
(
word_counts
,
Not
(
WhenSorted
(
ElementsAre
(
Pair
(
"the"
,
1
))));
Pair
(
"and"
,
1
),
Pair
(
"the"
,
1
),
Pair
(
"buffalo"
,
2
)))));
EXPECT_THAT
(
word_counts
,
Not
(
WhenSorted
(
ElementsAre
(
Pair
(
"and"
,
1
),
Pair
(
"the"
,
1
),
Pair
(
"buffalo"
,
2
)))));
}
}
TEST
(
WhenSortedTest
,
WorksForMultiMapTypes
)
{
TEST
(
WhenSortedTest
,
WorksForMultiMapTypes
)
{
...
@@ -4763,7 +4769,7 @@ TEST(UnorderedElementsAreArrayTest, TakesInitializerList) {
...
@@ -4763,7 +4769,7 @@ TEST(UnorderedElementsAreArrayTest, TakesInitializerList) {
}
}
TEST
(
UnorderedElementsAreArrayTest
,
TakesInitializerListOfCStrings
)
{
TEST
(
UnorderedElementsAreArrayTest
,
TakesInitializerListOfCStrings
)
{
const
string
a
[
5
]
=
{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
};
const
std
::
string
a
[
5
]
=
{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
};
EXPECT_THAT
(
a
,
UnorderedElementsAreArray
({
"a"
,
"b"
,
"c"
,
"d"
,
"e"
}));
EXPECT_THAT
(
a
,
UnorderedElementsAreArray
({
"a"
,
"b"
,
"c"
,
"d"
,
"e"
}));
EXPECT_THAT
(
a
,
Not
(
UnorderedElementsAreArray
({
"a"
,
"b"
,
"c"
,
"d"
,
"ef"
})));
EXPECT_THAT
(
a
,
Not
(
UnorderedElementsAreArray
({
"a"
,
"b"
,
"c"
,
"d"
,
"ef"
})));
}
}
...
@@ -4937,7 +4943,7 @@ TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedMatcherAndElement) {
...
@@ -4937,7 +4943,7 @@ TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedMatcherAndElement) {
}
}
// Test helper for formatting element, matcher index pairs in expectations.
// Test helper for formatting element, matcher index pairs in expectations.
static
string
EMString
(
int
element
,
int
matcher
)
{
static
std
::
string
EMString
(
int
element
,
int
matcher
)
{
stringstream
ss
;
stringstream
ss
;
ss
<<
"(element #"
<<
element
<<
", matcher #"
<<
matcher
<<
")"
;
ss
<<
"(element #"
<<
element
<<
", matcher #"
<<
matcher
<<
")"
;
return
ss
.
str
();
return
ss
.
str
();
...
@@ -4946,7 +4952,7 @@ static string EMString(int element, int matcher) {
...
@@ -4946,7 +4952,7 @@ static string EMString(int element, int matcher) {
TEST_F
(
UnorderedElementsAreTest
,
FailMessageImperfectMatchOnly
)
{
TEST_F
(
UnorderedElementsAreTest
,
FailMessageImperfectMatchOnly
)
{
// A situation where all elements and matchers have a match
// A situation where all elements and matchers have a match
// associated with them, but the max matching is not perfect.
// associated with them, but the max matching is not perfect.
std
::
vector
<
string
>
v
;
std
::
vector
<
std
::
string
>
v
;
v
.
push_back
(
"a"
);
v
.
push_back
(
"a"
);
v
.
push_back
(
"b"
);
v
.
push_back
(
"b"
);
v
.
push_back
(
"c"
);
v
.
push_back
(
"c"
);
...
@@ -4955,7 +4961,7 @@ TEST_F(UnorderedElementsAreTest, FailMessageImperfectMatchOnly) {
...
@@ -4955,7 +4961,7 @@ TEST_F(UnorderedElementsAreTest, FailMessageImperfectMatchOnly) {
UnorderedElementsAre
(
"a"
,
"a"
,
AnyOf
(
"b"
,
"c"
)),
v
,
&
listener
))
UnorderedElementsAre
(
"a"
,
"a"
,
AnyOf
(
"b"
,
"c"
)),
v
,
&
listener
))
<<
listener
.
str
();
<<
listener
.
str
();
string
prefix
=
std
::
string
prefix
=
"where no permutation of the elements can satisfy all matchers, "
"where no permutation of the elements can satisfy all matchers, "
"and the closest match is 2 of 3 matchers with the "
"and the closest match is 2 of 3 matchers with the "
"pairings:
\n
"
;
"pairings:
\n
"
;
...
@@ -5366,13 +5372,13 @@ TEST(EachTest, MatchesVectorWhenAllElementsMatch) {
...
@@ -5366,13 +5372,13 @@ TEST(EachTest, MatchesVectorWhenAllElementsMatch) {
EXPECT_THAT
(
some_vector
,
Not
(
Each
(
3
)));
EXPECT_THAT
(
some_vector
,
Not
(
Each
(
3
)));
EXPECT_THAT
(
some_vector
,
Each
(
Lt
(
3.5
)));
EXPECT_THAT
(
some_vector
,
Each
(
Lt
(
3.5
)));
vector
<
string
>
another_vector
;
vector
<
std
::
string
>
another_vector
;
another_vector
.
push_back
(
"fee"
);
another_vector
.
push_back
(
"fee"
);
EXPECT_THAT
(
another_vector
,
Each
(
string
(
"fee"
)));
EXPECT_THAT
(
another_vector
,
Each
(
std
::
string
(
"fee"
)));
another_vector
.
push_back
(
"fie"
);
another_vector
.
push_back
(
"fie"
);
another_vector
.
push_back
(
"foe"
);
another_vector
.
push_back
(
"foe"
);
another_vector
.
push_back
(
"fum"
);
another_vector
.
push_back
(
"fum"
);
EXPECT_THAT
(
another_vector
,
Not
(
Each
(
string
(
"fee"
))));
EXPECT_THAT
(
another_vector
,
Not
(
Each
(
std
::
string
(
"fee"
))));
}
}
TEST
(
EachTest
,
MatchesMapWhenAllElementsMatch
)
{
TEST
(
EachTest
,
MatchesMapWhenAllElementsMatch
)
{
...
@@ -5381,15 +5387,15 @@ TEST(EachTest, MatchesMapWhenAllElementsMatch) {
...
@@ -5381,15 +5387,15 @@ TEST(EachTest, MatchesMapWhenAllElementsMatch) {
my_map
[
bar
]
=
2
;
my_map
[
bar
]
=
2
;
EXPECT_THAT
(
my_map
,
Each
(
make_pair
(
bar
,
2
)));
EXPECT_THAT
(
my_map
,
Each
(
make_pair
(
bar
,
2
)));
map
<
string
,
int
>
another_map
;
map
<
std
::
string
,
int
>
another_map
;
EXPECT_THAT
(
another_map
,
Each
(
make_pair
(
string
(
"fee"
),
1
)));
EXPECT_THAT
(
another_map
,
Each
(
make_pair
(
std
::
string
(
"fee"
),
1
)));
another_map
[
"fee"
]
=
1
;
another_map
[
"fee"
]
=
1
;
EXPECT_THAT
(
another_map
,
Each
(
make_pair
(
string
(
"fee"
),
1
)));
EXPECT_THAT
(
another_map
,
Each
(
make_pair
(
std
::
string
(
"fee"
),
1
)));
another_map
[
"fie"
]
=
2
;
another_map
[
"fie"
]
=
2
;
another_map
[
"foe"
]
=
3
;
another_map
[
"foe"
]
=
3
;
another_map
[
"fum"
]
=
4
;
another_map
[
"fum"
]
=
4
;
EXPECT_THAT
(
another_map
,
Not
(
Each
(
make_pair
(
string
(
"fee"
),
1
))));
EXPECT_THAT
(
another_map
,
Not
(
Each
(
make_pair
(
std
::
string
(
"fee"
),
1
))));
EXPECT_THAT
(
another_map
,
Not
(
Each
(
make_pair
(
string
(
"fum"
),
1
))));
EXPECT_THAT
(
another_map
,
Not
(
Each
(
make_pair
(
std
::
string
(
"fum"
),
1
))));
EXPECT_THAT
(
another_map
,
Each
(
Pair
(
_
,
Gt
(
0
))));
EXPECT_THAT
(
another_map
,
Each
(
Pair
(
_
,
Gt
(
0
))));
}
}
...
...
googlemock/test/gmock-more-actions_test.cc
View file @
7cc548dc
...
@@ -94,12 +94,12 @@ const char* Plus1(const char* s) { return s + 1; }
...
@@ -94,12 +94,12 @@ const char* Plus1(const char* s) { return s + 1; }
void
VoidUnary
(
int
/* n */
)
{
g_done
=
true
;
}
void
VoidUnary
(
int
/* n */
)
{
g_done
=
true
;
}
bool
ByConstRef
(
const
string
&
s
)
{
return
s
==
"Hi"
;
}
bool
ByConstRef
(
const
std
::
string
&
s
)
{
return
s
==
"Hi"
;
}
const
double
g_double
=
0
;
const
double
g_double
=
0
;
bool
ReferencesGlobalDouble
(
const
double
&
x
)
{
return
&
x
==
&
g_double
;
}
bool
ReferencesGlobalDouble
(
const
double
&
x
)
{
return
&
x
==
&
g_double
;
}
string
ByNonConstRef
(
string
&
s
)
{
return
s
+=
"+"
;
}
// NOLINT
std
::
string
ByNonConstRef
(
std
::
string
&
s
)
{
return
s
+=
"+"
;
}
// NOLINT
struct
UnaryFunctor
{
struct
UnaryFunctor
{
int
operator
()(
bool
x
)
{
return
x
?
1
:
-
1
;
}
int
operator
()(
bool
x
)
{
return
x
?
1
:
-
1
;
}
...
@@ -119,9 +119,9 @@ int SumOfFirst2(int a, int b, Unused, Unused) { return a + b; }
...
@@ -119,9 +119,9 @@ int SumOfFirst2(int a, int b, Unused, Unused) { return a + b; }
void
VoidFunctionWithFourArguments
(
char
,
int
,
float
,
double
)
{
g_done
=
true
;
}
void
VoidFunctionWithFourArguments
(
char
,
int
,
float
,
double
)
{
g_done
=
true
;
}
string
Concat4
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat4
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
)
{
const
char
*
s4
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
;
}
}
int
SumOf5
(
int
a
,
int
b
,
int
c
,
int
d
,
int
e
)
{
return
a
+
b
+
c
+
d
+
e
;
}
int
SumOf5
(
int
a
,
int
b
,
int
c
,
int
d
,
int
e
)
{
return
a
+
b
+
c
+
d
+
e
;
}
...
@@ -132,9 +132,9 @@ struct SumOf5Functor {
...
@@ -132,9 +132,9 @@ struct SumOf5Functor {
}
}
};
};
string
Concat5
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat5
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
)
{
const
char
*
s4
,
const
char
*
s5
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
;
}
}
int
SumOf6
(
int
a
,
int
b
,
int
c
,
int
d
,
int
e
,
int
f
)
{
int
SumOf6
(
int
a
,
int
b
,
int
c
,
int
d
,
int
e
,
int
f
)
{
...
@@ -147,34 +147,34 @@ struct SumOf6Functor {
...
@@ -147,34 +147,34 @@ struct SumOf6Functor {
}
}
};
};
string
Concat6
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat6
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
)
{
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
;
}
}
string
Concat7
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat7
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
)
{
const
char
*
s7
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
;
}
}
string
Concat8
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat8
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
)
{
const
char
*
s7
,
const
char
*
s8
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
;
}
}
string
Concat9
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat9
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
)
{
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
;
}
}
string
Concat10
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat10
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
,
const
char
*
s10
)
{
const
char
*
s10
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
+
s10
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
+
s10
;
}
}
class
Foo
{
class
Foo
{
...
@@ -185,7 +185,7 @@ class Foo {
...
@@ -185,7 +185,7 @@ class Foo {
short
Unary
(
long
x
)
{
return
static_cast
<
short
>
(
value_
+
x
);
}
// NOLINT
short
Unary
(
long
x
)
{
return
static_cast
<
short
>
(
value_
+
x
);
}
// NOLINT
string
Binary
(
const
string
&
str
,
char
c
)
const
{
return
str
+
c
;
}
std
::
string
Binary
(
const
std
::
string
&
str
,
char
c
)
const
{
return
str
+
c
;
}
int
Ternary
(
int
x
,
bool
y
,
char
z
)
{
return
value_
+
x
+
y
*
z
;
}
int
Ternary
(
int
x
,
bool
y
,
char
z
)
{
return
value_
+
x
+
y
*
z
;
}
...
@@ -201,29 +201,29 @@ class Foo {
...
@@ -201,29 +201,29 @@ class Foo {
return
a
+
b
+
c
+
d
+
e
+
f
;
return
a
+
b
+
c
+
d
+
e
+
f
;
}
}
string
Concat7
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat7
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
)
{
const
char
*
s7
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
;
}
}
string
Concat8
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat8
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
)
{
const
char
*
s7
,
const
char
*
s8
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
;
}
}
string
Concat9
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat9
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
)
{
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
;
}
}
string
Concat10
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
std
::
string
Concat10
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
,
const
char
*
s10
)
{
const
char
*
s10
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
+
s10
;
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
+
s10
;
}
}
private:
private:
...
@@ -280,9 +280,9 @@ inline const char* CharPtr(const char* s) { return s; }
...
@@ -280,9 +280,9 @@ inline const char* CharPtr(const char* s) { return s; }
// Tests using Invoke() with a 7-argument function.
// Tests using Invoke() with a 7-argument function.
TEST
(
InvokeTest
,
FunctionThatTakes7Arguments
)
{
TEST
(
InvokeTest
,
FunctionThatTakes7Arguments
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
const
char
*
,
const
char
*
,
const
char
*
)
>
Invoke
(
Concat7
);
a
=
Invoke
(
Concat7
);
EXPECT_EQ
(
"1234567"
,
EXPECT_EQ
(
"1234567"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
...
@@ -291,9 +291,9 @@ TEST(InvokeTest, FunctionThatTakes7Arguments) {
...
@@ -291,9 +291,9 @@ TEST(InvokeTest, FunctionThatTakes7Arguments) {
// Tests using Invoke() with a 8-argument function.
// Tests using Invoke() with a 8-argument function.
TEST
(
InvokeTest
,
FunctionThatTakes8Arguments
)
{
TEST
(
InvokeTest
,
FunctionThatTakes8Arguments
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
Invoke
(
Concat8
);
a
=
Invoke
(
Concat8
);
EXPECT_EQ
(
"12345678"
,
EXPECT_EQ
(
"12345678"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
...
@@ -302,9 +302,10 @@ TEST(InvokeTest, FunctionThatTakes8Arguments) {
...
@@ -302,9 +302,10 @@ TEST(InvokeTest, FunctionThatTakes8Arguments) {
// Tests using Invoke() with a 9-argument function.
// Tests using Invoke() with a 9-argument function.
TEST
(
InvokeTest
,
FunctionThatTakes9Arguments
)
{
TEST
(
InvokeTest
,
FunctionThatTakes9Arguments
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
Concat9
);
const
char
*
)
>
a
=
Invoke
(
Concat9
);
EXPECT_EQ
(
"123456789"
,
EXPECT_EQ
(
"123456789"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
...
@@ -313,9 +314,10 @@ TEST(InvokeTest, FunctionThatTakes9Arguments) {
...
@@ -313,9 +314,10 @@ TEST(InvokeTest, FunctionThatTakes9Arguments) {
// Tests using Invoke() with a 10-argument function.
// Tests using Invoke() with a 10-argument function.
TEST
(
InvokeTest
,
FunctionThatTakes10Arguments
)
{
TEST
(
InvokeTest
,
FunctionThatTakes10Arguments
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
Concat10
);
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
Concat10
);
EXPECT_EQ
(
"1234567890"
,
EXPECT_EQ
(
"1234567890"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
...
@@ -339,8 +341,7 @@ TEST(InvokeTest, FunctionWithUnusedParameters) {
...
@@ -339,8 +341,7 @@ TEST(InvokeTest, FunctionWithUnusedParameters) {
// Tests using Invoke() with methods with parameters declared as Unused.
// Tests using Invoke() with methods with parameters declared as Unused.
TEST
(
InvokeTest
,
MethodWithUnusedParameters
)
{
TEST
(
InvokeTest
,
MethodWithUnusedParameters
)
{
Foo
foo
;
Foo
foo
;
Action
<
int
(
string
,
bool
,
int
,
int
)
>
a1
=
Action
<
int
(
std
::
string
,
bool
,
int
,
int
)
>
a1
=
Invoke
(
&
foo
,
&
Foo
::
SumOfLast2
);
Invoke
(
&
foo
,
&
Foo
::
SumOfLast2
);
EXPECT_EQ
(
12
,
a1
.
Perform
(
make_tuple
(
CharPtr
(
"hi"
),
true
,
10
,
2
)));
EXPECT_EQ
(
12
,
a1
.
Perform
(
make_tuple
(
CharPtr
(
"hi"
),
true
,
10
,
2
)));
Action
<
int
(
char
,
double
,
int
,
int
)
>
a2
=
Action
<
int
(
char
,
double
,
int
,
int
)
>
a2
=
...
@@ -417,9 +418,9 @@ TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
...
@@ -417,9 +418,9 @@ TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
// Tests using Invoke() with a 7-argument method.
// Tests using Invoke() with a 7-argument method.
TEST
(
InvokeMethodTest
,
MethodThatTakes7Arguments
)
{
TEST
(
InvokeMethodTest
,
MethodThatTakes7Arguments
)
{
Foo
foo
;
Foo
foo
;
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
const
char
*
,
const
char
*
,
const
char
*
)
>
Invoke
(
&
foo
,
&
Foo
::
Concat7
);
a
=
Invoke
(
&
foo
,
&
Foo
::
Concat7
);
EXPECT_EQ
(
"1234567"
,
EXPECT_EQ
(
"1234567"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
...
@@ -429,9 +430,9 @@ TEST(InvokeMethodTest, MethodThatTakes7Arguments) {
...
@@ -429,9 +430,9 @@ TEST(InvokeMethodTest, MethodThatTakes7Arguments) {
// Tests using Invoke() with a 8-argument method.
// Tests using Invoke() with a 8-argument method.
TEST
(
InvokeMethodTest
,
MethodThatTakes8Arguments
)
{
TEST
(
InvokeMethodTest
,
MethodThatTakes8Arguments
)
{
Foo
foo
;
Foo
foo
;
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
Invoke
(
&
foo
,
&
Foo
::
Concat8
);
a
=
Invoke
(
&
foo
,
&
Foo
::
Concat8
);
EXPECT_EQ
(
"12345678"
,
EXPECT_EQ
(
"12345678"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
...
@@ -441,9 +442,10 @@ TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
...
@@ -441,9 +442,10 @@ TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
// Tests using Invoke() with a 9-argument method.
// Tests using Invoke() with a 9-argument method.
TEST
(
InvokeMethodTest
,
MethodThatTakes9Arguments
)
{
TEST
(
InvokeMethodTest
,
MethodThatTakes9Arguments
)
{
Foo
foo
;
Foo
foo
;
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Concat9
);
const
char
*
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Concat9
);
EXPECT_EQ
(
"123456789"
,
EXPECT_EQ
(
"123456789"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
...
@@ -453,9 +455,10 @@ TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
...
@@ -453,9 +455,10 @@ TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
// Tests using Invoke() with a 10-argument method.
// Tests using Invoke() with a 10-argument method.
TEST
(
InvokeMethodTest
,
MethodThatTakes10Arguments
)
{
TEST
(
InvokeMethodTest
,
MethodThatTakes10Arguments
)
{
Foo
foo
;
Foo
foo
;
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Concat10
);
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Concat10
);
EXPECT_EQ
(
"1234567890"
,
EXPECT_EQ
(
"1234567890"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
...
@@ -495,8 +498,8 @@ TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) {
...
@@ -495,8 +498,8 @@ TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) {
}
}
TEST
(
ReturnArgActionTest
,
WorksForMultiArgStringArg2
)
{
TEST
(
ReturnArgActionTest
,
WorksForMultiArgStringArg2
)
{
const
Action
<
string
(
int
,
int
,
string
,
int
)
>
a
=
ReturnArg
<
2
>
();
const
Action
<
std
::
string
(
int
,
int
,
std
::
string
,
int
)
>
a
=
ReturnArg
<
2
>
();
EXPECT_EQ
(
"seven"
,
a
.
Perform
(
make_tuple
(
5
,
6
,
string
(
"seven"
),
8
)));
EXPECT_EQ
(
"seven"
,
a
.
Perform
(
make_tuple
(
5
,
6
,
std
::
string
(
"seven"
),
8
)));
}
}
TEST
(
SaveArgActionTest
,
WorksForSameType
)
{
TEST
(
SaveArgActionTest
,
WorksForSameType
)
{
...
...
googlemock/test/gmock-nice-strict_test.cc
View file @
7cc548dc
...
@@ -51,7 +51,6 @@ class Mock {
...
@@ -51,7 +51,6 @@ class Mock {
namespace
testing
{
namespace
testing
{
namespace
gmock_nice_strict_test
{
namespace
gmock_nice_strict_test
{
using
testing
::
internal
::
string
;
using
testing
::
GMOCK_FLAG
(
verbose
);
using
testing
::
GMOCK_FLAG
(
verbose
);
using
testing
::
HasSubstr
;
using
testing
::
HasSubstr
;
using
testing
::
NaggyMock
;
using
testing
::
NaggyMock
;
...
@@ -87,23 +86,23 @@ class MockFoo : public Foo {
...
@@ -87,23 +86,23 @@ class MockFoo : public Foo {
class
MockBar
{
class
MockBar
{
public:
public:
explicit
MockBar
(
const
string
&
s
)
:
str_
(
s
)
{}
explicit
MockBar
(
const
std
::
string
&
s
)
:
str_
(
s
)
{}
MockBar
(
char
a1
,
char
a2
,
string
a3
,
string
a4
,
int
a5
,
int
a6
,
MockBar
(
char
a1
,
char
a2
,
std
::
string
a3
,
std
::
string
a4
,
int
a5
,
int
a6
,
const
string
&
a7
,
const
string
&
a8
,
bool
a9
,
bool
a10
)
{
const
std
::
string
&
a7
,
const
std
::
string
&
a8
,
bool
a9
,
bool
a10
)
{
str_
=
string
()
+
a1
+
a2
+
a3
+
a4
+
static_cast
<
char
>
(
a5
)
+
str_
=
std
::
string
()
+
a1
+
a2
+
a3
+
a4
+
static_cast
<
char
>
(
a5
)
+
static_cast
<
char
>
(
a6
)
+
a7
+
a8
+
(
a9
?
'T'
:
'F'
)
+
(
a10
?
'T'
:
'F'
);
static_cast
<
char
>
(
a6
)
+
a7
+
a8
+
(
a9
?
'T'
:
'F'
)
+
(
a10
?
'T'
:
'F'
);
}
}
virtual
~
MockBar
()
{}
virtual
~
MockBar
()
{}
const
string
&
str
()
const
{
return
str_
;
}
const
std
::
string
&
str
()
const
{
return
str_
;
}
MOCK_METHOD0
(
This
,
int
());
MOCK_METHOD0
(
This
,
int
());
MOCK_METHOD2
(
That
,
string
(
int
,
bool
));
MOCK_METHOD2
(
That
,
std
::
string
(
int
,
bool
));
private:
private:
string
str_
;
std
::
string
str_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockBar
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockBar
);
};
};
...
@@ -112,7 +111,7 @@ class MockBar {
...
@@ -112,7 +111,7 @@ class MockBar {
// Tests that a raw mock generates warnings for uninteresting calls.
// Tests that a raw mock generates warnings for uninteresting calls.
TEST
(
RawMockTest
,
WarningForUninterestingCall
)
{
TEST
(
RawMockTest
,
WarningForUninterestingCall
)
{
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
const
std
::
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
"warning"
;
GMOCK_FLAG
(
verbose
)
=
"warning"
;
MockFoo
raw_foo
;
MockFoo
raw_foo
;
...
@@ -129,7 +128,7 @@ TEST(RawMockTest, WarningForUninterestingCall) {
...
@@ -129,7 +128,7 @@ TEST(RawMockTest, WarningForUninterestingCall) {
// Tests that a raw mock generates warnings for uninteresting calls
// Tests that a raw mock generates warnings for uninteresting calls
// that delete the mock object.
// that delete the mock object.
TEST
(
RawMockTest
,
WarningForUninterestingCallAfterDeath
)
{
TEST
(
RawMockTest
,
WarningForUninterestingCallAfterDeath
)
{
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
const
std
::
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
"warning"
;
GMOCK_FLAG
(
verbose
)
=
"warning"
;
MockFoo
*
const
raw_foo
=
new
MockFoo
;
MockFoo
*
const
raw_foo
=
new
MockFoo
;
...
@@ -150,7 +149,7 @@ TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
...
@@ -150,7 +149,7 @@ TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
TEST
(
RawMockTest
,
InfoForUninterestingCall
)
{
TEST
(
RawMockTest
,
InfoForUninterestingCall
)
{
MockFoo
raw_foo
;
MockFoo
raw_foo
;
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
const
std
::
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
"info"
;
GMOCK_FLAG
(
verbose
)
=
"info"
;
CaptureStdout
();
CaptureStdout
();
raw_foo
.
DoThis
();
raw_foo
.
DoThis
();
...
@@ -188,7 +187,7 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
...
@@ -188,7 +187,7 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
TEST
(
NiceMockTest
,
InfoForUninterestingCall
)
{
TEST
(
NiceMockTest
,
InfoForUninterestingCall
)
{
NiceMock
<
MockFoo
>
nice_foo
;
NiceMock
<
MockFoo
>
nice_foo
;
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
const
std
::
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
"info"
;
GMOCK_FLAG
(
verbose
)
=
"info"
;
CaptureStdout
();
CaptureStdout
();
nice_foo
.
DoThis
();
nice_foo
.
DoThis
();
...
@@ -257,7 +256,7 @@ TEST(NiceMockTest, AcceptsClassNamedMock) {
...
@@ -257,7 +256,7 @@ TEST(NiceMockTest, AcceptsClassNamedMock) {
// Tests that a naggy mock generates warnings for uninteresting calls.
// Tests that a naggy mock generates warnings for uninteresting calls.
TEST
(
NaggyMockTest
,
WarningForUninterestingCall
)
{
TEST
(
NaggyMockTest
,
WarningForUninterestingCall
)
{
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
const
std
::
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
"warning"
;
GMOCK_FLAG
(
verbose
)
=
"warning"
;
NaggyMock
<
MockFoo
>
naggy_foo
;
NaggyMock
<
MockFoo
>
naggy_foo
;
...
@@ -274,7 +273,7 @@ TEST(NaggyMockTest, WarningForUninterestingCall) {
...
@@ -274,7 +273,7 @@ TEST(NaggyMockTest, WarningForUninterestingCall) {
// Tests that a naggy mock generates a warning for an uninteresting call
// Tests that a naggy mock generates a warning for an uninteresting call
// that deletes the mock object.
// that deletes the mock object.
TEST
(
NaggyMockTest
,
WarningForUninterestingCallAfterDeath
)
{
TEST
(
NaggyMockTest
,
WarningForUninterestingCallAfterDeath
)
{
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
const
std
::
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
"warning"
;
GMOCK_FLAG
(
verbose
)
=
"warning"
;
NaggyMock
<
MockFoo
>*
const
naggy_foo
=
new
NaggyMock
<
MockFoo
>
;
NaggyMock
<
MockFoo
>*
const
naggy_foo
=
new
NaggyMock
<
MockFoo
>
;
...
...
googlemock/test/gmock-spec-builders_test.cc
View file @
7cc548dc
...
@@ -97,7 +97,6 @@ using testing::internal::kErrorVerbosity;
...
@@ -97,7 +97,6 @@ using testing::internal::kErrorVerbosity;
using
testing
::
internal
::
kInfoVerbosity
;
using
testing
::
internal
::
kInfoVerbosity
;
using
testing
::
internal
::
kWarningVerbosity
;
using
testing
::
internal
::
kWarningVerbosity
;
using
testing
::
internal
::
linked_ptr
;
using
testing
::
internal
::
linked_ptr
;
using
testing
::
internal
::
string
;
#if GTEST_HAS_STREAM_REDIRECTION
#if GTEST_HAS_STREAM_REDIRECTION
using
testing
::
HasSubstr
;
using
testing
::
HasSubstr
;
...
@@ -1954,7 +1953,7 @@ class MockC {
...
@@ -1954,7 +1953,7 @@ class MockC {
public:
public:
MockC
()
{}
MockC
()
{}
MOCK_METHOD6
(
VoidMethod
,
void
(
bool
cond
,
int
n
,
string
s
,
void
*
p
,
MOCK_METHOD6
(
VoidMethod
,
void
(
bool
cond
,
int
n
,
std
::
string
s
,
void
*
p
,
const
Printable
&
x
,
Unprintable
y
));
const
Printable
&
x
,
Unprintable
y
));
MOCK_METHOD0
(
NonVoidMethod
,
int
());
// NOLINT
MOCK_METHOD0
(
NonVoidMethod
,
int
());
// NOLINT
...
@@ -1970,7 +1969,7 @@ class VerboseFlagPreservingFixture : public testing::Test {
...
@@ -1970,7 +1969,7 @@ class VerboseFlagPreservingFixture : public testing::Test {
~
VerboseFlagPreservingFixture
()
{
GMOCK_FLAG
(
verbose
)
=
saved_verbose_flag_
;
}
~
VerboseFlagPreservingFixture
()
{
GMOCK_FLAG
(
verbose
)
=
saved_verbose_flag_
;
}
private:
private:
const
string
saved_verbose_flag_
;
const
std
::
string
saved_verbose_flag_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
VerboseFlagPreservingFixture
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
VerboseFlagPreservingFixture
);
};
};
...
@@ -2062,8 +2061,8 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
...
@@ -2062,8 +2061,8 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
// contain the given function name in the stack trace. When it's
// contain the given function name in the stack trace. When it's
// false, the output should be empty.)
// false, the output should be empty.)
void
VerifyOutput
(
const
std
::
string
&
output
,
bool
should_print
,
void
VerifyOutput
(
const
std
::
string
&
output
,
bool
should_print
,
const
string
&
expected_substring
,
const
std
::
string
&
expected_substring
,
const
string
&
function_name
)
{
const
std
::
string
&
function_name
)
{
if
(
should_print
)
{
if
(
should_print
)
{
EXPECT_THAT
(
output
.
c_str
(),
HasSubstr
(
expected_substring
));
EXPECT_THAT
(
output
.
c_str
(),
HasSubstr
(
expected_substring
));
# ifndef NDEBUG
# ifndef NDEBUG
...
@@ -2113,7 +2112,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
...
@@ -2113,7 +2112,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
// Tests how the flag affects uninteresting calls on a naggy mock.
// Tests how the flag affects uninteresting calls on a naggy mock.
void
TestUninterestingCallOnNaggyMock
(
bool
should_print
)
{
void
TestUninterestingCallOnNaggyMock
(
bool
should_print
)
{
NaggyMock
<
MockA
>
a
;
NaggyMock
<
MockA
>
a
;
const
string
note
=
const
std
::
string
note
=
"NOTE: You can safely ignore the above warning unless this "
"NOTE: You can safely ignore the above warning unless this "
"call should not happen. Do not suppress it by blindly adding "
"call should not happen. Do not suppress it by blindly adding "
"an EXPECT_CALL() if you don't mean to enforce the call. "
"an EXPECT_CALL() if you don't mean to enforce the call. "
...
...
googlemock/test/gmock_stress_test.cc
View file @
7cc548dc
...
@@ -51,7 +51,7 @@ const int kRepeat = 50;
...
@@ -51,7 +51,7 @@ const int kRepeat = 50;
class
MockFoo
{
class
MockFoo
{
public:
public:
MOCK_METHOD1
(
Bar
,
int
(
int
n
));
// NOLINT
MOCK_METHOD1
(
Bar
,
int
(
int
n
));
// NOLINT
MOCK_METHOD2
(
Baz
,
char
(
const
char
*
s1
,
const
internal
::
string
&
s2
));
// NOLINT
MOCK_METHOD2
(
Baz
,
char
(
const
char
*
s1
,
const
std
::
string
&
s2
));
// NOLINT
};
};
// Helper for waiting for the given thread to finish and then deleting it.
// Helper for waiting for the given thread to finish and then deleting it.
...
...
googletest/include/gtest/gtest-printers.h
View file @
7cc548dc
...
@@ -151,10 +151,10 @@ template <typename T>
...
@@ -151,10 +151,10 @@ template <typename T>
class
TypeWithoutFormatter
<
T
,
kProtobuf
>
{
class
TypeWithoutFormatter
<
T
,
kProtobuf
>
{
public:
public:
static
void
PrintValue
(
const
T
&
value
,
::
std
::
ostream
*
os
)
{
static
void
PrintValue
(
const
T
&
value
,
::
std
::
ostream
*
os
)
{
const
::
testing
::
internal
::
string
short
_str
=
value
.
ShortDebugString
();
std
::
string
pretty
_str
=
value
.
ShortDebugString
();
const
::
testing
::
in
t
er
nal
::
string
pretty_str
=
if
(
pretty_str
.
length
()
>
kProtobufOneL
iner
MaxLength
)
{
short_str
.
length
()
<=
kProtobufOneLinerMaxLength
?
pretty_str
=
"
\n
"
+
value
.
DebugString
();
short_str
:
(
"
\n
"
+
value
.
DebugString
());
}
*
os
<<
(
"<"
+
pretty_str
+
">"
);
*
os
<<
(
"<"
+
pretty_str
+
">"
);
}
}
};
};
...
@@ -805,7 +805,7 @@ class UniversalTersePrinter<const char*> {
...
@@ -805,7 +805,7 @@ class UniversalTersePrinter<const char*> {
if
(
str
==
NULL
)
{
if
(
str
==
NULL
)
{
*
os
<<
"NULL"
;
*
os
<<
"NULL"
;
}
else
{
}
else
{
UniversalPrint
(
string
(
str
),
os
);
UniversalPrint
(
std
::
string
(
str
),
os
);
}
}
}
}
};
};
...
...
googletest/include/gtest/gtest-spi.h
View file @
7cc548dc
...
@@ -97,13 +97,12 @@ class GTEST_API_ SingleFailureChecker {
...
@@ -97,13 +97,12 @@ class GTEST_API_ SingleFailureChecker {
public:
public:
// The constructor remembers the arguments.
// The constructor remembers the arguments.
SingleFailureChecker
(
const
TestPartResultArray
*
results
,
SingleFailureChecker
(
const
TestPartResultArray
*
results
,
TestPartResult
::
Type
type
,
TestPartResult
::
Type
type
,
const
std
::
string
&
substr
);
const
string
&
substr
);
~
SingleFailureChecker
();
~
SingleFailureChecker
();
private:
private:
const
TestPartResultArray
*
const
results_
;
const
TestPartResultArray
*
const
results_
;
const
TestPartResult
::
Type
type_
;
const
TestPartResult
::
Type
type_
;
const
string
substr_
;
const
std
::
string
substr_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
SingleFailureChecker
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
SingleFailureChecker
);
};
};
...
...
googletest/include/gtest/internal/gtest-internal.h
View file @
7cc548dc
...
@@ -502,9 +502,10 @@ typedef void (*SetUpTestCaseFunc)();
...
@@ -502,9 +502,10 @@ typedef void (*SetUpTestCaseFunc)();
typedef
void
(
*
TearDownTestCaseFunc
)();
typedef
void
(
*
TearDownTestCaseFunc
)();
struct
CodeLocation
{
struct
CodeLocation
{
CodeLocation
(
const
string
&
a_file
,
int
a_line
)
:
file
(
a_file
),
line
(
a_line
)
{}
CodeLocation
(
const
std
::
string
&
a_file
,
int
a_line
)
:
file
(
a_file
),
line
(
a_line
)
{}
string
file
;
std
::
string
file
;
int
line
;
int
line
;
};
};
...
...
googletest/include/gtest/internal/gtest-param-util.h
View file @
7cc548dc
...
@@ -472,7 +472,7 @@ class ParameterizedTestCaseInfoBase {
...
@@ -472,7 +472,7 @@ class ParameterizedTestCaseInfoBase {
virtual
~
ParameterizedTestCaseInfoBase
()
{}
virtual
~
ParameterizedTestCaseInfoBase
()
{}
// Base part of test case name for display purposes.
// Base part of test case name for display purposes.
virtual
const
string
&
GetTestCaseName
()
const
=
0
;
virtual
const
std
::
string
&
GetTestCaseName
()
const
=
0
;
// Test case id to verify identity.
// Test case id to verify identity.
virtual
TypeId
GetTestCaseTypeId
()
const
=
0
;
virtual
TypeId
GetTestCaseTypeId
()
const
=
0
;
// UnitTest class invokes this method to register tests in this
// UnitTest class invokes this method to register tests in this
...
@@ -511,7 +511,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
...
@@ -511,7 +511,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
:
test_case_name_
(
name
),
code_location_
(
code_location
)
{}
:
test_case_name_
(
name
),
code_location_
(
code_location
)
{}
// Test case base name for display purposes.
// Test case base name for display purposes.
virtual
const
string
&
GetTestCaseName
()
const
{
return
test_case_name_
;
}
virtual
const
std
::
string
&
GetTestCaseName
()
const
{
return
test_case_name_
;
}
// Test case id to verify identity.
// Test case id to verify identity.
virtual
TypeId
GetTestCaseTypeId
()
const
{
return
GetTypeId
<
TestCase
>
();
}
virtual
TypeId
GetTestCaseTypeId
()
const
{
return
GetTypeId
<
TestCase
>
();
}
// TEST_P macro uses AddTestPattern() to record information
// TEST_P macro uses AddTestPattern() to record information
...
@@ -529,11 +529,10 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
...
@@ -529,11 +529,10 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
}
}
// INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information
// INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information
// about a generator.
// about a generator.
int
AddTestCaseInstantiation
(
const
string
&
instantiation_name
,
int
AddTestCaseInstantiation
(
const
std
::
string
&
instantiation_name
,
GeneratorCreationFunc
*
func
,
GeneratorCreationFunc
*
func
,
ParamNameGeneratorFunc
*
name_func
,
ParamNameGeneratorFunc
*
name_func
,
const
char
*
file
,
const
char
*
file
,
int
line
)
{
int
line
)
{
instantiations_
.
push_back
(
instantiations_
.
push_back
(
InstantiationInfo
(
instantiation_name
,
func
,
name_func
,
file
,
line
));
InstantiationInfo
(
instantiation_name
,
func
,
name_func
,
file
,
line
));
return
0
;
// Return value used only to run this method in namespace scope.
return
0
;
// Return value used only to run this method in namespace scope.
...
@@ -550,13 +549,13 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
...
@@ -550,13 +549,13 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
for
(
typename
InstantiationContainer
::
iterator
gen_it
=
for
(
typename
InstantiationContainer
::
iterator
gen_it
=
instantiations_
.
begin
();
gen_it
!=
instantiations_
.
end
();
instantiations_
.
begin
();
gen_it
!=
instantiations_
.
end
();
++
gen_it
)
{
++
gen_it
)
{
const
string
&
instantiation_name
=
gen_it
->
name
;
const
std
::
string
&
instantiation_name
=
gen_it
->
name
;
ParamGenerator
<
ParamType
>
generator
((
*
gen_it
->
generator
)());
ParamGenerator
<
ParamType
>
generator
((
*
gen_it
->
generator
)());
ParamNameGeneratorFunc
*
name_func
=
gen_it
->
name_func
;
ParamNameGeneratorFunc
*
name_func
=
gen_it
->
name_func
;
const
char
*
file
=
gen_it
->
file
;
const
char
*
file
=
gen_it
->
file
;
int
line
=
gen_it
->
line
;
int
line
=
gen_it
->
line
;
string
test_case_name
;
std
::
string
test_case_name
;
if
(
!
instantiation_name
.
empty
()
)
if
(
!
instantiation_name
.
empty
()
)
test_case_name
=
instantiation_name
+
"/"
;
test_case_name
=
instantiation_name
+
"/"
;
test_case_name
+=
test_info
->
test_case_base_name
;
test_case_name
+=
test_info
->
test_case_base_name
;
...
@@ -609,8 +608,8 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
...
@@ -609,8 +608,8 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
test_base_name
(
a_test_base_name
),
test_base_name
(
a_test_base_name
),
test_meta_factory
(
a_test_meta_factory
)
{}
test_meta_factory
(
a_test_meta_factory
)
{}
const
string
test_case_base_name
;
const
std
::
string
test_case_base_name
;
const
string
test_base_name
;
const
std
::
string
test_base_name
;
const
scoped_ptr
<
TestMetaFactoryBase
<
ParamType
>
>
test_meta_factory
;
const
scoped_ptr
<
TestMetaFactoryBase
<
ParamType
>
>
test_meta_factory
;
};
};
typedef
::
std
::
vector
<
linked_ptr
<
TestInfo
>
>
TestInfoContainer
;
typedef
::
std
::
vector
<
linked_ptr
<
TestInfo
>
>
TestInfoContainer
;
...
@@ -651,7 +650,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
...
@@ -651,7 +650,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
return
true
;
return
true
;
}
}
const
string
test_case_name_
;
const
std
::
string
test_case_name_
;
CodeLocation
code_location_
;
CodeLocation
code_location_
;
TestInfoContainer
tests_
;
TestInfoContainer
tests_
;
InstantiationContainer
instantiations_
;
InstantiationContainer
instantiations_
;
...
...
Prev
1
2
Next
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