Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
25905b9f
Commit
25905b9f
authored
Jan 02, 2019
by
Gennadiy Civil
Browse files
Merge branch 'master' of
https://github.com/google/googletest
parents
4665eee1
3bedb5a9
Changes
143
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1921 additions
and
1039 deletions
+1921
-1039
googlemock/test/BUILD.bazel
googlemock/test/BUILD.bazel
+8
-25
googlemock/test/gmock-actions_test.cc
googlemock/test/gmock-actions_test.cc
+211
-107
googlemock/test/gmock-cardinalities_test.cc
googlemock/test/gmock-cardinalities_test.cc
+3
-3
googlemock/test/gmock-function-mocker_nc.cc
googlemock/test/gmock-function-mocker_nc.cc
+16
-0
googlemock/test/gmock-function-mocker_nc_test.py
googlemock/test/gmock-function-mocker_nc_test.py
+43
-0
googlemock/test/gmock-function-mocker_test.cc
googlemock/test/gmock-function-mocker_test.cc
+657
-0
googlemock/test/gmock-generated-actions_test.cc
googlemock/test/gmock-generated-actions_test.cc
+92
-257
googlemock/test/gmock-generated-function-mockers_test.cc
googlemock/test/gmock-generated-function-mockers_test.cc
+5
-21
googlemock/test/gmock-generated-internal-utils_test.cc
googlemock/test/gmock-generated-internal-utils_test.cc
+21
-19
googlemock/test/gmock-generated-matchers_test.cc
googlemock/test/gmock-generated-matchers_test.cc
+7
-166
googlemock/test/gmock-internal-utils_test.cc
googlemock/test/gmock-internal-utils_test.cc
+26
-41
googlemock/test/gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+426
-169
googlemock/test/gmock-more-actions_test.cc
googlemock/test/gmock-more-actions_test.cc
+80
-91
googlemock/test/gmock-nice-strict_test.cc
googlemock/test/gmock-nice-strict_test.cc
+36
-22
googlemock/test/gmock-pp-string_test.cc
googlemock/test/gmock-pp-string_test.cc
+206
-0
googlemock/test/gmock-pp_test.cc
googlemock/test/gmock-pp_test.cc
+73
-0
googlemock/test/gmock-spec-builders_test.cc
googlemock/test/gmock-spec-builders_test.cc
+10
-8
googlemock/test/gmock_link_test.h
googlemock/test/gmock_link_test.h
+1
-1
googlemock/test/gmock_stress_test.cc
googlemock/test/gmock_stress_test.cc
+0
-81
googletest/CMakeLists.txt
googletest/CMakeLists.txt
+0
-28
No files found.
googlemock/test/BUILD.bazel
View file @
25905b9f
...
...
@@ -34,28 +34,19 @@
licenses
([
"notice"
])
""" gmock own tests """
# Tests for GMock itself
cc_test
(
name
=
"gmock_all_test"
,
size
=
"small"
,
srcs
=
glob
(
include
=
[
"gmock-*.cc"
,
],
),
srcs
=
glob
(
include
=
[
"gmock-*.cc"
]),
linkopts
=
select
({
"//:windows"
:
[],
"//:windows_msvc"
:
[],
"//conditions:default"
:
[
"-pthread"
,
],
"//conditions:default"
:
[
"-pthread"
],
}),
deps
=
[
"//:gtest"
],
)
# Py tests
# Python tests
py_library
(
name
=
"gmock_test_utils"
,
testonly
=
1
,
...
...
@@ -66,9 +57,7 @@ cc_binary(
name
=
"gmock_leak_test_"
,
testonly
=
1
,
srcs
=
[
"gmock_leak_test_.cc"
],
deps
=
[
"//:gtest_main"
,
],
deps
=
[
"//:gtest_main"
],
)
py_test
(
...
...
@@ -89,17 +78,13 @@ cc_test(
"gmock_link_test.cc"
,
"gmock_link_test.h"
,
],
deps
=
[
"//:gtest_main"
,
],
deps
=
[
"//:gtest_main"
],
)
cc_binary
(
name
=
"gmock_output_test_"
,
srcs
=
[
"gmock_output_test_.cc"
],
deps
=
[
"//:gtest"
,
],
deps
=
[
"//:gtest"
],
)
py_test
(
...
...
@@ -117,7 +102,5 @@ cc_test(
name
=
"gmock_test"
,
size
=
"small"
,
srcs
=
[
"gmock_test.cc"
],
deps
=
[
"//:gtest_main"
,
],
deps
=
[
"//:gtest_main"
],
)
googlemock/test/gmock-actions_test.cc
View file @
25905b9f
...
...
@@ -33,9 +33,9 @@
// This file tests the built-in actions.
// Silence C4800 (C4800: 'int *const ': forcing value
// to bool 'true' or 'false') for MSVC
14,
15
// to bool 'true' or 'false') for MSVC 15
#ifdef _MSC_VER
#if _MSC_VER
<
= 1900
#if _MSC_VER
=
= 1900
# pragma warning(push)
# pragma warning(disable:4800)
#endif
...
...
@@ -74,14 +74,11 @@ using testing::ReturnRefOfCopy;
using
testing
::
SetArgPointee
;
using
testing
::
SetArgumentPointee
;
using
testing
::
Unused
;
using
testing
::
WithArgs
;
using
testing
::
_
;
using
testing
::
get
;
using
testing
::
internal
::
BuiltInDefaultValue
;
using
testing
::
internal
::
Int64
;
using
testing
::
internal
::
UInt64
;
using
testing
::
make_tuple
;
using
testing
::
tuple
;
using
testing
::
tuple_element
;
#if !GTEST_OS_WINDOWS_MOBILE
using
testing
::
SetErrnoAndReturn
;
...
...
@@ -223,7 +220,6 @@ class MyNonDefaultConstructible {
int
value_
;
};
#if GTEST_LANG_CXX11
TEST
(
BuiltInDefaultValueTest
,
ExistsForDefaultConstructibleType
)
{
EXPECT_TRUE
(
BuiltInDefaultValue
<
MyDefaultConstructible
>::
Exists
());
...
...
@@ -233,7 +229,6 @@ TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) {
EXPECT_EQ
(
42
,
BuiltInDefaultValue
<
MyDefaultConstructible
>::
Get
().
value
());
}
#endif // GTEST_LANG_CXX11
TEST
(
BuiltInDefaultValueTest
,
DoesNotExistForNonDefaultConstructibleType
)
{
EXPECT_FALSE
(
BuiltInDefaultValue
<
MyNonDefaultConstructible
>::
Exists
());
...
...
@@ -303,7 +298,6 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
},
""
);
}
#if GTEST_HAS_STD_UNIQUE_PTR_
TEST
(
DefaultValueTest
,
GetWorksForMoveOnlyIfSet
)
{
EXPECT_TRUE
(
DefaultValue
<
std
::
unique_ptr
<
int
>>::
Exists
());
EXPECT_TRUE
(
DefaultValue
<
std
::
unique_ptr
<
int
>>::
Get
()
==
nullptr
);
...
...
@@ -314,7 +308,6 @@ TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) {
std
::
unique_ptr
<
int
>
i
=
DefaultValue
<
std
::
unique_ptr
<
int
>>::
Get
();
EXPECT_EQ
(
42
,
*
i
);
}
#endif // GTEST_HAS_STD_UNIQUE_PTR_
// Tests that DefaultValue<void>::Get() returns void.
TEST
(
DefaultValueTest
,
GetWorksForVoid
)
{
...
...
@@ -382,8 +375,8 @@ typedef int MyGlobalFunction(bool, int);
class
MyActionImpl
:
public
ActionInterface
<
MyGlobalFunction
>
{
public:
virtual
int
Perform
(
const
tuple
<
bool
,
int
>&
args
)
{
return
get
<
0
>
(
args
)
?
get
<
1
>
(
args
)
:
0
;
int
Perform
(
const
std
::
tuple
<
bool
,
int
>&
args
)
override
{
return
std
::
get
<
0
>
(
args
)
?
std
::
get
<
1
>
(
args
)
:
0
;
}
};
...
...
@@ -399,8 +392,8 @@ TEST(ActionInterfaceTest, MakeAction) {
// it a tuple whose size and type are compatible with F's argument
// types. For example, if F is int(), then Perform() takes a
// 0-tuple; if F is void(bool, int), then Perform() takes a
// tuple<bool, int>, and so on.
EXPECT_EQ
(
5
,
action
.
Perform
(
make_tuple
(
true
,
5
)));
//
std::
tuple<bool, int>, and so on.
EXPECT_EQ
(
5
,
action
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
}
// Tests that Action<F> can be contructed from a pointer to
...
...
@@ -413,8 +406,8 @@ TEST(ActionTest, CanBeConstructedFromActionInterface) {
TEST
(
ActionTest
,
DelegatesWorkToActionInterface
)
{
const
Action
<
MyGlobalFunction
>
action
(
new
MyActionImpl
);
EXPECT_EQ
(
5
,
action
.
Perform
(
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
action
.
Perform
(
make_tuple
(
false
,
1
)));
EXPECT_EQ
(
5
,
action
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
action
.
Perform
(
std
::
make_tuple
(
false
,
1
)));
}
// Tests that Action<F> can be copied.
...
...
@@ -423,22 +416,22 @@ TEST(ActionTest, IsCopyable) {
Action
<
MyGlobalFunction
>
a2
(
a1
);
// Tests the copy constructor.
// a1 should continue to work after being copied from.
EXPECT_EQ
(
5
,
a1
.
Perform
(
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a1
.
Perform
(
make_tuple
(
false
,
1
)));
EXPECT_EQ
(
5
,
a1
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a1
.
Perform
(
std
::
make_tuple
(
false
,
1
)));
// a2 should work like the action it was copied from.
EXPECT_EQ
(
5
,
a2
.
Perform
(
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
make_tuple
(
false
,
1
)));
EXPECT_EQ
(
5
,
a2
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
std
::
make_tuple
(
false
,
1
)));
a2
=
a1
;
// Tests the assignment operator.
// a1 should continue to work after being copied from.
EXPECT_EQ
(
5
,
a1
.
Perform
(
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a1
.
Perform
(
make_tuple
(
false
,
1
)));
EXPECT_EQ
(
5
,
a1
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a1
.
Perform
(
std
::
make_tuple
(
false
,
1
)));
// a2 should work like the action it was copied from.
EXPECT_EQ
(
5
,
a2
.
Perform
(
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
make_tuple
(
false
,
1
)));
EXPECT_EQ
(
5
,
a2
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
std
::
make_tuple
(
false
,
1
)));
}
// Tests that an Action<From> object can be converted to a
...
...
@@ -446,8 +439,8 @@ TEST(ActionTest, IsCopyable) {
class
IsNotZero
:
public
ActionInterface
<
bool
(
int
)
>
{
// NOLINT
public:
virtual
bool
Perform
(
const
tuple
<
int
>&
arg
)
{
return
get
<
0
>
(
arg
)
!=
0
;
bool
Perform
(
const
std
::
tuple
<
int
>&
arg
)
override
{
return
std
::
get
<
0
>
(
arg
)
!=
0
;
}
};
...
...
@@ -460,8 +453,8 @@ class IsNotZero : public ActionInterface<bool(int)> { // NOLINT
TEST
(
ActionTest
,
CanBeConvertedToOtherActionType
)
{
const
Action
<
bool
(
int
)
>
a1
(
new
IsNotZero
);
// NOLINT
const
Action
<
int
(
char
)
>
a2
=
Action
<
int
(
char
)
>
(
a1
);
// NOLINT
EXPECT_EQ
(
1
,
a2
.
Perform
(
make_tuple
(
'a'
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
make_tuple
(
'\0'
)));
EXPECT_EQ
(
1
,
a2
.
Perform
(
std
::
make_tuple
(
'a'
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
std
::
make_tuple
(
'\0'
)));
}
#endif // !GTEST_OS_SYMBIAN
...
...
@@ -475,7 +468,9 @@ class ReturnSecondArgumentAction {
// polymorphic action whose Perform() method template is either
// const or not. This lets us verify the non-const case.
template
<
typename
Result
,
typename
ArgumentTuple
>
Result
Perform
(
const
ArgumentTuple
&
args
)
{
return
get
<
1
>
(
args
);
}
Result
Perform
(
const
ArgumentTuple
&
args
)
{
return
std
::
get
<
1
>
(
args
);
}
};
// Implements a polymorphic action that can be used in a nullary
...
...
@@ -490,7 +485,9 @@ class ReturnZeroFromNullaryFunctionAction {
// polymorphic action whose Perform() method template is either
// const or not. This lets us verify the const case.
template
<
typename
Result
>
Result
Perform
(
const
tuple
<>&
)
const
{
return
0
;
}
Result
Perform
(
const
std
::
tuple
<>&
)
const
{
return
0
;
}
};
// These functions verify that MakePolymorphicAction() returns a
...
...
@@ -509,42 +506,42 @@ ReturnZeroFromNullaryFunction() {
// implementation class into a polymorphic action.
TEST
(
MakePolymorphicActionTest
,
ConstructsActionFromImpl
)
{
Action
<
int
(
bool
,
int
,
double
)
>
a1
=
ReturnSecondArgument
();
// NOLINT
EXPECT_EQ
(
5
,
a1
.
Perform
(
make_tuple
(
false
,
5
,
2.0
)));
EXPECT_EQ
(
5
,
a1
.
Perform
(
std
::
make_tuple
(
false
,
5
,
2.0
)));
}
// Tests that MakePolymorphicAction() works when the implementation
// class' Perform() method template has only one template parameter.
TEST
(
MakePolymorphicActionTest
,
WorksWhenPerformHasOneTemplateParameter
)
{
Action
<
int
()
>
a1
=
ReturnZeroFromNullaryFunction
();
EXPECT_EQ
(
0
,
a1
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
0
,
a1
.
Perform
(
std
::
make_tuple
()));
Action
<
void
*
()
>
a2
=
ReturnZeroFromNullaryFunction
();
EXPECT_TRUE
(
a2
.
Perform
(
make_tuple
())
==
nullptr
);
EXPECT_TRUE
(
a2
.
Perform
(
std
::
make_tuple
())
==
nullptr
);
}
// Tests that Return() works as an action for void-returning
// functions.
TEST
(
ReturnTest
,
WorksForVoid
)
{
const
Action
<
void
(
int
)
>
ret
=
Return
();
// NOLINT
return
ret
.
Perform
(
make_tuple
(
1
));
return
ret
.
Perform
(
std
::
make_tuple
(
1
));
}
// Tests that Return(v) returns v.
TEST
(
ReturnTest
,
ReturnsGivenValue
)
{
Action
<
int
()
>
ret
=
Return
(
1
);
// NOLINT
EXPECT_EQ
(
1
,
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
1
,
ret
.
Perform
(
std
::
make_tuple
()));
ret
=
Return
(
-
5
);
EXPECT_EQ
(
-
5
,
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
-
5
,
ret
.
Perform
(
std
::
make_tuple
()));
}
// Tests that Return("string literal") works.
TEST
(
ReturnTest
,
AcceptsStringLiteral
)
{
Action
<
const
char
*
()
>
a1
=
Return
(
"Hello"
);
EXPECT_STREQ
(
"Hello"
,
a1
.
Perform
(
make_tuple
()));
EXPECT_STREQ
(
"Hello"
,
a1
.
Perform
(
std
::
make_tuple
()));
Action
<
std
::
string
()
>
a2
=
Return
(
"world"
);
EXPECT_EQ
(
"world"
,
a2
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
"world"
,
a2
.
Perform
(
std
::
make_tuple
()));
}
// Test struct which wraps a vector of integers. Used in
...
...
@@ -563,7 +560,7 @@ TEST(ReturnTest, SupportsWrapperReturnType) {
// Return() called with 'v' as argument. The Action will return the same data
// as 'v' (copy) but it will be wrapped in an IntegerVectorWrapper.
Action
<
IntegerVectorWrapper
()
>
a
=
Return
(
v
);
const
std
::
vector
<
int
>&
result
=
*
(
a
.
Perform
(
make_tuple
()).
v
);
const
std
::
vector
<
int
>&
result
=
*
(
a
.
Perform
(
std
::
make_tuple
()).
v
);
EXPECT_THAT
(
result
,
::
testing
::
ElementsAre
(
0
,
1
,
2
,
3
,
4
));
}
...
...
@@ -581,10 +578,10 @@ TEST(ReturnTest, IsCovariant) {
Base
base
;
Derived
derived
;
Action
<
Base
*
()
>
ret
=
Return
(
&
base
);
EXPECT_EQ
(
&
base
,
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
&
base
,
ret
.
Perform
(
std
::
make_tuple
()));
ret
=
Return
(
&
derived
);
EXPECT_EQ
(
&
derived
,
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
&
derived
,
ret
.
Perform
(
std
::
make_tuple
()));
}
// Tests that the type of the value passed into Return is converted into T
...
...
@@ -615,7 +612,7 @@ TEST(ReturnTest, ConvertsArgumentWhenConverted) {
EXPECT_TRUE
(
converted
)
<<
"Return must convert its argument in its own "
<<
"conversion operator."
;
converted
=
false
;
action
.
Perform
(
tuple
<>
());
action
.
Perform
(
std
::
tuple
<>
());
EXPECT_FALSE
(
converted
)
<<
"Action must NOT convert its argument "
<<
"when performed."
;
}
...
...
@@ -636,30 +633,28 @@ TEST(ReturnTest, CanConvertArgumentUsingNonConstTypeCastOperator) {
// Tests that ReturnNull() returns NULL in a pointer-returning function.
TEST
(
ReturnNullTest
,
WorksInPointerReturningFunction
)
{
const
Action
<
int
*
()
>
a1
=
ReturnNull
();
EXPECT_TRUE
(
a1
.
Perform
(
make_tuple
())
==
nullptr
);
EXPECT_TRUE
(
a1
.
Perform
(
std
::
make_tuple
())
==
nullptr
);
const
Action
<
const
char
*
(
bool
)
>
a2
=
ReturnNull
();
// NOLINT
EXPECT_TRUE
(
a2
.
Perform
(
make_tuple
(
true
))
==
nullptr
);
EXPECT_TRUE
(
a2
.
Perform
(
std
::
make_tuple
(
true
))
==
nullptr
);
}
#if GTEST_HAS_STD_UNIQUE_PTR_
// Tests that ReturnNull() returns NULL for shared_ptr and unique_ptr returning
// functions.
TEST
(
ReturnNullTest
,
WorksInSmartPointerReturningFunction
)
{
const
Action
<
std
::
unique_ptr
<
const
int
>
()
>
a1
=
ReturnNull
();
EXPECT_TRUE
(
a1
.
Perform
(
make_tuple
())
==
nullptr
);
EXPECT_TRUE
(
a1
.
Perform
(
std
::
make_tuple
())
==
nullptr
);
const
Action
<
std
::
shared_ptr
<
int
>
(
std
::
string
)
>
a2
=
ReturnNull
();
EXPECT_TRUE
(
a2
.
Perform
(
make_tuple
(
"foo"
))
==
nullptr
);
EXPECT_TRUE
(
a2
.
Perform
(
std
::
make_tuple
(
"foo"
))
==
nullptr
);
}
#endif // GTEST_HAS_STD_UNIQUE_PTR_
// Tests that ReturnRef(v) works for reference types.
TEST
(
ReturnRefTest
,
WorksForReference
)
{
const
int
n
=
0
;
const
Action
<
const
int
&
(
bool
)
>
ret
=
ReturnRef
(
n
);
// NOLINT
EXPECT_EQ
(
&
n
,
&
ret
.
Perform
(
make_tuple
(
true
)));
EXPECT_EQ
(
&
n
,
&
ret
.
Perform
(
std
::
make_tuple
(
true
)));
}
// Tests that ReturnRef(v) is covariant.
...
...
@@ -667,10 +662,10 @@ TEST(ReturnRefTest, IsCovariant) {
Base
base
;
Derived
derived
;
Action
<
Base
&
()
>
a
=
ReturnRef
(
base
);
EXPECT_EQ
(
&
base
,
&
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
&
base
,
&
a
.
Perform
(
std
::
make_tuple
()));
a
=
ReturnRef
(
derived
);
EXPECT_EQ
(
&
derived
,
&
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
&
derived
,
&
a
.
Perform
(
std
::
make_tuple
()));
}
// Tests that ReturnRefOfCopy(v) works for reference types.
...
...
@@ -678,12 +673,12 @@ TEST(ReturnRefOfCopyTest, WorksForReference) {
int
n
=
42
;
const
Action
<
const
int
&
()
>
ret
=
ReturnRefOfCopy
(
n
);
EXPECT_NE
(
&
n
,
&
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
42
,
ret
.
Perform
(
make_tuple
()));
EXPECT_NE
(
&
n
,
&
ret
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
42
,
ret
.
Perform
(
std
::
make_tuple
()));
n
=
43
;
EXPECT_NE
(
&
n
,
&
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
42
,
ret
.
Perform
(
make_tuple
()));
EXPECT_NE
(
&
n
,
&
ret
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
42
,
ret
.
Perform
(
std
::
make_tuple
()));
}
// Tests that ReturnRefOfCopy(v) is covariant.
...
...
@@ -691,10 +686,10 @@ TEST(ReturnRefOfCopyTest, IsCovariant) {
Base
base
;
Derived
derived
;
Action
<
Base
&
()
>
a
=
ReturnRefOfCopy
(
base
);
EXPECT_NE
(
&
base
,
&
a
.
Perform
(
make_tuple
()));
EXPECT_NE
(
&
base
,
&
a
.
Perform
(
std
::
make_tuple
()));
a
=
ReturnRefOfCopy
(
derived
);
EXPECT_NE
(
&
derived
,
&
a
.
Perform
(
make_tuple
()));
EXPECT_NE
(
&
derived
,
&
a
.
Perform
(
std
::
make_tuple
()));
}
// Tests that DoDefault() does the default action for the mock method.
...
...
@@ -705,14 +700,12 @@ class MockClass {
MOCK_METHOD1
(
IntFunc
,
int
(
bool
flag
));
// NOLINT
MOCK_METHOD0
(
Foo
,
MyNonDefaultConstructible
());
#if GTEST_HAS_STD_UNIQUE_PTR_
MOCK_METHOD0
(
MakeUnique
,
std
::
unique_ptr
<
int
>
());
MOCK_METHOD0
(
MakeUniqueBase
,
std
::
unique_ptr
<
Base
>
());
MOCK_METHOD0
(
MakeVectorUnique
,
std
::
vector
<
std
::
unique_ptr
<
int
>>
());
MOCK_METHOD1
(
TakeUnique
,
int
(
std
::
unique_ptr
<
int
>
));
MOCK_METHOD2
(
TakeUnique
,
int
(
const
std
::
unique_ptr
<
int
>&
,
std
::
unique_ptr
<
int
>
));
#endif
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockClass
);
...
...
@@ -800,14 +793,14 @@ TEST(SetArgPointeeTest, SetsTheNthPointee) {
int
n
=
0
;
char
ch
=
'\0'
;
a
.
Perform
(
make_tuple
(
true
,
&
n
,
&
ch
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
n
,
&
ch
));
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'\0'
,
ch
);
a
=
SetArgPointee
<
2
>
(
'a'
);
n
=
0
;
ch
=
'\0'
;
a
.
Perform
(
make_tuple
(
true
,
&
n
,
&
ch
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
n
,
&
ch
));
EXPECT_EQ
(
0
,
n
);
EXPECT_EQ
(
'a'
,
ch
);
}
...
...
@@ -820,13 +813,13 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) {
Action
<
MyFunction
>
a
=
SetArgPointee
<
0
>
(
"hi"
);
std
::
string
str
;
const
char
*
ptr
=
nullptr
;
a
.
Perform
(
make_tuple
(
&
str
,
&
ptr
));
a
.
Perform
(
std
::
make_tuple
(
&
str
,
&
ptr
));
EXPECT_EQ
(
"hi"
,
str
);
EXPECT_TRUE
(
ptr
==
nullptr
);
a
=
SetArgPointee
<
1
>
(
"world"
);
str
=
""
;
a
.
Perform
(
make_tuple
(
&
str
,
&
ptr
));
a
.
Perform
(
std
::
make_tuple
(
&
str
,
&
ptr
));
EXPECT_EQ
(
""
,
str
);
EXPECT_STREQ
(
"world"
,
ptr
);
}
...
...
@@ -835,7 +828,7 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
typedef
void
MyFunction
(
const
wchar_t
**
);
Action
<
MyFunction
>
a
=
SetArgPointee
<
0
>
(
L"world"
);
const
wchar_t
*
ptr
=
nullptr
;
a
.
Perform
(
make_tuple
(
&
ptr
));
a
.
Perform
(
std
::
make_tuple
(
&
ptr
));
EXPECT_STREQ
(
L"world"
,
ptr
);
# if GTEST_HAS_STD_WSTRING
...
...
@@ -843,7 +836,7 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
typedef
void
MyStringFunction
(
std
::
wstring
*
);
Action
<
MyStringFunction
>
a2
=
SetArgPointee
<
0
>
(
L"world"
);
std
::
wstring
str
=
L""
;
a2
.
Perform
(
make_tuple
(
&
str
));
a2
.
Perform
(
std
::
make_tuple
(
&
str
));
EXPECT_EQ
(
L"world"
,
str
);
# endif
...
...
@@ -857,7 +850,7 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) {
Action
<
MyFunction
>
a
=
SetArgPointee
<
1
>
(
hi
);
std
::
string
str
;
const
char
*
ptr
=
nullptr
;
a
.
Perform
(
make_tuple
(
true
,
&
str
,
&
ptr
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
str
,
&
ptr
));
EXPECT_EQ
(
"hi"
,
str
);
EXPECT_TRUE
(
ptr
==
nullptr
);
...
...
@@ -865,7 +858,7 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) {
char
*
const
world
=
world_array
;
a
=
SetArgPointee
<
2
>
(
world
);
str
=
""
;
a
.
Perform
(
make_tuple
(
true
,
&
str
,
&
ptr
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
str
,
&
ptr
));
EXPECT_EQ
(
""
,
str
);
EXPECT_EQ
(
world
,
ptr
);
}
...
...
@@ -875,7 +868,7 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) {
const
wchar_t
*
const
hi
=
L"hi"
;
Action
<
MyFunction
>
a
=
SetArgPointee
<
1
>
(
hi
);
const
wchar_t
*
ptr
=
nullptr
;
a
.
Perform
(
make_tuple
(
true
,
&
ptr
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
ptr
));
EXPECT_EQ
(
hi
,
ptr
);
# if GTEST_HAS_STD_WSTRING
...
...
@@ -885,7 +878,7 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) {
wchar_t
*
const
world
=
world_array
;
Action
<
MyStringFunction
>
a2
=
SetArgPointee
<
1
>
(
world
);
std
::
wstring
str
;
a2
.
Perform
(
make_tuple
(
true
,
&
str
));
a2
.
Perform
(
std
::
make_tuple
(
true
,
&
str
));
EXPECT_EQ
(
world_array
,
str
);
# endif
}
...
...
@@ -898,14 +891,14 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointee) {
int
n
=
0
;
char
ch
=
'\0'
;
a
.
Perform
(
make_tuple
(
true
,
&
n
,
&
ch
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
n
,
&
ch
));
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'\0'
,
ch
);
a
=
SetArgumentPointee
<
2
>
(
'a'
);
n
=
0
;
ch
=
'\0'
;
a
.
Perform
(
make_tuple
(
true
,
&
n
,
&
ch
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
n
,
&
ch
));
EXPECT_EQ
(
0
,
n
);
EXPECT_EQ
(
'a'
,
ch
);
}
...
...
@@ -926,6 +919,21 @@ class VoidNullaryFunctor {
void
operator
()()
{
g_done
=
true
;
}
};
short
Short
(
short
n
)
{
return
n
;
}
// NOLINT
char
Char
(
char
ch
)
{
return
ch
;
}
const
char
*
CharPtr
(
const
char
*
s
)
{
return
s
;
}
bool
Unary
(
int
x
)
{
return
x
<
0
;
}
const
char
*
Binary
(
const
char
*
input
,
short
n
)
{
return
input
+
n
;
}
// NOLINT
void
VoidBinary
(
int
,
char
)
{
g_done
=
true
;
}
int
Ternary
(
int
x
,
char
y
,
short
z
)
{
return
x
+
y
+
z
;
}
// NOLINT
int
SumOf4
(
int
a
,
int
b
,
int
c
,
int
d
)
{
return
a
+
b
+
c
+
d
;
}
class
Foo
{
public:
Foo
()
:
value_
(
123
)
{}
...
...
@@ -940,16 +948,16 @@ class Foo {
TEST
(
InvokeWithoutArgsTest
,
Function
)
{
// As an action that takes one argument.
Action
<
int
(
int
)
>
a
=
InvokeWithoutArgs
(
Nullary
);
// NOLINT
EXPECT_EQ
(
1
,
a
.
Perform
(
make_tuple
(
2
)));
EXPECT_EQ
(
1
,
a
.
Perform
(
std
::
make_tuple
(
2
)));
// As an action that takes two arguments.
Action
<
int
(
int
,
double
)
>
a2
=
InvokeWithoutArgs
(
Nullary
);
// NOLINT
EXPECT_EQ
(
1
,
a2
.
Perform
(
make_tuple
(
2
,
3.5
)));
EXPECT_EQ
(
1
,
a2
.
Perform
(
std
::
make_tuple
(
2
,
3.5
)));
// As an action that returns void.
Action
<
void
(
int
)
>
a3
=
InvokeWithoutArgs
(
VoidNullary
);
// NOLINT
g_done
=
false
;
a3
.
Perform
(
make_tuple
(
1
));
a3
.
Perform
(
std
::
make_tuple
(
1
));
EXPECT_TRUE
(
g_done
);
}
...
...
@@ -957,17 +965,17 @@ TEST(InvokeWithoutArgsTest, Function) {
TEST
(
InvokeWithoutArgsTest
,
Functor
)
{
// As an action that takes no argument.
Action
<
int
()
>
a
=
InvokeWithoutArgs
(
NullaryFunctor
());
// NOLINT
EXPECT_EQ
(
2
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
2
,
a
.
Perform
(
std
::
make_tuple
()));
// As an action that takes three arguments.
Action
<
int
(
int
,
double
,
char
)
>
a2
=
// NOLINT
InvokeWithoutArgs
(
NullaryFunctor
());
EXPECT_EQ
(
2
,
a2
.
Perform
(
make_tuple
(
3
,
3.5
,
'a'
)));
EXPECT_EQ
(
2
,
a2
.
Perform
(
std
::
make_tuple
(
3
,
3.5
,
'a'
)));
// As an action that returns void.
Action
<
void
()
>
a3
=
InvokeWithoutArgs
(
VoidNullaryFunctor
());
g_done
=
false
;
a3
.
Perform
(
make_tuple
());
a3
.
Perform
(
std
::
make_tuple
());
EXPECT_TRUE
(
g_done
);
}
...
...
@@ -976,13 +984,13 @@ TEST(InvokeWithoutArgsTest, Method) {
Foo
foo
;
Action
<
int
(
bool
,
char
)
>
a
=
// NOLINT
InvokeWithoutArgs
(
&
foo
,
&
Foo
::
Nullary
);
EXPECT_EQ
(
123
,
a
.
Perform
(
make_tuple
(
true
,
'a'
)));
EXPECT_EQ
(
123
,
a
.
Perform
(
std
::
make_tuple
(
true
,
'a'
)));
}
// Tests using IgnoreResult() on a polymorphic action.
TEST
(
IgnoreResultTest
,
PolymorphicAction
)
{
Action
<
void
(
int
)
>
a
=
IgnoreResult
(
Return
(
5
));
// NOLINT
a
.
Perform
(
make_tuple
(
1
));
a
.
Perform
(
std
::
make_tuple
(
1
));
}
// Tests using IgnoreResult() on a monomorphic action.
...
...
@@ -995,7 +1003,7 @@ int ReturnOne() {
TEST
(
IgnoreResultTest
,
MonomorphicAction
)
{
g_done
=
false
;
Action
<
void
()
>
a
=
IgnoreResult
(
Invoke
(
ReturnOne
));
a
.
Perform
(
make_tuple
());
a
.
Perform
(
std
::
make_tuple
());
EXPECT_TRUE
(
g_done
);
}
...
...
@@ -1010,55 +1018,155 @@ TEST(IgnoreResultTest, ActionReturningClass) {
g_done
=
false
;
Action
<
void
(
int
)
>
a
=
IgnoreResult
(
Invoke
(
ReturnMyNonDefaultConstructible
));
// NOLINT
a
.
Perform
(
make_tuple
(
2
));
a
.
Perform
(
std
::
make_tuple
(
2
));
EXPECT_TRUE
(
g_done
);
}
TEST
(
AssignTest
,
Int
)
{
int
x
=
0
;
Action
<
void
(
int
)
>
a
=
Assign
(
&
x
,
5
);
a
.
Perform
(
make_tuple
(
0
));
a
.
Perform
(
std
::
make_tuple
(
0
));
EXPECT_EQ
(
5
,
x
);
}
TEST
(
AssignTest
,
String
)
{
::
std
::
string
x
;
Action
<
void
(
void
)
>
a
=
Assign
(
&
x
,
"Hello, world"
);
a
.
Perform
(
make_tuple
());
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
"Hello, world"
,
x
);
}
TEST
(
AssignTest
,
CompatibleTypes
)
{
double
x
=
0
;
Action
<
void
(
int
)
>
a
=
Assign
(
&
x
,
5
);
a
.
Perform
(
make_tuple
(
0
));
a
.
Perform
(
std
::
make_tuple
(
0
));
EXPECT_DOUBLE_EQ
(
5
,
x
);
}
// Tests using WithArgs and with an action that takes 1 argument.
TEST
(
WithArgsTest
,
OneArg
)
{
Action
<
bool
(
double
x
,
int
n
)
>
a
=
WithArgs
<
1
>
(
Invoke
(
Unary
));
// NOLINT
EXPECT_TRUE
(
a
.
Perform
(
std
::
make_tuple
(
1.5
,
-
1
)));
EXPECT_FALSE
(
a
.
Perform
(
std
::
make_tuple
(
1.5
,
1
)));
}
// Tests using WithArgs with an action that takes 2 arguments.
TEST
(
WithArgsTest
,
TwoArgs
)
{
Action
<
const
char
*
(
const
char
*
s
,
double
x
,
short
n
)
>
a
=
// NOLINT
WithArgs
<
0
,
2
>
(
Invoke
(
Binary
));
const
char
s
[]
=
"Hello"
;
EXPECT_EQ
(
s
+
2
,
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
s
),
0.5
,
Short
(
2
))));
}
struct
ConcatAll
{
std
::
string
operator
()()
const
{
return
{};
}
template
<
typename
...
I
>
std
::
string
operator
()(
const
char
*
a
,
I
...
i
)
const
{
return
a
+
ConcatAll
()(
i
...);
}
};
// Tests using WithArgs with an action that takes 10 arguments.
TEST
(
WithArgsTest
,
TenArgs
)
{
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
2
,
1
,
0
,
1
,
2
,
3
>
(
Invoke
(
ConcatAll
{}));
EXPECT_EQ
(
"0123210123"
,
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
}
// Tests using WithArgs with an action that is not Invoke().
class
SubtractAction
:
public
ActionInterface
<
int
(
int
,
int
)
>
{
public:
int
Perform
(
const
std
::
tuple
<
int
,
int
>&
args
)
override
{
return
std
::
get
<
0
>
(
args
)
-
std
::
get
<
1
>
(
args
);
}
};
TEST
(
WithArgsTest
,
NonInvokeAction
)
{
Action
<
int
(
const
std
::
string
&
,
int
,
int
)
>
a
=
WithArgs
<
2
,
1
>
(
MakeAction
(
new
SubtractAction
));
std
::
tuple
<
std
::
string
,
int
,
int
>
dummy
=
std
::
make_tuple
(
std
::
string
(
"hi"
),
2
,
10
);
EXPECT_EQ
(
8
,
a
.
Perform
(
dummy
));
}
// Tests using WithArgs to pass all original arguments in the original order.
TEST
(
WithArgsTest
,
Identity
)
{
Action
<
int
(
int
x
,
char
y
,
short
z
)
>
a
=
// NOLINT
WithArgs
<
0
,
1
,
2
>
(
Invoke
(
Ternary
));
EXPECT_EQ
(
123
,
a
.
Perform
(
std
::
make_tuple
(
100
,
Char
(
20
),
Short
(
3
))));
}
// Tests using WithArgs with repeated arguments.
TEST
(
WithArgsTest
,
RepeatedArguments
)
{
Action
<
int
(
bool
,
int
m
,
int
n
)
>
a
=
// NOLINT
WithArgs
<
1
,
1
,
1
,
1
>
(
Invoke
(
SumOf4
));
EXPECT_EQ
(
4
,
a
.
Perform
(
std
::
make_tuple
(
false
,
1
,
10
)));
}
// Tests using WithArgs with reversed argument order.
TEST
(
WithArgsTest
,
ReversedArgumentOrder
)
{
Action
<
const
char
*
(
short
n
,
const
char
*
input
)
>
a
=
// NOLINT
WithArgs
<
1
,
0
>
(
Invoke
(
Binary
));
const
char
s
[]
=
"Hello"
;
EXPECT_EQ
(
s
+
2
,
a
.
Perform
(
std
::
make_tuple
(
Short
(
2
),
CharPtr
(
s
))));
}
// Tests using WithArgs with compatible, but not identical, argument types.
TEST
(
WithArgsTest
,
ArgsOfCompatibleTypes
)
{
Action
<
long
(
short
x
,
char
y
,
double
z
,
char
c
)
>
a
=
// NOLINT
WithArgs
<
0
,
1
,
3
>
(
Invoke
(
Ternary
));
EXPECT_EQ
(
123
,
a
.
Perform
(
std
::
make_tuple
(
Short
(
100
),
Char
(
20
),
5.6
,
Char
(
3
))));
}
// Tests using WithArgs with an action that returns void.
TEST
(
WithArgsTest
,
VoidAction
)
{
Action
<
void
(
double
x
,
char
c
,
int
n
)
>
a
=
WithArgs
<
2
,
1
>
(
Invoke
(
VoidBinary
));
g_done
=
false
;
a
.
Perform
(
std
::
make_tuple
(
1.5
,
'a'
,
3
));
EXPECT_TRUE
(
g_done
);
}
TEST
(
WithArgsTest
,
ReturnReference
)
{
Action
<
int
&
(
int
&
,
void
*
)
>
aa
=
WithArgs
<
0
>
([](
int
&
a
)
->
int
&
{
return
a
;
});
int
i
=
0
;
const
int
&
res
=
aa
.
Perform
(
std
::
forward_as_tuple
(
i
,
nullptr
));
EXPECT_EQ
(
&
i
,
&
res
);
}
TEST
(
WithArgsTest
,
InnerActionWithConversion
)
{
Action
<
Derived
*
()
>
inner
=
[]
{
return
nullptr
;
};
Action
<
Base
*
(
double
)
>
a
=
testing
::
WithoutArgs
(
inner
);
EXPECT_EQ
(
nullptr
,
a
.
Perform
(
std
::
make_tuple
(
1.1
)));
}
#if !GTEST_OS_WINDOWS_MOBILE
class
SetErrnoAndReturnTest
:
public
testing
::
Test
{
protected:
virtual
void
SetUp
()
{
errno
=
0
;
}
virtual
void
TearDown
()
{
errno
=
0
;
}
void
SetUp
()
override
{
errno
=
0
;
}
void
TearDown
()
override
{
errno
=
0
;
}
};
TEST_F
(
SetErrnoAndReturnTest
,
Int
)
{
Action
<
int
(
void
)
>
a
=
SetErrnoAndReturn
(
ENOTTY
,
-
5
);
EXPECT_EQ
(
-
5
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
-
5
,
a
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
ENOTTY
,
errno
);
}
TEST_F
(
SetErrnoAndReturnTest
,
Ptr
)
{
int
x
;
Action
<
int
*
(
void
)
>
a
=
SetErrnoAndReturn
(
ENOTTY
,
&
x
);
EXPECT_EQ
(
&
x
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
&
x
,
a
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
ENOTTY
,
errno
);
}
TEST_F
(
SetErrnoAndReturnTest
,
CompatibleTypes
)
{
Action
<
double
()
>
a
=
SetErrnoAndReturn
(
EINVAL
,
5
);
EXPECT_DOUBLE_EQ
(
5.0
,
a
.
Perform
(
make_tuple
()));
EXPECT_DOUBLE_EQ
(
5.0
,
a
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
EINVAL
,
errno
);
}
...
...
@@ -1149,7 +1257,6 @@ TEST(ByRefTest, PrintsCorrectly) {
EXPECT_EQ
(
expected
.
str
(),
actual
.
str
());
}
#if GTEST_HAS_STD_UNIQUE_PTR_
std
::
unique_ptr
<
int
>
UniquePtrSource
()
{
return
std
::
unique_ptr
<
int
>
(
new
int
(
19
));
...
...
@@ -1262,9 +1369,7 @@ TEST(MockMethodTest, CanTakeMoveOnlyValue) {
EXPECT_EQ
(
42
,
*
saved
);
}
#endif // GTEST_HAS_STD_UNIQUE_PTR_
#if GTEST_LANG_CXX11
// Tests for std::function based action.
int
Add
(
int
val
,
int
&
ref
,
int
*
ptr
)
{
// NOLINT
...
...
@@ -1298,47 +1403,47 @@ TEST(FunctorActionTest, ActionFromFunction) {
TEST
(
FunctorActionTest
,
ActionFromLambda
)
{
Action
<
int
(
bool
,
int
)
>
a1
=
[](
bool
b
,
int
i
)
{
return
b
?
i
:
0
;
};
EXPECT_EQ
(
5
,
a1
.
Perform
(
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a1
.
Perform
(
make_tuple
(
false
,
5
)));
EXPECT_EQ
(
5
,
a1
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a1
.
Perform
(
std
::
make_tuple
(
false
,
5
)));
std
::
unique_ptr
<
int
>
saved
;
Action
<
void
(
std
::
unique_ptr
<
int
>
)
>
a2
=
[
&
saved
](
std
::
unique_ptr
<
int
>
p
)
{
saved
=
std
::
move
(
p
);
};
a2
.
Perform
(
make_tuple
(
UniqueInt
(
5
)));
a2
.
Perform
(
std
::
make_tuple
(
UniqueInt
(
5
)));
EXPECT_EQ
(
5
,
*
saved
);
}
TEST
(
FunctorActionTest
,
PolymorphicFunctor
)
{
Action
<
int
(
int
)
>
ai
=
Double
();
EXPECT_EQ
(
2
,
ai
.
Perform
(
make_tuple
(
1
)));
EXPECT_EQ
(
2
,
ai
.
Perform
(
std
::
make_tuple
(
1
)));
Action
<
double
(
double
)
>
ad
=
Double
();
// Double? Double double!
EXPECT_EQ
(
3.0
,
ad
.
Perform
(
make_tuple
(
1.5
)));
EXPECT_EQ
(
3.0
,
ad
.
Perform
(
std
::
make_tuple
(
1.5
)));
}
TEST
(
FunctorActionTest
,
TypeConversion
)
{
// Numeric promotions are allowed.
const
Action
<
bool
(
int
)
>
a1
=
[](
int
i
)
{
return
i
>
1
;
};
const
Action
<
int
(
bool
)
>
a2
=
Action
<
int
(
bool
)
>
(
a1
);
EXPECT_EQ
(
1
,
a1
.
Perform
(
make_tuple
(
42
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
make_tuple
(
42
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
(
42
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
std
::
make_tuple
(
42
)));
// Implicit constructors are allowed.
const
Action
<
bool
(
std
::
string
)
>
s1
=
[](
std
::
string
s
)
{
return
!
s
.
empty
();
};
const
Action
<
int
(
const
char
*
)
>
s2
=
Action
<
int
(
const
char
*
)
>
(
s1
);
EXPECT_EQ
(
0
,
s2
.
Perform
(
make_tuple
(
""
)));
EXPECT_EQ
(
1
,
s2
.
Perform
(
make_tuple
(
"hello"
)));
EXPECT_EQ
(
0
,
s2
.
Perform
(
std
::
make_tuple
(
""
)));
EXPECT_EQ
(
1
,
s2
.
Perform
(
std
::
make_tuple
(
"hello"
)));
// Also between the lambda and the action itself.
const
Action
<
bool
(
std
::
string
)
>
x
=
[](
Unused
)
{
return
42
;
};
EXPECT_TRUE
(
x
.
Perform
(
make_tuple
(
"hello"
)));
EXPECT_TRUE
(
x
.
Perform
(
std
::
make_tuple
(
"hello"
)));
}
TEST
(
FunctorActionTest
,
UnusedArguments
)
{
// Verify that users can ignore uninteresting arguments.
Action
<
int
(
int
,
double
y
,
double
z
)
>
a
=
[](
int
i
,
Unused
,
Unused
)
{
return
2
*
i
;
};
tuple
<
int
,
double
,
double
>
dummy
=
make_tuple
(
3
,
7.3
,
9.44
);
std
::
tuple
<
int
,
double
,
double
>
dummy
=
std
::
make_tuple
(
3
,
7.3
,
9.44
);
EXPECT_EQ
(
6
,
a
.
Perform
(
dummy
));
}
...
...
@@ -1349,18 +1454,17 @@ TEST(FunctorActionTest, UnusedArguments) {
// so maybe it's better to make users use lambdas instead.
TEST
(
MoveOnlyArgumentsTest
,
ReturningActions
)
{
Action
<
int
(
std
::
unique_ptr
<
int
>
)
>
a
=
Return
(
1
);
EXPECT_EQ
(
1
,
a
.
Perform
(
make_tuple
(
nullptr
)));
EXPECT_EQ
(
1
,
a
.
Perform
(
std
::
make_tuple
(
nullptr
)));
a
=
testing
::
WithoutArgs
([]()
{
return
7
;
});
EXPECT_EQ
(
7
,
a
.
Perform
(
make_tuple
(
nullptr
)));
EXPECT_EQ
(
7
,
a
.
Perform
(
std
::
make_tuple
(
nullptr
)));
Action
<
void
(
std
::
unique_ptr
<
int
>
,
int
*
)
>
a2
=
testing
::
SetArgPointee
<
1
>
(
3
);
int
x
=
0
;
a2
.
Perform
(
make_tuple
(
nullptr
,
&
x
));
a2
.
Perform
(
std
::
make_tuple
(
nullptr
,
&
x
));
EXPECT_EQ
(
x
,
3
);
}
#endif // GTEST_LANG_CXX11
}
// Unnamed namespace
...
...
googlemock/test/gmock-cardinalities_test.cc
View file @
25905b9f
...
...
@@ -396,17 +396,17 @@ TEST(ExactlyTest, HasCorrectBounds) {
class
EvenCardinality
:
public
CardinalityInterface
{
public:
// Returns true iff call_count calls will satisfy this cardinality.
virtual
bool
IsSatisfiedByCallCount
(
int
call_count
)
const
{
bool
IsSatisfiedByCallCount
(
int
call_count
)
const
override
{
return
(
call_count
%
2
==
0
);
}
// Returns true iff call_count calls will saturate this cardinality.
virtual
bool
IsSaturatedByCallCount
(
int
/* call_count */
)
const
{
bool
IsSaturatedByCallCount
(
int
/* call_count */
)
const
override
{
return
false
;
}
// Describes self to an ostream.
virtual
void
DescribeTo
(
::
std
::
ostream
*
ss
)
const
{
void
DescribeTo
(
::
std
::
ostream
*
ss
)
const
override
{
*
ss
<<
"called even number of times"
;
}
};
...
...
googlemock/test/gmock-function-mocker_nc.cc
0 → 100644
View file @
25905b9f
#include "gmock/gmock.h"
#include <memory>
#include <string>
#if defined(TEST_MOCK_METHOD_INVALID_CONST_SPEC)
struct
Base
{
MOCK_METHOD
(
int
,
F
,
(),
(
onst
));
};
#else
// Sanity check - this should compile.
#endif
googlemock/test/gmock-function-mocker_nc_test.py
0 → 100644
View file @
25905b9f
"""Negative compilation tests for Google Mock macro MOCK_METHOD."""
import
os
import
sys
IS_LINUX
=
os
.
name
==
"posix"
and
os
.
uname
()[
0
]
==
"Linux"
if
not
IS_LINUX
:
sys
.
stderr
.
write
(
"WARNING: Negative compilation tests are not supported on this platform"
)
sys
.
exit
(
0
)
# Suppresses the 'Import not at the top of the file' lint complaint.
# pylint: disable-msg=C6204
from
google3.testing.pybase
import
fake_target_util
from
google3.testing.pybase
import
googletest
# pylint: enable-msg=C6204
class
GMockMethodNCTest
(
googletest
.
TestCase
):
"""Negative compilation tests for MOCK_METHOD."""
# The class body is intentionally empty. The actual test*() methods
# will be defined at run time by a call to
# DefineNegativeCompilationTests() later.
pass
# Defines a list of test specs, where each element is a tuple
# (test name, list of regexes for matching the compiler errors).
TEST_SPECS
=
[
(
"MOCK_METHOD_INVALID_CONST_SPEC"
,
[
r
"onst cannot be recognized as a valid specification modifier"
]),
]
# Define a test method in GMockNCTest for each element in TEST_SPECS.
fake_target_util
.
DefineNegativeCompilationTests
(
GMockMethodNCTest
,
"google3/third_party/googletest/googlemock/test/gmock-function-mocker_nc"
,
"gmock-function-mocker_nc.o"
,
TEST_SPECS
)
if
__name__
==
"__main__"
:
googletest
.
main
()
googlemock/test/gmock-function-mocker_test.cc
0 → 100644
View file @
25905b9f
// Copyright 2007, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Mock - a framework for writing C++ mock classes.
//
// This file tests the function mocker classes.
#include "gmock/gmock-generated-function-mockers.h"
#if GTEST_OS_WINDOWS
// MSDN says the header file to be included for STDMETHOD is BaseTyps.h but
// we are getting compiler errors if we use basetyps.h, hence including
// objbase.h for definition of STDMETHOD.
# include <objbase.h>
#endif // GTEST_OS_WINDOWS
#include <map>
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
// There is a bug in MSVC (fixed in VS 2008) that prevents creating a
// mock for a function with const arguments, so we don't test such
// cases for MSVC versions older than 2008.
#if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
# define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
#endif // !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
namespace
testing
{
namespace
gmock_function_mocker_test
{
using
testing
::
_
;
using
testing
::
A
;
using
testing
::
An
;
using
testing
::
AnyNumber
;
using
testing
::
Const
;
using
testing
::
DoDefault
;
using
testing
::
Eq
;
using
testing
::
Lt
;
using
testing
::
MockFunction
;
using
testing
::
Ref
;
using
testing
::
Return
;
using
testing
::
ReturnRef
;
using
testing
::
TypedEq
;
class
FooInterface
{
public:
virtual
~
FooInterface
()
{}
virtual
void
VoidReturning
(
int
x
)
=
0
;
virtual
int
Nullary
()
=
0
;
virtual
bool
Unary
(
int
x
)
=
0
;
virtual
long
Binary
(
short
x
,
int
y
)
=
0
;
// NOLINT
virtual
int
Decimal
(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
// NOLINT
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
std
::
string
&
k
)
=
0
;
virtual
bool
TakesNonConstReference
(
int
&
n
)
=
0
;
// NOLINT
virtual
std
::
string
TakesConstReference
(
const
int
&
n
)
=
0
;
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
virtual
bool
TakesConst
(
const
int
x
)
=
0
;
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
virtual
int
OverloadedOnArgumentNumber
()
=
0
;
virtual
int
OverloadedOnArgumentNumber
(
int
n
)
=
0
;
virtual
int
OverloadedOnArgumentType
(
int
n
)
=
0
;
virtual
char
OverloadedOnArgumentType
(
char
c
)
=
0
;
virtual
int
OverloadedOnConstness
()
=
0
;
virtual
char
OverloadedOnConstness
()
const
=
0
;
virtual
int
TypeWithHole
(
int
(
*
func
)())
=
0
;
virtual
int
TypeWithComma
(
const
std
::
map
<
int
,
std
::
string
>&
a_map
)
=
0
;
#if GTEST_OS_WINDOWS
STDMETHOD_
(
int
,
CTNullary
)()
=
0
;
STDMETHOD_
(
bool
,
CTUnary
)(
int
x
)
=
0
;
STDMETHOD_
(
int
,
CTDecimal
)
(
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
;
#endif // GTEST_OS_WINDOWS
};
// Const qualifiers on arguments were once (incorrectly) considered
// significant in determining whether two virtual functions had the same
// signature. This was fixed in Visual Studio 2008. However, the compiler
// still emits a warning that alerts about this change in behavior.
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4373)
#endif
class
MockFoo
:
public
FooInterface
{
public:
MockFoo
()
{}
// Makes sure that a mock function parameter can be named.
MOCK_METHOD
(
void
,
VoidReturning
,
(
int
n
));
// NOLINT
MOCK_METHOD
(
int
,
Nullary
,
());
// NOLINT
// Makes sure that a mock function parameter can be unnamed.
MOCK_METHOD
(
bool
,
Unary
,
(
int
));
// NOLINT
MOCK_METHOD
(
long
,
Binary
,
(
short
,
int
));
// NOLINT
MOCK_METHOD
(
int
,
Decimal
,
(
bool
,
char
,
short
,
int
,
long
,
float
,
// NOLINT
double
,
unsigned
,
char
*
,
const
std
::
string
&
str
),
(
override
));
MOCK_METHOD
(
bool
,
TakesNonConstReference
,
(
int
&
));
// NOLINT
MOCK_METHOD
(
std
::
string
,
TakesConstReference
,
(
const
int
&
));
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
MOCK_METHOD
(
bool
,
TakesConst
,
(
const
int
));
// NOLINT
#endif
// Tests that the function return type can contain unprotected comma.
MOCK_METHOD
((
std
::
map
<
int
,
std
::
string
>
),
ReturnTypeWithComma
,
(),
());
MOCK_METHOD
((
std
::
map
<
int
,
std
::
string
>
),
ReturnTypeWithComma
,
(
int
),
(
const
));
// NOLINT
MOCK_METHOD
(
int
,
OverloadedOnArgumentNumber
,
());
// NOLINT
MOCK_METHOD
(
int
,
OverloadedOnArgumentNumber
,
(
int
));
// NOLINT
MOCK_METHOD
(
int
,
OverloadedOnArgumentType
,
(
int
));
// NOLINT
MOCK_METHOD
(
char
,
OverloadedOnArgumentType
,
(
char
));
// NOLINT
MOCK_METHOD
(
int
,
OverloadedOnConstness
,
(),
(
override
));
// NOLINT
MOCK_METHOD
(
char
,
OverloadedOnConstness
,
(),
(
override
,
const
));
// NOLINT
MOCK_METHOD
(
int
,
TypeWithHole
,
(
int
(
*
)()),
());
// NOLINT
MOCK_METHOD
(
int
,
TypeWithComma
,
((
const
std
::
map
<
int
,
std
::
string
>&
)));
#if GTEST_OS_WINDOWS
MOCK_METHOD
(
int
,
CTNullary
,
(),
(
Calltype
(
STDMETHODCALLTYPE
)));
MOCK_METHOD
(
bool
,
CTUnary
,
(
int
),
(
Calltype
(
STDMETHODCALLTYPE
)));
MOCK_METHOD
(
int
,
CTDecimal
,
(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
std
::
string
&
k
),
(
Calltype
(
STDMETHODCALLTYPE
)));
MOCK_METHOD
(
char
,
CTConst
,
(
int
),
(
const
,
Calltype
(
STDMETHODCALLTYPE
)));
MOCK_METHOD
((
std
::
map
<
int
,
std
::
string
>
),
CTReturnTypeWithComma
,
(),
(
Calltype
(
STDMETHODCALLTYPE
)));
#endif // GTEST_OS_WINDOWS
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockFoo
);
};
#ifdef _MSC_VER
# pragma warning(pop)
#endif
class
MockMethodFunctionMockerTest
:
public
testing
::
Test
{
protected:
MockMethodFunctionMockerTest
()
:
foo_
(
&
mock_foo_
)
{}
FooInterface
*
const
foo_
;
MockFoo
mock_foo_
;
};
// Tests mocking a void-returning function.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksVoidFunction
)
{
EXPECT_CALL
(
mock_foo_
,
VoidReturning
(
Lt
(
100
)));
foo_
->
VoidReturning
(
0
);
}
// Tests mocking a nullary function.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksNullaryFunction
)
{
EXPECT_CALL
(
mock_foo_
,
Nullary
())
.
WillOnce
(
DoDefault
())
.
WillOnce
(
Return
(
1
));
EXPECT_EQ
(
0
,
foo_
->
Nullary
());
EXPECT_EQ
(
1
,
foo_
->
Nullary
());
}
// Tests mocking a unary function.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksUnaryFunction
)
{
EXPECT_CALL
(
mock_foo_
,
Unary
(
Eq
(
2
)))
.
Times
(
2
)
.
WillOnce
(
Return
(
true
));
EXPECT_TRUE
(
foo_
->
Unary
(
2
));
EXPECT_FALSE
(
foo_
->
Unary
(
2
));
}
// Tests mocking a binary function.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksBinaryFunction
)
{
EXPECT_CALL
(
mock_foo_
,
Binary
(
2
,
_
))
.
WillOnce
(
Return
(
3
));
EXPECT_EQ
(
3
,
foo_
->
Binary
(
2
,
1
));
}
// Tests mocking a decimal function.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksDecimalFunction
)
{
EXPECT_CALL
(
mock_foo_
,
Decimal
(
true
,
'a'
,
0
,
0
,
1L
,
A
<
float
>
(),
Lt
(
100
),
5U
,
NULL
,
"hi"
))
.
WillOnce
(
Return
(
5
));
EXPECT_EQ
(
5
,
foo_
->
Decimal
(
true
,
'a'
,
0
,
0
,
1
,
0
,
0
,
5
,
nullptr
,
"hi"
));
}
// Tests mocking a function that takes a non-const reference.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksFunctionWithNonConstReferenceArgument
)
{
int
a
=
0
;
EXPECT_CALL
(
mock_foo_
,
TakesNonConstReference
(
Ref
(
a
)))
.
WillOnce
(
Return
(
true
));
EXPECT_TRUE
(
foo_
->
TakesNonConstReference
(
a
));
}
// Tests mocking a function that takes a const reference.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksFunctionWithConstReferenceArgument
)
{
int
a
=
0
;
EXPECT_CALL
(
mock_foo_
,
TakesConstReference
(
Ref
(
a
)))
.
WillOnce
(
Return
(
"Hello"
));
EXPECT_EQ
(
"Hello"
,
foo_
->
TakesConstReference
(
a
));
}
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
// Tests mocking a function that takes a const variable.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksFunctionWithConstArgument
)
{
EXPECT_CALL
(
mock_foo_
,
TakesConst
(
Lt
(
10
)))
.
WillOnce
(
DoDefault
());
EXPECT_FALSE
(
foo_
->
TakesConst
(
5
));
}
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
// Tests mocking functions overloaded on the number of arguments.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksFunctionsOverloadedOnArgumentNumber
)
{
EXPECT_CALL
(
mock_foo_
,
OverloadedOnArgumentNumber
())
.
WillOnce
(
Return
(
1
));
EXPECT_CALL
(
mock_foo_
,
OverloadedOnArgumentNumber
(
_
))
.
WillOnce
(
Return
(
2
));
EXPECT_EQ
(
2
,
foo_
->
OverloadedOnArgumentNumber
(
1
));
EXPECT_EQ
(
1
,
foo_
->
OverloadedOnArgumentNumber
());
}
// Tests mocking functions overloaded on the types of argument.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksFunctionsOverloadedOnArgumentType
)
{
EXPECT_CALL
(
mock_foo_
,
OverloadedOnArgumentType
(
An
<
int
>
()))
.
WillOnce
(
Return
(
1
));
EXPECT_CALL
(
mock_foo_
,
OverloadedOnArgumentType
(
TypedEq
<
char
>
(
'a'
)))
.
WillOnce
(
Return
(
'b'
));
EXPECT_EQ
(
1
,
foo_
->
OverloadedOnArgumentType
(
0
));
EXPECT_EQ
(
'b'
,
foo_
->
OverloadedOnArgumentType
(
'a'
));
}
// Tests mocking functions overloaded on the const-ness of this object.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksFunctionsOverloadedOnConstnessOfThis
)
{
EXPECT_CALL
(
mock_foo_
,
OverloadedOnConstness
());
EXPECT_CALL
(
Const
(
mock_foo_
),
OverloadedOnConstness
())
.
WillOnce
(
Return
(
'a'
));
EXPECT_EQ
(
0
,
foo_
->
OverloadedOnConstness
());
EXPECT_EQ
(
'a'
,
Const
(
*
foo_
).
OverloadedOnConstness
());
}
TEST_F
(
MockMethodFunctionMockerTest
,
MocksReturnTypeWithComma
)
{
const
std
::
map
<
int
,
std
::
string
>
a_map
;
EXPECT_CALL
(
mock_foo_
,
ReturnTypeWithComma
())
.
WillOnce
(
Return
(
a_map
));
EXPECT_CALL
(
mock_foo_
,
ReturnTypeWithComma
(
42
))
.
WillOnce
(
Return
(
a_map
));
EXPECT_EQ
(
a_map
,
mock_foo_
.
ReturnTypeWithComma
());
EXPECT_EQ
(
a_map
,
mock_foo_
.
ReturnTypeWithComma
(
42
));
}
#if GTEST_OS_WINDOWS
// Tests mocking a nullary function with calltype.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksNullaryFunctionWithCallType
)
{
EXPECT_CALL
(
mock_foo_
,
CTNullary
())
.
WillOnce
(
Return
(
-
1
))
.
WillOnce
(
Return
(
0
));
EXPECT_EQ
(
-
1
,
foo_
->
CTNullary
());
EXPECT_EQ
(
0
,
foo_
->
CTNullary
());
}
// Tests mocking a unary function with calltype.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksUnaryFunctionWithCallType
)
{
EXPECT_CALL
(
mock_foo_
,
CTUnary
(
Eq
(
2
)))
.
Times
(
2
)
.
WillOnce
(
Return
(
true
))
.
WillOnce
(
Return
(
false
));
EXPECT_TRUE
(
foo_
->
CTUnary
(
2
));
EXPECT_FALSE
(
foo_
->
CTUnary
(
2
));
}
// Tests mocking a decimal function with calltype.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksDecimalFunctionWithCallType
)
{
EXPECT_CALL
(
mock_foo_
,
CTDecimal
(
true
,
'a'
,
0
,
0
,
1L
,
A
<
float
>
(),
Lt
(
100
),
5U
,
NULL
,
"hi"
))
.
WillOnce
(
Return
(
10
));
EXPECT_EQ
(
10
,
foo_
->
CTDecimal
(
true
,
'a'
,
0
,
0
,
1
,
0
,
0
,
5
,
NULL
,
"hi"
));
}
// Tests mocking functions overloaded on the const-ness of this object.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksFunctionsConstFunctionWithCallType
)
{
EXPECT_CALL
(
Const
(
mock_foo_
),
CTConst
(
_
))
.
WillOnce
(
Return
(
'a'
));
EXPECT_EQ
(
'a'
,
Const
(
*
foo_
).
CTConst
(
0
));
}
TEST_F
(
MockMethodFunctionMockerTest
,
MocksReturnTypeWithCommaAndCallType
)
{
const
std
::
map
<
int
,
std
::
string
>
a_map
;
EXPECT_CALL
(
mock_foo_
,
CTReturnTypeWithComma
())
.
WillOnce
(
Return
(
a_map
));
EXPECT_EQ
(
a_map
,
mock_foo_
.
CTReturnTypeWithComma
());
}
#endif // GTEST_OS_WINDOWS
class
MockB
{
public:
MockB
()
{}
MOCK_METHOD
(
void
,
DoB
,
());
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockB
);
};
// Tests that functions with no EXPECT_CALL() rules can be called any
// number of times.
TEST
(
MockMethodExpectCallTest
,
UnmentionedFunctionCanBeCalledAnyNumberOfTimes
)
{
{
MockB
b
;
}
{
MockB
b
;
b
.
DoB
();
}
{
MockB
b
;
b
.
DoB
();
b
.
DoB
();
}
}
// Tests mocking template interfaces.
template
<
typename
T
>
class
StackInterface
{
public:
virtual
~
StackInterface
()
{}
// Template parameter appears in function parameter.
virtual
void
Push
(
const
T
&
value
)
=
0
;
virtual
void
Pop
()
=
0
;
virtual
int
GetSize
()
const
=
0
;
// Template parameter appears in function return type.
virtual
const
T
&
GetTop
()
const
=
0
;
};
template
<
typename
T
>
class
MockStack
:
public
StackInterface
<
T
>
{
public:
MockStack
()
{}
MOCK_METHOD
(
void
,
Push
,
(
const
T
&
elem
),
());
MOCK_METHOD
(
void
,
Pop
,
(),
(
final
));
MOCK_METHOD
(
int
,
GetSize
,
(),
(
const
,
override
));
MOCK_METHOD
(
const
T
&
,
GetTop
,
(),
(
const
));
// Tests that the function return type can contain unprotected comma.
MOCK_METHOD
((
std
::
map
<
int
,
int
>
),
ReturnTypeWithComma
,
(),
());
MOCK_METHOD
((
std
::
map
<
int
,
int
>
),
ReturnTypeWithComma
,
(
int
),
(
const
));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockStack
);
};
// Tests that template mock works.
TEST
(
MockMethodTemplateMockTest
,
Works
)
{
MockStack
<
int
>
mock
;
EXPECT_CALL
(
mock
,
GetSize
())
.
WillOnce
(
Return
(
0
))
.
WillOnce
(
Return
(
1
))
.
WillOnce
(
Return
(
0
));
EXPECT_CALL
(
mock
,
Push
(
_
));
int
n
=
5
;
EXPECT_CALL
(
mock
,
GetTop
())
.
WillOnce
(
ReturnRef
(
n
));
EXPECT_CALL
(
mock
,
Pop
())
.
Times
(
AnyNumber
());
EXPECT_EQ
(
0
,
mock
.
GetSize
());
mock
.
Push
(
5
);
EXPECT_EQ
(
1
,
mock
.
GetSize
());
EXPECT_EQ
(
5
,
mock
.
GetTop
());
mock
.
Pop
();
EXPECT_EQ
(
0
,
mock
.
GetSize
());
}
TEST
(
MockMethodTemplateMockTest
,
MethodWithCommaInReturnTypeWorks
)
{
MockStack
<
int
>
mock
;
const
std
::
map
<
int
,
int
>
a_map
;
EXPECT_CALL
(
mock
,
ReturnTypeWithComma
())
.
WillOnce
(
Return
(
a_map
));
EXPECT_CALL
(
mock
,
ReturnTypeWithComma
(
1
))
.
WillOnce
(
Return
(
a_map
));
EXPECT_EQ
(
a_map
,
mock
.
ReturnTypeWithComma
());
EXPECT_EQ
(
a_map
,
mock
.
ReturnTypeWithComma
(
1
));
}
#if GTEST_OS_WINDOWS
// Tests mocking template interfaces with calltype.
template
<
typename
T
>
class
StackInterfaceWithCallType
{
public:
virtual
~
StackInterfaceWithCallType
()
{}
// Template parameter appears in function parameter.
STDMETHOD_
(
void
,
Push
)(
const
T
&
value
)
=
0
;
STDMETHOD_
(
void
,
Pop
)()
=
0
;
STDMETHOD_
(
int
,
GetSize
)()
const
=
0
;
// Template parameter appears in function return type.
STDMETHOD_
(
const
T
&
,
GetTop
)()
const
=
0
;
};
template
<
typename
T
>
class
MockStackWithCallType
:
public
StackInterfaceWithCallType
<
T
>
{
public:
MockStackWithCallType
()
{}
MOCK_METHOD
(
void
,
Push
,
(
const
T
&
elem
),
(
Calltype
(
STDMETHODCALLTYPE
),
override
));
MOCK_METHOD
(
void
,
Pop
,
(),
(
Calltype
(
STDMETHODCALLTYPE
),
override
));
MOCK_METHOD
(
int
,
GetSize
,
(),
(
Calltype
(
STDMETHODCALLTYPE
),
override
,
const
));
MOCK_METHOD
(
const
T
&
,
GetTop
,
(),
(
Calltype
(
STDMETHODCALLTYPE
),
override
,
const
));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockStackWithCallType
);
};
// Tests that template mock with calltype works.
TEST
(
MockMethodTemplateMockTestWithCallType
,
Works
)
{
MockStackWithCallType
<
int
>
mock
;
EXPECT_CALL
(
mock
,
GetSize
())
.
WillOnce
(
Return
(
0
))
.
WillOnce
(
Return
(
1
))
.
WillOnce
(
Return
(
0
));
EXPECT_CALL
(
mock
,
Push
(
_
));
int
n
=
5
;
EXPECT_CALL
(
mock
,
GetTop
())
.
WillOnce
(
ReturnRef
(
n
));
EXPECT_CALL
(
mock
,
Pop
())
.
Times
(
AnyNumber
());
EXPECT_EQ
(
0
,
mock
.
GetSize
());
mock
.
Push
(
5
);
EXPECT_EQ
(
1
,
mock
.
GetSize
());
EXPECT_EQ
(
5
,
mock
.
GetTop
());
mock
.
Pop
();
EXPECT_EQ
(
0
,
mock
.
GetSize
());
}
#endif // GTEST_OS_WINDOWS
#define MY_MOCK_METHODS1_ \
MOCK_METHOD(void, Overloaded, ()); \
MOCK_METHOD(int, Overloaded, (int), (const)); \
MOCK_METHOD(bool, Overloaded, (bool f, int n))
class
MockOverloadedOnArgNumber
{
public:
MockOverloadedOnArgNumber
()
{}
MY_MOCK_METHODS1_
;
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockOverloadedOnArgNumber
);
};
TEST
(
MockMethodOverloadedMockMethodTest
,
CanOverloadOnArgNumberInMacroBody
)
{
MockOverloadedOnArgNumber
mock
;
EXPECT_CALL
(
mock
,
Overloaded
());
EXPECT_CALL
(
mock
,
Overloaded
(
1
)).
WillOnce
(
Return
(
2
));
EXPECT_CALL
(
mock
,
Overloaded
(
true
,
1
)).
WillOnce
(
Return
(
true
));
mock
.
Overloaded
();
EXPECT_EQ
(
2
,
mock
.
Overloaded
(
1
));
EXPECT_TRUE
(
mock
.
Overloaded
(
true
,
1
));
}
#define MY_MOCK_METHODS2_ \
MOCK_CONST_METHOD1(Overloaded, int(int n)); \
MOCK_METHOD1(Overloaded, int(int n));
class
MockOverloadedOnConstness
{
public:
MockOverloadedOnConstness
()
{}
MY_MOCK_METHODS2_
;
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockOverloadedOnConstness
);
};
TEST
(
MockMethodOverloadedMockMethodTest
,
CanOverloadOnConstnessInMacroBody
)
{
MockOverloadedOnConstness
mock
;
const
MockOverloadedOnConstness
*
const_mock
=
&
mock
;
EXPECT_CALL
(
mock
,
Overloaded
(
1
)).
WillOnce
(
Return
(
2
));
EXPECT_CALL
(
*
const_mock
,
Overloaded
(
1
)).
WillOnce
(
Return
(
3
));
EXPECT_EQ
(
2
,
mock
.
Overloaded
(
1
));
EXPECT_EQ
(
3
,
const_mock
->
Overloaded
(
1
));
}
TEST
(
MockMethodMockFunctionTest
,
WorksForVoidNullary
)
{
MockFunction
<
void
()
>
foo
;
EXPECT_CALL
(
foo
,
Call
());
foo
.
Call
();
}
TEST
(
MockMethodMockFunctionTest
,
WorksForNonVoidNullary
)
{
MockFunction
<
int
()
>
foo
;
EXPECT_CALL
(
foo
,
Call
())
.
WillOnce
(
Return
(
1
))
.
WillOnce
(
Return
(
2
));
EXPECT_EQ
(
1
,
foo
.
Call
());
EXPECT_EQ
(
2
,
foo
.
Call
());
}
TEST
(
MockMethodMockFunctionTest
,
WorksForVoidUnary
)
{
MockFunction
<
void
(
int
)
>
foo
;
EXPECT_CALL
(
foo
,
Call
(
1
));
foo
.
Call
(
1
);
}
TEST
(
MockMethodMockFunctionTest
,
WorksForNonVoidBinary
)
{
MockFunction
<
int
(
bool
,
int
)
>
foo
;
EXPECT_CALL
(
foo
,
Call
(
false
,
42
))
.
WillOnce
(
Return
(
1
))
.
WillOnce
(
Return
(
2
));
EXPECT_CALL
(
foo
,
Call
(
true
,
Ge
(
100
)))
.
WillOnce
(
Return
(
3
));
EXPECT_EQ
(
1
,
foo
.
Call
(
false
,
42
));
EXPECT_EQ
(
2
,
foo
.
Call
(
false
,
42
));
EXPECT_EQ
(
3
,
foo
.
Call
(
true
,
120
));
}
TEST
(
MockMethodMockFunctionTest
,
WorksFor10Arguments
)
{
MockFunction
<
int
(
bool
a0
,
char
a1
,
int
a2
,
int
a3
,
int
a4
,
int
a5
,
int
a6
,
char
a7
,
int
a8
,
bool
a9
)
>
foo
;
EXPECT_CALL
(
foo
,
Call
(
_
,
'a'
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
))
.
WillOnce
(
Return
(
1
))
.
WillOnce
(
Return
(
2
));
EXPECT_EQ
(
1
,
foo
.
Call
(
false
,
'a'
,
0
,
0
,
0
,
0
,
0
,
'b'
,
0
,
true
));
EXPECT_EQ
(
2
,
foo
.
Call
(
true
,
'a'
,
0
,
0
,
0
,
0
,
0
,
'b'
,
1
,
false
));
}
TEST
(
MockMethodMockFunctionTest
,
AsStdFunction
)
{
MockFunction
<
int
(
int
)
>
foo
;
auto
call
=
[](
const
std
::
function
<
int
(
int
)
>
&
f
,
int
i
)
{
return
f
(
i
);
};
EXPECT_CALL
(
foo
,
Call
(
1
)).
WillOnce
(
Return
(
-
1
));
EXPECT_CALL
(
foo
,
Call
(
2
)).
WillOnce
(
Return
(
-
2
));
EXPECT_EQ
(
-
1
,
call
(
foo
.
AsStdFunction
(),
1
));
EXPECT_EQ
(
-
2
,
call
(
foo
.
AsStdFunction
(),
2
));
}
TEST
(
MockMethodMockFunctionTest
,
AsStdFunctionReturnsReference
)
{
MockFunction
<
int
&
()
>
foo
;
int
value
=
1
;
EXPECT_CALL
(
foo
,
Call
()).
WillOnce
(
ReturnRef
(
value
));
int
&
ref
=
foo
.
AsStdFunction
()();
EXPECT_EQ
(
1
,
ref
);
value
=
2
;
EXPECT_EQ
(
2
,
ref
);
}
TEST
(
MockMethodMockFunctionTest
,
AsStdFunctionWithReferenceParameter
)
{
MockFunction
<
int
(
int
&
)
>
foo
;
auto
call
=
[](
const
std
::
function
<
int
(
int
&
)
>
&
f
,
int
&
i
)
{
return
f
(
i
);
};
int
i
=
42
;
EXPECT_CALL
(
foo
,
Call
(
i
)).
WillOnce
(
Return
(
-
1
));
EXPECT_EQ
(
-
1
,
call
(
foo
.
AsStdFunction
(),
i
));
}
struct
MockMethodSizes0
{
MOCK_METHOD
(
void
,
func
,
());
};
struct
MockMethodSizes1
{
MOCK_METHOD
(
void
,
func
,
(
int
));
};
struct
MockMethodSizes2
{
MOCK_METHOD
(
void
,
func
,
(
int
,
int
));
};
struct
MockMethodSizes3
{
MOCK_METHOD
(
void
,
func
,
(
int
,
int
,
int
));
};
struct
MockMethodSizes4
{
MOCK_METHOD
(
void
,
func
,
(
int
,
int
,
int
,
int
));
};
TEST
(
MockMethodMockFunctionTest
,
MockMethodSizeOverhead
)
{
EXPECT_EQ
(
sizeof
(
MockMethodSizes0
),
sizeof
(
MockMethodSizes1
));
EXPECT_EQ
(
sizeof
(
MockMethodSizes0
),
sizeof
(
MockMethodSizes2
));
EXPECT_EQ
(
sizeof
(
MockMethodSizes0
),
sizeof
(
MockMethodSizes3
));
EXPECT_EQ
(
sizeof
(
MockMethodSizes0
),
sizeof
(
MockMethodSizes4
));
}
}
// namespace gmock_function_mocker_test
}
// namespace testing
googlemock/test/gmock-generated-actions_test.cc
View file @
25905b9f
...
...
@@ -35,6 +35,7 @@
#include "gmock/gmock-generated-actions.h"
#include <functional>
#include <memory>
#include <sstream>
#include <string>
#include "gmock/gmock.h"
...
...
@@ -45,10 +46,6 @@ namespace gmock_generated_actions_test {
using
::
std
::
plus
;
using
::
std
::
string
;
using
testing
::
get
;
using
testing
::
make_tuple
;
using
testing
::
tuple
;
using
testing
::
tuple_element
;
using
testing
::
_
;
using
testing
::
Action
;
using
testing
::
ActionInterface
;
...
...
@@ -60,7 +57,6 @@ using testing::ReturnNew;
using
testing
::
SetArgPointee
;
using
testing
::
StaticAssertTypeEq
;
using
testing
::
Unused
;
using
testing
::
WithArgs
;
// For suppressing compiler warnings on conversion possibly losing precision.
inline
short
Short
(
short
n
)
{
return
n
;
}
// NOLINT
...
...
@@ -69,43 +65,19 @@ inline char Char(char ch) { return ch; }
// Sample functions and functors for testing various actions.
int
Nullary
()
{
return
1
;
}
class
NullaryFunctor
{
public:
int
operator
()()
{
return
2
;
}
};
bool
g_done
=
false
;
bool
Unary
(
int
x
)
{
return
x
<
0
;
}
const
char
*
Plus1
(
const
char
*
s
)
{
return
s
+
1
;
}
bool
ByConstRef
(
const
std
::
string
&
s
)
{
return
s
==
"Hi"
;
}
const
double
g_double
=
0
;
bool
ReferencesGlobalDouble
(
const
double
&
x
)
{
return
&
x
==
&
g_double
;
}
std
::
string
ByNonConstRef
(
std
::
string
&
s
)
{
return
s
+=
"+"
;
}
// NOLINT
struct
UnaryFunctor
{
int
operator
()(
bool
x
)
{
return
x
?
1
:
-
1
;
}
};
const
char
*
Binary
(
const
char
*
input
,
short
n
)
{
return
input
+
n
;
}
// NOLINT
void
VoidBinary
(
int
,
char
)
{
g_done
=
true
;
}
int
Ternary
(
int
x
,
char
y
,
short
z
)
{
return
x
+
y
+
z
;
}
// NOLINT
void
VoidTernary
(
int
,
char
,
bool
)
{
g_done
=
true
;
}
int
SumOf4
(
int
a
,
int
b
,
int
c
,
int
d
)
{
return
a
+
b
+
c
+
d
;
}
std
::
string
Concat4
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
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
;
}
struct
SumOf5Functor
{
...
...
@@ -168,41 +140,41 @@ inline const char* CharPtr(const char* s) { return s; }
// Tests using InvokeArgument with a nullary function.
TEST
(
InvokeArgumentTest
,
Function0
)
{
Action
<
int
(
int
,
int
(
*
)())
>
a
=
InvokeArgument
<
1
>
();
// NOLINT
EXPECT_EQ
(
1
,
a
.
Perform
(
make_tuple
(
2
,
&
Nullary
)));
EXPECT_EQ
(
1
,
a
.
Perform
(
std
::
make_tuple
(
2
,
&
Nullary
)));
}
// Tests using InvokeArgument with a unary function.
TEST
(
InvokeArgumentTest
,
Functor1
)
{
Action
<
int
(
UnaryFunctor
)
>
a
=
InvokeArgument
<
0
>
(
true
);
// NOLINT
EXPECT_EQ
(
1
,
a
.
Perform
(
make_tuple
(
UnaryFunctor
())));
EXPECT_EQ
(
1
,
a
.
Perform
(
std
::
make_tuple
(
UnaryFunctor
())));
}
// Tests using InvokeArgument with a 5-ary function.
TEST
(
InvokeArgumentTest
,
Function5
)
{
Action
<
int
(
int
(
*
)(
int
,
int
,
int
,
int
,
int
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
10000
,
2000
,
300
,
40
,
5
);
EXPECT_EQ
(
12345
,
a
.
Perform
(
make_tuple
(
&
SumOf5
)));
EXPECT_EQ
(
12345
,
a
.
Perform
(
std
::
make_tuple
(
&
SumOf5
)));
}
// Tests using InvokeArgument with a 5-ary functor.
TEST
(
InvokeArgumentTest
,
Functor5
)
{
Action
<
int
(
SumOf5Functor
)
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
10000
,
2000
,
300
,
40
,
5
);
EXPECT_EQ
(
12345
,
a
.
Perform
(
make_tuple
(
SumOf5Functor
())));
EXPECT_EQ
(
12345
,
a
.
Perform
(
std
::
make_tuple
(
SumOf5Functor
())));
}
// Tests using InvokeArgument with a 6-ary function.
TEST
(
InvokeArgumentTest
,
Function6
)
{
Action
<
int
(
int
(
*
)(
int
,
int
,
int
,
int
,
int
,
int
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
100000
,
20000
,
3000
,
400
,
50
,
6
);
EXPECT_EQ
(
123456
,
a
.
Perform
(
make_tuple
(
&
SumOf6
)));
EXPECT_EQ
(
123456
,
a
.
Perform
(
std
::
make_tuple
(
&
SumOf6
)));
}
// Tests using InvokeArgument with a 6-ary functor.
TEST
(
InvokeArgumentTest
,
Functor6
)
{
Action
<
int
(
SumOf6Functor
)
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
100000
,
20000
,
3000
,
400
,
50
,
6
);
EXPECT_EQ
(
123456
,
a
.
Perform
(
make_tuple
(
SumOf6Functor
())));
EXPECT_EQ
(
123456
,
a
.
Perform
(
std
::
make_tuple
(
SumOf6Functor
())));
}
// Tests using InvokeArgument with a 7-ary function.
...
...
@@ -211,7 +183,7 @@ TEST(InvokeArgumentTest, Function7) {
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
);
EXPECT_EQ
(
"1234567"
,
a
.
Perform
(
make_tuple
(
&
Concat7
)));
EXPECT_EQ
(
"1234567"
,
a
.
Perform
(
std
::
make_tuple
(
&
Concat7
)));
}
// Tests using InvokeArgument with a 8-ary function.
...
...
@@ -220,7 +192,7 @@ TEST(InvokeArgumentTest, Function8) {
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
);
EXPECT_EQ
(
"12345678"
,
a
.
Perform
(
make_tuple
(
&
Concat8
)));
EXPECT_EQ
(
"12345678"
,
a
.
Perform
(
std
::
make_tuple
(
&
Concat8
)));
}
// Tests using InvokeArgument with a 9-ary function.
...
...
@@ -229,7 +201,7 @@ TEST(InvokeArgumentTest, Function9) {
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
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
(
std
::
make_tuple
(
&
Concat9
)));
}
// Tests using InvokeArgument with a 10-ary function.
...
...
@@ -238,14 +210,14 @@ TEST(InvokeArgumentTest, Function10) {
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
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
(
std
::
make_tuple
(
&
Concat10
)));
}
// Tests using InvokeArgument with a function that takes a pointer argument.
TEST
(
InvokeArgumentTest
,
ByPointerFunction
)
{
Action
<
const
char
*
(
const
char
*
(
*
)(
const
char
*
input
,
short
n
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
static_cast
<
const
char
*>
(
"Hi"
),
Short
(
1
));
EXPECT_STREQ
(
"i"
,
a
.
Perform
(
make_tuple
(
&
Binary
)));
EXPECT_STREQ
(
"i"
,
a
.
Perform
(
std
::
make_tuple
(
&
Binary
)));
}
// Tests using InvokeArgument with a function that takes a const char*
...
...
@@ -253,7 +225,7 @@ TEST(InvokeArgumentTest, ByPointerFunction) {
TEST
(
InvokeArgumentTest
,
FunctionWithCStringLiteral
)
{
Action
<
const
char
*
(
const
char
*
(
*
)(
const
char
*
input
,
short
n
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
"Hi"
,
Short
(
1
));
EXPECT_STREQ
(
"i"
,
a
.
Perform
(
make_tuple
(
&
Binary
)));
EXPECT_STREQ
(
"i"
,
a
.
Perform
(
std
::
make_tuple
(
&
Binary
)));
}
// Tests using InvokeArgument with a function that takes a const reference.
...
...
@@ -263,7 +235,7 @@ TEST(InvokeArgumentTest, ByConstReferenceFunction) {
// 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
// temporary object has already died.
EXPECT_TRUE
(
a
.
Perform
(
make_tuple
(
&
ByConstRef
)));
EXPECT_TRUE
(
a
.
Perform
(
std
::
make_tuple
(
&
ByConstRef
)));
}
// Tests using InvokeArgument with ByRef() and a function that takes a
...
...
@@ -272,148 +244,11 @@ TEST(InvokeArgumentTest, ByExplicitConstReferenceFunction) {
Action
<
bool
(
bool
(
*
)(
const
double
&
x
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
ByRef
(
g_double
));
// The above line calls ByRef() on a const value.
EXPECT_TRUE
(
a
.
Perform
(
make_tuple
(
&
ReferencesGlobalDouble
)));
EXPECT_TRUE
(
a
.
Perform
(
std
::
make_tuple
(
&
ReferencesGlobalDouble
)));
double
x
=
0
;
a
=
InvokeArgument
<
0
>
(
ByRef
(
x
));
// This calls ByRef() on a non-const.
EXPECT_FALSE
(
a
.
Perform
(
make_tuple
(
&
ReferencesGlobalDouble
)));
}
// Tests using WithArgs and with an action that takes 1 argument.
TEST
(
WithArgsTest
,
OneArg
)
{
Action
<
bool
(
double
x
,
int
n
)
>
a
=
WithArgs
<
1
>
(
Invoke
(
Unary
));
// NOLINT
EXPECT_TRUE
(
a
.
Perform
(
make_tuple
(
1.5
,
-
1
)));
EXPECT_FALSE
(
a
.
Perform
(
make_tuple
(
1.5
,
1
)));
}
// Tests using WithArgs with an action that takes 2 arguments.
TEST
(
WithArgsTest
,
TwoArgs
)
{
Action
<
const
char
*
(
const
char
*
s
,
double
x
,
short
n
)
>
a
=
WithArgs
<
0
,
2
>
(
Invoke
(
Binary
));
const
char
s
[]
=
"Hello"
;
EXPECT_EQ
(
s
+
2
,
a
.
Perform
(
make_tuple
(
CharPtr
(
s
),
0.5
,
Short
(
2
))));
}
// Tests using WithArgs with an action that takes 3 arguments.
TEST
(
WithArgsTest
,
ThreeArgs
)
{
Action
<
int
(
int
,
double
,
char
,
short
)
>
a
=
// NOLINT
WithArgs
<
0
,
2
,
3
>
(
Invoke
(
Ternary
));
EXPECT_EQ
(
123
,
a
.
Perform
(
make_tuple
(
100
,
6.5
,
Char
(
20
),
Short
(
3
))));
}
// Tests using WithArgs with an action that takes 4 arguments.
TEST
(
WithArgsTest
,
FourArgs
)
{
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
double
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
4
,
3
,
1
,
0
>
(
Invoke
(
Concat4
));
EXPECT_EQ
(
"4310"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
2.5
,
CharPtr
(
"3"
),
CharPtr
(
"4"
))));
}
// Tests using WithArgs with an action that takes 5 arguments.
TEST
(
WithArgsTest
,
FiveArgs
)
{
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
4
,
3
,
2
,
1
,
0
>
(
Invoke
(
Concat5
));
EXPECT_EQ
(
"43210"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
))));
}
// Tests using WithArgs with an action that takes 6 arguments.
TEST
(
WithArgsTest
,
SixArgs
)
{
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
2
,
1
,
0
>
(
Invoke
(
Concat6
));
EXPECT_EQ
(
"012210"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
))));
}
// Tests using WithArgs with an action that takes 7 arguments.
TEST
(
WithArgsTest
,
SevenArgs
)
{
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
2
,
1
,
0
>
(
Invoke
(
Concat7
));
EXPECT_EQ
(
"0123210"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
}
// Tests using WithArgs with an action that takes 8 arguments.
TEST
(
WithArgsTest
,
EightArgs
)
{
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
0
,
1
,
2
,
3
>
(
Invoke
(
Concat8
));
EXPECT_EQ
(
"01230123"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
}
// Tests using WithArgs with an action that takes 9 arguments.
TEST
(
WithArgsTest
,
NineArgs
)
{
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
1
,
2
,
3
,
2
,
3
>
(
Invoke
(
Concat9
));
EXPECT_EQ
(
"012312323"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
}
// Tests using WithArgs with an action that takes 10 arguments.
TEST
(
WithArgsTest
,
TenArgs
)
{
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
));
EXPECT_EQ
(
"0123210123"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
}
// Tests using WithArgs with an action that is not Invoke().
class
SubstractAction
:
public
ActionInterface
<
int
(
int
,
int
)
>
{
// NOLINT
public:
virtual
int
Perform
(
const
tuple
<
int
,
int
>&
args
)
{
return
get
<
0
>
(
args
)
-
get
<
1
>
(
args
);
}
};
TEST
(
WithArgsTest
,
NonInvokeAction
)
{
Action
<
int
(
const
std
::
string
&
,
int
,
int
)
>
a
=
// NOLINT
WithArgs
<
2
,
1
>
(
MakeAction
(
new
SubstractAction
));
tuple
<
std
::
string
,
int
,
int
>
dummy
=
make_tuple
(
std
::
string
(
"hi"
),
2
,
10
);
EXPECT_EQ
(
8
,
a
.
Perform
(
dummy
));
}
// Tests using WithArgs to pass all original arguments in the original order.
TEST
(
WithArgsTest
,
Identity
)
{
Action
<
int
(
int
x
,
char
y
,
short
z
)
>
a
=
// NOLINT
WithArgs
<
0
,
1
,
2
>
(
Invoke
(
Ternary
));
EXPECT_EQ
(
123
,
a
.
Perform
(
make_tuple
(
100
,
Char
(
20
),
Short
(
3
))));
}
// Tests using WithArgs with repeated arguments.
TEST
(
WithArgsTest
,
RepeatedArguments
)
{
Action
<
int
(
bool
,
int
m
,
int
n
)
>
a
=
// NOLINT
WithArgs
<
1
,
1
,
1
,
1
>
(
Invoke
(
SumOf4
));
EXPECT_EQ
(
4
,
a
.
Perform
(
make_tuple
(
false
,
1
,
10
)));
}
// Tests using WithArgs with reversed argument order.
TEST
(
WithArgsTest
,
ReversedArgumentOrder
)
{
Action
<
const
char
*
(
short
n
,
const
char
*
input
)
>
a
=
// NOLINT
WithArgs
<
1
,
0
>
(
Invoke
(
Binary
));
const
char
s
[]
=
"Hello"
;
EXPECT_EQ
(
s
+
2
,
a
.
Perform
(
make_tuple
(
Short
(
2
),
CharPtr
(
s
))));
}
// Tests using WithArgs with compatible, but not identical, argument types.
TEST
(
WithArgsTest
,
ArgsOfCompatibleTypes
)
{
Action
<
long
(
short
x
,
char
y
,
double
z
,
char
c
)
>
a
=
// NOLINT
WithArgs
<
0
,
1
,
3
>
(
Invoke
(
Ternary
));
EXPECT_EQ
(
123
,
a
.
Perform
(
make_tuple
(
Short
(
100
),
Char
(
20
),
5.6
,
Char
(
3
))));
}
// Tests using WithArgs with an action that returns void.
TEST
(
WithArgsTest
,
VoidAction
)
{
Action
<
void
(
double
x
,
char
c
,
int
n
)
>
a
=
WithArgs
<
2
,
1
>
(
Invoke
(
VoidBinary
));
g_done
=
false
;
a
.
Perform
(
make_tuple
(
1.5
,
'a'
,
3
));
EXPECT_TRUE
(
g_done
);
EXPECT_FALSE
(
a
.
Perform
(
std
::
make_tuple
(
&
ReferencesGlobalDouble
)));
}
// Tests DoAll(a1, a2).
...
...
@@ -421,7 +256,7 @@ TEST(DoAllTest, TwoActions) {
int
n
=
0
;
Action
<
int
(
int
*
)
>
a
=
DoAll
(
SetArgPointee
<
0
>
(
1
),
// NOLINT
Return
(
2
));
EXPECT_EQ
(
2
,
a
.
Perform
(
make_tuple
(
&
n
)));
EXPECT_EQ
(
2
,
a
.
Perform
(
std
::
make_tuple
(
&
n
)));
EXPECT_EQ
(
1
,
n
);
}
...
...
@@ -431,7 +266,7 @@ TEST(DoAllTest, ThreeActions) {
Action
<
int
(
int
*
,
int
*
)
>
a
=
DoAll
(
SetArgPointee
<
0
>
(
1
),
// NOLINT
SetArgPointee
<
1
>
(
2
),
Return
(
3
));
EXPECT_EQ
(
3
,
a
.
Perform
(
make_tuple
(
&
m
,
&
n
)));
EXPECT_EQ
(
3
,
a
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
}
...
...
@@ -445,7 +280,7 @@ TEST(DoAllTest, FourActions) {
SetArgPointee
<
1
>
(
2
),
SetArgPointee
<
2
>
(
'a'
),
Return
(
3
));
EXPECT_EQ
(
3
,
a
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
ch
)));
EXPECT_EQ
(
3
,
a
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
ch
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
ch
);
...
...
@@ -461,7 +296,7 @@ TEST(DoAllTest, FiveActions) {
SetArgPointee
<
2
>
(
'a'
),
SetArgPointee
<
3
>
(
'b'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -479,7 +314,7 @@ TEST(DoAllTest, SixActions) {
SetArgPointee
<
3
>
(
'b'
),
SetArgPointee
<
4
>
(
'c'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -499,7 +334,7 @@ TEST(DoAllTest, SevenActions) {
SetArgPointee
<
4
>
(
'c'
),
SetArgPointee
<
5
>
(
'd'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -522,7 +357,7 @@ TEST(DoAllTest, EightActions) {
SetArgPointee
<
5
>
(
'd'
),
SetArgPointee
<
6
>
(
'e'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -547,7 +382,7 @@ TEST(DoAllTest, NineActions) {
SetArgPointee
<
6
>
(
'e'
),
SetArgPointee
<
7
>
(
'f'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
,
&
f
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
,
&
f
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -575,7 +410,8 @@ TEST(DoAllTest, TenActions) {
SetArgPointee
<
7
>
(
'f'
),
SetArgPointee
<
8
>
(
'g'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
,
&
f
,
&
g
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
,
&
f
,
&
g
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -592,11 +428,12 @@ TEST(DoAllTest, TenActions) {
// the macro definition, as the warnings are generated when the macro
// is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here.
// Also suppress C4503 decorated name length exceeded, name was truncated
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable:4100)
# pragma warning(disable:4503)
#endif
// Tests the ACTION*() macro family.
// Tests that ACTION() can define an action that doesn't reference the
...
...
@@ -605,10 +442,10 @@ ACTION(Return5) { return 5; }
TEST
(
ActionMacroTest
,
WorksWhenNotReferencingArguments
)
{
Action
<
double
()
>
a1
=
Return5
();
EXPECT_DOUBLE_EQ
(
5
,
a1
.
Perform
(
make_tuple
()));
EXPECT_DOUBLE_EQ
(
5
,
a1
.
Perform
(
std
::
make_tuple
()));
Action
<
int
(
double
,
bool
)
>
a2
=
Return5
();
EXPECT_EQ
(
5
,
a2
.
Perform
(
make_tuple
(
1
,
true
)));
EXPECT_EQ
(
5
,
a2
.
Perform
(
std
::
make_tuple
(
1
,
true
)));
}
// Tests that ACTION() can define an action that returns void.
...
...
@@ -617,7 +454,7 @@ ACTION(IncrementArg1) { (*arg1)++; }
TEST
(
ActionMacroTest
,
WorksWhenReturningVoid
)
{
Action
<
void
(
int
,
int
*
)
>
a1
=
IncrementArg1
();
int
n
=
0
;
a1
.
Perform
(
make_tuple
(
5
,
&
n
));
a1
.
Perform
(
std
::
make_tuple
(
5
,
&
n
));
EXPECT_EQ
(
1
,
n
);
}
...
...
@@ -632,22 +469,22 @@ ACTION(IncrementArg2) {
TEST
(
ActionMacroTest
,
CanReferenceArgumentType
)
{
Action
<
void
(
int
,
bool
,
int
*
)
>
a1
=
IncrementArg2
();
int
n
=
0
;
a1
.
Perform
(
make_tuple
(
5
,
false
,
&
n
));
a1
.
Perform
(
std
::
make_tuple
(
5
,
false
,
&
n
));
EXPECT_EQ
(
1
,
n
);
}
// Tests that the body of ACTION() can reference the argument tuple
// via args_type and args.
ACTION
(
Sum2
)
{
StaticAssertTypeEq
<
tuple
<
int
,
char
,
int
*>
,
args_type
>
();
StaticAssertTypeEq
<
std
::
tuple
<
int
,
char
,
int
*>
,
args_type
>
();
args_type
args_copy
=
args
;
return
get
<
0
>
(
args_copy
)
+
get
<
1
>
(
args_copy
);
return
std
::
get
<
0
>
(
args_copy
)
+
std
::
get
<
1
>
(
args_copy
);
}
TEST
(
ActionMacroTest
,
CanReferenceArgumentTuple
)
{
Action
<
int
(
int
,
char
,
int
*
)
>
a1
=
Sum2
();
int
dummy
=
0
;
EXPECT_EQ
(
11
,
a1
.
Perform
(
make_tuple
(
5
,
Char
(
6
),
&
dummy
)));
EXPECT_EQ
(
11
,
a1
.
Perform
(
std
::
make_tuple
(
5
,
Char
(
6
),
&
dummy
)));
}
// Tests that the body of ACTION() can reference the mock function
...
...
@@ -662,8 +499,8 @@ ACTION(InvokeDummy) {
TEST
(
ActionMacroTest
,
CanReferenceMockFunctionType
)
{
Action
<
int
(
bool
)
>
a1
=
InvokeDummy
();
EXPECT_EQ
(
1
,
a1
.
Perform
(
make_tuple
(
true
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
make_tuple
(
false
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
(
true
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
(
false
)));
}
// Tests that the body of ACTION() can reference the mock function's
...
...
@@ -676,8 +513,8 @@ ACTION(InvokeDummy2) {
TEST
(
ActionMacroTest
,
CanReferenceMockFunctionReturnType
)
{
Action
<
int
(
bool
)
>
a1
=
InvokeDummy2
();
EXPECT_EQ
(
1
,
a1
.
Perform
(
make_tuple
(
true
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
make_tuple
(
false
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
(
true
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
(
false
)));
}
// Tests that ACTION() works for arguments passed by const reference.
...
...
@@ -689,7 +526,7 @@ ACTION(ReturnAddrOfConstBoolReferenceArg) {
TEST
(
ActionMacroTest
,
WorksForConstReferenceArg
)
{
Action
<
const
bool
*
(
int
,
const
bool
&
)
>
a
=
ReturnAddrOfConstBoolReferenceArg
();
const
bool
b
=
false
;
EXPECT_EQ
(
&
b
,
a
.
Perform
(
tuple
<
int
,
const
bool
&>
(
0
,
b
)));
EXPECT_EQ
(
&
b
,
a
.
Perform
(
std
::
tuple
<
int
,
const
bool
&>
(
0
,
b
)));
}
// Tests that ACTION() works for arguments passed by non-const reference.
...
...
@@ -701,7 +538,7 @@ ACTION(ReturnAddrOfIntReferenceArg) {
TEST
(
ActionMacroTest
,
WorksForNonConstReferenceArg
)
{
Action
<
int
*
(
int
&
,
bool
,
int
)
>
a
=
ReturnAddrOfIntReferenceArg
();
int
n
=
0
;
EXPECT_EQ
(
&
n
,
a
.
Perform
(
tuple
<
int
&
,
bool
,
int
>
(
n
,
true
,
1
)));
EXPECT_EQ
(
&
n
,
a
.
Perform
(
std
::
tuple
<
int
&
,
bool
,
int
>
(
n
,
true
,
1
)));
}
// Tests that ACTION() can be used in a namespace.
...
...
@@ -711,7 +548,7 @@ ACTION(Sum) { return arg0 + arg1; }
TEST
(
ActionMacroTest
,
WorksInNamespace
)
{
Action
<
int
(
int
,
int
)
>
a1
=
action_test
::
Sum
();
EXPECT_EQ
(
3
,
a1
.
Perform
(
make_tuple
(
1
,
2
)));
EXPECT_EQ
(
3
,
a1
.
Perform
(
std
::
make_tuple
(
1
,
2
)));
}
// Tests that the same ACTION definition works for mock functions with
...
...
@@ -720,11 +557,11 @@ ACTION(PlusTwo) { return arg0 + 2; }
TEST
(
ActionMacroTest
,
WorksForDifferentArgumentNumbers
)
{
Action
<
int
(
int
)
>
a1
=
PlusTwo
();
EXPECT_EQ
(
4
,
a1
.
Perform
(
make_tuple
(
2
)));
EXPECT_EQ
(
4
,
a1
.
Perform
(
std
::
make_tuple
(
2
)));
Action
<
double
(
float
,
void
*
)
>
a2
=
PlusTwo
();
int
dummy
;
EXPECT_DOUBLE_EQ
(
6
,
a2
.
Perform
(
make_tuple
(
4.0
f
,
&
dummy
)));
EXPECT_DOUBLE_EQ
(
6
,
a2
.
Perform
(
std
::
make_tuple
(
4.0
f
,
&
dummy
)));
}
// Tests that ACTION_P can define a parameterized action.
...
...
@@ -732,7 +569,7 @@ ACTION_P(Plus, n) { return arg0 + n; }
TEST
(
ActionPMacroTest
,
DefinesParameterizedAction
)
{
Action
<
int
(
int
m
,
bool
t
)
>
a1
=
Plus
(
9
);
EXPECT_EQ
(
10
,
a1
.
Perform
(
make_tuple
(
1
,
true
)));
EXPECT_EQ
(
10
,
a1
.
Perform
(
std
::
make_tuple
(
1
,
true
)));
}
// Tests that the body of ACTION_P can reference the argument types
...
...
@@ -745,7 +582,7 @@ ACTION_P(TypedPlus, n) {
TEST
(
ActionPMacroTest
,
CanReferenceArgumentAndParameterTypes
)
{
Action
<
int
(
char
m
,
bool
t
)
>
a1
=
TypedPlus
(
9
);
EXPECT_EQ
(
10
,
a1
.
Perform
(
make_tuple
(
Char
(
1
),
true
)));
EXPECT_EQ
(
10
,
a1
.
Perform
(
std
::
make_tuple
(
Char
(
1
),
true
)));
}
// Tests that a parameterized action can be used in any mock function
...
...
@@ -753,7 +590,7 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) {
TEST
(
ActionPMacroTest
,
WorksInCompatibleMockFunction
)
{
Action
<
std
::
string
(
const
std
::
string
&
s
)
>
a1
=
Plus
(
"tail"
);
const
std
::
string
re
=
"re"
;
tuple
<
const
std
::
string
>
dummy
=
make_tuple
(
re
);
std
::
tuple
<
const
std
::
string
>
dummy
=
std
::
make_tuple
(
re
);
EXPECT_EQ
(
"retail"
,
a1
.
Perform
(
dummy
));
}
...
...
@@ -774,16 +611,16 @@ TEST(ActionMacroTest, CanDefineOverloadedActions) {
typedef
Action
<
const
char
*
(
bool
,
const
char
*
)
>
MyAction
;
const
MyAction
a1
=
OverloadedAction
();
EXPECT_STREQ
(
"hello"
,
a1
.
Perform
(
make_tuple
(
false
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"world"
,
a1
.
Perform
(
make_tuple
(
true
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"hello"
,
a1
.
Perform
(
std
::
make_tuple
(
false
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"world"
,
a1
.
Perform
(
std
::
make_tuple
(
true
,
CharPtr
(
"world"
))));
const
MyAction
a2
=
OverloadedAction
(
"hi"
);
EXPECT_STREQ
(
"hi"
,
a2
.
Perform
(
make_tuple
(
false
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"world"
,
a2
.
Perform
(
make_tuple
(
true
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"hi"
,
a2
.
Perform
(
std
::
make_tuple
(
false
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"world"
,
a2
.
Perform
(
std
::
make_tuple
(
true
,
CharPtr
(
"world"
))));
const
MyAction
a3
=
OverloadedAction
(
"hi"
,
"you"
);
EXPECT_STREQ
(
"hi"
,
a3
.
Perform
(
make_tuple
(
true
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"you"
,
a3
.
Perform
(
make_tuple
(
false
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"hi"
,
a3
.
Perform
(
std
::
make_tuple
(
true
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"you"
,
a3
.
Perform
(
std
::
make_tuple
(
false
,
CharPtr
(
"world"
))));
}
// Tests ACTION_Pn where n >= 3.
...
...
@@ -792,11 +629,11 @@ ACTION_P3(Plus, m, n, k) { return arg0 + m + n + k; }
TEST
(
ActionPnMacroTest
,
WorksFor3Parameters
)
{
Action
<
double
(
int
m
,
bool
t
)
>
a1
=
Plus
(
100
,
20
,
3.4
);
EXPECT_DOUBLE_EQ
(
3123.4
,
a1
.
Perform
(
make_tuple
(
3000
,
true
)));
EXPECT_DOUBLE_EQ
(
3123.4
,
a1
.
Perform
(
std
::
make_tuple
(
3000
,
true
)));
Action
<
std
::
string
(
const
std
::
string
&
s
)
>
a2
=
Plus
(
"tail"
,
"-"
,
">"
);
const
std
::
string
re
=
"re"
;
tuple
<
const
std
::
string
>
dummy
=
make_tuple
(
re
);
std
::
tuple
<
const
std
::
string
>
dummy
=
std
::
make_tuple
(
re
);
EXPECT_EQ
(
"retail->"
,
a2
.
Perform
(
dummy
));
}
...
...
@@ -804,14 +641,14 @@ ACTION_P4(Plus, p0, p1, p2, p3) { return arg0 + p0 + p1 + p2 + p3; }
TEST
(
ActionPnMacroTest
,
WorksFor4Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P5
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
)
{
return
arg0
+
p0
+
p1
+
p2
+
p3
+
p4
;
}
TEST
(
ActionPnMacroTest
,
WorksFor5Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P6
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
,
p5
)
{
...
...
@@ -820,7 +657,7 @@ ACTION_P6(Plus, p0, p1, p2, p3, p4, p5) {
TEST
(
ActionPnMacroTest
,
WorksFor6Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
,
6
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P7
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
)
{
...
...
@@ -829,7 +666,7 @@ ACTION_P7(Plus, p0, p1, p2, p3, p4, p5, p6) {
TEST
(
ActionPnMacroTest
,
WorksFor7Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
,
6
,
7
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P8
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
)
{
...
...
@@ -838,7 +675,8 @@ ACTION_P8(Plus, p0, p1, p2, p3, p4, p5, p6, p7) {
TEST
(
ActionPnMacroTest
,
WorksFor8Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P9
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
)
{
...
...
@@ -847,7 +685,8 @@ ACTION_P9(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8) {
TEST
(
ActionPnMacroTest
,
WorksFor9Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P10
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
,
last_param
)
{
...
...
@@ -859,7 +698,7 @@ ACTION_P10(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8, last_param) {
TEST
(
ActionPnMacroTest
,
WorksFor10Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
,
a1
.
Perform
(
make_tuple
(
10
)));
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
// Tests that the action body can promote the parameter types.
...
...
@@ -876,8 +715,8 @@ TEST(ActionPnMacroTest, SimpleTypePromotion) {
PadArgument
(
std
::
string
(
"foo"
),
'r'
);
Action
<
std
::
string
(
const
char
*
)
>
promo
=
PadArgument
(
"foo"
,
static_cast
<
int
>
(
'r'
));
EXPECT_EQ
(
"foobar"
,
no_promo
.
Perform
(
make_tuple
(
CharPtr
(
"ba"
))));
EXPECT_EQ
(
"foobar"
,
promo
.
Perform
(
make_tuple
(
CharPtr
(
"ba"
))));
EXPECT_EQ
(
"foobar"
,
no_promo
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"ba"
))));
EXPECT_EQ
(
"foobar"
,
promo
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"ba"
))));
}
// Tests that we can partially restrict parameter types using a
...
...
@@ -926,10 +765,10 @@ Concat(T1 a, int b, T2 c) {
TEST
(
ActionPnMacroTest
,
CanPartiallyRestrictParameterTypes
)
{
Action
<
const
std
::
string
()
>
a1
=
Concat
(
"Hello"
,
"1"
,
2
);
EXPECT_EQ
(
"Hello12"
,
a1
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
"Hello12"
,
a1
.
Perform
(
std
::
make_tuple
()));
a1
=
Concat
(
1
,
2
,
3
);
EXPECT_EQ
(
"123"
,
a1
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
"123"
,
a1
.
Perform
(
std
::
make_tuple
()));
}
// Verifies the type of an ACTION*.
...
...
@@ -987,7 +826,7 @@ ACTION_P10(Plus10, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
TEST
(
ActionPnMacroTest
,
CanExplicitlyInstantiateWithReferenceTypes
)
{
int
x
=
1
,
y
=
2
,
z
=
3
;
const
tuple
<>
empty
=
make_tuple
();
const
std
::
tuple
<>
empty
=
std
::
make_tuple
();
Action
<
int
()
>
a
=
Plus1
<
int
&>
(
x
);
EXPECT_EQ
(
1
,
a
.
Perform
(
empty
));
...
...
@@ -1014,7 +853,7 @@ class NullaryConstructorClass {
// Tests using ReturnNew() with a nullary constructor.
TEST
(
ReturnNewTest
,
NoArgs
)
{
Action
<
NullaryConstructorClass
*
()
>
a
=
ReturnNew
<
NullaryConstructorClass
>
();
NullaryConstructorClass
*
c
=
a
.
Perform
(
make_tuple
());
NullaryConstructorClass
*
c
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
123
,
c
->
value_
);
delete
c
;
}
...
...
@@ -1028,7 +867,7 @@ class UnaryConstructorClass {
// Tests using ReturnNew() with a unary constructor.
TEST
(
ReturnNewTest
,
Unary
)
{
Action
<
UnaryConstructorClass
*
()
>
a
=
ReturnNew
<
UnaryConstructorClass
>
(
4000
);
UnaryConstructorClass
*
c
=
a
.
Perform
(
make_tuple
());
UnaryConstructorClass
*
c
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
4000
,
c
->
value_
);
delete
c
;
}
...
...
@@ -1036,7 +875,7 @@ TEST(ReturnNewTest, Unary) {
TEST
(
ReturnNewTest
,
UnaryWorksWhenMockMethodHasArgs
)
{
Action
<
UnaryConstructorClass
*
(
bool
,
int
)
>
a
=
ReturnNew
<
UnaryConstructorClass
>
(
4000
);
UnaryConstructorClass
*
c
=
a
.
Perform
(
make_tuple
(
false
,
5
));
UnaryConstructorClass
*
c
=
a
.
Perform
(
std
::
make_tuple
(
false
,
5
));
EXPECT_EQ
(
4000
,
c
->
value_
);
delete
c
;
}
...
...
@@ -1044,7 +883,7 @@ TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) {
TEST
(
ReturnNewTest
,
UnaryWorksWhenMockMethodReturnsPointerToConst
)
{
Action
<
const
UnaryConstructorClass
*
()
>
a
=
ReturnNew
<
UnaryConstructorClass
>
(
4000
);
const
UnaryConstructorClass
*
c
=
a
.
Perform
(
make_tuple
());
const
UnaryConstructorClass
*
c
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
4000
,
c
->
value_
);
delete
c
;
}
...
...
@@ -1064,7 +903,7 @@ TEST(ReturnNewTest, ConstructorThatTakes10Arguments) {
ReturnNew
<
TenArgConstructorClass
>
(
1000000000
,
200000000
,
30000000
,
4000000
,
500000
,
60000
,
7000
,
800
,
90
,
0
);
TenArgConstructorClass
*
c
=
a
.
Perform
(
make_tuple
());
TenArgConstructorClass
*
c
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
1234567890
,
c
->
value_
);
delete
c
;
}
...
...
@@ -1078,7 +917,7 @@ ACTION_TEMPLATE(CreateNew,
TEST
(
ActionTemplateTest
,
WorksWithoutValueParam
)
{
const
Action
<
int
*
()
>
a
=
CreateNew
<
int
>
();
int
*
p
=
a
.
Perform
(
make_tuple
());
int
*
p
=
a
.
Perform
(
std
::
make_tuple
());
delete
p
;
}
...
...
@@ -1091,7 +930,7 @@ ACTION_TEMPLATE(CreateNew,
TEST
(
ActionTemplateTest
,
WorksWithValueParams
)
{
const
Action
<
int
*
()
>
a
=
CreateNew
<
int
>
(
42
);
int
*
p
=
a
.
Perform
(
make_tuple
());
int
*
p
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
42
,
*
p
);
delete
p
;
}
...
...
@@ -1100,7 +939,7 @@ TEST(ActionTemplateTest, WorksWithValueParams) {
ACTION_TEMPLATE
(
MyDeleteArg
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_0_VALUE_PARAMS
())
{
delete
get
<
k
>
(
args
);
delete
std
::
get
<
k
>
(
args
);
}
// Resets a bool variable in the destructor.
...
...
@@ -1117,7 +956,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) {
int
n
=
0
;
bool
b
=
true
;
BoolResetter
*
resetter
=
new
BoolResetter
(
&
b
);
a
.
Perform
(
make_tuple
(
&
n
,
resetter
));
a
.
Perform
(
std
::
make_tuple
(
&
n
,
resetter
));
EXPECT_FALSE
(
b
);
// Verifies that resetter is deleted.
}
...
...
@@ -1130,9 +969,9 @@ ACTION_TEMPLATE(ReturnSmartPointer,
}
TEST
(
ActionTemplateTest
,
WorksForTemplateTemplateParameters
)
{
using
::
testing
::
internal
::
linked_ptr
;
const
Action
<
linked_ptr
<
int
>
()
>
a
=
ReturnSmartPointer
<
link
ed_ptr
>
(
42
);
link
ed_ptr
<
int
>
p
=
a
.
Perform
(
make_tuple
());
const
Action
<
std
::
shared_ptr
<
int
>
()
>
a
=
ReturnSmartPointer
<
std
::
shar
ed_ptr
>
(
42
);
std
::
shar
ed_ptr
<
int
>
p
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
42
,
*
p
);
}
...
...
@@ -1162,12 +1001,11 @@ ACTION_TEMPLATE(ReturnGiant,
}
TEST
(
ActionTemplateTest
,
WorksFor10TemplateParameters
)
{
using
::
testing
::
internal
::
linked_ptr
;
typedef
GiantTemplate
<
linked_ptr
<
int
>
,
bool
,
double
,
5
,
true
,
6
,
char
,
unsigned
,
int
>
Giant
;
const
Action
<
Giant
()
>
a
=
ReturnGiant
<
int
,
bool
,
double
,
5
,
true
,
6
,
char
,
unsigned
,
int
,
linked_ptr
>
(
42
);
Giant
giant
=
a
.
Perform
(
make_tuple
());
using
Giant
=
GiantTemplate
<
std
::
shared_ptr
<
int
>
,
bool
,
double
,
5
,
true
,
6
,
char
,
unsigned
,
int
>
;
const
Action
<
Giant
()
>
a
=
ReturnGiant
<
int
,
bool
,
double
,
5
,
true
,
6
,
char
,
unsigned
,
int
,
std
::
shared_ptr
>
(
42
);
Giant
giant
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
42
,
giant
.
value
);
}
...
...
@@ -1180,7 +1018,7 @@ ACTION_TEMPLATE(ReturnSum,
TEST
(
ActionTemplateTest
,
WorksFor10ValueParameters
)
{
const
Action
<
int
()
>
a
=
ReturnSum
<
int
>
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
);
EXPECT_EQ
(
55
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
55
,
a
.
Perform
(
std
::
make_tuple
()));
}
// Tests that ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded
...
...
@@ -1214,16 +1052,13 @@ TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) {
const
Action
<
int
()
>
a2
=
ReturnSum
<
int
>
(
1
,
2
);
const
Action
<
int
()
>
a3
=
ReturnSum
<
int
>
(
1
,
2
,
3
);
const
Action
<
int
()
>
a4
=
ReturnSum
<
int
,
10000
>
(
2000
,
300
,
40
,
5
);
EXPECT_EQ
(
0
,
a0
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
1
,
a1
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
3
,
a2
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
6
,
a3
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
12345
,
a4
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
0
,
a0
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
3
,
a2
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
6
,
a3
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
12345
,
a4
.
Perform
(
std
::
make_tuple
()));
}
#ifdef _MSC_VER
# pragma warning(pop)
#endif
}
// namespace gmock_generated_actions_test
}
// namespace testing
googlemock/test/gmock-generated-function-mockers_test.cc
View file @
25905b9f
...
...
@@ -46,13 +46,6 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
// There is a bug in MSVC (fixed in VS 2008) that prevents creating a
// mock for a function with const arguments, so we don't test such
// cases for MSVC versions older than 2008.
#if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
# define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
#endif // !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
namespace
testing
{
namespace
gmock_generated_function_mockers_test
{
...
...
@@ -85,9 +78,7 @@ class FooInterface {
virtual
bool
TakesNonConstReference
(
int
&
n
)
=
0
;
// NOLINT
virtual
std
::
string
TakesConstReference
(
const
int
&
n
)
=
0
;
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
virtual
bool
TakesConst
(
const
int
x
)
=
0
;
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
virtual
int
OverloadedOnArgumentNumber
()
=
0
;
virtual
int
OverloadedOnArgumentNumber
(
int
n
)
=
0
;
...
...
@@ -136,10 +127,7 @@ class MockFoo : public FooInterface {
MOCK_METHOD1
(
TakesNonConstReference
,
bool
(
int
&
));
// NOLINT
MOCK_METHOD1
(
TakesConstReference
,
std
::
string
(
const
int
&
));
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
MOCK_METHOD1
(
TakesConst
,
bool
(
const
int
));
// NOLINT
#endif
// Tests that the function return type can contain unprotected comma.
MOCK_METHOD0
(
ReturnTypeWithComma
,
std
::
map
<
int
,
std
::
string
>
());
...
...
@@ -224,8 +212,8 @@ TEST_F(FunctionMockerTest, MocksBinaryFunction) {
// Tests mocking a decimal function.
TEST_F
(
FunctionMockerTest
,
MocksDecimalFunction
)
{
EXPECT_CALL
(
mock_foo_
,
Decimal
(
true
,
'a'
,
0
,
0
,
1L
,
A
<
float
>
(),
Lt
(
100
),
5U
,
NULL
,
"hi"
))
EXPECT_CALL
(
mock_foo_
,
Decimal
(
true
,
'a'
,
0
,
0
,
1L
,
A
<
float
>
(),
Lt
(
100
),
5U
,
nullptr
,
"hi"
))
.
WillOnce
(
Return
(
5
));
EXPECT_EQ
(
5
,
foo_
->
Decimal
(
true
,
'a'
,
0
,
0
,
1
,
0
,
0
,
5
,
nullptr
,
"hi"
));
...
...
@@ -249,7 +237,6 @@ TEST_F(FunctionMockerTest, MocksFunctionWithConstReferenceArgument) {
EXPECT_EQ
(
"Hello"
,
foo_
->
TakesConstReference
(
a
));
}
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
// Tests mocking a function that takes a const variable.
TEST_F
(
FunctionMockerTest
,
MocksFunctionWithConstArgument
)
{
EXPECT_CALL
(
mock_foo_
,
TakesConst
(
Lt
(
10
)))
...
...
@@ -257,7 +244,6 @@ TEST_F(FunctionMockerTest, MocksFunctionWithConstArgument) {
EXPECT_FALSE
(
foo_
->
TakesConst
(
5
));
}
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
// Tests mocking functions overloaded on the number of arguments.
TEST_F
(
FunctionMockerTest
,
MocksFunctionsOverloadedOnArgumentNumber
)
{
...
...
@@ -326,11 +312,11 @@ TEST_F(FunctionMockerTest, MocksUnaryFunctionWithCallType) {
// Tests mocking a decimal function with calltype.
TEST_F
(
FunctionMockerTest
,
MocksDecimalFunctionWithCallType
)
{
EXPECT_CALL
(
mock_foo_
,
CTDecimal
(
true
,
'a'
,
0
,
0
,
1L
,
A
<
float
>
(),
Lt
(
100
),
5U
,
NULL
,
"hi"
))
EXPECT_CALL
(
mock_foo_
,
CTDecimal
(
true
,
'a'
,
0
,
0
,
1L
,
A
<
float
>
(),
Lt
(
100
),
5U
,
nullptr
,
"hi"
))
.
WillOnce
(
Return
(
10
));
EXPECT_EQ
(
10
,
foo_
->
CTDecimal
(
true
,
'a'
,
0
,
0
,
1
,
0
,
0
,
5
,
NULL
,
"hi"
));
EXPECT_EQ
(
10
,
foo_
->
CTDecimal
(
true
,
'a'
,
0
,
0
,
1
,
0
,
0
,
5
,
nullptr
,
"hi"
));
}
// Tests mocking functions overloaded on the const-ness of this object.
...
...
@@ -596,7 +582,6 @@ TEST(MockFunctionTest, WorksFor10Arguments) {
EXPECT_EQ
(
2
,
foo
.
Call
(
true
,
'a'
,
0
,
0
,
0
,
0
,
0
,
'b'
,
1
,
false
));
}
#if GTEST_HAS_STD_FUNCTION_
TEST
(
MockFunctionTest
,
AsStdFunction
)
{
MockFunction
<
int
(
int
)
>
foo
;
auto
call
=
[](
const
std
::
function
<
int
(
int
)
>
&
f
,
int
i
)
{
...
...
@@ -628,7 +613,6 @@ TEST(MockFunctionTest, AsStdFunctionWithReferenceParameter) {
EXPECT_EQ
(
-
1
,
call
(
foo
.
AsStdFunction
(),
i
));
}
#endif // GTEST_HAS_STD_FUNCTION_
struct
MockMethodSizes0
{
MOCK_METHOD0
(
func
,
void
());
...
...
googlemock/test/gmock-generated-internal-utils_test.cc
View file @
25905b9f
...
...
@@ -38,7 +38,6 @@
namespace
{
using
::
testing
::
tuple
;
using
::
testing
::
Matcher
;
using
::
testing
::
internal
::
CompileAssertTypesEqual
;
using
::
testing
::
internal
::
MatcherTuple
;
...
...
@@ -48,24 +47,24 @@ using ::testing::internal::IgnoredValue;
// Tests the MatcherTuple template struct.
TEST
(
MatcherTupleTest
,
ForSize0
)
{
CompileAssertTypesEqual
<
tuple
<>
,
MatcherTuple
<
tuple
<>
>::
type
>
();
CompileAssertTypesEqual
<
std
::
tuple
<>
,
MatcherTuple
<
std
::
tuple
<>
>::
type
>
();
}
TEST
(
MatcherTupleTest
,
ForSize1
)
{
CompileAssertTypesEqual
<
tuple
<
Matcher
<
int
>
>
,
MatcherTuple
<
tuple
<
int
>
>::
type
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
int
>
>
,
MatcherTuple
<
std
::
tuple
<
int
>
>::
type
>
();
}
TEST
(
MatcherTupleTest
,
ForSize2
)
{
CompileAssertTypesEqual
<
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
>
,
MatcherTuple
<
tuple
<
int
,
char
>
>::
type
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
>
,
MatcherTuple
<
std
::
tuple
<
int
,
char
>
>::
type
>
();
}
TEST
(
MatcherTupleTest
,
ForSize5
)
{
CompileAssertTypesEqual
<
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
double
>
,
std
::
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
double
>
,
Matcher
<
char
*>
>
,
MatcherTuple
<
tuple
<
int
,
char
,
bool
,
double
,
char
*>
>::
type
>
();
MatcherTuple
<
std
::
tuple
<
int
,
char
,
bool
,
double
,
char
*>
>::
type
>
();
}
// Tests the Function template struct.
...
...
@@ -73,8 +72,8 @@ TEST(MatcherTupleTest, ForSize5) {
TEST
(
FunctionTest
,
Nullary
)
{
typedef
Function
<
int
()
>
F
;
// NOLINT
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
tuple
<>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
tuple
<>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(),
F
::
MakeResultVoid
>
();
CompileAssertTypesEqual
<
IgnoredValue
(),
F
::
MakeResultIgnoredValue
>
();
}
...
...
@@ -83,8 +82,9 @@ TEST(FunctionTest, Unary) {
typedef
Function
<
int
(
bool
)
>
F
;
// NOLINT
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
bool
,
F
::
Argument1
>
();
CompileAssertTypesEqual
<
tuple
<
bool
>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
tuple
<
Matcher
<
bool
>
>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
bool
>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
bool
>
>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
),
F
::
MakeResultVoid
>
();
// NOLINT
CompileAssertTypesEqual
<
IgnoredValue
(
bool
),
// NOLINT
F
::
MakeResultIgnoredValue
>
();
...
...
@@ -95,9 +95,10 @@ TEST(FunctionTest, Binary) {
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
bool
,
F
::
Argument1
>
();
CompileAssertTypesEqual
<
const
long
&
,
F
::
Argument2
>
();
// NOLINT
CompileAssertTypesEqual
<
tuple
<
bool
,
const
long
&>
,
F
::
ArgumentTuple
>
();
// NOLINT
CompileAssertTypesEqual
<
std
::
tuple
<
bool
,
const
long
&>
,
// NOLINT
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
tuple
<
Matcher
<
bool
>
,
Matcher
<
const
long
&>
>
,
// NOLINT
std
::
tuple
<
Matcher
<
bool
>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
,
const
long
&
),
F
::
MakeResultVoid
>
();
// NOLINT
CompileAssertTypesEqual
<
IgnoredValue
(
bool
,
const
long
&
),
// NOLINT
...
...
@@ -112,10 +113,11 @@ TEST(FunctionTest, LongArgumentList) {
CompileAssertTypesEqual
<
char
*
,
F
::
Argument3
>
();
CompileAssertTypesEqual
<
int
&
,
F
::
Argument4
>
();
CompileAssertTypesEqual
<
const
long
&
,
F
::
Argument5
>
();
// NOLINT
CompileAssertTypesEqual
<
tuple
<
bool
,
int
,
char
*
,
int
&
,
const
long
&>
,
// NOLINT
CompileAssertTypesEqual
<
std
::
tuple
<
bool
,
int
,
char
*
,
int
&
,
const
long
&>
,
// NOLINT
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
tuple
<
Matcher
<
bool
>
,
Matcher
<
int
>
,
Matcher
<
char
*>
,
Matcher
<
int
&>
,
std
::
tuple
<
Matcher
<
bool
>
,
Matcher
<
int
>
,
Matcher
<
char
*>
,
Matcher
<
int
&>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
,
int
,
char
*
,
int
&
,
const
long
&
),
// NOLINT
...
...
googlemock/test/gmock-generated-matchers_test.cc
View file @
25905b9f
...
...
@@ -62,9 +62,6 @@ using std::pair;
using
std
::
set
;
using
std
::
stringstream
;
using
std
::
vector
;
using
testing
::
get
;
using
testing
::
make_tuple
;
using
testing
::
tuple
;
using
testing
::
_
;
using
testing
::
AllOf
;
using
testing
::
AnyOf
;
...
...
@@ -115,164 +112,16 @@ std::string Explain(const MatcherType& m, const Value& x) {
return
ss
.
str
();
}
// Tests Args<k0, ..., kn>(m).
TEST
(
ArgsTest
,
AcceptsZeroTemplateArg
)
{
const
tuple
<
int
,
bool
>
t
(
5
,
true
);
EXPECT_THAT
(
t
,
Args
<>
(
Eq
(
tuple
<>
())));
EXPECT_THAT
(
t
,
Not
(
Args
<>
(
Ne
(
tuple
<>
()))));
}
TEST
(
ArgsTest
,
AcceptsOneTemplateArg
)
{
const
tuple
<
int
,
bool
>
t
(
5
,
true
);
EXPECT_THAT
(
t
,
Args
<
0
>
(
Eq
(
make_tuple
(
5
))));
EXPECT_THAT
(
t
,
Args
<
1
>
(
Eq
(
make_tuple
(
true
))));
EXPECT_THAT
(
t
,
Not
(
Args
<
1
>
(
Eq
(
make_tuple
(
false
)))));
}
TEST
(
ArgsTest
,
AcceptsTwoTemplateArgs
)
{
const
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
0
,
1
>
(
Lt
())));
EXPECT_THAT
(
t
,
(
Args
<
1
,
2
>
(
Lt
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
0
,
2
>
(
Gt
())));
}
TEST
(
ArgsTest
,
AcceptsRepeatedTemplateArgs
)
{
const
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
0
,
0
>
(
Eq
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
1
,
1
>
(
Ne
())));
}
TEST
(
ArgsTest
,
AcceptsDecreasingTemplateArgs
)
{
const
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
2
,
0
>
(
Gt
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
2
,
1
>
(
Lt
())));
}
// The MATCHER*() macros trigger warning C4100 (unreferenced formal
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
// the macro definition, as the warnings are generated when the macro
// is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here.
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable:4100)
#endif
MATCHER
(
SumIsZero
,
""
)
{
return
get
<
0
>
(
arg
)
+
get
<
1
>
(
arg
)
+
get
<
2
>
(
arg
)
==
0
;
}
TEST
(
ArgsTest
,
AcceptsMoreTemplateArgsThanArityOfOriginalTuple
)
{
EXPECT_THAT
(
make_tuple
(
-
1
,
2
),
(
Args
<
0
,
0
,
1
>
(
SumIsZero
())));
EXPECT_THAT
(
make_tuple
(
1
,
2
),
Not
(
Args
<
0
,
0
,
1
>
(
SumIsZero
())));
}
TEST
(
ArgsTest
,
CanBeNested
)
{
const
tuple
<
short
,
int
,
long
,
int
>
t
(
4
,
5
,
6L
,
6
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
1
,
2
,
3
>
(
Args
<
1
,
2
>
(
Eq
()))));
EXPECT_THAT
(
t
,
(
Args
<
0
,
1
,
3
>
(
Args
<
0
,
2
>
(
Lt
()))));
}
TEST
(
ArgsTest
,
CanMatchTupleByValue
)
{
typedef
tuple
<
char
,
int
,
int
>
Tuple3
;
const
Matcher
<
Tuple3
>
m
=
Args
<
1
,
2
>
(
Lt
());
EXPECT_TRUE
(
m
.
Matches
(
Tuple3
(
'a'
,
1
,
2
)));
EXPECT_FALSE
(
m
.
Matches
(
Tuple3
(
'b'
,
2
,
2
)));
}
TEST
(
ArgsTest
,
CanMatchTupleByReference
)
{
typedef
tuple
<
char
,
char
,
int
>
Tuple3
;
const
Matcher
<
const
Tuple3
&>
m
=
Args
<
0
,
1
>
(
Lt
());
EXPECT_TRUE
(
m
.
Matches
(
Tuple3
(
'a'
,
'b'
,
2
)));
EXPECT_FALSE
(
m
.
Matches
(
Tuple3
(
'b'
,
'b'
,
2
)));
}
// Validates that arg is printed as str.
MATCHER_P
(
PrintsAs
,
str
,
""
)
{
return
testing
::
PrintToString
(
arg
)
==
str
;
}
TEST
(
ArgsTest
,
AcceptsTenTemplateArgs
)
{
EXPECT_THAT
(
make_tuple
(
0
,
1L
,
2
,
3L
,
4
,
5
,
6
,
7
,
8
,
9
),
(
Args
<
9
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
,
0
>
(
PrintsAs
(
"(9, 8, 7, 6, 5, 4, 3, 2, 1, 0)"
))));
EXPECT_THAT
(
make_tuple
(
0
,
1L
,
2
,
3L
,
4
,
5
,
6
,
7
,
8
,
9
),
Not
(
Args
<
9
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
,
0
>
(
PrintsAs
(
"(0, 8, 7, 6, 5, 4, 3, 2, 1, 0)"
))));
}
TEST
(
ArgsTest
,
DescirbesSelfCorrectly
)
{
const
Matcher
<
tuple
<
int
,
bool
,
char
>
>
m
=
Args
<
2
,
0
>
(
Lt
());
EXPECT_EQ
(
"are a tuple whose fields (#2, #0) are a pair where "
"the first < the second"
,
Describe
(
m
));
}
TEST
(
ArgsTest
,
DescirbesNestedArgsCorrectly
)
{
const
Matcher
<
const
tuple
<
int
,
bool
,
char
,
int
>&>
m
=
Args
<
0
,
2
,
3
>
(
Args
<
2
,
0
>
(
Lt
()));
EXPECT_EQ
(
"are a tuple whose fields (#0, #2, #3) are a tuple "
"whose fields (#2, #0) are a pair where the first < the second"
,
Describe
(
m
));
}
TEST
(
ArgsTest
,
DescribesNegationCorrectly
)
{
const
Matcher
<
tuple
<
int
,
char
>
>
m
=
Args
<
1
,
0
>
(
Gt
());
EXPECT_EQ
(
"are a tuple whose fields (#1, #0) aren't a pair "
"where the first > the second"
,
DescribeNegation
(
m
));
}
TEST
(
ArgsTest
,
ExplainsMatchResultWithoutInnerExplanation
)
{
const
Matcher
<
tuple
<
bool
,
int
,
int
>
>
m
=
Args
<
1
,
2
>
(
Eq
());
EXPECT_EQ
(
"whose fields (#1, #2) are (42, 42)"
,
Explain
(
m
,
make_tuple
(
false
,
42
,
42
)));
EXPECT_EQ
(
"whose fields (#1, #2) are (42, 43)"
,
Explain
(
m
,
make_tuple
(
false
,
42
,
43
)));
}
// For testing Args<>'s explanation.
class
LessThanMatcher
:
public
MatcherInterface
<
tuple
<
char
,
int
>
>
{
public:
virtual
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{}
virtual
bool
MatchAndExplain
(
tuple
<
char
,
int
>
value
,
MatchResultListener
*
listener
)
const
{
const
int
diff
=
get
<
0
>
(
value
)
-
get
<
1
>
(
value
);
if
(
diff
>
0
)
{
*
listener
<<
"where the first value is "
<<
diff
<<
" more than the second"
;
}
return
diff
<
0
;
}
};
Matcher
<
tuple
<
char
,
int
>
>
LessThan
()
{
return
MakeMatcher
(
new
LessThanMatcher
);
}
TEST
(
ArgsTest
,
ExplainsMatchResultWithInnerExplanation
)
{
const
Matcher
<
tuple
<
char
,
int
,
int
>
>
m
=
Args
<
0
,
2
>
(
LessThan
());
EXPECT_EQ
(
"whose fields (#0, #2) are ('a' (97, 0x61), 42), "
"where the first value is 55 more than the second"
,
Explain
(
m
,
make_tuple
(
'a'
,
42
,
42
)));
EXPECT_EQ
(
"whose fields (#0, #2) are ('
\\
0', 43)"
,
Explain
(
m
,
make_tuple
(
'\0'
,
42
,
43
)));
}
// For testing ExplainMatchResultTo().
class
GreaterThanMatcher
:
public
MatcherInterface
<
int
>
{
public:
explicit
GreaterThanMatcher
(
int
rhs
)
:
rhs_
(
rhs
)
{}
virtual
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
override
{
*
os
<<
"is greater than "
<<
rhs_
;
}
virtual
bool
MatchAndExplain
(
int
lhs
,
MatchResultListener
*
listener
)
const
{
bool
MatchAndExplain
(
int
lhs
,
MatchResultListener
*
listener
)
const
override
{
const
int
diff
=
lhs
-
rhs_
;
if
(
diff
>
0
)
{
*
listener
<<
"which is "
<<
diff
<<
" more than "
<<
rhs_
;
...
...
@@ -517,7 +366,7 @@ class NativeArrayPassedAsPointerAndSize {
TEST
(
ElementsAreTest
,
WorksWithNativeArrayPassedAsPointerAndSize
)
{
int
array
[]
=
{
0
,
1
};
::
testing
::
tuple
<
int
*
,
size_t
>
array_as_tuple
(
array
,
2
);
::
std
::
tuple
<
int
*
,
size_t
>
array_as_tuple
(
array
,
2
);
EXPECT_THAT
(
array_as_tuple
,
ElementsAre
(
0
,
1
));
EXPECT_THAT
(
array_as_tuple
,
Not
(
ElementsAre
(
0
)));
...
...
@@ -571,7 +420,7 @@ TEST(ElementsAreTest, MakesCopyOfArguments) {
int
x
=
1
;
int
y
=
2
;
// This should make a copy of x and y.
::
testing
::
internal
::
ElementsAreMatcher
<
testing
::
tuple
<
int
,
int
>
>
::
testing
::
internal
::
ElementsAreMatcher
<
std
::
tuple
<
int
,
int
>
>
polymorphic_matcher
=
ElementsAre
(
x
,
y
);
// Changing x and y now shouldn't affect the meaning of the above matcher.
x
=
y
=
0
;
...
...
@@ -640,7 +489,6 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithVector) {
EXPECT_THAT
(
test_vector
,
Not
(
ElementsAreArray
(
expected
)));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
ElementsAreArrayTest
,
TakesInitializerList
)
{
const
int
a
[
5
]
=
{
1
,
2
,
3
,
4
,
5
};
...
...
@@ -676,7 +524,6 @@ TEST(ElementsAreArrayTest,
{
Eq
(
1
),
Ne
(
-
2
),
Ge
(
3
),
Le
(
4
),
Eq
(
6
)
})));
}
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
ElementsAreArrayTest
,
CanBeCreatedWithMatcherVector
)
{
const
int
a
[]
=
{
1
,
2
,
3
};
...
...
@@ -1235,8 +1082,8 @@ TEST(ContainsTest, AcceptsMatcher) {
TEST
(
ContainsTest
,
WorksForNativeArrayAsTuple
)
{
const
int
a
[]
=
{
1
,
2
};
const
int
*
const
pointer
=
a
;
EXPECT_THAT
(
make_tuple
(
pointer
,
2
),
Contains
(
1
));
EXPECT_THAT
(
make_tuple
(
pointer
,
2
),
Not
(
Contains
(
Gt
(
3
))));
EXPECT_THAT
(
std
::
make_tuple
(
pointer
,
2
),
Contains
(
1
));
EXPECT_THAT
(
std
::
make_tuple
(
pointer
,
2
),
Not
(
Contains
(
Gt
(
3
))));
}
TEST
(
ContainsTest
,
WorksForTwoDimensionalNativeArray
)
{
...
...
@@ -1290,11 +1137,6 @@ TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
}
// namespace adl_test
#ifdef _MSC_VER
# pragma warning(pop)
#endif
#if GTEST_LANG_CXX11
TEST
(
AllOfTest
,
WorksOnMoveOnlyType
)
{
std
::
unique_ptr
<
int
>
p
(
new
int
(
3
));
...
...
@@ -1332,7 +1174,6 @@ TEST(MatcherPMacroTest, WorksOnMoveOnlyType) {
EXPECT_THAT
(
p
,
Not
(
UniquePointee
(
2
)));
}
#endif // GTEST_LASNG_CXX11
}
// namespace
...
...
googlemock/test/gmock-internal-utils_test.cc
View file @
25905b9f
...
...
@@ -123,15 +123,9 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
}
TEST
(
PointeeOfTest
,
WorksForSmartPointers
)
{
CompileAssertTypesEqual
<
const
char
,
PointeeOf
<
internal
::
linked_ptr
<
const
char
>
>::
type
>
();
#if GTEST_HAS_STD_UNIQUE_PTR_
CompileAssertTypesEqual
<
int
,
PointeeOf
<
std
::
unique_ptr
<
int
>
>::
type
>
();
#endif // GTEST_HAS_STD_UNIQUE_PTR_
#if GTEST_HAS_STD_SHARED_PTR_
CompileAssertTypesEqual
<
std
::
string
,
PointeeOf
<
std
::
shared_ptr
<
std
::
string
>
>::
type
>
();
#endif // GTEST_HAS_STD_SHARED_PTR_
}
TEST
(
PointeeOfTest
,
WorksForRawPointers
)
{
...
...
@@ -141,20 +135,12 @@ TEST(PointeeOfTest, WorksForRawPointers) {
}
TEST
(
GetRawPointerTest
,
WorksForSmartPointers
)
{
#if GTEST_HAS_STD_UNIQUE_PTR_
const
char
*
const
raw_p1
=
new
const
char
(
'a'
);
// NOLINT
const
std
::
unique_ptr
<
const
char
>
p1
(
raw_p1
);
EXPECT_EQ
(
raw_p1
,
GetRawPointer
(
p1
));
#endif // GTEST_HAS_STD_UNIQUE_PTR_
#if GTEST_HAS_STD_SHARED_PTR_
double
*
const
raw_p2
=
new
double
(
2.5
);
// NOLINT
const
std
::
shared_ptr
<
double
>
p2
(
raw_p2
);
EXPECT_EQ
(
raw_p2
,
GetRawPointer
(
p2
));
#endif // GTEST_HAS_STD_SHARED_PTR_
const
char
*
const
raw_p4
=
new
const
char
(
'a'
);
// NOLINT
const
internal
::
linked_ptr
<
const
char
>
p4
(
raw_p4
);
EXPECT_EQ
(
raw_p4
,
GetRawPointer
(
p4
));
}
TEST
(
GetRawPointerTest
,
WorksForRawPointers
)
{
...
...
@@ -308,26 +294,23 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
// Tests the TupleMatches() template function.
TEST
(
TupleMatchesTest
,
WorksForSize0
)
{
tuple
<>
matchers
;
tuple
<>
values
;
std
::
tuple
<>
matchers
;
std
::
tuple
<>
values
;
EXPECT_TRUE
(
TupleMatches
(
matchers
,
values
));
}
TEST
(
TupleMatchesTest
,
WorksForSize1
)
{
tuple
<
Matcher
<
int
>
>
matchers
(
Eq
(
1
));
tuple
<
int
>
values1
(
1
),
values2
(
2
);
std
::
tuple
<
Matcher
<
int
>
>
matchers
(
Eq
(
1
));
std
::
tuple
<
int
>
values1
(
1
),
values2
(
2
);
EXPECT_TRUE
(
TupleMatches
(
matchers
,
values1
));
EXPECT_FALSE
(
TupleMatches
(
matchers
,
values2
));
}
TEST
(
TupleMatchesTest
,
WorksForSize2
)
{
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
>
matchers
(
Eq
(
1
),
Eq
(
'a'
));
tuple
<
int
,
char
>
values1
(
1
,
'a'
),
values2
(
1
,
'b'
),
values3
(
2
,
'a'
),
std
::
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
>
matchers
(
Eq
(
1
),
Eq
(
'a'
));
std
::
tuple
<
int
,
char
>
values1
(
1
,
'a'
),
values2
(
1
,
'b'
),
values3
(
2
,
'a'
),
values4
(
2
,
'b'
);
EXPECT_TRUE
(
TupleMatches
(
matchers
,
values1
));
...
...
@@ -337,10 +320,11 @@ TEST(TupleMatchesTest, WorksForSize2) {
}
TEST
(
TupleMatchesTest
,
WorksForSize5
)
{
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
long
>
,
// NOLINT
std
::
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
long
>
,
// NOLINT
Matcher
<
std
::
string
>
>
matchers
(
Eq
(
1
),
Eq
(
'a'
),
Eq
(
true
),
Eq
(
2L
),
Eq
(
"hi"
));
tuple
<
int
,
char
,
bool
,
long
,
std
::
string
>
// NOLINT
std
::
tuple
<
int
,
char
,
bool
,
long
,
std
::
string
>
// NOLINT
values1
(
1
,
'a'
,
true
,
2L
,
"hi"
),
values2
(
1
,
'a'
,
true
,
2L
,
"hello"
),
values3
(
2
,
'a'
,
true
,
2L
,
"hi"
);
...
...
@@ -387,11 +371,9 @@ TEST(ExpectTest, FailsNonfatallyOnFalse) {
class
LogIsVisibleTest
:
public
::
testing
::
Test
{
protected:
virtual
void
SetUp
()
{
original_verbose_
=
GMOCK_FLAG
(
verbose
);
}
void
SetUp
()
override
{
original_verbose_
=
GMOCK_FLAG
(
verbose
);
}
virtual
void
TearDown
()
{
GMOCK_FLAG
(
verbose
)
=
original_verbose_
;
}
void
TearDown
()
override
{
GMOCK_FLAG
(
verbose
)
=
original_verbose_
;
}
std
::
string
original_verbose_
;
};
...
...
@@ -450,11 +432,11 @@ TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
}
struct
MockStackTraceGetter
:
testing
::
internal
::
OsStackTraceGetterInterface
{
virtual
std
::
string
CurrentStackTrace
(
int
max_depth
,
int
skip_count
)
{
std
::
string
CurrentStackTrace
(
int
max_depth
,
int
skip_count
)
override
{
return
(
testing
::
Message
()
<<
max_depth
<<
"::"
<<
skip_count
<<
"
\n
"
)
.
GetString
();
}
virtual
void
UponLeavingGTest
()
{}
void
UponLeavingGTest
()
override
{}
};
// Tests that in opt mode, a positive stack_frames_to_skip argument is
...
...
@@ -686,22 +668,25 @@ TEST(StlContainerViewTest, WorksForStaticNativeArray) {
TEST
(
StlContainerViewTest
,
WorksForDynamicNativeArray
)
{
StaticAssertTypeEq
<
NativeArray
<
int
>
,
StlContainerView
<
tuple
<
const
int
*
,
size_t
>
>::
type
>
();
StaticAssertTypeEq
<
NativeArray
<
double
>
,
StlContainerView
<
tuple
<
linked_ptr
<
double
>
,
int
>
>::
type
>
();
StlContainerView
<
std
::
tuple
<
const
int
*
,
size_t
>
>::
type
>
();
StaticAssertTypeEq
<
NativeArray
<
double
>
,
StlContainerView
<
std
::
tuple
<
std
::
shared_ptr
<
double
>
,
int
>
>::
type
>
();
StaticAssertTypeEq
<
const
NativeArray
<
int
>
,
StlContainerView
<
tuple
<
const
int
*
,
int
>
>::
const_reference
>
();
StaticAssertTypeEq
<
const
NativeArray
<
int
>
,
StlContainerView
<
std
::
tuple
<
const
int
*
,
int
>
>::
const_reference
>
();
int
a1
[
3
]
=
{
0
,
1
,
2
};
const
int
*
const
p1
=
a1
;
NativeArray
<
int
>
a2
=
StlContainerView
<
tuple
<
const
int
*
,
int
>
>::
ConstReference
(
make_tuple
(
p1
,
3
));
NativeArray
<
int
>
a2
=
StlContainerView
<
std
::
tuple
<
const
int
*
,
int
>
>::
ConstReference
(
std
::
make_tuple
(
p1
,
3
));
EXPECT_EQ
(
3U
,
a2
.
size
());
EXPECT_EQ
(
a1
,
a2
.
begin
());
const
NativeArray
<
int
>
a3
=
StlContainerView
<
tuple
<
int
*
,
size_t
>
>::
Copy
(
make_tuple
(
static_cast
<
int
*>
(
a1
),
3
));
const
NativeArray
<
int
>
a3
=
StlContainerView
<
std
::
tuple
<
int
*
,
size_t
>
>::
Copy
(
std
::
make_tuple
(
static_cast
<
int
*>
(
a1
),
3
));
ASSERT_EQ
(
3U
,
a3
.
size
());
EXPECT_EQ
(
0
,
a3
.
begin
()[
0
]);
EXPECT_EQ
(
1
,
a3
.
begin
()[
1
]);
...
...
googlemock/test/gmock-matchers_test.cc
View file @
25905b9f
...
...
@@ -32,12 +32,21 @@
//
// This file tests some commonly used argument matchers.
// Silence warning C4244: 'initializing': conversion from 'int' to 'short',
// possible loss of data and C4100, unreferenced local parameter
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable:4244)
# pragma warning(disable:4100)
#endif
#include "gmock/gmock-matchers.h"
#include "gmock/gmock-more-matchers.h"
#include <string.h>
#include <time.h>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <iterator>
...
...
@@ -48,22 +57,16 @@
#include <set>
#include <sstream>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
#if GTEST_HAS_STD_FORWARD_LIST_
# include <forward_list> // NOLINT
#endif
#if GTEST_LANG_CXX11
# include <type_traits>
#endif
namespace
testing
{
namespace
gmock_matchers_test
{
namespace
{
using
std
::
greater
;
using
std
::
less
;
...
...
@@ -77,6 +80,7 @@ using std::pair;
using
std
::
set
;
using
std
::
stringstream
;
using
std
::
vector
;
using
testing
::
_
;
using
testing
::
A
;
using
testing
::
AllArgs
;
using
testing
::
AllOf
;
...
...
@@ -102,12 +106,12 @@ using testing::Le;
using
testing
::
Lt
;
using
testing
::
MakeMatcher
;
using
testing
::
MakePolymorphicMatcher
;
using
testing
::
MatchResultListener
;
using
testing
::
Matcher
;
using
testing
::
MatcherCast
;
using
testing
::
MatcherInterface
;
using
testing
::
Matches
;
using
testing
::
MatchesRegex
;
using
testing
::
MatchResultListener
;
using
testing
::
NanSensitiveDoubleEq
;
using
testing
::
NanSensitiveDoubleNear
;
using
testing
::
NanSensitiveFloatEq
;
...
...
@@ -127,16 +131,14 @@ using testing::StartsWith;
using
testing
::
StrCaseEq
;
using
testing
::
StrCaseNe
;
using
testing
::
StrEq
;
using
testing
::
StrNe
;
using
testing
::
StringMatchResultListener
;
using
testing
::
StrNe
;
using
testing
::
Truly
;
using
testing
::
TypedEq
;
using
testing
::
UnorderedPointwise
;
using
testing
::
Value
;
using
testing
::
WhenSorted
;
using
testing
::
WhenSortedBy
;
using
testing
::
_
;
using
testing
::
get
;
using
testing
::
internal
::
DummyMatchResultListener
;
using
testing
::
internal
::
ElementMatcherPair
;
using
testing
::
internal
::
ElementMatcherPairs
;
...
...
@@ -144,29 +146,34 @@ using testing::internal::ExplainMatchFailureTupleTo;
using
testing
::
internal
::
FloatingEqMatcher
;
using
testing
::
internal
::
FormatMatcherDescription
;
using
testing
::
internal
::
IsReadableTypeName
;
using
testing
::
internal
::
linked_ptr
;
using
testing
::
internal
::
MatchMatrix
;
using
testing
::
internal
::
PredicateFormatterFromMatcher
;
using
testing
::
internal
::
RE
;
using
testing
::
internal
::
scoped_ptr
;
using
testing
::
internal
::
StreamMatchResultListener
;
using
testing
::
internal
::
Strings
;
using
testing
::
internal
::
linked_ptr
;
using
testing
::
internal
::
scoped_ptr
;
using
testing
::
internal
::
string
;
using
testing
::
make_tuple
;
using
testing
::
tuple
;
using
testing
::
internal
::
Strings
;
// Helper for testing container-valued matchers in mock method context. It is
// important to test matchers in this context, since it requires additional type
// deduction beyond what EXPECT_THAT does, thus making it more restrictive.
struct
ContainerHelper
{
MOCK_METHOD1
(
Call
,
void
(
std
::
vector
<
std
::
unique_ptr
<
int
>>
));
};
std
::
vector
<
std
::
unique_ptr
<
int
>>
MakeUniquePtrs
(
const
std
::
vector
<
int
>&
ints
)
{
std
::
vector
<
std
::
unique_ptr
<
int
>>
pointers
;
for
(
int
i
:
ints
)
pointers
.
emplace_back
(
new
int
(
i
));
return
pointers
;
}
// For testing ExplainMatchResultTo().
class
GreaterThanMatcher
:
public
MatcherInterface
<
int
>
{
public:
explicit
GreaterThanMatcher
(
int
rhs
)
:
rhs_
(
rhs
)
{}
virtual
void
DescribeTo
(
ostream
*
os
)
const
{
*
os
<<
"is > "
<<
rhs_
;
}
void
DescribeTo
(
ostream
*
os
)
const
override
{
*
os
<<
"is > "
<<
rhs_
;
}
virtual
bool
MatchAndExplain
(
int
lhs
,
MatchResultListener
*
listener
)
const
{
bool
MatchAndExplain
(
int
lhs
,
MatchResultListener
*
listener
)
const
override
{
const
int
diff
=
lhs
-
rhs_
;
if
(
diff
>
0
)
{
*
listener
<<
"which is "
<<
diff
<<
" more than "
<<
rhs_
;
...
...
@@ -256,14 +263,12 @@ TEST(MatchResultListenerTest, IsInterestedWorks) {
// change.
class
EvenMatcherImpl
:
public
MatcherInterface
<
int
>
{
public:
virtual
bool
MatchAndExplain
(
int
x
,
MatchResultListener
*
/* listener */
)
const
{
bool
MatchAndExplain
(
int
x
,
MatchResultListener
*
/* listener */
)
const
override
{
return
x
%
2
==
0
;
}
virtual
void
DescribeTo
(
ostream
*
os
)
const
{
*
os
<<
"is an even number"
;
}
void
DescribeTo
(
ostream
*
os
)
const
override
{
*
os
<<
"is an even number"
;
}
// We deliberately don't define DescribeNegationTo() and
// ExplainMatchResultTo() here, to make sure the definition of these
...
...
@@ -279,7 +284,7 @@ TEST(MatcherInterfaceTest, CanBeImplementedUsingPublishedAPI) {
class
NewEvenMatcherImpl
:
public
MatcherInterface
<
int
>
{
public:
virtual
bool
MatchAndExplain
(
int
x
,
MatchResultListener
*
listener
)
const
{
bool
MatchAndExplain
(
int
x
,
MatchResultListener
*
listener
)
const
override
{
const
bool
match
=
x
%
2
==
0
;
// Verifies that we can stream to a listener directly.
*
listener
<<
"value % "
<<
2
;
...
...
@@ -291,9 +296,7 @@ class NewEvenMatcherImpl : public MatcherInterface<int> {
return
match
;
}
virtual
void
DescribeTo
(
ostream
*
os
)
const
{
*
os
<<
"is an even number"
;
}
void
DescribeTo
(
ostream
*
os
)
const
override
{
*
os
<<
"is an even number"
;
}
};
TEST
(
MatcherInterfaceTest
,
CanBeImplementedUsingNewAPI
)
{
...
...
@@ -326,7 +329,7 @@ TEST(MatcherTest, CanBeImplicitlyConstructedFromValue) {
// Tests that NULL can be used in place of Eq(NULL).
TEST
(
MatcherTest
,
CanBeImplicitlyConstructedFromNULL
)
{
Matcher
<
int
*>
m1
=
NULL
;
Matcher
<
int
*>
m1
=
nullptr
;
EXPECT_TRUE
(
m1
.
Matches
(
nullptr
));
int
n
=
0
;
EXPECT_FALSE
(
m1
.
Matches
(
&
n
));
...
...
@@ -1180,32 +1183,12 @@ TEST(IsNullTest, MatchesNullPointer) {
#endif
}
TEST
(
IsNullTest
,
LinkedPtr
)
{
const
Matcher
<
linked_ptr
<
int
>
>
m
=
IsNull
();
const
linked_ptr
<
int
>
null_p
;
const
linked_ptr
<
int
>
non_null_p
(
new
int
);
EXPECT_TRUE
(
m
.
Matches
(
null_p
));
EXPECT_FALSE
(
m
.
Matches
(
non_null_p
));
}
TEST
(
IsNullTest
,
ReferenceToConstLinkedPtr
)
{
const
Matcher
<
const
linked_ptr
<
double
>&>
m
=
IsNull
();
const
linked_ptr
<
double
>
null_p
;
const
linked_ptr
<
double
>
non_null_p
(
new
double
);
EXPECT_TRUE
(
m
.
Matches
(
null_p
));
EXPECT_FALSE
(
m
.
Matches
(
non_null_p
));
}
#if GTEST_LANG_CXX11
TEST
(
IsNullTest
,
StdFunction
)
{
const
Matcher
<
std
::
function
<
void
()
>>
m
=
IsNull
();
EXPECT_TRUE
(
m
.
Matches
(
std
::
function
<
void
()
>
()));
EXPECT_FALSE
(
m
.
Matches
([]{}));
}
#endif // GTEST_LANG_CXX11
// Tests that IsNull() describes itself properly.
TEST
(
IsNullTest
,
CanDescribeSelf
)
{
...
...
@@ -1229,31 +1212,29 @@ TEST(NotNullTest, MatchesNonNullPointer) {
}
TEST
(
NotNullTest
,
LinkedPtr
)
{
const
Matcher
<
link
ed_ptr
<
int
>
>
m
=
NotNull
();
const
link
ed_ptr
<
int
>
null_p
;
const
link
ed_ptr
<
int
>
non_null_p
(
new
int
);
const
Matcher
<
std
::
shar
ed_ptr
<
int
>>
m
=
NotNull
();
const
std
::
shar
ed_ptr
<
int
>
null_p
;
const
std
::
shar
ed_ptr
<
int
>
non_null_p
(
new
int
);
EXPECT_FALSE
(
m
.
Matches
(
null_p
));
EXPECT_TRUE
(
m
.
Matches
(
non_null_p
));
}
TEST
(
NotNullTest
,
ReferenceToConstLinkedPtr
)
{
const
Matcher
<
const
link
ed_ptr
<
double
>&>
m
=
NotNull
();
const
link
ed_ptr
<
double
>
null_p
;
const
link
ed_ptr
<
double
>
non_null_p
(
new
double
);
const
Matcher
<
const
std
::
shar
ed_ptr
<
double
>&>
m
=
NotNull
();
const
std
::
shar
ed_ptr
<
double
>
null_p
;
const
std
::
shar
ed_ptr
<
double
>
non_null_p
(
new
double
);
EXPECT_FALSE
(
m
.
Matches
(
null_p
));
EXPECT_TRUE
(
m
.
Matches
(
non_null_p
));
}
#if GTEST_LANG_CXX11
TEST
(
NotNullTest
,
StdFunction
)
{
const
Matcher
<
std
::
function
<
void
()
>>
m
=
NotNull
();
EXPECT_TRUE
(
m
.
Matches
([]{}));
EXPECT_FALSE
(
m
.
Matches
(
std
::
function
<
void
()
>
()));
}
#endif // GTEST_LANG_CXX11
// Tests that NotNull() describes itself properly.
TEST
(
NotNullTest
,
CanDescribeSelf
)
{
...
...
@@ -1536,7 +1517,6 @@ TEST(KeyTest, MatchesCorrectly) {
EXPECT_THAT
(
p
,
Not
(
Key
(
Lt
(
25
))));
}
#if GTEST_LANG_CXX11
template
<
size_t
I
>
struct
Tag
{};
...
...
@@ -1563,7 +1543,6 @@ TEST(PairTest, MatchesPairWithGetCorrectly) {
std
::
vector
<
PairWithGet
>
v
=
{{
11
,
"Foo"
},
{
29
,
"gMockIsBestMock"
}};
EXPECT_THAT
(
v
,
Contains
(
Key
(
29
)));
}
#endif // GTEST_LANG_CXX11
TEST
(
KeyTest
,
SafelyCastsInnerMatcher
)
{
Matcher
<
int
>
is_positive
=
Gt
(
0
);
...
...
@@ -1702,7 +1681,12 @@ TEST(PairTest, InsideContainsUsingMap) {
EXPECT_THAT
(
container
,
Not
(
Contains
(
Pair
(
3
,
_
))));
}
#if GTEST_LANG_CXX11
TEST
(
ContainsTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
Contains
(
Pointee
(
2
))));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
}
TEST
(
PairTest
,
UseGetInsteadOfMembers
)
{
PairWithGet
pair
{
7
,
"ABC"
};
EXPECT_THAT
(
pair
,
Pair
(
7
,
"ABC"
));
...
...
@@ -1712,7 +1696,6 @@ TEST(PairTest, UseGetInsteadOfMembers) {
std
::
vector
<
PairWithGet
>
v
=
{{
11
,
"Foo"
},
{
29
,
"gMockIsBestMock"
}};
EXPECT_THAT
(
v
,
ElementsAre
(
Pair
(
11
,
string
(
"Foo"
)),
Pair
(
Ge
(
10
),
Not
(
""
))));
}
#endif // GTEST_LANG_CXX11
// Tests StartsWith(s).
...
...
@@ -2239,8 +2222,7 @@ TEST(GlobalWideEndsWithTest, CanDescribeSelf) {
#endif // GTEST_HAS_GLOBAL_WSTRING
typedef
::
testing
::
tuple
<
long
,
int
>
Tuple2
;
// NOLINT
typedef
::
std
::
tuple
<
long
,
int
>
Tuple2
;
// NOLINT
// Tests that Eq() matches a 2-tuple where the first field == the
// second field.
...
...
@@ -2334,7 +2316,7 @@ TEST(Ne2Test, CanDescribeSelf) {
// Tests that FloatEq() matches a 2-tuple where
// FloatEq(first field) matches the second field.
TEST
(
FloatEq2Test
,
MatchesEqualArguments
)
{
typedef
::
testing
::
tuple
<
float
,
float
>
Tpl
;
typedef
::
std
::
tuple
<
float
,
float
>
Tpl
;
Matcher
<
const
Tpl
&>
m
=
FloatEq
();
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.0
f
,
1.0
f
)));
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
0.3
f
,
0.1
f
+
0.1
f
+
0.1
f
)));
...
...
@@ -2343,14 +2325,14 @@ TEST(FloatEq2Test, MatchesEqualArguments) {
// Tests that FloatEq() describes itself properly.
TEST
(
FloatEq2Test
,
CanDescribeSelf
)
{
Matcher
<
const
::
testing
::
tuple
<
float
,
float
>&>
m
=
FloatEq
();
Matcher
<
const
::
std
::
tuple
<
float
,
float
>&>
m
=
FloatEq
();
EXPECT_EQ
(
"are an almost-equal pair"
,
Describe
(
m
));
}
// Tests that NanSensitiveFloatEq() matches a 2-tuple where
// NanSensitiveFloatEq(first field) matches the second field.
TEST
(
NanSensitiveFloatEqTest
,
MatchesEqualArgumentsWithNaN
)
{
typedef
::
testing
::
tuple
<
float
,
float
>
Tpl
;
typedef
::
std
::
tuple
<
float
,
float
>
Tpl
;
Matcher
<
const
Tpl
&>
m
=
NanSensitiveFloatEq
();
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.0
f
,
1.0
f
)));
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
std
::
numeric_limits
<
float
>::
quiet_NaN
(),
...
...
@@ -2362,14 +2344,14 @@ TEST(NanSensitiveFloatEqTest, MatchesEqualArgumentsWithNaN) {
// Tests that NanSensitiveFloatEq() describes itself properly.
TEST
(
NanSensitiveFloatEqTest
,
CanDescribeSelfWithNaNs
)
{
Matcher
<
const
::
testing
::
tuple
<
float
,
float
>&>
m
=
NanSensitiveFloatEq
();
Matcher
<
const
::
std
::
tuple
<
float
,
float
>&>
m
=
NanSensitiveFloatEq
();
EXPECT_EQ
(
"are an almost-equal pair"
,
Describe
(
m
));
}
// Tests that DoubleEq() matches a 2-tuple where
// DoubleEq(first field) matches the second field.
TEST
(
DoubleEq2Test
,
MatchesEqualArguments
)
{
typedef
::
testing
::
tuple
<
double
,
double
>
Tpl
;
typedef
::
std
::
tuple
<
double
,
double
>
Tpl
;
Matcher
<
const
Tpl
&>
m
=
DoubleEq
();
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.0
,
1.0
)));
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
0.3
,
0.1
+
0.1
+
0.1
)));
...
...
@@ -2378,14 +2360,14 @@ TEST(DoubleEq2Test, MatchesEqualArguments) {
// Tests that DoubleEq() describes itself properly.
TEST
(
DoubleEq2Test
,
CanDescribeSelf
)
{
Matcher
<
const
::
testing
::
tuple
<
double
,
double
>&>
m
=
DoubleEq
();
Matcher
<
const
::
std
::
tuple
<
double
,
double
>&>
m
=
DoubleEq
();
EXPECT_EQ
(
"are an almost-equal pair"
,
Describe
(
m
));
}
// Tests that NanSensitiveDoubleEq() matches a 2-tuple where
// NanSensitiveDoubleEq(first field) matches the second field.
TEST
(
NanSensitiveDoubleEqTest
,
MatchesEqualArgumentsWithNaN
)
{
typedef
::
testing
::
tuple
<
double
,
double
>
Tpl
;
typedef
::
std
::
tuple
<
double
,
double
>
Tpl
;
Matcher
<
const
Tpl
&>
m
=
NanSensitiveDoubleEq
();
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.0
f
,
1.0
f
)));
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
std
::
numeric_limits
<
double
>::
quiet_NaN
(),
...
...
@@ -2397,14 +2379,14 @@ TEST(NanSensitiveDoubleEqTest, MatchesEqualArgumentsWithNaN) {
// Tests that DoubleEq() describes itself properly.
TEST
(
NanSensitiveDoubleEqTest
,
CanDescribeSelfWithNaNs
)
{
Matcher
<
const
::
testing
::
tuple
<
double
,
double
>&>
m
=
NanSensitiveDoubleEq
();
Matcher
<
const
::
std
::
tuple
<
double
,
double
>&>
m
=
NanSensitiveDoubleEq
();
EXPECT_EQ
(
"are an almost-equal pair"
,
Describe
(
m
));
}
// Tests that FloatEq() matches a 2-tuple where
// FloatNear(first field, max_abs_error) matches the second field.
TEST
(
FloatNear2Test
,
MatchesEqualArguments
)
{
typedef
::
testing
::
tuple
<
float
,
float
>
Tpl
;
typedef
::
std
::
tuple
<
float
,
float
>
Tpl
;
Matcher
<
const
Tpl
&>
m
=
FloatNear
(
0.5
f
);
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.0
f
,
1.0
f
)));
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.3
f
,
1.0
f
)));
...
...
@@ -2413,14 +2395,14 @@ TEST(FloatNear2Test, MatchesEqualArguments) {
// Tests that FloatNear() describes itself properly.
TEST
(
FloatNear2Test
,
CanDescribeSelf
)
{
Matcher
<
const
::
testing
::
tuple
<
float
,
float
>&>
m
=
FloatNear
(
0.5
f
);
Matcher
<
const
::
std
::
tuple
<
float
,
float
>&>
m
=
FloatNear
(
0.5
f
);
EXPECT_EQ
(
"are an almost-equal pair"
,
Describe
(
m
));
}
// Tests that NanSensitiveFloatNear() matches a 2-tuple where
// NanSensitiveFloatNear(first field) matches the second field.
TEST
(
NanSensitiveFloatNearTest
,
MatchesNearbyArgumentsWithNaN
)
{
typedef
::
testing
::
tuple
<
float
,
float
>
Tpl
;
typedef
::
std
::
tuple
<
float
,
float
>
Tpl
;
Matcher
<
const
Tpl
&>
m
=
NanSensitiveFloatNear
(
0.5
f
);
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.0
f
,
1.0
f
)));
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.1
f
,
1.0
f
)));
...
...
@@ -2433,15 +2415,14 @@ TEST(NanSensitiveFloatNearTest, MatchesNearbyArgumentsWithNaN) {
// Tests that NanSensitiveFloatNear() describes itself properly.
TEST
(
NanSensitiveFloatNearTest
,
CanDescribeSelfWithNaNs
)
{
Matcher
<
const
::
testing
::
tuple
<
float
,
float
>&>
m
=
NanSensitiveFloatNear
(
0.5
f
);
Matcher
<
const
::
std
::
tuple
<
float
,
float
>&>
m
=
NanSensitiveFloatNear
(
0.5
f
);
EXPECT_EQ
(
"are an almost-equal pair"
,
Describe
(
m
));
}
// Tests that FloatEq() matches a 2-tuple where
// DoubleNear(first field, max_abs_error) matches the second field.
TEST
(
DoubleNear2Test
,
MatchesEqualArguments
)
{
typedef
::
testing
::
tuple
<
double
,
double
>
Tpl
;
typedef
::
std
::
tuple
<
double
,
double
>
Tpl
;
Matcher
<
const
Tpl
&>
m
=
DoubleNear
(
0.5
);
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.0
,
1.0
)));
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.3
,
1.0
)));
...
...
@@ -2450,14 +2431,14 @@ TEST(DoubleNear2Test, MatchesEqualArguments) {
// Tests that DoubleNear() describes itself properly.
TEST
(
DoubleNear2Test
,
CanDescribeSelf
)
{
Matcher
<
const
::
testing
::
tuple
<
double
,
double
>&>
m
=
DoubleNear
(
0.5
);
Matcher
<
const
::
std
::
tuple
<
double
,
double
>&>
m
=
DoubleNear
(
0.5
);
EXPECT_EQ
(
"are an almost-equal pair"
,
Describe
(
m
));
}
// Tests that NanSensitiveDoubleNear() matches a 2-tuple where
// NanSensitiveDoubleNear(first field) matches the second field.
TEST
(
NanSensitiveDoubleNearTest
,
MatchesNearbyArgumentsWithNaN
)
{
typedef
::
testing
::
tuple
<
double
,
double
>
Tpl
;
typedef
::
std
::
tuple
<
double
,
double
>
Tpl
;
Matcher
<
const
Tpl
&>
m
=
NanSensitiveDoubleNear
(
0.5
f
);
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.0
f
,
1.0
f
)));
EXPECT_TRUE
(
m
.
Matches
(
Tpl
(
1.1
f
,
1.0
f
)));
...
...
@@ -2470,8 +2451,7 @@ TEST(NanSensitiveDoubleNearTest, MatchesNearbyArgumentsWithNaN) {
// Tests that NanSensitiveDoubleNear() describes itself properly.
TEST
(
NanSensitiveDoubleNearTest
,
CanDescribeSelfWithNaNs
)
{
Matcher
<
const
::
testing
::
tuple
<
double
,
double
>&>
m
=
NanSensitiveDoubleNear
(
0.5
f
);
Matcher
<
const
::
std
::
tuple
<
double
,
double
>&>
m
=
NanSensitiveDoubleNear
(
0.5
f
);
EXPECT_EQ
(
"are an almost-equal pair"
,
Describe
(
m
));
}
...
...
@@ -2686,7 +2666,6 @@ static void AnyOfMatches(int num, const Matcher<int>& m) {
EXPECT_FALSE
(
m
.
Matches
(
num
+
1
));
}
#if GTEST_LANG_CXX11
static
void
AnyOfStringMatches
(
int
num
,
const
Matcher
<
std
::
string
>&
m
)
{
SCOPED_TRACE
(
Describe
(
m
));
EXPECT_FALSE
(
m
.
Matches
(
std
::
to_string
(
0
)));
...
...
@@ -2696,7 +2675,6 @@ static void AnyOfStringMatches(int num, const Matcher<std::string>& m) {
}
EXPECT_FALSE
(
m
.
Matches
(
std
::
to_string
(
num
+
1
)));
}
#endif
// Tests that AnyOf(m1, ..., mn) matches any value that matches at
// least one of the given matchers.
...
...
@@ -2741,7 +2719,6 @@ TEST(AnyOfTest, MatchesWhenAnyMatches) {
AnyOfMatches
(
10
,
AnyOf
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
));
}
#if GTEST_LANG_CXX11
// Tests the variadic version of the AnyOfMatcher.
TEST
(
AnyOfTest
,
VariadicMatchesWhenAnyMatches
)
{
// Also make sure AnyOf is defined in the right namespace and does not depend
...
...
@@ -2790,33 +2767,26 @@ TEST(ElementsAreTest, HugeMatcherUnordered) {
Eq
(
3
),
Eq
(
9
),
Eq
(
12
),
Eq
(
11
),
Ne
(
122
)));
}
#endif // GTEST_LANG_CXX11
// Tests that AnyOf(m1, ..., mn) describes itself properly.
TEST
(
AnyOfTest
,
CanDescribeSelf
)
{
Matcher
<
int
>
m
;
m
=
AnyOf
(
Le
(
1
),
Ge
(
3
));
EXPECT_EQ
(
"(is <= 1) or (is >= 3)"
,
Describe
(
m
));
m
=
AnyOf
(
Lt
(
0
),
Eq
(
1
),
Eq
(
2
));
EXPECT_EQ
(
"(is < 0) or "
"((is equal to 1) or (is equal to 2))"
,
Describe
(
m
));
EXPECT_EQ
(
"(is < 0) or (is equal to 1) or (is equal to 2)"
,
Describe
(
m
));
m
=
AnyOf
(
Lt
(
0
),
Eq
(
1
),
Eq
(
2
),
Eq
(
3
));
EXPECT_EQ
(
"((is < 0) or "
"(is equal to 1)) or "
"((is equal to 2) or "
"(is equal to 3))"
,
EXPECT_EQ
(
"(is < 0) or (is equal to 1) or (is equal to 2) or (is equal to 3)"
,
Describe
(
m
));
m
=
AnyOf
(
Le
(
0
),
Gt
(
10
),
3
,
5
,
7
);
EXPECT_EQ
(
"((is <= 0) or "
"(is > 10)) or "
"((is equal to 3) or "
"((is equal to 5) or "
"(is equal to 7)))"
,
EXPECT_EQ
(
"(is <= 0) or (is > 10) or (is equal to 3) or (is equal to 5) or (is "
"equal to 7)"
,
Describe
(
m
));
}
...
...
@@ -2828,23 +2798,19 @@ TEST(AnyOfTest, CanDescribeNegation) {
DescribeNegation
(
m
));
m
=
AnyOf
(
Lt
(
0
),
Eq
(
1
),
Eq
(
2
));
EXPECT_EQ
(
"(isn't < 0) and "
"((isn't equal to 1) and (isn't equal to 2))"
,
EXPECT_EQ
(
"(isn't < 0) and (isn't equal to 1) and (isn't equal to 2)"
,
DescribeNegation
(
m
));
m
=
AnyOf
(
Lt
(
0
),
Eq
(
1
),
Eq
(
2
),
Eq
(
3
));
EXPECT_EQ
(
"((isn't < 0) and "
"(isn't equal to 1)) and "
"((isn't equal to 2) and "
"(isn't equal to 3))"
,
EXPECT_EQ
(
"(isn't < 0) and (isn't equal to 1) and (isn't equal to 2) and (isn't "
"equal to 3)"
,
DescribeNegation
(
m
));
m
=
AnyOf
(
Le
(
0
),
Gt
(
10
),
3
,
5
,
7
);
EXPECT_EQ
(
"((isn't <= 0) and "
"(isn't > 10)) and "
"((isn't equal to 3) and "
"((isn't equal to 5) and "
"(isn't equal to 7)))"
,
EXPECT_EQ
(
"(isn't <= 0) and (isn't > 10) and (isn't equal to 3) and (isn't equal "
"to 5) and (isn't equal to 7)"
,
DescribeNegation
(
m
));
}
...
...
@@ -3081,8 +3047,8 @@ TEST(DescribeMatcherTest, WorksWithPolymorphicMatcher) {
}
TEST
(
AllArgsTest
,
WorksForTuple
)
{
EXPECT_THAT
(
make_tuple
(
1
,
2L
),
AllArgs
(
Lt
()));
EXPECT_THAT
(
make_tuple
(
2L
,
1
),
Not
(
AllArgs
(
Lt
())));
EXPECT_THAT
(
std
::
make_tuple
(
1
,
2L
),
AllArgs
(
Lt
()));
EXPECT_THAT
(
std
::
make_tuple
(
2L
,
1
),
Not
(
AllArgs
(
Lt
())));
}
TEST
(
AllArgsTest
,
WorksForNonTuple
)
{
...
...
@@ -4171,9 +4137,7 @@ class AClass {
// A getter that returns a reference to const.
const
std
::
string
&
s
()
const
{
return
s_
;
}
#if GTEST_LANG_CXX11
const
std
::
string
&
s_ref
()
const
&
{
return
s_
;
}
#endif
void
set_s
(
const
std
::
string
&
new_s
)
{
s_
=
new_s
;
}
...
...
@@ -4230,7 +4194,6 @@ TEST(PropertyTest, WorksForReferenceToConstProperty) {
EXPECT_FALSE
(
m_with_name
.
Matches
(
a
));
}
#if GTEST_LANG_CXX11
// Tests that Property(&Foo::property, ...) works when property() is
// ref-qualified.
TEST
(
PropertyTest
,
WorksForRefQualifiedProperty
)
{
...
...
@@ -4247,7 +4210,6 @@ TEST(PropertyTest, WorksForRefQualifiedProperty) {
EXPECT_FALSE
(
m
.
Matches
(
a
));
EXPECT_FALSE
(
m_with_name
.
Matches
(
a
));
}
#endif
// Tests that Property(&Foo::property, ...) works when property()
// returns a reference to non-const.
...
...
@@ -4610,7 +4572,6 @@ TEST(ResultOfTest, WorksForPolymorphicFunctors) {
EXPECT_FALSE
(
matcher_string
.
Matches
(
"shrt"
));
}
#if GTEST_LANG_CXX11
TEST
(
ResultOfTest
,
WorksForPolymorphicFunctorsIgnoringResultType
)
{
Matcher
<
int
*>
matcher
=
ResultOf
(
PolymorphicFunctor
(),
"good ptr"
);
...
...
@@ -4625,7 +4586,6 @@ TEST(ResultOfTest, WorksForLambdas) {
EXPECT_TRUE
(
matcher
.
Matches
(
3
));
EXPECT_FALSE
(
matcher
.
Matches
(
1
));
}
#endif
const
int
*
ReferencingFunction
(
const
int
&
n
)
{
return
&
n
;
}
...
...
@@ -4788,6 +4748,12 @@ TEST(IsEmptyTest, ExplainsResult) {
EXPECT_EQ
(
"whose size is 1"
,
Explain
(
m
,
container
));
}
TEST
(
IsEmptyTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
IsEmpty
()));
helper
.
Call
({});
}
TEST
(
IsTrueTest
,
IsTrueIsFalse
)
{
EXPECT_THAT
(
true
,
IsTrue
());
EXPECT_THAT
(
false
,
IsFalse
());
...
...
@@ -4795,8 +4761,8 @@ TEST(IsTrueTest, IsTrueIsFalse) {
EXPECT_THAT
(
false
,
Not
(
IsTrue
()));
EXPECT_THAT
(
0
,
Not
(
IsTrue
()));
EXPECT_THAT
(
0
,
IsFalse
());
EXPECT_THAT
(
NULL
,
Not
(
IsTrue
()));
EXPECT_THAT
(
NULL
,
IsFalse
());
EXPECT_THAT
(
nullptr
,
Not
(
IsTrue
()));
EXPECT_THAT
(
nullptr
,
IsFalse
());
EXPECT_THAT
(
-
1
,
IsTrue
());
EXPECT_THAT
(
-
1
,
Not
(
IsFalse
()));
EXPECT_THAT
(
1
,
IsTrue
());
...
...
@@ -4810,7 +4776,6 @@ TEST(IsTrueTest, IsTrueIsFalse) {
EXPECT_THAT
(
&
a
,
Not
(
IsFalse
()));
EXPECT_THAT
(
false
,
Not
(
IsTrue
()));
EXPECT_THAT
(
true
,
Not
(
IsFalse
()));
#if GTEST_LANG_CXX11
EXPECT_THAT
(
std
::
true_type
(),
IsTrue
());
EXPECT_THAT
(
std
::
true_type
(),
Not
(
IsFalse
()));
EXPECT_THAT
(
std
::
false_type
(),
IsFalse
());
...
...
@@ -4823,7 +4788,6 @@ TEST(IsTrueTest, IsTrueIsFalse) {
EXPECT_THAT
(
null_unique
,
IsFalse
());
EXPECT_THAT
(
nonnull_unique
,
IsTrue
());
EXPECT_THAT
(
nonnull_unique
,
Not
(
IsFalse
()));
#endif // GTEST_LANG_CXX11
}
TEST
(
SizeIsTest
,
ImplementsSizeIs
)
{
...
...
@@ -4858,6 +4822,23 @@ TEST(SizeIsTest, WorksWithReferences) {
EXPECT_THAT
(
container
,
m
);
}
TEST
(
SizeIsTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
SizeIs
(
3
)));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
,
3
}));
}
// SizeIs should work for any type that provides a size() member function.
// For example, a size_type member type should not need to be provided.
struct
MinimalistCustomType
{
int
size
()
const
{
return
1
;
}
};
TEST
(
SizeIsTest
,
WorksWithMinimalistCustomType
)
{
MinimalistCustomType
container
;
EXPECT_THAT
(
container
,
SizeIs
(
1
));
EXPECT_THAT
(
container
,
Not
(
SizeIs
(
0
)));
}
TEST
(
SizeIsTest
,
CanDescribeSelf
)
{
Matcher
<
vector
<
int
>
>
m
=
SizeIs
(
2
);
EXPECT_EQ
(
"size is equal to 2"
,
Describe
(
m
));
...
...
@@ -4958,7 +4939,7 @@ TYPED_TEST(ContainerEqTest, DuplicateDifference) {
}
#endif // GTEST_HAS_TYPED_TEST
// Tests that mu
t
liple missing values are reported.
// Tests that mul
t
iple missing values are reported.
// Using just vector here, so order is predictable.
TEST
(
ContainerEqExtraTest
,
MultipleValuesMissing
)
{
static
const
int
vals
[]
=
{
1
,
1
,
2
,
3
,
5
,
8
};
...
...
@@ -5060,11 +5041,11 @@ TEST(ContainerEqExtraTest, WorksForNativeArrayAsTuple) {
const
int
b
[]
=
{
1
,
2
,
3
,
4
};
const
int
*
const
p1
=
a1
;
EXPECT_THAT
(
make_tuple
(
p1
,
3
),
ContainerEq
(
a2
));
EXPECT_THAT
(
make_tuple
(
p1
,
3
),
Not
(
ContainerEq
(
b
)));
EXPECT_THAT
(
std
::
make_tuple
(
p1
,
3
),
ContainerEq
(
a2
));
EXPECT_THAT
(
std
::
make_tuple
(
p1
,
3
),
Not
(
ContainerEq
(
b
)));
const
int
c
[]
=
{
1
,
3
,
2
};
EXPECT_THAT
(
make_tuple
(
p1
,
3
),
Not
(
ContainerEq
(
c
)));
EXPECT_THAT
(
std
::
make_tuple
(
p1
,
3
),
Not
(
ContainerEq
(
c
)));
}
TEST
(
ContainerEqExtraTest
,
CopiesNativeArrayParameter
)
{
...
...
@@ -5306,7 +5287,6 @@ TEST(StreamlikeTest, Iteration) {
}
}
#if GTEST_HAS_STD_FORWARD_LIST_
TEST
(
BeginEndDistanceIsTest
,
WorksWithForwardList
)
{
std
::
forward_list
<
int
>
container
;
EXPECT_THAT
(
container
,
BeginEndDistanceIs
(
0
));
...
...
@@ -5318,7 +5298,6 @@ TEST(BeginEndDistanceIsTest, WorksWithForwardList) {
EXPECT_THAT
(
container
,
Not
(
BeginEndDistanceIs
(
0
)));
EXPECT_THAT
(
container
,
BeginEndDistanceIs
(
2
));
}
#endif // GTEST_HAS_STD_FORWARD_LIST_
TEST
(
BeginEndDistanceIsTest
,
WorksWithNonStdList
)
{
const
int
a
[
5
]
=
{
1
,
2
,
3
,
4
,
5
};
...
...
@@ -5333,6 +5312,12 @@ TEST(BeginEndDistanceIsTest, CanDescribeSelf) {
DescribeNegation
(
m
));
}
TEST
(
BeginEndDistanceIsTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
BeginEndDistanceIs
(
2
)));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
}
TEST
(
BeginEndDistanceIsTest
,
ExplainsResult
)
{
Matcher
<
vector
<
int
>
>
m1
=
BeginEndDistanceIs
(
2
);
Matcher
<
vector
<
int
>
>
m2
=
BeginEndDistanceIs
(
Lt
(
2
));
...
...
@@ -5494,13 +5479,19 @@ TEST(IsSupersetOfTest, MatchAndExplain) {
" - element #2 is matched by matcher #0"
));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
IsSupersetOfTest
,
WorksForRhsInitializerList
)
{
const
int
numbers
[]
=
{
1
,
3
,
6
,
2
,
4
,
5
};
EXPECT_THAT
(
numbers
,
IsSupersetOf
({
1
,
2
}));
EXPECT_THAT
(
numbers
,
Not
(
IsSupersetOf
({
3
,
0
})));
}
#endif
TEST
(
IsSupersetOfTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
IsSupersetOf
({
Pointee
(
1
)})));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
EXPECT_CALL
(
helper
,
Call
(
Not
(
IsSupersetOf
({
Pointee
(
1
),
Pointee
(
2
)}))));
helper
.
Call
(
MakeUniquePtrs
({
2
}));
}
TEST
(
IsSubsetOfTest
,
WorksForNativeArray
)
{
const
int
subset
[]
=
{
1
,
4
};
...
...
@@ -5616,13 +5607,19 @@ TEST(IsSubsetOfTest, MatchAndExplain) {
" - element #1 is matched by matcher #2"
));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
IsSubsetOfTest
,
WorksForRhsInitializerList
)
{
const
int
numbers
[]
=
{
1
,
2
,
3
};
EXPECT_THAT
(
numbers
,
IsSubsetOf
({
1
,
2
,
3
,
4
}));
EXPECT_THAT
(
numbers
,
Not
(
IsSubsetOf
({
1
,
2
})));
}
#endif
TEST
(
IsSubsetOfTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
IsSubsetOf
({
Pointee
(
1
),
Pointee
(
2
)})));
helper
.
Call
(
MakeUniquePtrs
({
1
}));
EXPECT_CALL
(
helper
,
Call
(
Not
(
IsSubsetOf
({
Pointee
(
1
)}))));
helper
.
Call
(
MakeUniquePtrs
({
2
}));
}
// Tests using ElementsAre() and ElementsAreArray() with stream-like
// "containers".
...
...
@@ -5657,6 +5654,15 @@ TEST(ElementsAreTest, WorksWithUncopyable) {
EXPECT_THAT
(
objs
,
ElementsAre
(
UncopyableIs
(
-
3
),
Truly
(
ValueIsPositive
)));
}
TEST
(
ElementsAreTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
ElementsAre
(
Pointee
(
1
),
Pointee
(
2
))));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
EXPECT_CALL
(
helper
,
Call
(
ElementsAreArray
({
Pointee
(
3
),
Pointee
(
4
)})));
helper
.
Call
(
MakeUniquePtrs
({
3
,
4
}));
}
TEST
(
ElementsAreTest
,
TakesStlContainer
)
{
const
int
actual
[]
=
{
3
,
1
,
2
};
...
...
@@ -5724,7 +5730,6 @@ TEST(UnorderedElementsAreArrayTest, TakesStlContainer) {
EXPECT_THAT
(
actual
,
Not
(
UnorderedElementsAreArray
(
expected
)));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
UnorderedElementsAreArrayTest
,
TakesInitializerList
)
{
const
int
a
[
5
]
=
{
2
,
1
,
4
,
5
,
3
};
...
...
@@ -5758,7 +5763,13 @@ TEST(UnorderedElementsAreArrayTest,
{
Eq
(
1
),
Ne
(
-
2
),
Ge
(
3
),
Le
(
4
),
Eq
(
6
)})));
}
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
UnorderedElementsAreArrayTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
UnorderedElementsAreArray
({
Pointee
(
1
),
Pointee
(
2
)})));
helper
.
Call
(
MakeUniquePtrs
({
2
,
1
}));
}
class
UnorderedElementsAreTest
:
public
testing
::
Test
{
protected:
...
...
@@ -5807,6 +5818,12 @@ TEST_F(UnorderedElementsAreTest, WorksForStreamlike) {
EXPECT_THAT
(
s
,
Not
(
UnorderedElementsAre
(
2
,
2
,
3
,
4
,
5
)));
}
TEST_F
(
UnorderedElementsAreTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
UnorderedElementsAre
(
Pointee
(
1
),
Pointee
(
2
))));
helper
.
Call
(
MakeUniquePtrs
({
2
,
1
}));
}
// One naive implementation of the matcher runs in O(N!) time, which is too
// slow for many real-world inputs. This test shows that our matcher can match
// 100 inputs very quickly (a few milliseconds). An O(100!) is 10^158
...
...
@@ -6246,13 +6263,15 @@ TEST(PolymorphicMatcherTest, CanAccessImpl) {
TEST
(
MatcherTupleTest
,
ExplainsMatchFailure
)
{
stringstream
ss1
;
ExplainMatchFailureTupleTo
(
make_tuple
(
Matcher
<
char
>
(
Eq
(
'a'
)),
GreaterThan
(
5
)),
make_tuple
(
'a'
,
10
),
&
ss1
);
ExplainMatchFailureTupleTo
(
std
::
make_tuple
(
Matcher
<
char
>
(
Eq
(
'a'
)),
GreaterThan
(
5
)),
std
::
make_tuple
(
'a'
,
10
),
&
ss1
);
EXPECT_EQ
(
""
,
ss1
.
str
());
// Successful match.
stringstream
ss2
;
ExplainMatchFailureTupleTo
(
make_tuple
(
GreaterThan
(
5
),
Matcher
<
char
>
(
Eq
(
'a'
))),
make_tuple
(
2
,
'b'
),
&
ss2
);
ExplainMatchFailureTupleTo
(
std
::
make_tuple
(
GreaterThan
(
5
),
Matcher
<
char
>
(
Eq
(
'a'
))),
std
::
make_tuple
(
2
,
'b'
),
&
ss2
);
EXPECT_EQ
(
" Expected arg #0: is > 5
\n
"
" Actual: 2, which is 3 less than 5
\n
"
" Expected arg #1: is equal to 'a' (97, 0x61)
\n
"
...
...
@@ -6260,8 +6279,9 @@ TEST(MatcherTupleTest, ExplainsMatchFailure) {
ss2
.
str
());
// Failed match where both arguments need explanation.
stringstream
ss3
;
ExplainMatchFailureTupleTo
(
make_tuple
(
GreaterThan
(
5
),
Matcher
<
char
>
(
Eq
(
'a'
))),
make_tuple
(
2
,
'a'
),
&
ss3
);
ExplainMatchFailureTupleTo
(
std
::
make_tuple
(
GreaterThan
(
5
),
Matcher
<
char
>
(
Eq
(
'a'
))),
std
::
make_tuple
(
2
,
'a'
),
&
ss3
);
EXPECT_EQ
(
" Expected arg #0: is > 5
\n
"
" Actual: 2, which is 3 less than 5
\n
"
,
ss3
.
str
());
// Failed match where only one argument needs
...
...
@@ -6350,21 +6370,27 @@ TEST(EachTest, AcceptsMatcher) {
TEST
(
EachTest
,
WorksForNativeArrayAsTuple
)
{
const
int
a
[]
=
{
1
,
2
};
const
int
*
const
pointer
=
a
;
EXPECT_THAT
(
make_tuple
(
pointer
,
2
),
Each
(
Gt
(
0
)));
EXPECT_THAT
(
make_tuple
(
pointer
,
2
),
Not
(
Each
(
Gt
(
1
))));
EXPECT_THAT
(
std
::
make_tuple
(
pointer
,
2
),
Each
(
Gt
(
0
)));
EXPECT_THAT
(
std
::
make_tuple
(
pointer
,
2
),
Not
(
Each
(
Gt
(
1
))));
}
TEST
(
EachTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
Each
(
Pointee
(
Gt
(
0
)))));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
}
// For testing Pointwise().
class
IsHalfOfMatcher
{
public:
template
<
typename
T1
,
typename
T2
>
bool
MatchAndExplain
(
const
tuple
<
T1
,
T2
>&
a_pair
,
bool
MatchAndExplain
(
const
std
::
tuple
<
T1
,
T2
>&
a_pair
,
MatchResultListener
*
listener
)
const
{
if
(
get
<
0
>
(
a_pair
)
==
get
<
1
>
(
a_pair
)
/
2
)
{
*
listener
<<
"where the second is "
<<
get
<
1
>
(
a_pair
);
if
(
std
::
get
<
0
>
(
a_pair
)
==
std
::
get
<
1
>
(
a_pair
)
/
2
)
{
*
listener
<<
"where the second is "
<<
std
::
get
<
1
>
(
a_pair
);
return
true
;
}
else
{
*
listener
<<
"where the second/2 is "
<<
get
<
1
>
(
a_pair
)
/
2
;
*
listener
<<
"where the second/2 is "
<<
std
::
get
<
1
>
(
a_pair
)
/
2
;
return
false
;
}
}
...
...
@@ -6441,7 +6467,6 @@ TEST(PointwiseTest, WorksForVectorOfBool) {
EXPECT_THAT
(
lhs
,
Not
(
Pointwise
(
Eq
(),
rhs
)));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
PointwiseTest
,
WorksForRhsInitializerList
)
{
const
vector
<
int
>
lhs
{
2
,
4
,
6
};
...
...
@@ -6449,7 +6474,6 @@ TEST(PointwiseTest, WorksForRhsInitializerList) {
EXPECT_THAT
(
lhs
,
Not
(
Pointwise
(
Lt
(),
{
3
,
3
,
7
})));
}
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
PointwiseTest
,
RejectsWrongSize
)
{
const
double
lhs
[
2
]
=
{
1
,
2
};
...
...
@@ -6481,17 +6505,28 @@ TEST(PointwiseTest, AcceptsCorrectContent) {
TEST
(
PointwiseTest
,
AllowsMonomorphicInnerMatcher
)
{
const
double
lhs
[
3
]
=
{
1
,
2
,
3
};
const
int
rhs
[
3
]
=
{
2
,
4
,
6
};
const
Matcher
<
tuple
<
const
double
&
,
const
int
&>
>
m1
=
IsHalfOf
();
const
Matcher
<
std
::
tuple
<
const
double
&
,
const
int
&>>
m1
=
IsHalfOf
();
EXPECT_THAT
(
lhs
,
Pointwise
(
m1
,
rhs
));
EXPECT_EQ
(
""
,
Explain
(
Pointwise
(
m1
,
rhs
),
lhs
));
// This type works as a tuple<const double&, const int&> can be
// implicitly cast to tuple<double, int>.
const
Matcher
<
tuple
<
double
,
int
>
>
m2
=
IsHalfOf
();
// This type works as a
std::
tuple<const double&, const int&> can be
// implicitly cast to
std::
tuple<double, int>.
const
Matcher
<
std
::
tuple
<
double
,
int
>>
m2
=
IsHalfOf
();
EXPECT_THAT
(
lhs
,
Pointwise
(
m2
,
rhs
));
EXPECT_EQ
(
""
,
Explain
(
Pointwise
(
m2
,
rhs
),
lhs
));
}
MATCHER
(
PointeeEquals
,
"Points to an equal value"
)
{
return
ExplainMatchResult
(
::
testing
::
Pointee
(
::
testing
::
get
<
1
>
(
arg
)),
::
testing
::
get
<
0
>
(
arg
),
result_listener
);
}
TEST
(
PointwiseTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
Pointwise
(
PointeeEquals
(),
std
::
vector
<
int
>
{
1
,
2
})));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
}
TEST
(
UnorderedPointwiseTest
,
DescribesSelf
)
{
vector
<
int
>
rhs
;
rhs
.
push_back
(
1
);
...
...
@@ -6552,7 +6587,6 @@ TEST(UnorderedPointwiseTest, WorksForRhsNativeArray) {
EXPECT_THAT
(
lhs
,
Not
(
UnorderedPointwise
(
Lt
(),
rhs
)));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
UnorderedPointwiseTest
,
WorksForRhsInitializerList
)
{
const
vector
<
int
>
lhs
{
2
,
4
,
6
};
...
...
@@ -6560,7 +6594,6 @@ TEST(UnorderedPointwiseTest, WorksForRhsInitializerList) {
EXPECT_THAT
(
lhs
,
Not
(
UnorderedPointwise
(
Lt
(),
{
1
,
1
,
7
})));
}
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
UnorderedPointwiseTest
,
RejectsWrongSize
)
{
const
double
lhs
[
2
]
=
{
1
,
2
};
...
...
@@ -6597,15 +6630,22 @@ TEST(UnorderedPointwiseTest, AcceptsCorrectContentInDifferentOrder) {
TEST
(
UnorderedPointwiseTest
,
AllowsMonomorphicInnerMatcher
)
{
const
double
lhs
[
3
]
=
{
1
,
2
,
3
};
const
int
rhs
[
3
]
=
{
4
,
6
,
2
};
const
Matcher
<
tuple
<
const
double
&
,
const
int
&>
>
m1
=
IsHalfOf
();
const
Matcher
<
std
::
tuple
<
const
double
&
,
const
int
&>>
m1
=
IsHalfOf
();
EXPECT_THAT
(
lhs
,
UnorderedPointwise
(
m1
,
rhs
));
// This type works as a tuple<const double&, const int&> can be
// implicitly cast to tuple<double, int>.
const
Matcher
<
tuple
<
double
,
int
>
>
m2
=
IsHalfOf
();
// This type works as a
std::
tuple<const double&, const int&> can be
// implicitly cast to
std::
tuple<double, int>.
const
Matcher
<
std
::
tuple
<
double
,
int
>>
m2
=
IsHalfOf
();
EXPECT_THAT
(
lhs
,
UnorderedPointwise
(
m2
,
rhs
));
}
TEST
(
UnorderedPointwiseTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
UnorderedPointwise
(
PointeeEquals
(),
std
::
vector
<
int
>
{
1
,
2
})));
helper
.
Call
(
MakeUniquePtrs
({
2
,
1
}));
}
// Sample optional type implementation with minimal requirements for use with
// Optional matcher.
class
SampleOptionalInt
{
...
...
@@ -6746,7 +6786,6 @@ TEST(AnyWithTest, TestBadCastType) {
EXPECT_FALSE
(
m
.
Matches
(
SampleAnyType
(
1
)));
}
#if GTEST_LANG_CXX11
TEST
(
AnyWithTest
,
TestUseInContainers
)
{
std
::
vector
<
SampleAnyType
>
a
;
a
.
emplace_back
(
1
);
...
...
@@ -6763,7 +6802,6 @@ TEST(AnyWithTest, TestUseInContainers) {
AnyWith
<
std
::
string
>
(
"merhaba"
),
AnyWith
<
std
::
string
>
(
"salut"
)}));
}
#endif // GTEST_LANG_CXX11
TEST
(
AnyWithTest
,
TestCompare
)
{
EXPECT_THAT
(
SampleAnyType
(
1
),
AnyWith
<
int
>
(
Gt
(
0
)));
}
...
...
@@ -6783,8 +6821,6 @@ TEST(AnyWithTest, ExplainsSelf) {
EXPECT_THAT
(
Explain
(
m
,
SampleAnyType
(
2
)),
"whose value 2 doesn't match"
);
}
#if GTEST_LANG_CXX11
TEST
(
PointeeTest
,
WorksOnMoveOnlyType
)
{
std
::
unique_ptr
<
int
>
p
(
new
int
(
3
));
EXPECT_THAT
(
p
,
Pointee
(
Eq
(
3
)));
...
...
@@ -6797,7 +6833,228 @@ TEST(NotTest, WorksOnMoveOnlyType) {
EXPECT_THAT
(
p
,
Not
(
Pointee
(
Eq
(
2
))));
}
#endif // GTEST_LANG_CXX11
// Tests Args<k0, ..., kn>(m).
TEST
(
ArgsTest
,
AcceptsZeroTemplateArg
)
{
const
std
::
tuple
<
int
,
bool
>
t
(
5
,
true
);
EXPECT_THAT
(
t
,
Args
<>
(
Eq
(
std
::
tuple
<>
())));
EXPECT_THAT
(
t
,
Not
(
Args
<>
(
Ne
(
std
::
tuple
<>
()))));
}
TEST
(
ArgsTest
,
AcceptsOneTemplateArg
)
{
const
std
::
tuple
<
int
,
bool
>
t
(
5
,
true
);
EXPECT_THAT
(
t
,
Args
<
0
>
(
Eq
(
std
::
make_tuple
(
5
))));
EXPECT_THAT
(
t
,
Args
<
1
>
(
Eq
(
std
::
make_tuple
(
true
))));
EXPECT_THAT
(
t
,
Not
(
Args
<
1
>
(
Eq
(
std
::
make_tuple
(
false
)))));
}
TEST
(
ArgsTest
,
AcceptsTwoTemplateArgs
)
{
const
std
::
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
0
,
1
>
(
Lt
())));
EXPECT_THAT
(
t
,
(
Args
<
1
,
2
>
(
Lt
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
0
,
2
>
(
Gt
())));
}
TEST
(
ArgsTest
,
AcceptsRepeatedTemplateArgs
)
{
const
std
::
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
0
,
0
>
(
Eq
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
1
,
1
>
(
Ne
())));
}
TEST
(
ArgsTest
,
AcceptsDecreasingTemplateArgs
)
{
const
std
::
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
2
,
0
>
(
Gt
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
2
,
1
>
(
Lt
())));
}
MATCHER
(
SumIsZero
,
""
)
{
return
std
::
get
<
0
>
(
arg
)
+
std
::
get
<
1
>
(
arg
)
+
std
::
get
<
2
>
(
arg
)
==
0
;
}
TEST
(
ArgsTest
,
AcceptsMoreTemplateArgsThanArityOfOriginalTuple
)
{
EXPECT_THAT
(
std
::
make_tuple
(
-
1
,
2
),
(
Args
<
0
,
0
,
1
>
(
SumIsZero
())));
EXPECT_THAT
(
std
::
make_tuple
(
1
,
2
),
Not
(
Args
<
0
,
0
,
1
>
(
SumIsZero
())));
}
TEST
(
ArgsTest
,
CanBeNested
)
{
const
std
::
tuple
<
short
,
int
,
long
,
int
>
t
(
4
,
5
,
6L
,
6
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
1
,
2
,
3
>
(
Args
<
1
,
2
>
(
Eq
()))));
EXPECT_THAT
(
t
,
(
Args
<
0
,
1
,
3
>
(
Args
<
0
,
2
>
(
Lt
()))));
}
TEST
(
ArgsTest
,
CanMatchTupleByValue
)
{
typedef
std
::
tuple
<
char
,
int
,
int
>
Tuple3
;
const
Matcher
<
Tuple3
>
m
=
Args
<
1
,
2
>
(
Lt
());
EXPECT_TRUE
(
m
.
Matches
(
Tuple3
(
'a'
,
1
,
2
)));
EXPECT_FALSE
(
m
.
Matches
(
Tuple3
(
'b'
,
2
,
2
)));
}
TEST
(
ArgsTest
,
CanMatchTupleByReference
)
{
typedef
std
::
tuple
<
char
,
char
,
int
>
Tuple3
;
const
Matcher
<
const
Tuple3
&>
m
=
Args
<
0
,
1
>
(
Lt
());
EXPECT_TRUE
(
m
.
Matches
(
Tuple3
(
'a'
,
'b'
,
2
)));
EXPECT_FALSE
(
m
.
Matches
(
Tuple3
(
'b'
,
'b'
,
2
)));
}
// Validates that arg is printed as str.
MATCHER_P
(
PrintsAs
,
str
,
""
)
{
return
testing
::
PrintToString
(
arg
)
==
str
;
}
TEST
(
ArgsTest
,
AcceptsTenTemplateArgs
)
{
EXPECT_THAT
(
std
::
make_tuple
(
0
,
1L
,
2
,
3L
,
4
,
5
,
6
,
7
,
8
,
9
),
(
Args
<
9
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
,
0
>
(
PrintsAs
(
"(9, 8, 7, 6, 5, 4, 3, 2, 1, 0)"
))));
EXPECT_THAT
(
std
::
make_tuple
(
0
,
1L
,
2
,
3L
,
4
,
5
,
6
,
7
,
8
,
9
),
Not
(
Args
<
9
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
,
0
>
(
PrintsAs
(
"(0, 8, 7, 6, 5, 4, 3, 2, 1, 0)"
))));
}
TEST
(
ArgsTest
,
DescirbesSelfCorrectly
)
{
const
Matcher
<
std
::
tuple
<
int
,
bool
,
char
>
>
m
=
Args
<
2
,
0
>
(
Lt
());
EXPECT_EQ
(
"are a tuple whose fields (#2, #0) are a pair where "
"the first < the second"
,
Describe
(
m
));
}
TEST
(
ArgsTest
,
DescirbesNestedArgsCorrectly
)
{
const
Matcher
<
const
std
::
tuple
<
int
,
bool
,
char
,
int
>&>
m
=
Args
<
0
,
2
,
3
>
(
Args
<
2
,
0
>
(
Lt
()));
EXPECT_EQ
(
"are a tuple whose fields (#0, #2, #3) are a tuple "
"whose fields (#2, #0) are a pair where the first < the second"
,
Describe
(
m
));
}
TEST
(
ArgsTest
,
DescribesNegationCorrectly
)
{
const
Matcher
<
std
::
tuple
<
int
,
char
>
>
m
=
Args
<
1
,
0
>
(
Gt
());
EXPECT_EQ
(
"are a tuple whose fields (#1, #0) aren't a pair "
"where the first > the second"
,
DescribeNegation
(
m
));
}
TEST
(
ArgsTest
,
ExplainsMatchResultWithoutInnerExplanation
)
{
const
Matcher
<
std
::
tuple
<
bool
,
int
,
int
>
>
m
=
Args
<
1
,
2
>
(
Eq
());
EXPECT_EQ
(
"whose fields (#1, #2) are (42, 42)"
,
Explain
(
m
,
std
::
make_tuple
(
false
,
42
,
42
)));
EXPECT_EQ
(
"whose fields (#1, #2) are (42, 43)"
,
Explain
(
m
,
std
::
make_tuple
(
false
,
42
,
43
)));
}
// For testing Args<>'s explanation.
class
LessThanMatcher
:
public
MatcherInterface
<
std
::
tuple
<
char
,
int
>
>
{
public:
virtual
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{}
virtual
bool
MatchAndExplain
(
std
::
tuple
<
char
,
int
>
value
,
MatchResultListener
*
listener
)
const
{
const
int
diff
=
std
::
get
<
0
>
(
value
)
-
std
::
get
<
1
>
(
value
);
if
(
diff
>
0
)
{
*
listener
<<
"where the first value is "
<<
diff
<<
" more than the second"
;
}
return
diff
<
0
;
}
};
Matcher
<
std
::
tuple
<
char
,
int
>
>
LessThan
()
{
return
MakeMatcher
(
new
LessThanMatcher
);
}
TEST
(
ArgsTest
,
ExplainsMatchResultWithInnerExplanation
)
{
const
Matcher
<
std
::
tuple
<
char
,
int
,
int
>
>
m
=
Args
<
0
,
2
>
(
LessThan
());
EXPECT_EQ
(
"whose fields (#0, #2) are ('a' (97, 0x61), 42), "
"where the first value is 55 more than the second"
,
Explain
(
m
,
std
::
make_tuple
(
'a'
,
42
,
42
)));
EXPECT_EQ
(
"whose fields (#0, #2) are ('
\\
0', 43)"
,
Explain
(
m
,
std
::
make_tuple
(
'\0'
,
42
,
43
)));
}
class
PredicateFormatterFromMatcherTest
:
public
::
testing
::
Test
{
protected:
enum
Behavior
{
kInitialSuccess
,
kAlwaysFail
,
kFlaky
};
// A matcher that can return different results when used multiple times on the
// same input. No real matcher should do this; but this lets us test that we
// detect such behavior and fail appropriately.
class
MockMatcher
:
public
MatcherInterface
<
Behavior
>
{
public:
bool
MatchAndExplain
(
Behavior
behavior
,
MatchResultListener
*
listener
)
const
override
{
*
listener
<<
"[MatchAndExplain]"
;
switch
(
behavior
)
{
case
kInitialSuccess
:
// The first call to MatchAndExplain should use a "not interested"
// listener; so this is expected to return |true|. There should be no
// subsequent calls.
return
!
listener
->
IsInterested
();
case
kAlwaysFail
:
return
false
;
case
kFlaky
:
// The first call to MatchAndExplain should use a "not interested"
// listener; so this will return |false|. Subsequent calls should have
// an "interested" listener; so this will return |true|, thus
// simulating a flaky matcher.
return
listener
->
IsInterested
();
}
GTEST_LOG_
(
FATAL
)
<<
"This should never be reached"
;
return
false
;
}
void
DescribeTo
(
ostream
*
os
)
const
override
{
*
os
<<
"[DescribeTo]"
;
}
void
DescribeNegationTo
(
ostream
*
os
)
const
override
{
*
os
<<
"[DescribeNegationTo]"
;
}
};
AssertionResult
RunPredicateFormatter
(
Behavior
behavior
)
{
auto
matcher
=
MakeMatcher
(
new
MockMatcher
);
PredicateFormatterFromMatcher
<
Matcher
<
Behavior
>>
predicate_formatter
(
matcher
);
return
predicate_formatter
(
"dummy-name"
,
behavior
);
}
const
std
::
string
kMatcherType
=
"testing::gmock_matchers_test::PredicateFormatterFromMatcherTest::"
"Behavior"
;
};
TEST_F
(
PredicateFormatterFromMatcherTest
,
ShortCircuitOnSuccess
)
{
AssertionResult
result
=
RunPredicateFormatter
(
kInitialSuccess
);
EXPECT_TRUE
(
result
);
// Implicit cast to bool.
std
::
string
expect
;
EXPECT_EQ
(
expect
,
result
.
message
());
}
TEST_F
(
PredicateFormatterFromMatcherTest
,
NoShortCircuitOnFailure
)
{
AssertionResult
result
=
RunPredicateFormatter
(
kAlwaysFail
);
EXPECT_FALSE
(
result
);
// Implicit cast to bool.
std
::
string
expect
=
"Value of: dummy-name
\n
Expected: [DescribeTo]
\n
"
" Actual: 1, [MatchAndExplain]"
;
EXPECT_EQ
(
expect
,
result
.
message
());
}
TEST_F
(
PredicateFormatterFromMatcherTest
,
DetectsFlakyShortCircuit
)
{
AssertionResult
result
=
RunPredicateFormatter
(
kFlaky
);
EXPECT_FALSE
(
result
);
// Implicit cast to bool.
std
::
string
expect
=
"Value of: dummy-name
\n
Expected: [DescribeTo]
\n
"
" The matcher failed on the initial attempt; but passed when rerun to "
"generate the explanation.
\n
"
" Actual: 2, [MatchAndExplain]"
;
EXPECT_EQ
(
expect
,
result
.
message
());
}
}
// namespace
}
// namespace gmock_matchers_test
}
// namespace testing
#ifdef _MSC_VER
# pragma warning(pop)
#endif
googlemock/test/gmock-more-actions_test.cc
View file @
25905b9f
...
...
@@ -35,21 +35,17 @@
#include "gmock/gmock-more-actions.h"
#include <functional>
#include <memory>
#include <sstream>
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "gtest/internal/gtest-linked_ptr.h"
namespace
testing
{
namespace
gmock_more_actions_test
{
using
::
std
::
plus
;
using
::
std
::
string
;
using
testing
::
get
;
using
testing
::
make_tuple
;
using
testing
::
tuple
;
using
testing
::
tuple_element
;
using
testing
::
_
;
using
testing
::
Action
;
using
testing
::
ActionInterface
;
...
...
@@ -65,7 +61,6 @@ using testing::StaticAssertTypeEq;
using
testing
::
Unused
;
using
testing
::
WithArg
;
using
testing
::
WithoutArgs
;
using
testing
::
internal
::
linked_ptr
;
// For suppressing compiler warnings on conversion possibly losing precision.
inline
short
Short
(
short
n
)
{
return
n
;
}
// NOLINT
...
...
@@ -232,45 +227,46 @@ class Foo {
// Tests using Invoke() with a nullary function.
TEST
(
InvokeTest
,
Nullary
)
{
Action
<
int
()
>
a
=
Invoke
(
Nullary
);
// NOLINT
EXPECT_EQ
(
1
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
1
,
a
.
Perform
(
std
::
make_tuple
()));
}
// Tests using Invoke() with a unary function.
TEST
(
InvokeTest
,
Unary
)
{
Action
<
bool
(
int
)
>
a
=
Invoke
(
Unary
);
// NOLINT
EXPECT_FALSE
(
a
.
Perform
(
make_tuple
(
1
)));
EXPECT_TRUE
(
a
.
Perform
(
make_tuple
(
-
1
)));
EXPECT_FALSE
(
a
.
Perform
(
std
::
make_tuple
(
1
)));
EXPECT_TRUE
(
a
.
Perform
(
std
::
make_tuple
(
-
1
)));
}
// Tests using Invoke() with a binary function.
TEST
(
InvokeTest
,
Binary
)
{
Action
<
const
char
*
(
const
char
*
,
short
)
>
a
=
Invoke
(
Binary
);
// NOLINT
const
char
*
p
=
"Hello"
;
EXPECT_EQ
(
p
+
2
,
a
.
Perform
(
make_tuple
(
p
,
Short
(
2
))));
EXPECT_EQ
(
p
+
2
,
a
.
Perform
(
std
::
make_tuple
(
p
,
Short
(
2
))));
}
// Tests using Invoke() with a ternary function.
TEST
(
InvokeTest
,
Ternary
)
{
Action
<
int
(
int
,
char
,
short
)
>
a
=
Invoke
(
Ternary
);
// NOLINT
EXPECT_EQ
(
6
,
a
.
Perform
(
make_tuple
(
1
,
'\2'
,
Short
(
3
))));
EXPECT_EQ
(
6
,
a
.
Perform
(
std
::
make_tuple
(
1
,
'\2'
,
Short
(
3
))));
}
// Tests using Invoke() with a 4-argument function.
TEST
(
InvokeTest
,
FunctionThatTakes4Arguments
)
{
Action
<
int
(
int
,
int
,
int
,
int
)
>
a
=
Invoke
(
SumOf4
);
// NOLINT
EXPECT_EQ
(
1234
,
a
.
Perform
(
make_tuple
(
1000
,
200
,
30
,
4
)));
EXPECT_EQ
(
1234
,
a
.
Perform
(
std
::
make_tuple
(
1000
,
200
,
30
,
4
)));
}
// Tests using Invoke() with a 5-argument function.
TEST
(
InvokeTest
,
FunctionThatTakes5Arguments
)
{
Action
<
int
(
int
,
int
,
int
,
int
,
int
)
>
a
=
Invoke
(
SumOf5
);
// NOLINT
EXPECT_EQ
(
12345
,
a
.
Perform
(
make_tuple
(
10000
,
2000
,
300
,
40
,
5
)));
EXPECT_EQ
(
12345
,
a
.
Perform
(
std
::
make_tuple
(
10000
,
2000
,
300
,
40
,
5
)));
}
// Tests using Invoke() with a 6-argument function.
TEST
(
InvokeTest
,
FunctionThatTakes6Arguments
)
{
Action
<
int
(
int
,
int
,
int
,
int
,
int
,
int
)
>
a
=
Invoke
(
SumOf6
);
// NOLINT
EXPECT_EQ
(
123456
,
a
.
Perform
(
make_tuple
(
100000
,
20000
,
3000
,
400
,
50
,
6
)));
EXPECT_EQ
(
123456
,
a
.
Perform
(
std
::
make_tuple
(
100000
,
20000
,
3000
,
400
,
50
,
6
)));
}
// A helper that turns the type of a C-string literal from const
...
...
@@ -283,7 +279,7 @@ TEST(InvokeTest, FunctionThatTakes7Arguments) {
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
Concat7
);
EXPECT_EQ
(
"1234567"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"7"
))));
}
...
...
@@ -294,7 +290,7 @@ TEST(InvokeTest, FunctionThatTakes8Arguments) {
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
Concat8
);
EXPECT_EQ
(
"12345678"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"7"
),
CharPtr
(
"8"
))));
}
...
...
@@ -305,8 +301,8 @@ TEST(InvokeTest, FunctionThatTakes9Arguments) {
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
Concat9
);
EXPECT_EQ
(
"123456789"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
EXPECT_EQ
(
"123456789"
,
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"7"
),
CharPtr
(
"8"
),
CharPtr
(
"9"
))));
}
...
...
@@ -318,7 +314,7 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) {
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
Concat10
);
EXPECT_EQ
(
"1234567890"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"7"
),
CharPtr
(
"8"
),
CharPtr
(
"9"
),
CharPtr
(
"0"
))));
...
...
@@ -327,37 +323,37 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) {
// Tests using Invoke() with functions with parameters declared as Unused.
TEST
(
InvokeTest
,
FunctionWithUnusedParameters
)
{
Action
<
int
(
int
,
int
,
double
,
const
std
::
string
&
)
>
a1
=
Invoke
(
SumOfFirst2
);
tuple
<
int
,
int
,
double
,
std
::
string
>
dummy
=
make_tuple
(
10
,
2
,
5.6
,
std
::
string
(
"hi"
));
std
::
tuple
<
int
,
int
,
double
,
std
::
string
>
dummy
=
std
::
make_tuple
(
10
,
2
,
5.6
,
std
::
string
(
"hi"
));
EXPECT_EQ
(
12
,
a1
.
Perform
(
dummy
));
Action
<
int
(
int
,
int
,
bool
,
int
*
)
>
a2
=
Invoke
(
SumOfFirst2
);
EXPECT_EQ
(
23
,
a2
.
Perform
(
make_tuple
(
20
,
3
,
true
,
static_cast
<
int
*>
(
nullptr
))));
EXPECT_EQ
(
23
,
a2
.
Perform
(
std
::
make_tuple
(
20
,
3
,
true
,
static_cast
<
int
*>
(
nullptr
))));
}
// Tests using Invoke() with methods with parameters declared as Unused.
TEST
(
InvokeTest
,
MethodWithUnusedParameters
)
{
Foo
foo
;
Action
<
int
(
std
::
string
,
bool
,
int
,
int
)
>
a1
=
Invoke
(
&
foo
,
&
Foo
::
SumOfLast2
);
EXPECT_EQ
(
12
,
a1
.
Perform
(
make_tuple
(
CharPtr
(
"hi"
),
true
,
10
,
2
)));
EXPECT_EQ
(
12
,
a1
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"hi"
),
true
,
10
,
2
)));
Action
<
int
(
char
,
double
,
int
,
int
)
>
a2
=
Invoke
(
&
foo
,
&
Foo
::
SumOfLast2
);
EXPECT_EQ
(
23
,
a2
.
Perform
(
make_tuple
(
'a'
,
2.5
,
20
,
3
)));
EXPECT_EQ
(
23
,
a2
.
Perform
(
std
::
make_tuple
(
'a'
,
2.5
,
20
,
3
)));
}
// Tests using Invoke() with a functor.
TEST
(
InvokeTest
,
Functor
)
{
Action
<
long
(
long
,
int
)
>
a
=
Invoke
(
plus
<
long
>
());
// NOLINT
EXPECT_EQ
(
3L
,
a
.
Perform
(
make_tuple
(
1
,
2
)));
EXPECT_EQ
(
3L
,
a
.
Perform
(
std
::
make_tuple
(
1
,
2
)));
}
// Tests using Invoke(f) as an action of a compatible type.
TEST
(
InvokeTest
,
FunctionWithCompatibleType
)
{
Action
<
long
(
int
,
short
,
char
,
bool
)
>
a
=
Invoke
(
SumOf4
);
// NOLINT
EXPECT_EQ
(
4321
,
a
.
Perform
(
make_tuple
(
4000
,
Short
(
300
),
Char
(
20
),
true
)));
EXPECT_EQ
(
4321
,
a
.
Perform
(
std
::
make_tuple
(
4000
,
Short
(
300
),
Char
(
20
),
true
)));
}
// Tests using Invoke() with an object pointer and a method pointer.
...
...
@@ -366,14 +362,14 @@ TEST(InvokeTest, FunctionWithCompatibleType) {
TEST
(
InvokeMethodTest
,
Nullary
)
{
Foo
foo
;
Action
<
int
()
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Nullary
);
// NOLINT
EXPECT_EQ
(
123
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
123
,
a
.
Perform
(
std
::
make_tuple
()));
}
// Tests using Invoke() with a unary method.
TEST
(
InvokeMethodTest
,
Unary
)
{
Foo
foo
;
Action
<
short
(
long
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Unary
);
// NOLINT
EXPECT_EQ
(
4123
,
a
.
Perform
(
make_tuple
(
4000
)));
EXPECT_EQ
(
4123
,
a
.
Perform
(
std
::
make_tuple
(
4000
)));
}
// Tests using Invoke() with a binary method.
...
...
@@ -381,7 +377,7 @@ TEST(InvokeMethodTest, Binary) {
Foo
foo
;
Action
<
std
::
string
(
const
std
::
string
&
,
char
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Binary
);
std
::
string
s
(
"Hell"
);
tuple
<
std
::
string
,
char
>
dummy
=
make_tuple
(
s
,
'o'
);
std
::
tuple
<
std
::
string
,
char
>
dummy
=
std
::
make_tuple
(
s
,
'o'
);
EXPECT_EQ
(
"Hello"
,
a
.
Perform
(
dummy
));
}
...
...
@@ -389,21 +385,21 @@ TEST(InvokeMethodTest, Binary) {
TEST
(
InvokeMethodTest
,
Ternary
)
{
Foo
foo
;
Action
<
int
(
int
,
bool
,
char
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Ternary
);
// NOLINT
EXPECT_EQ
(
1124
,
a
.
Perform
(
make_tuple
(
1000
,
true
,
Char
(
1
))));
EXPECT_EQ
(
1124
,
a
.
Perform
(
std
::
make_tuple
(
1000
,
true
,
Char
(
1
))));
}
// Tests using Invoke() with a 4-argument method.
TEST
(
InvokeMethodTest
,
MethodThatTakes4Arguments
)
{
Foo
foo
;
Action
<
int
(
int
,
int
,
int
,
int
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
SumOf4
);
// NOLINT
EXPECT_EQ
(
1357
,
a
.
Perform
(
make_tuple
(
1000
,
200
,
30
,
4
)));
EXPECT_EQ
(
1357
,
a
.
Perform
(
std
::
make_tuple
(
1000
,
200
,
30
,
4
)));
}
// Tests using Invoke() with a 5-argument method.
TEST
(
InvokeMethodTest
,
MethodThatTakes5Arguments
)
{
Foo
foo
;
Action
<
int
(
int
,
int
,
int
,
int
,
int
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
SumOf5
);
// NOLINT
EXPECT_EQ
(
12345
,
a
.
Perform
(
make_tuple
(
10000
,
2000
,
300
,
40
,
5
)));
EXPECT_EQ
(
12345
,
a
.
Perform
(
std
::
make_tuple
(
10000
,
2000
,
300
,
40
,
5
)));
}
// Tests using Invoke() with a 6-argument method.
...
...
@@ -411,7 +407,8 @@ TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
Foo
foo
;
Action
<
int
(
int
,
int
,
int
,
int
,
int
,
int
)
>
a
=
// NOLINT
Invoke
(
&
foo
,
&
Foo
::
SumOf6
);
EXPECT_EQ
(
123456
,
a
.
Perform
(
make_tuple
(
100000
,
20000
,
3000
,
400
,
50
,
6
)));
EXPECT_EQ
(
123456
,
a
.
Perform
(
std
::
make_tuple
(
100000
,
20000
,
3000
,
400
,
50
,
6
)));
}
// Tests using Invoke() with a 7-argument method.
...
...
@@ -421,7 +418,7 @@ TEST(InvokeMethodTest, MethodThatTakes7Arguments) {
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Concat7
);
EXPECT_EQ
(
"1234567"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"7"
))));
}
...
...
@@ -433,7 +430,7 @@ TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Concat8
);
EXPECT_EQ
(
"12345678"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"7"
),
CharPtr
(
"8"
))));
}
...
...
@@ -445,8 +442,8 @@ TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Concat9
);
EXPECT_EQ
(
"123456789"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
EXPECT_EQ
(
"123456789"
,
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"7"
),
CharPtr
(
"8"
),
CharPtr
(
"9"
))));
}
...
...
@@ -459,7 +456,7 @@ TEST(InvokeMethodTest, MethodThatTakes10Arguments) {
const
char
*
,
const
char
*
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Concat10
);
EXPECT_EQ
(
"1234567890"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
),
CharPtr
(
"5"
),
CharPtr
(
"6"
),
CharPtr
(
"7"
),
CharPtr
(
"8"
),
CharPtr
(
"9"
),
CharPtr
(
"0"
))));
...
...
@@ -470,48 +467,48 @@ TEST(InvokeMethodTest, MethodWithCompatibleType) {
Foo
foo
;
Action
<
long
(
int
,
short
,
char
,
bool
)
>
a
=
// NOLINT
Invoke
(
&
foo
,
&
Foo
::
SumOf4
);
EXPECT_EQ
(
4444
,
a
.
Perform
(
make_tuple
(
4000
,
Short
(
300
),
Char
(
20
),
true
)));
EXPECT_EQ
(
4444
,
a
.
Perform
(
std
::
make_tuple
(
4000
,
Short
(
300
),
Char
(
20
),
true
)));
}
// Tests using WithoutArgs with an action that takes no argument.
TEST
(
WithoutArgsTest
,
NoArg
)
{
Action
<
int
(
int
n
)
>
a
=
WithoutArgs
(
Invoke
(
Nullary
));
// NOLINT
EXPECT_EQ
(
1
,
a
.
Perform
(
make_tuple
(
2
)));
EXPECT_EQ
(
1
,
a
.
Perform
(
std
::
make_tuple
(
2
)));
}
// Tests using WithArg with an action that takes 1 argument.
TEST
(
WithArgTest
,
OneArg
)
{
Action
<
bool
(
double
x
,
int
n
)
>
b
=
WithArg
<
1
>
(
Invoke
(
Unary
));
// NOLINT
EXPECT_TRUE
(
b
.
Perform
(
make_tuple
(
1.5
,
-
1
)));
EXPECT_FALSE
(
b
.
Perform
(
make_tuple
(
1.5
,
1
)));
EXPECT_TRUE
(
b
.
Perform
(
std
::
make_tuple
(
1.5
,
-
1
)));
EXPECT_FALSE
(
b
.
Perform
(
std
::
make_tuple
(
1.5
,
1
)));
}
TEST
(
ReturnArgActionTest
,
WorksForOneArgIntArg0
)
{
const
Action
<
int
(
int
)
>
a
=
ReturnArg
<
0
>
();
EXPECT_EQ
(
5
,
a
.
Perform
(
make_tuple
(
5
)));
EXPECT_EQ
(
5
,
a
.
Perform
(
std
::
make_tuple
(
5
)));
}
TEST
(
ReturnArgActionTest
,
WorksForMultiArgBoolArg0
)
{
const
Action
<
bool
(
bool
,
bool
,
bool
)
>
a
=
ReturnArg
<
0
>
();
EXPECT_TRUE
(
a
.
Perform
(
make_tuple
(
true
,
false
,
false
)));
EXPECT_TRUE
(
a
.
Perform
(
std
::
make_tuple
(
true
,
false
,
false
)));
}
TEST
(
ReturnArgActionTest
,
WorksForMultiArgStringArg2
)
{
const
Action
<
std
::
string
(
int
,
int
,
std
::
string
,
int
)
>
a
=
ReturnArg
<
2
>
();
EXPECT_EQ
(
"seven"
,
a
.
Perform
(
make_tuple
(
5
,
6
,
std
::
string
(
"seven"
),
8
)));
EXPECT_EQ
(
"seven"
,
a
.
Perform
(
std
::
make_tuple
(
5
,
6
,
std
::
string
(
"seven"
),
8
)));
}
TEST
(
SaveArgActionTest
,
WorksForSameType
)
{
int
result
=
0
;
const
Action
<
void
(
int
n
)
>
a1
=
SaveArg
<
0
>
(
&
result
);
a1
.
Perform
(
make_tuple
(
5
));
a1
.
Perform
(
std
::
make_tuple
(
5
));
EXPECT_EQ
(
5
,
result
);
}
TEST
(
SaveArgActionTest
,
WorksForCompatibleType
)
{
int
result
=
0
;
const
Action
<
void
(
bool
,
char
)
>
a1
=
SaveArg
<
1
>
(
&
result
);
a1
.
Perform
(
make_tuple
(
true
,
'a'
));
a1
.
Perform
(
std
::
make_tuple
(
true
,
'a'
));
EXPECT_EQ
(
'a'
,
result
);
}
...
...
@@ -519,7 +516,7 @@ TEST(SaveArgPointeeActionTest, WorksForSameType) {
int
result
=
0
;
const
int
value
=
5
;
const
Action
<
void
(
const
int
*
)
>
a1
=
SaveArgPointee
<
0
>
(
&
result
);
a1
.
Perform
(
make_tuple
(
&
value
));
a1
.
Perform
(
std
::
make_tuple
(
&
value
));
EXPECT_EQ
(
5
,
result
);
}
...
...
@@ -527,36 +524,28 @@ TEST(SaveArgPointeeActionTest, WorksForCompatibleType) {
int
result
=
0
;
char
value
=
'a'
;
const
Action
<
void
(
bool
,
char
*
)
>
a1
=
SaveArgPointee
<
1
>
(
&
result
);
a1
.
Perform
(
make_tuple
(
true
,
&
value
));
a1
.
Perform
(
std
::
make_tuple
(
true
,
&
value
));
EXPECT_EQ
(
'a'
,
result
);
}
TEST
(
SaveArgPointeeActionTest
,
WorksForLinkedPtr
)
{
int
result
=
0
;
linked_ptr
<
int
>
value
(
new
int
(
5
));
const
Action
<
void
(
linked_ptr
<
int
>
)
>
a1
=
SaveArgPointee
<
0
>
(
&
result
);
a1
.
Perform
(
make_tuple
(
value
));
EXPECT_EQ
(
5
,
result
);
}
TEST
(
SetArgRefereeActionTest
,
WorksForSameType
)
{
int
value
=
0
;
const
Action
<
void
(
int
&
)
>
a1
=
SetArgReferee
<
0
>
(
1
);
a1
.
Perform
(
tuple
<
int
&>
(
value
));
a1
.
Perform
(
std
::
tuple
<
int
&>
(
value
));
EXPECT_EQ
(
1
,
value
);
}
TEST
(
SetArgRefereeActionTest
,
WorksForCompatibleType
)
{
int
value
=
0
;
const
Action
<
void
(
int
,
int
&
)
>
a1
=
SetArgReferee
<
1
>
(
'a'
);
a1
.
Perform
(
tuple
<
int
,
int
&>
(
0
,
value
));
a1
.
Perform
(
std
::
tuple
<
int
,
int
&>
(
0
,
value
));
EXPECT_EQ
(
'a'
,
value
);
}
TEST
(
SetArgRefereeActionTest
,
WorksWithExtraArguments
)
{
int
value
=
0
;
const
Action
<
void
(
bool
,
int
,
int
&
,
const
char
*
)
>
a1
=
SetArgReferee
<
2
>
(
'a'
);
a1
.
Perform
(
tuple
<
bool
,
int
,
int
&
,
const
char
*>
(
true
,
0
,
value
,
"hi"
));
a1
.
Perform
(
std
::
tuple
<
bool
,
int
,
int
&
,
const
char
*>
(
true
,
0
,
value
,
"hi"
));
EXPECT_EQ
(
'a'
,
value
);
}
...
...
@@ -583,7 +572,7 @@ TEST(DeleteArgActionTest, OneArg) {
DeletionTester
*
t
=
new
DeletionTester
(
&
is_deleted
);
const
Action
<
void
(
DeletionTester
*
)
>
a1
=
DeleteArg
<
0
>
();
// NOLINT
EXPECT_FALSE
(
is_deleted
);
a1
.
Perform
(
make_tuple
(
t
));
a1
.
Perform
(
std
::
make_tuple
(
t
));
EXPECT_TRUE
(
is_deleted
);
}
...
...
@@ -593,7 +582,7 @@ TEST(DeleteArgActionTest, TenArgs) {
const
Action
<
void
(
bool
,
int
,
int
,
const
char
*
,
bool
,
int
,
int
,
int
,
int
,
DeletionTester
*
)
>
a1
=
DeleteArg
<
9
>
();
EXPECT_FALSE
(
is_deleted
);
a1
.
Perform
(
make_tuple
(
true
,
5
,
6
,
CharPtr
(
"hi"
),
false
,
7
,
8
,
9
,
10
,
t
));
a1
.
Perform
(
std
::
make_tuple
(
true
,
5
,
6
,
CharPtr
(
"hi"
),
false
,
7
,
8
,
9
,
10
,
t
));
EXPECT_TRUE
(
is_deleted
);
}
...
...
@@ -601,19 +590,19 @@ TEST(DeleteArgActionTest, TenArgs) {
TEST
(
ThrowActionTest
,
ThrowsGivenExceptionInVoidFunction
)
{
const
Action
<
void
(
int
n
)
>
a
=
Throw
(
'a'
);
EXPECT_THROW
(
a
.
Perform
(
make_tuple
(
0
)),
char
);
EXPECT_THROW
(
a
.
Perform
(
std
::
make_tuple
(
0
)),
char
);
}
class
MyException
{};
TEST
(
ThrowActionTest
,
ThrowsGivenExceptionInNonVoidFunction
)
{
const
Action
<
double
(
char
ch
)
>
a
=
Throw
(
MyException
());
EXPECT_THROW
(
a
.
Perform
(
make_tuple
(
'0'
)),
MyException
);
EXPECT_THROW
(
a
.
Perform
(
std
::
make_tuple
(
'0'
)),
MyException
);
}
TEST
(
ThrowActionTest
,
ThrowsGivenExceptionInNullaryFunction
)
{
const
Action
<
double
()
>
a
=
Throw
(
MyException
());
EXPECT_THROW
(
a
.
Perform
(
make_tuple
()),
MyException
);
EXPECT_THROW
(
a
.
Perform
(
std
::
make_tuple
()),
MyException
);
}
#endif // GTEST_HAS_EXCEPTIONS
...
...
@@ -629,7 +618,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArray) {
int
*
pn
=
n
;
char
ch
[
4
]
=
{};
char
*
pch
=
ch
;
a
.
Perform
(
make_tuple
(
true
,
pn
,
pch
));
a
.
Perform
(
std
::
make_tuple
(
true
,
pn
,
pch
));
EXPECT_EQ
(
1
,
n
[
0
]);
EXPECT_EQ
(
2
,
n
[
1
]);
EXPECT_EQ
(
3
,
n
[
2
]);
...
...
@@ -644,7 +633,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArray) {
a
=
SetArrayArgument
<
2
>
(
letters
.
begin
(),
letters
.
end
());
std
::
fill_n
(
n
,
4
,
0
);
std
::
fill_n
(
ch
,
4
,
'\0'
);
a
.
Perform
(
make_tuple
(
true
,
pn
,
pch
));
a
.
Perform
(
std
::
make_tuple
(
true
,
pn
,
pch
));
EXPECT_EQ
(
0
,
n
[
0
]);
EXPECT_EQ
(
0
,
n
[
1
]);
EXPECT_EQ
(
0
,
n
[
2
]);
...
...
@@ -663,7 +652,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
int
n
[
4
]
=
{};
int
*
pn
=
n
;
a
.
Perform
(
make_tuple
(
true
,
pn
));
a
.
Perform
(
std
::
make_tuple
(
true
,
pn
));
EXPECT_EQ
(
0
,
n
[
0
]);
EXPECT_EQ
(
0
,
n
[
1
]);
EXPECT_EQ
(
0
,
n
[
2
]);
...
...
@@ -679,7 +668,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) {
int
codes
[
4
]
=
{
111
,
222
,
333
,
444
};
int
*
pcodes
=
codes
;
a
.
Perform
(
make_tuple
(
true
,
pcodes
));
a
.
Perform
(
std
::
make_tuple
(
true
,
pcodes
));
EXPECT_EQ
(
97
,
codes
[
0
]);
EXPECT_EQ
(
98
,
codes
[
1
]);
EXPECT_EQ
(
99
,
codes
[
2
]);
...
...
@@ -693,17 +682,17 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) {
Action
<
MyFunction
>
a
=
SetArrayArgument
<
1
>
(
letters
.
begin
(),
letters
.
end
());
std
::
string
s
;
a
.
Perform
(
make_tuple
(
true
,
back_inserter
(
s
)));
a
.
Perform
(
std
::
make_tuple
(
true
,
back_inserter
(
s
)));
EXPECT_EQ
(
letters
,
s
);
}
TEST
(
ReturnPointeeTest
,
Works
)
{
int
n
=
42
;
const
Action
<
int
()
>
a
=
ReturnPointee
(
&
n
);
EXPECT_EQ
(
42
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
42
,
a
.
Perform
(
std
::
make_tuple
()));
n
=
43
;
EXPECT_EQ
(
43
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
43
,
a
.
Perform
(
std
::
make_tuple
()));
}
}
// namespace gmock_generated_actions_test
...
...
googlemock/test/gmock-nice-strict_test.cc
View file @
25905b9f
...
...
@@ -27,8 +27,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "gmock/gmock-generated-nice-strict.h"
#include "gmock/gmock-nice-strict.h"
#include <string>
#include <utility>
...
...
@@ -114,23 +113,22 @@ class MockBar {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockBar
);
};
#if GTEST_GTEST_LANG_CXX11
class
MockBaz
{
public:
class
MoveOnly
{
public:
MoveOnly
()
=
default
;
MoveOnly
(
const
MoveOnly
&
)
=
delete
;
operator
=
(
const
MoveOnly
&
)
=
delete
;
MoveOnly
&
operator
=
(
const
MoveOnly
&
)
=
delete
;
MoveOnly
(
MoveOnly
&&
)
=
default
;
operator
=
(
MoveOnly
&&
)
=
default
;
MoveOnly
&
operator
=
(
MoveOnly
&&
)
=
default
;
};
MockBaz
(
MoveOnly
)
{}
}
#endif // GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
};
#if GTEST_HAS_STREAM_REDIRECTION
...
...
@@ -184,6 +182,13 @@ TEST(RawMockTest, InfoForUninterestingCall) {
GMOCK_FLAG
(
verbose
)
=
saved_flag
;
}
TEST
(
RawMockTest
,
IsNaggy_IsNice_IsStrict
)
{
MockFoo
raw_foo
;
EXPECT_TRUE
(
Mock
::
IsNaggy
(
&
raw_foo
));
EXPECT_FALSE
(
Mock
::
IsNice
(
&
raw_foo
));
EXPECT_FALSE
(
Mock
::
IsStrict
(
&
raw_foo
));
}
// Tests that a nice mock generates no warning for uninteresting calls.
TEST
(
NiceMockTest
,
NoWarningForUninterestingCall
)
{
NiceMock
<
MockFoo
>
nice_foo
;
...
...
@@ -285,14 +290,10 @@ TEST(NiceMockTest, AllowLeak) {
leaked
->
DoThis
();
}
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
TEST
(
NiceMockTest
,
MoveOnlyConstructor
)
{
NiceMock
<
MockBaz
>
nice_baz
(
MockBaz
::
MoveOnly
()
);
NiceMock
<
MockBaz
>
nice_baz
(
MockBaz
::
MoveOnly
{}
);
}
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that NiceMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to work around an
...
...
@@ -309,6 +310,13 @@ TEST(NiceMockTest, AcceptsClassNamedMock) {
}
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
TEST
(
NiceMockTest
,
IsNaggy_IsNice_IsStrict
)
{
NiceMock
<
MockFoo
>
nice_foo
;
EXPECT_FALSE
(
Mock
::
IsNaggy
(
&
nice_foo
));
EXPECT_TRUE
(
Mock
::
IsNice
(
&
nice_foo
));
EXPECT_FALSE
(
Mock
::
IsStrict
(
&
nice_foo
));
}
#if GTEST_HAS_STREAM_REDIRECTION
// Tests that a naggy mock generates warnings for uninteresting calls.
...
...
@@ -393,14 +401,10 @@ TEST(NaggyMockTest, AllowLeak) {
leaked
->
DoThis
();
}
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
TEST
(
NaggyMockTest
,
MoveOnlyConstructor
)
{
NaggyMock
<
MockBaz
>
naggy_baz
(
MockBaz
::
MoveOnly
()
);
NaggyMock
<
MockBaz
>
naggy_baz
(
MockBaz
::
MoveOnly
{}
);
}
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that NaggyMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to work around an
...
...
@@ -417,6 +421,13 @@ TEST(NaggyMockTest, AcceptsClassNamedMock) {
}
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
TEST
(
NaggyMockTest
,
IsNaggy_IsNice_IsStrict
)
{
NaggyMock
<
MockFoo
>
naggy_foo
;
EXPECT_TRUE
(
Mock
::
IsNaggy
(
&
naggy_foo
));
EXPECT_FALSE
(
Mock
::
IsNice
(
&
naggy_foo
));
EXPECT_FALSE
(
Mock
::
IsStrict
(
&
naggy_foo
));
}
// Tests that a strict mock allows expected calls.
TEST
(
StrictMockTest
,
AllowsExpectedCall
)
{
StrictMock
<
MockFoo
>
strict_foo
;
...
...
@@ -482,14 +493,10 @@ TEST(StrictMockTest, AllowLeak) {
leaked
->
DoThis
();
}
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
TEST
(
StrictMockTest
,
MoveOnlyConstructor
)
{
StrictMock
<
MockBaz
>
strict_baz
(
MockBaz
::
MoveOnly
()
);
StrictMock
<
MockBaz
>
strict_baz
(
MockBaz
::
MoveOnly
{}
);
}
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that StrictMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to work around an
...
...
@@ -506,5 +513,12 @@ TEST(StrictMockTest, AcceptsClassNamedMock) {
}
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
TEST
(
StrictMockTest
,
IsNaggy_IsNice_IsStrict
)
{
StrictMock
<
MockFoo
>
strict_foo
;
EXPECT_FALSE
(
Mock
::
IsNaggy
(
&
strict_foo
));
EXPECT_FALSE
(
Mock
::
IsNice
(
&
strict_foo
));
EXPECT_TRUE
(
Mock
::
IsStrict
(
&
strict_foo
));
}
}
// namespace gmock_nice_strict_test
}
// namespace testing
googlemock/test/gmock-pp-string_test.cc
0 → 100644
View file @
25905b9f
// Copyright 2018, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Mock - a framework for writing C++ mock classes.
//
// This file tests the internal preprocessor macro library.
#include "gmock/internal/gmock-pp.h"
#include <string>
#include "gmock/gmock.h"
namespace
testing
{
namespace
{
// Matcher to verify that to strings are identical up to whitespace
// Not 100% correct, because it treats "AB" as equal to "A B".
::
testing
::
Matcher
<
const
std
::
string
&>
SameExceptSpaces
(
const
std
::
string
&
s
)
{
auto
remove_spaces
=
[](
std
::
string
to_split
)
{
to_split
.
erase
(
std
::
remove
(
to_split
.
begin
(),
to_split
.
end
(),
' '
),
to_split
.
end
());
return
to_split
;
};
return
::
testing
::
ResultOf
(
remove_spaces
,
remove_spaces
(
s
));
}
// Verify that a macro expands to a given text. Ignores whitespace difference.
// In MSVC, GMOCK_PP_STRINGIZE() returns nothing, rather than "". So concatenate
// with an empty string.
#define EXPECT_EXPANSION(Result, Macro) \
EXPECT_THAT("" GMOCK_PP_STRINGIZE(Macro), SameExceptSpaces(Result))
TEST
(
Macros
,
Cat
)
{
EXPECT_EXPANSION
(
"14"
,
GMOCK_PP_CAT
(
1
,
4
));
EXPECT_EXPANSION
(
"+="
,
GMOCK_PP_CAT
(
+
,
=
));
}
TEST
(
Macros
,
Narg
)
{
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_NARG
());
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_NARG
(
x
));
EXPECT_EXPANSION
(
"2"
,
GMOCK_PP_NARG
(
x
,
y
));
EXPECT_EXPANSION
(
"3"
,
GMOCK_PP_NARG
(
x
,
y
,
z
));
EXPECT_EXPANSION
(
"4"
,
GMOCK_PP_NARG
(
x
,
y
,
z
,
w
));
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_NARG0
());
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_NARG0
(
x
));
EXPECT_EXPANSION
(
"2"
,
GMOCK_PP_NARG0
(
x
,
y
));
}
TEST
(
Macros
,
Comma
)
{
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_HAS_COMMA
());
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_HAS_COMMA
(,
));
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_HAS_COMMA
((,
)));
}
TEST
(
Macros
,
IsEmpty
)
{
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_IS_EMPTY
());
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_IS_EMPTY
(,
));
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_IS_EMPTY
(
a
));
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_IS_EMPTY
(()));
#define GMOCK_PP_INTERNAL_IS_EMPTY_TEST_1
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_IS_EMPTY
(
GMOCK_PP_INTERNAL_IS_EMPTY_TEST_1
));
}
TEST
(
Macros
,
If
)
{
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_IF
(
1
,
1
,
2
));
EXPECT_EXPANSION
(
"2"
,
GMOCK_PP_IF
(
0
,
1
,
2
));
}
TEST
(
Macros
,
HeadTail
)
{
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_HEAD
(
1
));
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_HEAD
(
1
,
2
));
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_HEAD
(
1
,
2
,
3
));
EXPECT_EXPANSION
(
""
,
GMOCK_PP_TAIL
(
1
));
EXPECT_EXPANSION
(
"2"
,
GMOCK_PP_TAIL
(
1
,
2
));
EXPECT_EXPANSION
(
"2"
,
GMOCK_PP_HEAD
(
GMOCK_PP_TAIL
(
1
,
2
,
3
)));
}
TEST
(
Macros
,
Parentheses
)
{
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_IS_BEGIN_PARENS
(
sss
));
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_IS_BEGIN_PARENS
(
sss
()));
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_IS_BEGIN_PARENS
(
sss
()
sss
));
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_IS_BEGIN_PARENS
((
sss
)));
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_IS_BEGIN_PARENS
((
sss
)
ss
));
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_IS_ENCLOSED_PARENS
(
sss
));
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_IS_ENCLOSED_PARENS
(
sss
()));
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_IS_ENCLOSED_PARENS
(
sss
()
sss
));
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_IS_ENCLOSED_PARENS
((
sss
)));
EXPECT_EXPANSION
(
"0"
,
GMOCK_PP_IS_ENCLOSED_PARENS
((
sss
)
ss
));
EXPECT_EXPANSION
(
"1 + 1"
,
GMOCK_PP_REMOVE_PARENS
((
1
+
1
)));
}
TEST
(
Macros
,
Increment
)
{
EXPECT_EXPANSION
(
"1"
,
GMOCK_PP_INC
(
0
));
EXPECT_EXPANSION
(
"2"
,
GMOCK_PP_INC
(
1
));
EXPECT_EXPANSION
(
"3"
,
GMOCK_PP_INC
(
2
));
EXPECT_EXPANSION
(
"4"
,
GMOCK_PP_INC
(
3
));
EXPECT_EXPANSION
(
"5"
,
GMOCK_PP_INC
(
4
));
EXPECT_EXPANSION
(
"16"
,
GMOCK_PP_INC
(
15
));
}
#define JOINER_CAT(a, b) a##b
#define JOINER(_N, _Data, _Elem) JOINER_CAT(_Data, _N) = _Elem
TEST
(
Macros
,
Repeat
)
{
EXPECT_EXPANSION
(
""
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
0
));
EXPECT_EXPANSION
(
"X0="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
1
));
EXPECT_EXPANSION
(
"X0= X1="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
2
));
EXPECT_EXPANSION
(
"X0= X1= X2="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
3
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
4
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3= X4="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
5
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3= X4= X5="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
6
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3= X4= X5= X6="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
7
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3= X4= X5= X6= X7="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
8
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3= X4= X5= X6= X7= X8="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
9
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3= X4= X5= X6= X7= X8= X9="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
10
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3= X4= X5= X6= X7= X8= X9= X10="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
11
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3= X4= X5= X6= X7= X8= X9= X10= X11="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
12
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3= X4= X5= X6= X7= X8= X9= X10= X11= X12="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
13
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3= X4= X5= X6= X7= X8= X9= X10= X11= X12= X13="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
14
));
EXPECT_EXPANSION
(
"X0= X1= X2= X3= X4= X5= X6= X7= X8= X9= X10= X11= X12= X13= X14="
,
GMOCK_PP_REPEAT
(
JOINER
,
X
,
15
));
}
TEST
(
Macros
,
ForEach
)
{
EXPECT_EXPANSION
(
""
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
()));
EXPECT_EXPANSION
(
"X0=a"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
)));
EXPECT_EXPANSION
(
"X0=a X1=b"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d X4=e"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
,
e
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d X4=e X5=f"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
,
e
,
f
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
,
e
,
f
,
g
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
,
j
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j X10=k"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
,
j
,
k
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j X10=k X11=l"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
,
j
,
k
,
l
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j X10=k X11=l X12=m"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
,
j
,
k
,
l
,
m
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j X10=k X11=l X12=m "
"X13=n"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
,
j
,
k
,
l
,
m
,
n
)));
EXPECT_EXPANSION
(
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j X10=k X11=l X12=m "
"X13=n X14=o"
,
GMOCK_PP_FOR_EACH
(
JOINER
,
X
,
(
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
,
j
,
k
,
l
,
m
,
n
,
o
)));
}
}
// namespace
}
// namespace testing
googlemock/test/gmock-pp_test.cc
0 → 100644
View file @
25905b9f
#include "gmock/internal/gmock-pp.h"
// Static assertions.
namespace
testing
{
namespace
internal
{
namespace
gmockpp
{
static_assert
(
GMOCK_PP_CAT
(
1
,
4
)
==
14
,
""
);
static_assert
(
GMOCK_PP_INTERNAL_INTERNAL_16TH
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
)
==
16
,
""
);
static_assert
(
GMOCK_PP_NARG
()
==
1
,
""
);
static_assert
(
GMOCK_PP_NARG
(
x
)
==
1
,
""
);
static_assert
(
GMOCK_PP_NARG
(
x
,
y
)
==
2
,
""
);
static_assert
(
GMOCK_PP_NARG
(
x
,
y
,
z
)
==
3
,
""
);
static_assert
(
GMOCK_PP_NARG
(
x
,
y
,
z
,
w
)
==
4
,
""
);
static_assert
(
!
GMOCK_PP_HAS_COMMA
(),
""
);
static_assert
(
GMOCK_PP_HAS_COMMA
(
b
,
),
""
);
static_assert
(
!
GMOCK_PP_HAS_COMMA
((,
)),
""
);
static_assert
(
!
GMOCK_PP_IS_EMPTY
(,
),
""
);
static_assert
(
!
GMOCK_PP_IS_EMPTY
(
a
),
""
);
static_assert
(
!
GMOCK_PP_IS_EMPTY
(()),
""
);
static_assert
(
GMOCK_PP_IF
(
1
,
1
,
2
)
==
1
,
""
);
static_assert
(
GMOCK_PP_IF
(
0
,
1
,
2
)
==
2
,
""
);
static_assert
(
GMOCK_PP_NARG0
(
x
)
==
1
,
""
);
static_assert
(
GMOCK_PP_NARG0
(
x
,
y
)
==
2
,
""
);
static_assert
(
GMOCK_PP_HEAD
(
1
)
==
1
,
""
);
static_assert
(
GMOCK_PP_HEAD
(
1
,
2
)
==
1
,
""
);
static_assert
(
GMOCK_PP_HEAD
(
1
,
2
,
3
)
==
1
,
""
);
static_assert
(
GMOCK_PP_TAIL
(
1
,
2
)
==
2
,
""
);
static_assert
(
GMOCK_PP_HEAD
(
GMOCK_PP_TAIL
(
1
,
2
,
3
))
==
2
,
""
);
static_assert
(
!
GMOCK_PP_IS_BEGIN_PARENS
(
sss
),
""
);
static_assert
(
!
GMOCK_PP_IS_BEGIN_PARENS
(
sss
()),
""
);
static_assert
(
!
GMOCK_PP_IS_BEGIN_PARENS
(
sss
()
sss
),
""
);
static_assert
(
GMOCK_PP_IS_BEGIN_PARENS
((
sss
)),
""
);
static_assert
(
GMOCK_PP_IS_BEGIN_PARENS
((
sss
)
ss
),
""
);
static_assert
(
!
GMOCK_PP_IS_ENCLOSED_PARENS
(
sss
),
""
);
static_assert
(
!
GMOCK_PP_IS_ENCLOSED_PARENS
(
sss
()),
""
);
static_assert
(
!
GMOCK_PP_IS_ENCLOSED_PARENS
(
sss
()
sss
),
""
);
static_assert
(
!
GMOCK_PP_IS_ENCLOSED_PARENS
((
sss
)
ss
),
""
);
static_assert
(
GMOCK_PP_REMOVE_PARENS
((
1
+
1
))
*
2
==
3
,
""
);
static_assert
(
GMOCK_PP_INC
(
4
)
==
5
,
""
);
template
<
class
...
Args
>
struct
Test
{
static
constexpr
int
kArgs
=
sizeof
...(
Args
);
};
#define GMOCK_PP_INTERNAL_TYPE_TEST(_i, _Data, _element) \
GMOCK_PP_COMMA_IF(_i) _element
static_assert
(
Test
<
GMOCK_PP_FOR_EACH
(
GMOCK_PP_INTERNAL_TYPE_TEST
,
~
,
(
int
,
float
,
double
,
char
))
>::
kArgs
==
4
,
""
);
#define GMOCK_PP_INTERNAL_VAR_TEST_1(_x) 1
#define GMOCK_PP_INTERNAL_VAR_TEST_2(_x, _y) 2
#define GMOCK_PP_INTERNAL_VAR_TEST_3(_x, _y, _z) 3
#define GMOCK_PP_INTERNAL_VAR_TEST(...) \
GMOCK_PP_VARIADIC_CALL(GMOCK_PP_INTERNAL_VAR_TEST_, __VA_ARGS__)
static_assert
(
GMOCK_PP_INTERNAL_VAR_TEST
(
x
,
y
)
==
2
,
""
);
static_assert
(
GMOCK_PP_INTERNAL_VAR_TEST
(
silly
)
==
1
,
""
);
static_assert
(
GMOCK_PP_INTERNAL_VAR_TEST
(
x
,
y
,
z
)
==
3
,
""
);
// TODO(iserna): The following asserts fail in --config=lexan.
#define GMOCK_PP_INTERNAL_IS_EMPTY_TEST_1
static_assert
(
GMOCK_PP_IS_EMPTY
(
GMOCK_PP_INTERNAL_IS_EMPTY_TEST_1
),
""
);
static_assert
(
GMOCK_PP_IS_EMPTY
(),
""
);
static_assert
(
GMOCK_PP_IS_ENCLOSED_PARENS
((
sss
)),
""
);
static_assert
(
GMOCK_PP_IS_EMPTY
(
GMOCK_PP_TAIL
(
1
)),
""
);
static_assert
(
GMOCK_PP_NARG0
()
==
0
,
""
);
}
// namespace gmockpp
}
// namespace internal
}
// namespace testing
googlemock/test/gmock-spec-builders_test.cc
View file @
25905b9f
...
...
@@ -34,6 +34,7 @@
#include "gmock/gmock-spec-builders.h"
#include <memory>
#include <ostream> // NOLINT
#include <sstream>
#include <string>
...
...
@@ -99,7 +100,6 @@ using testing::internal::kFail;
using
testing
::
internal
::
kInfoVerbosity
;
using
testing
::
internal
::
kWarn
;
using
testing
::
internal
::
kWarningVerbosity
;
using
testing
::
internal
::
linked_ptr
;
#if GTEST_HAS_STREAM_REDIRECTION
using
testing
::
HasSubstr
;
...
...
@@ -172,7 +172,7 @@ class ReferenceHoldingMock {
public:
ReferenceHoldingMock
()
{}
MOCK_METHOD1
(
AcceptReference
,
void
(
link
ed_ptr
<
MockA
>*
));
MOCK_METHOD1
(
AcceptReference
,
void
(
std
::
shar
ed_ptr
<
MockA
>*
));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
ReferenceHoldingMock
);
...
...
@@ -1952,17 +1952,17 @@ TEST(DeletingMockEarlyTest, Failure2) {
class
EvenNumberCardinality
:
public
CardinalityInterface
{
public:
// Returns true iff call_count calls will satisfy this cardinality.
virtual
bool
IsSatisfiedByCallCount
(
int
call_count
)
const
{
bool
IsSatisfiedByCallCount
(
int
call_count
)
const
override
{
return
call_count
%
2
==
0
;
}
// Returns true iff call_count calls will saturate this cardinality.
virtual
bool
IsSaturatedByCallCount
(
int
/* call_count */
)
const
{
bool
IsSaturatedByCallCount
(
int
/* call_count */
)
const
override
{
return
false
;
}
// Describes self to an ostream.
virtual
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
override
{
*
os
<<
"called even number of times"
;
}
};
...
...
@@ -2023,7 +2023,9 @@ class VerboseFlagPreservingFixture : public testing::Test {
VerboseFlagPreservingFixture
()
:
saved_verbose_flag_
(
GMOCK_FLAG
(
verbose
))
{}
~
VerboseFlagPreservingFixture
()
{
GMOCK_FLAG
(
verbose
)
=
saved_verbose_flag_
;
}
~
VerboseFlagPreservingFixture
()
override
{
GMOCK_FLAG
(
verbose
)
=
saved_verbose_flag_
;
}
private:
const
std
::
string
saved_verbose_flag_
;
...
...
@@ -2619,7 +2621,7 @@ TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) {
TEST
(
VerifyAndClearTest
,
DestroyingChainedMocksDoesNotDeadlockThroughExpectations
)
{
link
ed_ptr
<
MockA
>
a
(
new
MockA
);
std
::
shar
ed_ptr
<
MockA
>
a
(
new
MockA
);
ReferenceHoldingMock
test_mock
;
// EXPECT_CALL stores a reference to a inside test_mock.
...
...
@@ -2639,7 +2641,7 @@ TEST(VerifyAndClearTest,
TEST
(
VerifyAndClearTest
,
DestroyingChainedMocksDoesNotDeadlockThroughDefaultAction
)
{
link
ed_ptr
<
MockA
>
a
(
new
MockA
);
std
::
shar
ed_ptr
<
MockA
>
a
(
new
MockA
);
ReferenceHoldingMock
test_mock
;
// ON_CALL stores a reference to a inside test_mock.
...
...
googlemock/test/gmock_link_test.h
View file @
25905b9f
...
...
@@ -414,7 +414,7 @@ TEST(LinkTest, TestThrow) {
Mock
mock
;
EXPECT_CALL
(
mock
,
VoidFromString
(
_
)).
WillOnce
(
Throw
(
42
));
EXPECT_THROW
(
mock
.
VoidFromString
(
NULL
),
int
);
EXPECT_THROW
(
mock
.
VoidFromString
(
nullptr
),
int
);
}
#endif // GTEST_HAS_EXCEPTIONS
...
...
googlemock/test/gmock_stress_test.cc
View file @
25905b9f
...
...
@@ -60,87 +60,8 @@ void JoinAndDelete(ThreadWithParam<T>* t) {
delete
t
;
}
using
internal
::
linked_ptr
;
// Helper classes for testing using linked_ptr concurrently.
class
Base
{
public:
explicit
Base
(
int
a_x
)
:
x_
(
a_x
)
{}
virtual
~
Base
()
{}
int
x
()
const
{
return
x_
;
}
private:
int
x_
;
};
class
Derived1
:
public
Base
{
public:
Derived1
(
int
a_x
,
int
a_y
)
:
Base
(
a_x
),
y_
(
a_y
)
{}
int
y
()
const
{
return
y_
;
}
private:
int
y_
;
};
class
Derived2
:
public
Base
{
public:
Derived2
(
int
a_x
,
int
a_z
)
:
Base
(
a_x
),
z_
(
a_z
)
{}
int
z
()
const
{
return
z_
;
}
private:
int
z_
;
};
linked_ptr
<
Derived1
>
pointer1
(
new
Derived1
(
1
,
2
));
linked_ptr
<
Derived2
>
pointer2
(
new
Derived2
(
3
,
4
));
struct
Dummy
{};
// Tests that we can copy from a linked_ptr and read it concurrently.
void
TestConcurrentCopyAndReadLinkedPtr
(
Dummy
/* dummy */
)
{
// Reads pointer1 and pointer2 while they are being copied from in
// another thread.
EXPECT_EQ
(
1
,
pointer1
->
x
());
EXPECT_EQ
(
2
,
pointer1
->
y
());
EXPECT_EQ
(
3
,
pointer2
->
x
());
EXPECT_EQ
(
4
,
pointer2
->
z
());
// Copies from pointer1.
linked_ptr
<
Derived1
>
p1
(
pointer1
);
EXPECT_EQ
(
1
,
p1
->
x
());
EXPECT_EQ
(
2
,
p1
->
y
());
// Assigns from pointer2 where the LHS was empty.
linked_ptr
<
Base
>
p2
;
p2
=
pointer1
;
EXPECT_EQ
(
1
,
p2
->
x
());
// Assigns from pointer2 where the LHS was not empty.
p2
=
pointer2
;
EXPECT_EQ
(
3
,
p2
->
x
());
}
const
linked_ptr
<
Derived1
>
p0
(
new
Derived1
(
1
,
2
));
// Tests that we can concurrently modify two linked_ptrs that point to
// the same object.
void
TestConcurrentWriteToEqualLinkedPtr
(
Dummy
/* dummy */
)
{
// p1 and p2 point to the same, shared thing. One thread resets p1.
// Another thread assigns to p2. This will cause the same
// underlying "ring" to be updated concurrently.
linked_ptr
<
Derived1
>
p1
(
p0
);
linked_ptr
<
Derived1
>
p2
(
p0
);
EXPECT_EQ
(
1
,
p1
->
x
());
EXPECT_EQ
(
2
,
p1
->
y
());
EXPECT_EQ
(
1
,
p2
->
x
());
EXPECT_EQ
(
2
,
p2
->
y
());
p1
.
reset
();
p2
=
p0
;
EXPECT_EQ
(
1
,
p2
->
x
());
EXPECT_EQ
(
2
,
p2
->
y
());
}
// Tests that different mock objects can be used in their respective
// threads. This should generate no Google Test failure.
...
...
@@ -275,8 +196,6 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) {
// Tests using Google Mock constructs in many threads concurrently.
TEST
(
StressTest
,
CanUseGMockWithThreads
)
{
void
(
*
test_routines
[])(
Dummy
dummy
)
=
{
&
TestConcurrentCopyAndReadLinkedPtr
,
&
TestConcurrentWriteToEqualLinkedPtr
,
&
TestConcurrentMockObjects
,
&
TestConcurrentCallsOnSameObject
,
&
TestPartiallyOrderedExpectationsWithThreads
,
...
...
googletest/CMakeLists.txt
View file @
25905b9f
...
...
@@ -110,18 +110,6 @@ set(gtest_build_include_dirs
"
${
gtest_SOURCE_DIR
}
"
)
include_directories
(
${
gtest_build_include_dirs
}
)
# Summary of tuple support for Microsoft Visual Studio:
# Compiler version(MS) version(cmake) Support
# ---------- ----------- -------------- -----------------------------
# <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple.
# VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10
# VS 2013 12 1800 std::tr1::tuple
# VS 2015 14 1900 std::tuple
# VS 2017 15 >= 1910 std::tuple
if
(
MSVC AND MSVC_VERSION EQUAL 1700
)
add_definitions
(
/D _VARIADIC_MAX=10
)
endif
()
########################################################################
#
# Defines the gtest & gtest_main libraries. User tests should link
...
...
@@ -207,7 +195,6 @@ $env:Path = \"$project_bin;$env:Path\"
cxx_test
(
googletest-death-test-test gtest_main
)
cxx_test
(
gtest_environment_test gtest
)
cxx_test
(
googletest-filepath-test gtest_main
)
cxx_test
(
googletest-linked-ptr-test gtest_main
)
cxx_test
(
googletest-listener-test gtest_main
)
cxx_test
(
gtest_main_unittest gtest_main
)
cxx_test
(
googletest-message-test gtest_main
)
...
...
@@ -265,21 +252,6 @@ $env:Path = \"$project_bin;$env:Path\"
PROPERTIES
COMPILE_DEFINITIONS
"GTEST_LINKED_AS_SHARED_LIBRARY=1"
)
if
(
NOT MSVC OR MSVC_VERSION LESS 1600
)
# 1600 is Visual Studio 2010.
# Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
# conflict with our own definitions. Therefore using our own tuple does not
# work on those compilers.
cxx_library
(
gtest_main_use_own_tuple
"
${
cxx_use_own_tuple
}
"
src/gtest-all.cc src/gtest_main.cc
)
cxx_test_with_flags
(
googletest-tuple-test
"
${
cxx_use_own_tuple
}
"
gtest_main_use_own_tuple test/googletest-tuple-test.cc
)
cxx_test_with_flags
(
gtest_use_own_tuple_test
"
${
cxx_use_own_tuple
}
"
gtest_main_use_own_tuple
test/googletest-param-test-test.cc test/googletest-param-test2-test.cc
)
endif
()
############################################################
# Python tests.
...
...
Prev
1
2
3
4
5
6
7
8
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