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
1246e580
Unverified
Commit
1246e580
authored
Aug 15, 2018
by
Gennadiy Civil
Committed by
GitHub
Aug 15, 2018
Browse files
Merge branch 'master' into cleanup-cmake
parents
4b6a7a49
2172c08c
Changes
217
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
563 additions
and
300 deletions
+563
-300
googlemock/src/gmock-internal-utils.cc
googlemock/src/gmock-internal-utils.cc
+4
-3
googlemock/src/gmock-matchers.cc
googlemock/src/gmock-matchers.cc
+1
-2
googlemock/src/gmock-spec-builders.cc
googlemock/src/gmock-spec-builders.cc
+18
-4
googlemock/src/gmock.cc
googlemock/src/gmock.cc
+2
-3
googlemock/src/gmock_main.cc
googlemock/src/gmock_main.cc
+3
-3
googlemock/test/gmock-actions_test.cc
googlemock/test/gmock-actions_test.cc
+161
-205
googlemock/test/gmock-cardinalities_test.cc
googlemock/test/gmock-cardinalities_test.cc
+1
-2
googlemock/test/gmock-generated-actions_test.cc
googlemock/test/gmock-generated-actions_test.cc
+9
-8
googlemock/test/gmock-generated-function-mockers_test.cc
googlemock/test/gmock-generated-function-mockers_test.cc
+24
-2
googlemock/test/gmock-generated-internal-utils_test.cc
googlemock/test/gmock-generated-internal-utils_test.cc
+12
-11
googlemock/test/gmock-generated-matchers_test.cc
googlemock/test/gmock-generated-matchers_test.cc
+59
-4
googlemock/test/gmock-internal-utils_test.cc
googlemock/test/gmock-internal-utils_test.cc
+1
-2
googlemock/test/gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+109
-18
googlemock/test/gmock-more-actions_test.cc
googlemock/test/gmock-more-actions_test.cc
+9
-11
googlemock/test/gmock-nice-strict_test.cc
googlemock/test/gmock-nice-strict_test.cc
+69
-5
googlemock/test/gmock-port_test.cc
googlemock/test/gmock-port_test.cc
+1
-2
googlemock/test/gmock-spec-builders_test.cc
googlemock/test/gmock-spec-builders_test.cc
+75
-4
googlemock/test/gmock_all_test.cc
googlemock/test/gmock_all_test.cc
+1
-2
googlemock/test/gmock_ex_test.cc
googlemock/test/gmock_ex_test.cc
+4
-5
googlemock/test/gmock_leak_test.py
googlemock/test/gmock_leak_test.py
+0
-4
No files found.
googlemock/src/gmock-internal-utils.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -188,7 +187,9 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message,
std
::
cout
<<
::
std
::
flush
;
}
void
IllegalDoDefault
(
const
char
*
file
,
int
line
)
{
GTEST_API_
WithoutMatchers
GetWithoutMatchers
()
{
return
WithoutMatchers
();
}
GTEST_API_
void
IllegalDoDefault
(
const
char
*
file
,
int
line
)
{
internal
::
Assert
(
false
,
file
,
line
,
"You are using DoDefault() inside a composite action like "
...
...
googlemock/src/gmock-matchers.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
googlemock/src/gmock-spec-builders.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -49,6 +48,15 @@
# include <unistd.h> // NOLINT
#endif
// Silence C4800 (C4800: 'int *const ': forcing value
// to bool 'true' or 'false') for MSVC 14,15
#ifdef _MSC_VER
#if _MSC_VER <= 1900
# pragma warning(push)
# pragma warning(disable:4800)
#endif
#endif
namespace
testing
{
namespace
internal
{
...
...
@@ -598,7 +606,7 @@ class MockObjectRegistry {
if
(
it
->
second
.
leakable
)
// The user said it's fine to leak this object.
continue
;
//
TODO(wan@google.com)
: Print the type of the leaked object.
//
FIXME
: Print the type of the leaked object.
// This can help the user identify the leaked object.
std
::
cout
<<
"
\n
"
;
const
MockObjectState
&
state
=
it
->
second
;
...
...
@@ -774,7 +782,7 @@ void Mock::RegisterUseByOnCallOrExpectCall(const void* mock_obj,
const
TestInfo
*
const
test_info
=
UnitTest
::
GetInstance
()
->
current_test_info
();
if
(
test_info
!=
NULL
)
{
//
TODO(wan@google.com)
: record the test case name when the
//
FIXME
: record the test case name when the
// ON_CALL or EXPECT_CALL is invoked from SetUpTestCase() or
// TearDownTestCase().
state
.
first_used_test_case
=
test_info
->
test_case_name
();
...
...
@@ -866,3 +874,9 @@ InSequence::~InSequence() {
}
}
// namespace testing
#ifdef _MSC_VER
#if _MSC_VER <= 1900
# pragma warning(pop)
#endif
#endif
googlemock/src/gmock.cc
View file @
1246e580
...
...
@@ -26,15 +26,14 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
#include "gmock/gmock.h"
#include "gmock/internal/gmock-port.h"
namespace
testing
{
//
TODO(wan@google.com)
: support using environment variables to
//
FIXME
: support using environment variables to
// control the flag values, like what Google Test does.
GMOCK_DEFINE_bool_
(
catch_leaked_mocks
,
true
,
...
...
googlemock/src/gmock_main.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
#include <iostream>
#include "gmock/gmock.h"
...
...
@@ -37,7 +36,8 @@
// causes a link error when _tmain is defined in a static library and UNICODE
// is enabled. For this reason instead of _tmain, main function is used on
// Windows. See the following link to track the current status of this bug:
// http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=394464 // NOLINT
// https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library
// // NOLINT
#if GTEST_OS_WINDOWS_MOBILE
# include <tchar.h> // NOLINT
...
...
googlemock/test/gmock-actions_test.cc
View file @
1246e580
...
...
@@ -26,13 +26,21 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
// This file tests the built-in actions.
// Silence C4800 (C4800: 'int *const ': forcing value
// to bool 'true' or 'false') for MSVC 14,15
#ifdef _MSC_VER
#if _MSC_VER <= 1900
# pragma warning(push)
# pragma warning(disable:4800)
#endif
#endif
#include "gmock/gmock-actions.h"
#include <algorithm>
#include <iterator>
...
...
@@ -65,6 +73,7 @@ using testing::ReturnRef;
using
testing
::
ReturnRefOfCopy
;
using
testing
::
SetArgPointee
;
using
testing
::
SetArgumentPointee
;
using
testing
::
Unused
;
using
testing
::
_
;
using
testing
::
get
;
using
testing
::
internal
::
BuiltInDefaultValue
;
...
...
@@ -78,10 +87,6 @@ using testing::tuple_element;
using
testing
::
SetErrnoAndReturn
;
#endif
#if GTEST_HAS_PROTOBUF_
using
testing
::
internal
::
TestMessage
;
#endif // GTEST_HAS_PROTOBUF_
// Tests that BuiltInDefaultValue<T*>::Get() returns NULL.
TEST
(
BuiltInDefaultValueTest
,
IsNullForPointerTypes
)
{
EXPECT_TRUE
(
BuiltInDefaultValue
<
int
*>::
Get
()
==
NULL
);
...
...
@@ -705,6 +710,8 @@ class MockClass {
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:
...
...
@@ -756,7 +763,7 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) {
}
// Tests that DoDefault() returns the default value set by
// DefaultValue<T>::Set() when it's not overrid
d
en by an ON_CALL().
// DefaultValue<T>::Set() when it's not overriden by an ON_CALL().
TEST
(
DoDefaultTest
,
ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne
)
{
DefaultValue
<
int
>::
Set
(
1
);
MockClass
mock
;
...
...
@@ -883,105 +890,6 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) {
# endif
}
#if GTEST_HAS_PROTOBUF_
// Tests that SetArgPointee<N>(proto_buffer) sets the v1 protobuf
// variable pointed to by the N-th (0-based) argument to proto_buffer.
TEST
(
SetArgPointeeTest
,
SetsTheNthPointeeOfProtoBufferType
)
{
TestMessage
*
const
msg
=
new
TestMessage
;
msg
->
set_member
(
"yes"
);
TestMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
TestMessage
*
)
>
a
=
SetArgPointee
<
1
>
(
*
msg
);
// SetArgPointee<N>(proto_buffer) makes a copy of proto_buffer
// s.t. the action works even when the original proto_buffer has
// died. We ensure this behavior by deleting msg before using the
// action.
delete
msg
;
TestMessage
dest
;
EXPECT_FALSE
(
orig_msg
.
Equals
(
dest
));
a
.
Perform
(
make_tuple
(
true
,
&
dest
));
EXPECT_TRUE
(
orig_msg
.
Equals
(
dest
));
}
// Tests that SetArgPointee<N>(proto_buffer) sets the
// ::ProtocolMessage variable pointed to by the N-th (0-based)
// argument to proto_buffer.
TEST
(
SetArgPointeeTest
,
SetsTheNthPointeeOfProtoBufferBaseType
)
{
TestMessage
*
const
msg
=
new
TestMessage
;
msg
->
set_member
(
"yes"
);
TestMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
::
ProtocolMessage
*
)
>
a
=
SetArgPointee
<
1
>
(
*
msg
);
// SetArgPointee<N>(proto_buffer) makes a copy of proto_buffer
// s.t. the action works even when the original proto_buffer has
// died. We ensure this behavior by deleting msg before using the
// action.
delete
msg
;
TestMessage
dest
;
::
ProtocolMessage
*
const
dest_base
=
&
dest
;
EXPECT_FALSE
(
orig_msg
.
Equals
(
dest
));
a
.
Perform
(
make_tuple
(
true
,
dest_base
));
EXPECT_TRUE
(
orig_msg
.
Equals
(
dest
));
}
// Tests that SetArgPointee<N>(proto2_buffer) sets the v2
// protobuf variable pointed to by the N-th (0-based) argument to
// proto2_buffer.
TEST
(
SetArgPointeeTest
,
SetsTheNthPointeeOfProto2BufferType
)
{
using
testing
::
internal
::
FooMessage
;
FooMessage
*
const
msg
=
new
FooMessage
;
msg
->
set_int_field
(
2
);
msg
->
set_string_field
(
"hi"
);
FooMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
FooMessage
*
)
>
a
=
SetArgPointee
<
1
>
(
*
msg
);
// SetArgPointee<N>(proto2_buffer) makes a copy of
// proto2_buffer s.t. the action works even when the original
// proto2_buffer has died. We ensure this behavior by deleting msg
// before using the action.
delete
msg
;
FooMessage
dest
;
dest
.
set_int_field
(
0
);
a
.
Perform
(
make_tuple
(
true
,
&
dest
));
EXPECT_EQ
(
2
,
dest
.
int_field
());
EXPECT_EQ
(
"hi"
,
dest
.
string_field
());
}
// Tests that SetArgPointee<N>(proto2_buffer) sets the
// proto2::Message variable pointed to by the N-th (0-based) argument
// to proto2_buffer.
TEST
(
SetArgPointeeTest
,
SetsTheNthPointeeOfProto2BufferBaseType
)
{
using
testing
::
internal
::
FooMessage
;
FooMessage
*
const
msg
=
new
FooMessage
;
msg
->
set_int_field
(
2
);
msg
->
set_string_field
(
"hi"
);
FooMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
::
proto2
::
Message
*
)
>
a
=
SetArgPointee
<
1
>
(
*
msg
);
// SetArgPointee<N>(proto2_buffer) makes a copy of
// proto2_buffer s.t. the action works even when the original
// proto2_buffer has died. We ensure this behavior by deleting msg
// before using the action.
delete
msg
;
FooMessage
dest
;
dest
.
set_int_field
(
0
);
::
proto2
::
Message
*
const
dest_base
=
&
dest
;
a
.
Perform
(
make_tuple
(
true
,
dest_base
));
EXPECT_EQ
(
2
,
dest
.
int_field
());
EXPECT_EQ
(
"hi"
,
dest
.
string_field
());
}
#endif // GTEST_HAS_PROTOBUF_
// Tests that SetArgumentPointee<N>(v) sets the variable pointed to by
// the N-th (0-based) argument to v.
TEST
(
SetArgumentPointeeTest
,
SetsTheNthPointee
)
{
...
...
@@ -1002,105 +910,6 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointee) {
EXPECT_EQ
(
'a'
,
ch
);
}
#if GTEST_HAS_PROTOBUF_
// Tests that SetArgumentPointee<N>(proto_buffer) sets the v1 protobuf
// variable pointed to by the N-th (0-based) argument to proto_buffer.
TEST
(
SetArgumentPointeeTest
,
SetsTheNthPointeeOfProtoBufferType
)
{
TestMessage
*
const
msg
=
new
TestMessage
;
msg
->
set_member
(
"yes"
);
TestMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
TestMessage
*
)
>
a
=
SetArgumentPointee
<
1
>
(
*
msg
);
// SetArgumentPointee<N>(proto_buffer) makes a copy of proto_buffer
// s.t. the action works even when the original proto_buffer has
// died. We ensure this behavior by deleting msg before using the
// action.
delete
msg
;
TestMessage
dest
;
EXPECT_FALSE
(
orig_msg
.
Equals
(
dest
));
a
.
Perform
(
make_tuple
(
true
,
&
dest
));
EXPECT_TRUE
(
orig_msg
.
Equals
(
dest
));
}
// Tests that SetArgumentPointee<N>(proto_buffer) sets the
// ::ProtocolMessage variable pointed to by the N-th (0-based)
// argument to proto_buffer.
TEST
(
SetArgumentPointeeTest
,
SetsTheNthPointeeOfProtoBufferBaseType
)
{
TestMessage
*
const
msg
=
new
TestMessage
;
msg
->
set_member
(
"yes"
);
TestMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
::
ProtocolMessage
*
)
>
a
=
SetArgumentPointee
<
1
>
(
*
msg
);
// SetArgumentPointee<N>(proto_buffer) makes a copy of proto_buffer
// s.t. the action works even when the original proto_buffer has
// died. We ensure this behavior by deleting msg before using the
// action.
delete
msg
;
TestMessage
dest
;
::
ProtocolMessage
*
const
dest_base
=
&
dest
;
EXPECT_FALSE
(
orig_msg
.
Equals
(
dest
));
a
.
Perform
(
make_tuple
(
true
,
dest_base
));
EXPECT_TRUE
(
orig_msg
.
Equals
(
dest
));
}
// Tests that SetArgumentPointee<N>(proto2_buffer) sets the v2
// protobuf variable pointed to by the N-th (0-based) argument to
// proto2_buffer.
TEST
(
SetArgumentPointeeTest
,
SetsTheNthPointeeOfProto2BufferType
)
{
using
testing
::
internal
::
FooMessage
;
FooMessage
*
const
msg
=
new
FooMessage
;
msg
->
set_int_field
(
2
);
msg
->
set_string_field
(
"hi"
);
FooMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
FooMessage
*
)
>
a
=
SetArgumentPointee
<
1
>
(
*
msg
);
// SetArgumentPointee<N>(proto2_buffer) makes a copy of
// proto2_buffer s.t. the action works even when the original
// proto2_buffer has died. We ensure this behavior by deleting msg
// before using the action.
delete
msg
;
FooMessage
dest
;
dest
.
set_int_field
(
0
);
a
.
Perform
(
make_tuple
(
true
,
&
dest
));
EXPECT_EQ
(
2
,
dest
.
int_field
());
EXPECT_EQ
(
"hi"
,
dest
.
string_field
());
}
// Tests that SetArgumentPointee<N>(proto2_buffer) sets the
// proto2::Message variable pointed to by the N-th (0-based) argument
// to proto2_buffer.
TEST
(
SetArgumentPointeeTest
,
SetsTheNthPointeeOfProto2BufferBaseType
)
{
using
testing
::
internal
::
FooMessage
;
FooMessage
*
const
msg
=
new
FooMessage
;
msg
->
set_int_field
(
2
);
msg
->
set_string_field
(
"hi"
);
FooMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
::
proto2
::
Message
*
)
>
a
=
SetArgumentPointee
<
1
>
(
*
msg
);
// SetArgumentPointee<N>(proto2_buffer) makes a copy of
// proto2_buffer s.t. the action works even when the original
// proto2_buffer has died. We ensure this behavior by deleting msg
// before using the action.
delete
msg
;
FooMessage
dest
;
dest
.
set_int_field
(
0
);
::
proto2
::
Message
*
const
dest_base
=
&
dest
;
a
.
Perform
(
make_tuple
(
true
,
dest_base
));
EXPECT_EQ
(
2
,
dest
.
int_field
());
EXPECT_EQ
(
"hi"
,
dest
.
string_field
());
}
#endif // GTEST_HAS_PROTOBUF_
// Sample functions and functors for testing Invoke() and etc.
int
Nullary
()
{
return
1
;
}
...
...
@@ -1411,6 +1220,153 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) {
EXPECT_EQ
(
7
,
*
vresult
[
0
]);
}
TEST
(
MockMethodTest
,
CanTakeMoveOnlyValue
)
{
MockClass
mock
;
auto
make
=
[](
int
i
)
{
return
std
::
unique_ptr
<
int
>
(
new
int
(
i
));
};
EXPECT_CALL
(
mock
,
TakeUnique
(
_
)).
WillRepeatedly
([](
std
::
unique_ptr
<
int
>
i
)
{
return
*
i
;
});
// DoAll() does not compile, since it would move from its arguments twice.
// EXPECT_CALL(mock, TakeUnique(_, _))
// .WillRepeatedly(DoAll(Invoke([](std::unique_ptr<int> j) {}),
// Return(1)));
EXPECT_CALL
(
mock
,
TakeUnique
(
testing
::
Pointee
(
7
)))
.
WillOnce
(
Return
(
-
7
))
.
RetiresOnSaturation
();
EXPECT_CALL
(
mock
,
TakeUnique
(
testing
::
IsNull
()))
.
WillOnce
(
Return
(
-
1
))
.
RetiresOnSaturation
();
EXPECT_EQ
(
5
,
mock
.
TakeUnique
(
make
(
5
)));
EXPECT_EQ
(
-
7
,
mock
.
TakeUnique
(
make
(
7
)));
EXPECT_EQ
(
7
,
mock
.
TakeUnique
(
make
(
7
)));
EXPECT_EQ
(
7
,
mock
.
TakeUnique
(
make
(
7
)));
EXPECT_EQ
(
-
1
,
mock
.
TakeUnique
({}));
// Some arguments are moved, some passed by reference.
auto
lvalue
=
make
(
6
);
EXPECT_CALL
(
mock
,
TakeUnique
(
_
,
_
))
.
WillOnce
([](
const
std
::
unique_ptr
<
int
>&
i
,
std
::
unique_ptr
<
int
>
j
)
{
return
*
i
*
*
j
;
});
EXPECT_EQ
(
42
,
mock
.
TakeUnique
(
lvalue
,
make
(
7
)));
// The unique_ptr can be saved by the action.
std
::
unique_ptr
<
int
>
saved
;
EXPECT_CALL
(
mock
,
TakeUnique
(
_
)).
WillOnce
([
&
saved
](
std
::
unique_ptr
<
int
>
i
)
{
saved
=
std
::
move
(
i
);
return
0
;
});
EXPECT_EQ
(
0
,
mock
.
TakeUnique
(
make
(
42
)));
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
int
result
=
val
+
ref
+
*
ptr
;
ref
=
42
;
*
ptr
=
43
;
return
result
;
}
int
Deref
(
std
::
unique_ptr
<
int
>
ptr
)
{
return
*
ptr
;
}
struct
Double
{
template
<
typename
T
>
T
operator
()(
T
t
)
{
return
2
*
t
;
}
};
std
::
unique_ptr
<
int
>
UniqueInt
(
int
i
)
{
return
std
::
unique_ptr
<
int
>
(
new
int
(
i
));
}
TEST
(
FunctorActionTest
,
ActionFromFunction
)
{
Action
<
int
(
int
,
int
&
,
int
*
)
>
a
=
&
Add
;
int
x
=
1
,
y
=
2
,
z
=
3
;
EXPECT_EQ
(
6
,
a
.
Perform
(
std
::
forward_as_tuple
(
x
,
y
,
&
z
)));
EXPECT_EQ
(
42
,
y
);
EXPECT_EQ
(
43
,
z
);
Action
<
int
(
std
::
unique_ptr
<
int
>
)
>
a1
=
&
Deref
;
EXPECT_EQ
(
7
,
a1
.
Perform
(
std
::
make_tuple
(
UniqueInt
(
7
))));
}
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
)));
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
)));
EXPECT_EQ
(
5
,
*
saved
);
}
TEST
(
FunctorActionTest
,
PolymorphicFunctor
)
{
Action
<
int
(
int
)
>
ai
=
Double
();
EXPECT_EQ
(
2
,
ai
.
Perform
(
make_tuple
(
1
)));
Action
<
double
(
double
)
>
ad
=
Double
();
// Double? Double double!
EXPECT_EQ
(
3.0
,
ad
.
Perform
(
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
)));
// 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"
)));
// Also between the lambda and the action itself.
const
Action
<
bool
(
std
::
string
)
>
x
=
[](
Unused
)
{
return
42
;
};
EXPECT_TRUE
(
x
.
Perform
(
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
);
EXPECT_EQ
(
6
,
a
.
Perform
(
dummy
));
}
// Test that basic built-in actions work with move-only arguments.
// FIXME: Currently, almost all ActionInterface-based actions will not
// work, even if they only try to use other, copyable arguments. Implement them
// if necessary (but note that DoAll cannot work on non-copyable types anyway -
// 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
)));
a
=
testing
::
WithoutArgs
([]()
{
return
7
;
});
EXPECT_EQ
(
7
,
a
.
Perform
(
make_tuple
(
nullptr
)));
Action
<
void
(
std
::
unique_ptr
<
int
>
,
int
*
)
>
a2
=
testing
::
SetArgPointee
<
1
>
(
3
);
int
x
=
0
;
a2
.
Perform
(
make_tuple
(
nullptr
,
&
x
));
EXPECT_EQ
(
x
,
3
);
}
#endif // GTEST_LANG_CXX11
}
// Unnamed namespace
#ifdef _MSC_VER
#if _MSC_VER == 1900
# pragma warning(pop)
#endif
#endif
googlemock/test/gmock-cardinalities_test.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
googlemock/test/gmock-generated-actions_test.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -374,10 +373,10 @@ class SubstractAction : public ActionInterface<int(int, int)> { // NOLINT
};
TEST
(
WithArgsTest
,
NonInvokeAction
)
{
Action
<
int
(
const
string
&
,
int
,
int
)
>
a
=
// NOLINT
Action
<
int
(
const
std
::
string
&
,
int
,
int
)
>
a
=
// NOLINT
WithArgs
<
2
,
1
>
(
MakeAction
(
new
SubstractAction
));
string
s
(
"hello"
);
EXPECT_EQ
(
8
,
a
.
Perform
(
tuple
<
const
string
&
,
int
,
int
>
(
s
,
2
,
10
)
));
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.
...
...
@@ -754,7 +753,8 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) {
TEST
(
ActionPMacroTest
,
WorksInCompatibleMockFunction
)
{
Action
<
std
::
string
(
const
std
::
string
&
s
)
>
a1
=
Plus
(
"tail"
);
const
std
::
string
re
=
"re"
;
EXPECT_EQ
(
"retail"
,
a1
.
Perform
(
tuple
<
const
std
::
string
&>
(
re
)));
tuple
<
const
std
::
string
>
dummy
=
make_tuple
(
re
);
EXPECT_EQ
(
"retail"
,
a1
.
Perform
(
dummy
));
}
// Tests that we can use ACTION*() to define actions overloaded on the
...
...
@@ -796,7 +796,8 @@ TEST(ActionPnMacroTest, WorksFor3Parameters) {
Action
<
std
::
string
(
const
std
::
string
&
s
)
>
a2
=
Plus
(
"tail"
,
"-"
,
">"
);
const
std
::
string
re
=
"re"
;
EXPECT_EQ
(
"retail->"
,
a2
.
Perform
(
tuple
<
const
std
::
string
&>
(
re
)));
tuple
<
const
std
::
string
>
dummy
=
make_tuple
(
re
);
EXPECT_EQ
(
"retail->"
,
a2
.
Perform
(
dummy
));
}
ACTION_P4
(
Plus
,
p0
,
p1
,
p2
,
p3
)
{
return
arg0
+
p0
+
p1
+
p2
+
p3
;
}
...
...
@@ -1120,7 +1121,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) {
EXPECT_FALSE
(
b
);
// Verifies that resetter is deleted.
}
// Tests that ACTION_TEMPLATE works for
a
template
with
template parameters.
// Tests that ACTION_TEMPLATE
S
works for template template parameters.
ACTION_TEMPLATE
(
ReturnSmartPointer
,
HAS_1_TEMPLATE_PARAMS
(
template
<
typename
Pointee
>
class
,
Pointer
),
...
...
googlemock/test/gmock-generated-function-mockers_test.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -620,5 +619,28 @@ TEST(MockFunctionTest, AsStdFunctionReturnsReference) {
}
#endif // GTEST_HAS_STD_FUNCTION_
struct
MockMethodSizes0
{
MOCK_METHOD0
(
func
,
void
());
};
struct
MockMethodSizes1
{
MOCK_METHOD1
(
func
,
void
(
int
));
};
struct
MockMethodSizes2
{
MOCK_METHOD2
(
func
,
void
(
int
,
int
));
};
struct
MockMethodSizes3
{
MOCK_METHOD3
(
func
,
void
(
int
,
int
,
int
));
};
struct
MockMethodSizes4
{
MOCK_METHOD4
(
func
,
void
(
int
,
int
,
int
,
int
));
};
TEST
(
MockFunctionTest
,
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_generated_function_mockers_test
}
// namespace testing
googlemock/test/gmock-generated-internal-utils_test.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -63,10 +62,10 @@ TEST(MatcherTupleTest, ForSize2) {
}
TEST
(
MatcherTupleTest
,
ForSize5
)
{
CompileAssertTypesEqual
<
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
double
>
,
Matcher
<
char
*>
>
,
Matcher
Tuple
<
tuple
<
int
,
char
,
bool
,
double
,
char
*>
>::
type
>
();
CompileAssertTypesEqual
<
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
double
>
,
Matcher
<
char
*>
>
,
MatcherTuple
<
tuple
<
int
,
char
,
bool
,
double
,
char
*>
>::
type
>
();
}
// Tests the Function template struct.
...
...
@@ -97,8 +96,9 @@ TEST(FunctionTest, Binary) {
CompileAssertTypesEqual
<
bool
,
F
::
Argument1
>
();
CompileAssertTypesEqual
<
const
long
&
,
F
::
Argument2
>
();
// NOLINT
CompileAssertTypesEqual
<
tuple
<
bool
,
const
long
&>
,
F
::
ArgumentTuple
>
();
// NOLINT
CompileAssertTypesEqual
<
tuple
<
Matcher
<
bool
>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
tuple
<
Matcher
<
bool
>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
,
const
long
&
),
F
::
MakeResultVoid
>
();
// NOLINT
CompileAssertTypesEqual
<
IgnoredValue
(
bool
,
const
long
&
),
// NOLINT
F
::
MakeResultIgnoredValue
>
();
...
...
@@ -114,9 +114,10 @@ TEST(FunctionTest, LongArgumentList) {
CompileAssertTypesEqual
<
const
long
&
,
F
::
Argument5
>
();
// NOLINT
CompileAssertTypesEqual
<
tuple
<
bool
,
int
,
char
*
,
int
&
,
const
long
&>
,
// NOLINT
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
tuple
<
Matcher
<
bool
>
,
Matcher
<
int
>
,
Matcher
<
char
*>
,
Matcher
<
int
&>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
tuple
<
Matcher
<
bool
>
,
Matcher
<
int
>
,
Matcher
<
char
*>
,
Matcher
<
int
&>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
,
int
,
char
*
,
int
&
,
const
long
&
),
// NOLINT
F
::
MakeResultVoid
>
();
CompileAssertTypesEqual
<
...
...
googlemock/test/gmock-generated-matchers_test.cc
View file @
1246e580
...
...
@@ -31,10 +31,19 @@
//
// This file tests the built-in matchers generated by a script.
// Silence warning C4244: 'initializing': conversion from 'int' to 'short',
// possible loss of data and C4100, unreferenced local parameter
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable:4244)
# pragma warning(disable:4100)
#endif
#include "gmock/gmock-generated-matchers.h"
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
...
...
@@ -57,6 +66,8 @@ using testing::get;
using
testing
::
make_tuple
;
using
testing
::
tuple
;
using
testing
::
_
;
using
testing
::
AllOf
;
using
testing
::
AnyOf
;
using
testing
::
Args
;
using
testing
::
Contains
;
using
testing
::
ElementsAre
;
...
...
@@ -120,7 +131,7 @@ TEST(ArgsTest, AcceptsOneTemplateArg) {
}
TEST
(
ArgsTest
,
AcceptsTwoTemplateArgs
)
{
const
tuple
<
short
,
int
,
long
>
t
(
static_cast
<
short
>
(
4
)
,
5
,
6L
);
// NOLINT
const
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
0
,
1
>
(
Lt
())));
EXPECT_THAT
(
t
,
(
Args
<
1
,
2
>
(
Lt
())));
...
...
@@ -128,13 +139,13 @@ TEST(ArgsTest, AcceptsTwoTemplateArgs) {
}
TEST
(
ArgsTest
,
AcceptsRepeatedTemplateArgs
)
{
const
tuple
<
short
,
int
,
long
>
t
(
static_cast
<
short
>
(
4
)
,
5
,
6L
);
// NOLINT
const
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
0
,
0
>
(
Eq
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
1
,
1
>
(
Ne
())));
}
TEST
(
ArgsTest
,
AcceptsDecreasingTemplateArgs
)
{
const
tuple
<
short
,
int
,
long
>
t
(
static_cast
<
short
>
(
4
)
,
5
,
6L
);
// NOLINT
const
tuple
<
short
,
int
,
long
>
t
(
4
,
5
,
6L
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
2
,
0
>
(
Gt
())));
EXPECT_THAT
(
t
,
Not
(
Args
<
2
,
1
>
(
Lt
())));
}
...
...
@@ -159,7 +170,7 @@ TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) {
}
TEST
(
ArgsTest
,
CanBeNested
)
{
const
tuple
<
short
,
int
,
long
,
int
>
t
(
static_cast
<
short
>
(
4
)
,
5
,
6L
,
6
);
// NOLINT
const
tuple
<
short
,
int
,
long
,
int
>
t
(
4
,
5
,
6L
,
6
);
// NOLINT
EXPECT_THAT
(
t
,
(
Args
<
1
,
2
,
3
>
(
Args
<
1
,
2
>
(
Eq
()))));
EXPECT_THAT
(
t
,
(
Args
<
0
,
1
,
3
>
(
Args
<
0
,
2
>
(
Lt
()))));
}
...
...
@@ -1283,4 +1294,48 @@ TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
# pragma warning(pop)
#endif
#if GTEST_LANG_CXX11
TEST
(
AllOfTest
,
WorksOnMoveOnlyType
)
{
std
::
unique_ptr
<
int
>
p
(
new
int
(
3
));
EXPECT_THAT
(
p
,
AllOf
(
Pointee
(
Eq
(
3
)),
Pointee
(
Gt
(
0
)),
Pointee
(
Lt
(
5
))));
EXPECT_THAT
(
p
,
Not
(
AllOf
(
Pointee
(
Eq
(
3
)),
Pointee
(
Gt
(
0
)),
Pointee
(
Lt
(
3
)))));
}
TEST
(
AnyOfTest
,
WorksOnMoveOnlyType
)
{
std
::
unique_ptr
<
int
>
p
(
new
int
(
3
));
EXPECT_THAT
(
p
,
AnyOf
(
Pointee
(
Eq
(
5
)),
Pointee
(
Lt
(
0
)),
Pointee
(
Lt
(
5
))));
EXPECT_THAT
(
p
,
Not
(
AnyOf
(
Pointee
(
Eq
(
5
)),
Pointee
(
Lt
(
0
)),
Pointee
(
Gt
(
5
)))));
}
MATCHER
(
IsNotNull
,
""
)
{
return
arg
!=
nullptr
;
}
// Verifies that a matcher defined using MATCHER() can work on
// move-only types.
TEST
(
MatcherMacroTest
,
WorksOnMoveOnlyType
)
{
std
::
unique_ptr
<
int
>
p
(
new
int
(
3
));
EXPECT_THAT
(
p
,
IsNotNull
());
EXPECT_THAT
(
std
::
unique_ptr
<
int
>
(),
Not
(
IsNotNull
()));
}
MATCHER_P
(
UniquePointee
,
pointee
,
""
)
{
return
*
arg
==
pointee
;
}
// Verifies that a matcher defined using MATCHER_P*() can work on
// move-only types.
TEST
(
MatcherPMacroTest
,
WorksOnMoveOnlyType
)
{
std
::
unique_ptr
<
int
>
p
(
new
int
(
3
));
EXPECT_THAT
(
p
,
UniquePointee
(
3
));
EXPECT_THAT
(
p
,
Not
(
UniquePointee
(
2
)));
}
#endif // GTEST_LASNG_CXX11
}
// namespace
#ifdef _MSC_VER
# pragma warning(pop)
#endif
googlemock/test/gmock-internal-utils_test.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
googlemock/test/gmock-matchers_test.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -59,12 +58,6 @@
# include <forward_list> // NOLINT
#endif
// Disable MSVC2015 warning for std::pair:
// "decorated name length exceeded, name was truncated".
#if defined(_MSC_VER) && (_MSC_VER == 1900)
# pragma warning(disable:4503)
#endif
#if GTEST_LANG_CXX11
# include <type_traits>
#endif
...
...
@@ -748,6 +741,13 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) {
EXPECT_FALSE
(
m3
.
Matches
(
239
));
}
// ConvertibleFromAny does not work with MSVC. resulting in
// error C2440: 'initializing': cannot convert from 'Eq' to 'M'
// No constructor could take the source type, or constructor overload
// resolution was ambiguous
#if !defined _MSC_VER
// The below ConvertibleFromAny struct is implicitly constructible from anything
// and when in the same namespace can interact with other tests. In particular,
// if it is in the same namespace as other tests and one removes
...
...
@@ -760,7 +760,7 @@ namespace convertible_from_any {
struct
ConvertibleFromAny
{
ConvertibleFromAny
(
int
a_value
)
:
value
(
a_value
)
{}
template
<
typename
T
>
explicit
ConvertibleFromAny
(
const
T
&
/*a_value*/
)
:
value
(
-
1
)
{
ConvertibleFromAny
(
const
T
&
/*a_value*/
)
:
value
(
-
1
)
{
ADD_FAILURE
()
<<
"Conversion constructor called"
;
}
int
value
;
...
...
@@ -788,6 +788,8 @@ TEST(MatcherCastTest, FromConvertibleFromAny) {
}
}
// namespace convertible_from_any
#endif // !defined _MSC_VER
struct
IntReferenceWrapper
{
IntReferenceWrapper
(
const
int
&
a_value
)
:
value
(
&
a_value
)
{}
const
int
*
value
;
...
...
@@ -892,6 +894,8 @@ TEST(SafeMatcherCastTest, FromSameType) {
EXPECT_FALSE
(
m2
.
Matches
(
1
));
}
#if !defined _MSC_VER
namespace
convertible_from_any
{
TEST
(
SafeMatcherCastTest
,
ConversionConstructorIsUsed
)
{
Matcher
<
ConvertibleFromAny
>
m
=
SafeMatcherCast
<
ConvertibleFromAny
>
(
1
);
...
...
@@ -907,6 +911,8 @@ TEST(SafeMatcherCastTest, FromConvertibleFromAny) {
}
}
// namespace convertible_from_any
#endif // !defined _MSC_VER
TEST
(
SafeMatcherCastTest
,
ValueIsNotCopied
)
{
int
n
=
42
;
Matcher
<
IntReferenceWrapper
>
m
=
SafeMatcherCast
<
IntReferenceWrapper
>
(
n
);
...
...
@@ -2538,7 +2544,7 @@ TEST(AllOfTest, VariadicMatchesWhenAllMatch) {
::
testing
::
AllOf
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
);
Matcher
<
int
>
m
=
AllOf
(
Ne
(
1
),
Ne
(
2
),
Ne
(
3
),
Ne
(
4
),
Ne
(
5
),
Ne
(
6
),
Ne
(
7
),
Ne
(
8
),
Ne
(
9
),
Ne
(
10
),
Ne
(
11
));
EXPECT_THAT
(
Describe
(
m
),
EndsWith
(
"and (isn't equal to 11)
)))))))))
"
));
EXPECT_THAT
(
Describe
(
m
),
EndsWith
(
"and (isn't equal to 11)"
));
AllOfMatches
(
11
,
m
);
AllOfMatches
(
50
,
AllOf
(
Ne
(
1
),
Ne
(
2
),
Ne
(
3
),
Ne
(
4
),
Ne
(
5
),
Ne
(
6
),
Ne
(
7
),
Ne
(
8
),
Ne
(
9
),
Ne
(
10
),
Ne
(
11
),
Ne
(
12
),
Ne
(
13
),
Ne
(
14
),
Ne
(
15
),
...
...
@@ -2673,7 +2679,7 @@ TEST(AllOfTest, ExplainsResult) {
}
// Helper to allow easy testing of AnyOf matchers with num parameters.
void
AnyOfMatches
(
int
num
,
const
Matcher
<
int
>&
m
)
{
static
void
AnyOfMatches
(
int
num
,
const
Matcher
<
int
>&
m
)
{
SCOPED_TRACE
(
Describe
(
m
));
EXPECT_FALSE
(
m
.
Matches
(
0
));
for
(
int
i
=
1
;
i
<=
num
;
++
i
)
{
...
...
@@ -2682,6 +2688,18 @@ 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
)));
for
(
int
i
=
1
;
i
<=
num
;
++
i
)
{
EXPECT_TRUE
(
m
.
Matches
(
std
::
to_string
(
i
)));
}
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.
TEST
(
AnyOfTest
,
MatchesWhenAnyMatches
)
{
...
...
@@ -2732,13 +2750,46 @@ TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) {
// on ADL.
Matcher
<
int
>
m
=
::
testing
::
AnyOf
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
);
EXPECT_THAT
(
Describe
(
m
),
EndsWith
(
"or (is equal to 11)
)))))))))
"
));
EXPECT_THAT
(
Describe
(
m
),
EndsWith
(
"or (is equal to 11)"
));
AnyOfMatches
(
11
,
m
);
AnyOfMatches
(
50
,
AnyOf
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
,
24
,
25
,
26
,
27
,
28
,
29
,
30
,
31
,
32
,
33
,
34
,
35
,
36
,
37
,
38
,
39
,
40
,
41
,
42
,
43
,
44
,
45
,
46
,
47
,
48
,
49
,
50
));
AnyOfStringMatches
(
50
,
AnyOf
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"10"
,
"11"
,
"12"
,
"13"
,
"14"
,
"15"
,
"16"
,
"17"
,
"18"
,
"19"
,
"20"
,
"21"
,
"22"
,
"23"
,
"24"
,
"25"
,
"26"
,
"27"
,
"28"
,
"29"
,
"30"
,
"31"
,
"32"
,
"33"
,
"34"
,
"35"
,
"36"
,
"37"
,
"38"
,
"39"
,
"40"
,
"41"
,
"42"
,
"43"
,
"44"
,
"45"
,
"46"
,
"47"
,
"48"
,
"49"
,
"50"
));
}
// Tests the variadic version of the ElementsAreMatcher
TEST
(
ElementsAreTest
,
HugeMatcher
)
{
vector
<
int
>
test_vector
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
};
EXPECT_THAT
(
test_vector
,
ElementsAre
(
Eq
(
1
),
Eq
(
2
),
Lt
(
13
),
Eq
(
4
),
Eq
(
5
),
Eq
(
6
),
Eq
(
7
),
Eq
(
8
),
Eq
(
9
),
Eq
(
10
),
Gt
(
1
),
Eq
(
12
)));
}
// Tests the variadic version of the UnorderedElementsAreMatcher
TEST
(
ElementsAreTest
,
HugeMatcherStr
)
{
vector
<
string
>
test_vector
{
"literal_string"
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
};
EXPECT_THAT
(
test_vector
,
UnorderedElementsAre
(
"literal_string"
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
));
}
// Tests the variadic version of the UnorderedElementsAreMatcher
TEST
(
ElementsAreTest
,
HugeMatcherUnordered
)
{
vector
<
int
>
test_vector
{
2
,
1
,
8
,
5
,
4
,
6
,
7
,
3
,
9
,
12
,
11
,
10
};
EXPECT_THAT
(
test_vector
,
UnorderedElementsAre
(
Eq
(
2
),
Eq
(
1
),
Gt
(
7
),
Eq
(
5
),
Eq
(
4
),
Eq
(
6
),
Eq
(
7
),
Eq
(
3
),
Eq
(
9
),
Eq
(
12
),
Eq
(
11
),
Ne
(
122
)));
}
#endif // GTEST_LANG_CXX11
...
...
@@ -3065,6 +3116,44 @@ TEST(AllArgsTest, WorksInWithClause) {
EXPECT_EQ
(
2
,
helper
.
Helper
(
'a'
,
1
));
}
class
OptionalMatchersHelper
{
public:
OptionalMatchersHelper
()
{}
MOCK_METHOD0
(
NoArgs
,
int
());
MOCK_METHOD1
(
OneArg
,
int
(
int
y
));
MOCK_METHOD2
(
TwoArgs
,
int
(
char
x
,
int
y
));
MOCK_METHOD1
(
Overloaded
,
int
(
char
x
));
MOCK_METHOD2
(
Overloaded
,
int
(
char
x
,
int
y
));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
OptionalMatchersHelper
);
};
TEST
(
AllArgsTest
,
WorksWithoutMatchers
)
{
OptionalMatchersHelper
helper
;
ON_CALL
(
helper
,
NoArgs
).
WillByDefault
(
Return
(
10
));
ON_CALL
(
helper
,
OneArg
).
WillByDefault
(
Return
(
20
));
ON_CALL
(
helper
,
TwoArgs
).
WillByDefault
(
Return
(
30
));
EXPECT_EQ
(
10
,
helper
.
NoArgs
());
EXPECT_EQ
(
20
,
helper
.
OneArg
(
1
));
EXPECT_EQ
(
30
,
helper
.
TwoArgs
(
'\1'
,
2
));
EXPECT_CALL
(
helper
,
NoArgs
).
Times
(
1
);
EXPECT_CALL
(
helper
,
OneArg
).
WillOnce
(
Return
(
100
));
EXPECT_CALL
(
helper
,
OneArg
(
17
)).
WillOnce
(
Return
(
200
));
EXPECT_CALL
(
helper
,
TwoArgs
).
Times
(
0
);
EXPECT_EQ
(
10
,
helper
.
NoArgs
());
EXPECT_EQ
(
100
,
helper
.
OneArg
(
1
));
EXPECT_EQ
(
200
,
helper
.
OneArg
(
17
));
}
// Tests that ASSERT_THAT() and EXPECT_THAT() work when the value
// matches the matcher.
TEST
(
MatcherAssertionTest
,
WorksWhenMatcherIsSatisfied
)
{
...
...
@@ -3632,6 +3721,7 @@ MATCHER_P(FieldIIs, inner_matcher, "") {
return
ExplainMatchResult
(
inner_matcher
,
arg
.
i
,
result_listener
);
}
#if GTEST_HAS_RTTI
TEST
(
WhenDynamicCastToTest
,
SameType
)
{
Derived
derived
;
derived
.
i
=
4
;
...
...
@@ -3689,12 +3779,8 @@ TEST(WhenDynamicCastToTest, AmbiguousCast) {
TEST
(
WhenDynamicCastToTest
,
Describe
)
{
Matcher
<
Base
*>
matcher
=
WhenDynamicCastTo
<
Derived
*>
(
Pointee
(
_
));
#if GTEST_HAS_RTTI
const
std
::
string
prefix
=
"when dynamic_cast to "
+
internal
::
GetTypeName
<
Derived
*>
()
+
", "
;
#else // GTEST_HAS_RTTI
const
std
::
string
prefix
=
"when dynamic_cast, "
;
#endif // GTEST_HAS_RTTI
EXPECT_EQ
(
prefix
+
"points to a value that is anything"
,
Describe
(
matcher
));
EXPECT_EQ
(
prefix
+
"does not point to a value that is anything"
,
DescribeNegation
(
matcher
));
...
...
@@ -3727,6 +3813,7 @@ TEST(WhenDynamicCastToTest, BadReference) {
Base
&
as_base_ref
=
derived
;
EXPECT_THAT
(
as_base_ref
,
Not
(
WhenDynamicCastTo
<
const
OtherDerived
&>
(
_
)));
}
#endif // GTEST_HAS_RTTI
// Minimal const-propagating pointer.
template
<
typename
T
>
...
...
@@ -4150,13 +4237,17 @@ TEST(PropertyTest, WorksForReferenceToConstProperty) {
// ref-qualified.
TEST
(
PropertyTest
,
WorksForRefQualifiedProperty
)
{
Matcher
<
const
AClass
&>
m
=
Property
(
&
AClass
::
s_ref
,
StartsWith
(
"hi"
));
Matcher
<
const
AClass
&>
m_with_name
=
Property
(
"s"
,
&
AClass
::
s_ref
,
StartsWith
(
"hi"
));
AClass
a
;
a
.
set_s
(
"hill"
);
EXPECT_TRUE
(
m
.
Matches
(
a
));
EXPECT_TRUE
(
m_with_name
.
Matches
(
a
));
a
.
set_s
(
"hole"
);
EXPECT_FALSE
(
m
.
Matches
(
a
));
EXPECT_FALSE
(
m_with_name
.
Matches
(
a
));
}
#endif
...
...
@@ -4500,7 +4591,7 @@ TEST(ResultOfTest, WorksForFunctors) {
}
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
// functor with more th
e
n one operator() defined. ResultOf() must work
// functor with more th
a
n one operator() defined. ResultOf() must work
// for each defined operator().
struct
PolymorphicFunctor
{
typedef
int
result_type
;
...
...
@@ -6656,7 +6747,7 @@ TEST(AnyWithTest, TestUseInContainers) {
AnyWith
<
std
::
string
>
(
"merhaba"
),
AnyWith
<
std
::
string
>
(
"salut"
)}));
}
#endif // GTEST_LANG_CXX11
#endif
// GTEST_LANG_CXX11
TEST
(
AnyWithTest
,
TestCompare
)
{
EXPECT_THAT
(
SampleAnyType
(
1
),
AnyWith
<
int
>
(
Gt
(
0
)));
}
...
...
googlemock/test/gmock-more-actions_test.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -327,11 +326,10 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) {
// Tests using Invoke() with functions with parameters declared as Unused.
TEST
(
InvokeTest
,
FunctionWithUnusedParameters
)
{
Action
<
int
(
int
,
int
,
double
,
const
string
&
)
>
a1
=
Invoke
(
SumOfFirst2
);
string
s
(
"hi"
);
EXPECT_EQ
(
12
,
a1
.
Perform
(
tuple
<
int
,
int
,
double
,
const
string
&>
(
10
,
2
,
5.6
,
s
)));
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"
));
EXPECT_EQ
(
12
,
a1
.
Perform
(
dummy
));
Action
<
int
(
int
,
int
,
bool
,
int
*
)
>
a2
=
Invoke
(
SumOfFirst2
);
...
...
@@ -380,10 +378,10 @@ TEST(InvokeMethodTest, Unary) {
// Tests using Invoke() with a binary method.
TEST
(
InvokeMethodTest
,
Binary
)
{
Foo
foo
;
Action
<
string
(
const
string
&
,
char
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
Binary
);
string
s
(
"Hell"
);
EXPECT_EQ
(
"Hello"
,
a
.
Perform
(
tuple
<
const
string
&
,
char
>
(
s
,
'o'
)
));
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'
);
EXPECT_EQ
(
"Hello"
,
a
.
Perform
(
dummy
));
}
// Tests using Invoke() with a ternary method.
...
...
googlemock/test/gmock-nice-strict_test.cc
View file @
1246e580
...
...
@@ -26,15 +26,15 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
#include "gmock/gmock-generated-nice-strict.h"
#include <string>
#include <utility>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
// This must not be defined inside the ::testing namespace, or it will
// clash with ::testing::Mock.
...
...
@@ -114,6 +114,24 @@ class MockBar {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockBar
);
};
#if GTEST_GTEST_LANG_CXX11
class
MockBaz
{
public:
class
MoveOnly
{
MoveOnly
()
=
default
;
MoveOnly
(
const
MoveOnly
&
)
=
delete
;
operator
=
(
const
MoveOnly
&
)
=
delete
;
MoveOnly
(
MoveOnly
&&
)
=
default
;
operator
=
(
MoveOnly
&&
)
=
default
;
};
MockBaz
(
MoveOnly
)
{}
}
#endif // GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
#if GTEST_HAS_STREAM_REDIRECTION
// Tests that a raw mock generates warnings for uninteresting calls.
...
...
@@ -214,8 +232,9 @@ TEST(NiceMockTest, AllowsExpectedCall) {
nice_foo
.
DoThis
();
}
// Tests that an unexpected call on a nice mock which returns a not-default-constructible
// type throws an exception and the exception contains the method's name.
// Tests that an unexpected call on a nice mock which returns a
// not-default-constructible type throws an exception and the exception contains
// the method's name.
TEST
(
NiceMockTest
,
ThrowsExceptionForUnknownReturnTypes
)
{
NiceMock
<
MockFoo
>
nice_foo
;
#if GTEST_HAS_EXCEPTIONS
...
...
@@ -259,6 +278,21 @@ TEST(NiceMockTest, NonDefaultConstructor10) {
nice_bar
.
That
(
5
,
true
);
}
TEST
(
NiceMockTest
,
AllowLeak
)
{
NiceMock
<
MockFoo
>*
leaked
=
new
NiceMock
<
MockFoo
>
;
Mock
::
AllowLeak
(
leaked
);
EXPECT_CALL
(
*
leaked
,
DoThis
());
leaked
->
DoThis
();
}
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
TEST
(
NiceMockTest
,
MoveOnlyConstructor
)
{
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
...
...
@@ -352,6 +386,21 @@ TEST(NaggyMockTest, NonDefaultConstructor10) {
naggy_bar
.
That
(
5
,
true
);
}
TEST
(
NaggyMockTest
,
AllowLeak
)
{
NaggyMock
<
MockFoo
>*
leaked
=
new
NaggyMock
<
MockFoo
>
;
Mock
::
AllowLeak
(
leaked
);
EXPECT_CALL
(
*
leaked
,
DoThis
());
leaked
->
DoThis
();
}
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
TEST
(
NaggyMockTest
,
MoveOnlyConstructor
)
{
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
...
...
@@ -426,6 +475,21 @@ TEST(StrictMockTest, NonDefaultConstructor10) {
"Uninteresting mock function call"
);
}
TEST
(
StrictMockTest
,
AllowLeak
)
{
StrictMock
<
MockFoo
>*
leaked
=
new
StrictMock
<
MockFoo
>
;
Mock
::
AllowLeak
(
leaked
);
EXPECT_CALL
(
*
leaked
,
DoThis
());
leaked
->
DoThis
();
}
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
TEST
(
StrictMockTest
,
MoveOnlyConstructor
)
{
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
...
...
googlemock/test/gmock-port_test.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: vladl@google.com (Vlad Losev)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
googlemock/test/gmock-spec-builders_test.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -89,6 +88,7 @@ using testing::Mock;
using
testing
::
NaggyMock
;
using
testing
::
Ne
;
using
testing
::
Return
;
using
testing
::
SaveArg
;
using
testing
::
Sequence
;
using
testing
::
SetArgPointee
;
using
testing
::
internal
::
ExpectationTester
;
...
...
@@ -1175,7 +1175,7 @@ TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
TEST
(
UndefinedReturnValueTest
,
ReturnValueIsMandatoryWhenNotDefaultConstructible
)
{
MockA
a
;
//
TODO(wan@google.com)
: We should really verify the output message,
//
FIXME
: We should really verify the output message,
// but we cannot yet due to that EXPECT_DEATH only captures stderr
// while Google Mock logs to stdout.
#if GTEST_HAS_EXCEPTIONS
...
...
@@ -2173,7 +2173,9 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
"NOTE: You can safely ignore the above warning unless this "
"call should not happen. Do not suppress it by blindly adding "
"an EXPECT_CALL() if you don't mean to enforce the call. "
"See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#"
"See "
"https://github.com/google/googletest/blob/master/googlemock/docs/"
"CookBook.md#"
"knowing-when-to-expect for details."
;
// A void-returning function.
...
...
@@ -2679,6 +2681,75 @@ TEST(SynchronizationTest, CanCallMockMethodInAction) {
// EXPECT_CALL() did not specify an action.
}
TEST
(
ParameterlessExpectationsTest
,
CanSetExpectationsWithoutMatchers
)
{
MockA
a
;
int
do_a_arg0
=
0
;
ON_CALL
(
a
,
DoA
).
WillByDefault
(
SaveArg
<
0
>
(
&
do_a_arg0
));
int
do_a_47_arg0
=
0
;
ON_CALL
(
a
,
DoA
(
47
)).
WillByDefault
(
SaveArg
<
0
>
(
&
do_a_47_arg0
));
a
.
DoA
(
17
);
EXPECT_THAT
(
do_a_arg0
,
17
);
EXPECT_THAT
(
do_a_47_arg0
,
0
);
a
.
DoA
(
47
);
EXPECT_THAT
(
do_a_arg0
,
17
);
EXPECT_THAT
(
do_a_47_arg0
,
47
);
ON_CALL
(
a
,
Binary
).
WillByDefault
(
Return
(
true
));
ON_CALL
(
a
,
Binary
(
_
,
14
)).
WillByDefault
(
Return
(
false
));
EXPECT_THAT
(
a
.
Binary
(
14
,
17
),
true
);
EXPECT_THAT
(
a
.
Binary
(
17
,
14
),
false
);
}
TEST
(
ParameterlessExpectationsTest
,
CanSetExpectationsForOverloadedMethods
)
{
MockB
b
;
ON_CALL
(
b
,
DoB
()).
WillByDefault
(
Return
(
9
));
ON_CALL
(
b
,
DoB
(
5
)).
WillByDefault
(
Return
(
11
));
EXPECT_THAT
(
b
.
DoB
(),
9
);
EXPECT_THAT
(
b
.
DoB
(
1
),
0
);
// default value
EXPECT_THAT
(
b
.
DoB
(
5
),
11
);
}
struct
MockWithConstMethods
{
public:
MOCK_CONST_METHOD1
(
Foo
,
int
(
int
));
MOCK_CONST_METHOD2
(
Bar
,
int
(
int
,
const
char
*
));
};
TEST
(
ParameterlessExpectationsTest
,
CanSetExpectationsForConstMethods
)
{
MockWithConstMethods
mock
;
ON_CALL
(
mock
,
Foo
).
WillByDefault
(
Return
(
7
));
ON_CALL
(
mock
,
Bar
).
WillByDefault
(
Return
(
33
));
EXPECT_THAT
(
mock
.
Foo
(
17
),
7
);
EXPECT_THAT
(
mock
.
Bar
(
27
,
"purple"
),
33
);
}
class
MockConstOverload
{
public:
MOCK_METHOD1
(
Overloaded
,
int
(
int
));
MOCK_CONST_METHOD1
(
Overloaded
,
int
(
int
));
};
TEST
(
ParameterlessExpectationsTest
,
CanSetExpectationsForConstOverloadedMethods
)
{
MockConstOverload
mock
;
ON_CALL
(
mock
,
Overloaded
(
_
)).
WillByDefault
(
Return
(
7
));
ON_CALL
(
mock
,
Overloaded
(
5
)).
WillByDefault
(
Return
(
9
));
ON_CALL
(
Const
(
mock
),
Overloaded
(
5
)).
WillByDefault
(
Return
(
11
));
ON_CALL
(
Const
(
mock
),
Overloaded
(
7
)).
WillByDefault
(
Return
(
13
));
EXPECT_THAT
(
mock
.
Overloaded
(
1
),
7
);
EXPECT_THAT
(
mock
.
Overloaded
(
5
),
9
);
EXPECT_THAT
(
mock
.
Overloaded
(
7
),
7
);
const
MockConstOverload
&
const_mock
=
mock
;
EXPECT_THAT
(
const_mock
.
Overloaded
(
1
),
0
);
EXPECT_THAT
(
const_mock
.
Overloaded
(
5
),
11
);
EXPECT_THAT
(
const_mock
.
Overloaded
(
7
),
13
);
}
}
// namespace
// Allows the user to define their own main and then invoke gmock_main
...
...
googlemock/test/gmock_all_test.cc
View file @
1246e580
...
...
@@ -26,8 +26,7 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
//
// Tests for Google C++ Mocking Framework (Google Mock)
//
...
...
googlemock/test/gmock_ex_test.cc
View file @
1246e580
...
...
@@ -26,17 +26,18 @@
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Tests Google Mock's functionality that depends on exceptions.
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#if GTEST_HAS_EXCEPTIONS
namespace
{
using
testing
::
HasSubstr
;
using
testing
::
internal
::
GoogleTestFailureException
;
// A type that cannot be default constructed.
...
...
@@ -52,8 +53,6 @@ class MockFoo {
MOCK_METHOD0
(
GetNonDefaultConstructible
,
NonDefaultConstructible
());
};
#if GTEST_HAS_EXCEPTIONS
TEST
(
DefaultValueTest
,
ThrowsRuntimeErrorWhenNoDefaultValue
)
{
MockFoo
mock
;
try
{
...
...
@@ -76,6 +75,6 @@ TEST(DefaultValueTest, ThrowsRuntimeErrorWhenNoDefaultValue) {
}
}
#endif
}
// unnamed namespace
#endif
googlemock/test/gmock_leak_test.py
View file @
1246e580
...
...
@@ -31,12 +31,8 @@
"""Tests that leaked mock objects can be caught be Google Mock."""
__author__
=
'wan@google.com (Zhanyong Wan)'
import
gmock_test_utils
PROGRAM_PATH
=
gmock_test_utils
.
GetTestExecutablePath
(
'gmock_leak_test_'
)
TEST_WITH_EXPECT_CALL
=
[
PROGRAM_PATH
,
'--gtest_filter=*ExpectCall*'
]
TEST_WITH_ON_CALL
=
[
PROGRAM_PATH
,
'--gtest_filter=*OnCall*'
]
...
...
Prev
1
2
3
4
5
6
7
…
11
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