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
02f71065
Commit
02f71065
authored
May 10, 2010
by
zhanyong.wan
Browse files
Moves the universal printer from gmock to gtest (by Vlad Losev).
parent
76c1c612
Changes
22
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
66 additions
and
1973 deletions
+66
-1973
Makefile.am
Makefile.am
+1
-4
include/gmock/gmock-actions.h
include/gmock/gmock-actions.h
+4
-5
include/gmock/gmock-generated-function-mockers.h
include/gmock/gmock-generated-function-mockers.h
+11
-11
include/gmock/gmock-generated-function-mockers.h.pump
include/gmock/gmock-generated-function-mockers.h.pump
+1
-1
include/gmock/gmock-generated-matchers.h
include/gmock/gmock-generated-matchers.h
+11
-12
include/gmock/gmock-generated-matchers.h.pump
include/gmock/gmock-generated-matchers.h.pump
+2
-3
include/gmock/gmock-matchers.h
include/gmock/gmock-matchers.h
+24
-25
include/gmock/gmock-more-actions.h
include/gmock/gmock-more-actions.h
+1
-1
include/gmock/gmock-printers.h
include/gmock/gmock-printers.h
+0
-725
include/gmock/gmock-spec-builders.h
include/gmock/gmock-spec-builders.h
+0
-1
include/gmock/gmock.h
include/gmock/gmock.h
+0
-1
include/gmock/internal/gmock-internal-utils.h
include/gmock/internal/gmock-internal-utils.h
+3
-293
include/gmock/internal/gmock-port.h
include/gmock/internal/gmock-port.h
+0
-137
scons/SConscript
scons/SConscript
+0
-1
scripts/gmock_doctor.py
scripts/gmock_doctor.py
+1
-1
src/gmock-all.cc
src/gmock-all.cc
+0
-1
src/gmock-printers.cc
src/gmock-printers.cc
+0
-318
test/gmock-actions_test.cc
test/gmock-actions_test.cc
+4
-4
test/gmock-internal-utils_test.cc
test/gmock-internal-utils_test.cc
+2
-307
test/gmock-port_test.cc
test/gmock-port_test.cc
+1
-122
No files found.
Makefile.am
View file @
02f71065
...
...
@@ -38,7 +38,6 @@ pkginclude_HEADERS = include/gmock/gmock.h \
include/gmock/gmock-generated-nice-strict.h
\
include/gmock/gmock-matchers.h
\
include/gmock/gmock-more-actions.h
\
include/gmock/gmock-printers.h
\
include/gmock/gmock-spec-builders.h
pkginclude_internaldir
=
$(pkgincludedir)
/internal
...
...
@@ -92,7 +91,6 @@ GMOCK_SOURCE_INGLUDES = \
src/gmock-cardinalities.cc
\
src/gmock-internal-utils.cc
\
src/gmock-matchers.cc
\
src/gmock-printers.cc
\
src/gmock-spec-builders.cc
EXTRA_DIST
+=
$(GMOCK_SOURCE_INGLUDES)
...
...
@@ -110,8 +108,7 @@ EXTRA_DIST += \
test
/gmock-matchers_test.cc
\
test
/gmock-more-actions_test.cc
\
test
/gmock-nice-strict_test.cc
\
test
/gmock-port_test.cc
\
test
/gmock-printers_test.cc
test
/gmock-port_test.cc
# Python tests, which we don't run using autotools.
EXTRA_DIST
+=
\
...
...
include/gmock/gmock-actions.h
View file @
02f71065
...
...
@@ -43,7 +43,6 @@
#include <errno.h>
#endif
#include <gmock/gmock-printers.h>
#include <gmock/internal/gmock-internal-utils.h>
#include <gmock/internal/gmock-port.h>
...
...
@@ -477,7 +476,7 @@ class ReturnAction {
// and put the typedef both here (for use in assert statement) and
// in the Impl class. But both definitions must be the same.
typedef
typename
Function
<
F
>::
Result
Result
;
G
MOCK
_COMPILE_ASSERT_
(
G
TEST
_COMPILE_ASSERT_
(
!
internal
::
is_reference
<
Result
>::
value
,
use_ReturnRef_instead_of_Return_to_return_a_reference
);
return
Action
<
F
>
(
new
Impl
<
F
>
(
value_
));
...
...
@@ -504,7 +503,7 @@ class ReturnAction {
virtual
Result
Perform
(
const
ArgumentTuple
&
)
{
return
value_
;
}
private:
G
MOCK
_COMPILE_ASSERT_
(
!
internal
::
is_reference
<
Result
>::
value
,
G
TEST
_COMPILE_ASSERT_
(
!
internal
::
is_reference
<
Result
>::
value
,
Result_cannot_be_a_reference_type
);
Result
value_
;
...
...
@@ -522,7 +521,7 @@ class ReturnNullAction {
// Allows ReturnNull() to be used in any pointer-returning function.
template
<
typename
Result
,
typename
ArgumentTuple
>
static
Result
Perform
(
const
ArgumentTuple
&
)
{
G
MOCK
_COMPILE_ASSERT_
(
internal
::
is_pointer
<
Result
>::
value
,
G
TEST
_COMPILE_ASSERT_
(
internal
::
is_pointer
<
Result
>::
value
,
ReturnNull_can_be_used_to_return_a_pointer_only
);
return
NULL
;
}
...
...
@@ -555,7 +554,7 @@ class ReturnRefAction {
// Asserts that the function return type is a reference. This
// catches the user error of using ReturnRef(x) when Return(x)
// should be used, and generates some helpful error message.
G
MOCK
_COMPILE_ASSERT_
(
internal
::
is_reference
<
Result
>::
value
,
G
TEST
_COMPILE_ASSERT_
(
internal
::
is_reference
<
Result
>::
value
,
use_Return_instead_of_ReturnRef_to_return_a_value
);
return
Action
<
F
>
(
new
Impl
<
F
>
(
ref_
));
}
...
...
include/gmock/gmock-generated-function-mockers.h
View file @
02f71065
...
...
@@ -344,7 +344,7 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD0_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method() constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 0, \
this_method_does_not_take_0_arguments); \
GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \
...
...
@@ -359,7 +359,7 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD1_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1) constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 1, \
this_method_does_not_take_1_argument); \
GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \
...
...
@@ -376,7 +376,7 @@ using internal::FunctionMocker;
#define GMOCK_METHOD2_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \
GMOCK_ARG_(tn, F, 2) gmock_a2) constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 2, \
this_method_does_not_take_2_arguments); \
GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \
...
...
@@ -395,7 +395,7 @@ using internal::FunctionMocker;
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \
GMOCK_ARG_(tn, F, 2) gmock_a2, \
GMOCK_ARG_(tn, F, 3) gmock_a3) constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 3, \
this_method_does_not_take_3_arguments); \
GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \
...
...
@@ -417,7 +417,7 @@ using internal::FunctionMocker;
GMOCK_ARG_(tn, F, 2) gmock_a2, \
GMOCK_ARG_(tn, F, 3) gmock_a3, \
GMOCK_ARG_(tn, F, 4) gmock_a4) constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 4, \
this_method_does_not_take_4_arguments); \
GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \
...
...
@@ -442,7 +442,7 @@ using internal::FunctionMocker;
GMOCK_ARG_(tn, F, 3) gmock_a3, \
GMOCK_ARG_(tn, F, 4) gmock_a4, \
GMOCK_ARG_(tn, F, 5) gmock_a5) constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 5, \
this_method_does_not_take_5_arguments); \
GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \
...
...
@@ -469,7 +469,7 @@ using internal::FunctionMocker;
GMOCK_ARG_(tn, F, 4) gmock_a4, \
GMOCK_ARG_(tn, F, 5) gmock_a5, \
GMOCK_ARG_(tn, F, 6) gmock_a6) constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 6, \
this_method_does_not_take_6_arguments); \
GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \
...
...
@@ -498,7 +498,7 @@ using internal::FunctionMocker;
GMOCK_ARG_(tn, F, 5) gmock_a5, \
GMOCK_ARG_(tn, F, 6) gmock_a6, \
GMOCK_ARG_(tn, F, 7) gmock_a7) constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 7, \
this_method_does_not_take_7_arguments); \
GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \
...
...
@@ -529,7 +529,7 @@ using internal::FunctionMocker;
GMOCK_ARG_(tn, F, 6) gmock_a6, \
GMOCK_ARG_(tn, F, 7) gmock_a7, \
GMOCK_ARG_(tn, F, 8) gmock_a8) constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 8, \
this_method_does_not_take_8_arguments); \
GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \
...
...
@@ -562,7 +562,7 @@ using internal::FunctionMocker;
GMOCK_ARG_(tn, F, 7) gmock_a7, \
GMOCK_ARG_(tn, F, 8) gmock_a8, \
GMOCK_ARG_(tn, F, 9) gmock_a9) constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 9, \
this_method_does_not_take_9_arguments); \
GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \
...
...
@@ -598,7 +598,7 @@ using internal::FunctionMocker;
GMOCK_ARG_(tn, F, 8) gmock_a8, \
GMOCK_ARG_(tn, F, 9) gmock_a9, \
GMOCK_ARG_(tn, F, 10) gmock_a10) constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 10, \
this_method_does_not_take_10_arguments); \
GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \
...
...
include/gmock/gmock-generated-function-mockers.h.pump
View file @
02f71065
...
...
@@ -132,7 +132,7 @@ $var matcher_as = [[$for j, \
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method($arg_as) constness { \
G
MOCK
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
G
TEST
_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == $i, \
this_method_does_not_take_$i[[]]_argument[[$if i != 1 [[s]]]]); \
GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \
...
...
include/gmock/gmock-generated-matchers.h
View file @
02f71065
...
...
@@ -42,7 +42,6 @@
#include <string>
#include <vector>
#include <gmock/gmock-matchers.h>
#include <gmock/gmock-printers.h>
namespace
testing
{
namespace
internal
{
...
...
@@ -222,7 +221,7 @@ template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
class
ArgsMatcherImpl
:
public
MatcherInterface
<
ArgsTuple
>
{
public:
// ArgsTuple may have top-level const or reference modifiers.
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
ArgsTuple
))
RawArgsTuple
;
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
ArgsTuple
))
RawArgsTuple
;
typedef
typename
internal
::
TupleFields
<
RawArgsTuple
,
k0
,
k1
,
k2
,
k3
,
k4
,
k5
,
k6
,
k7
,
k8
,
k9
>::
type
SelectedArgs
;
typedef
Matcher
<
const
SelectedArgs
&>
MonomorphicInnerMatcher
;
...
...
@@ -315,7 +314,7 @@ class ElementsAreMatcher1 {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
@@ -344,7 +343,7 @@ class ElementsAreMatcher2 {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
@@ -372,7 +371,7 @@ class ElementsAreMatcher3 {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
@@ -402,7 +401,7 @@ class ElementsAreMatcher4 {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
@@ -434,7 +433,7 @@ class ElementsAreMatcher5 {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
@@ -470,7 +469,7 @@ class ElementsAreMatcher6 {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
@@ -508,7 +507,7 @@ class ElementsAreMatcher7 {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
@@ -548,7 +547,7 @@ class ElementsAreMatcher8 {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
@@ -591,7 +590,7 @@ class ElementsAreMatcher9 {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
@@ -636,7 +635,7 @@ class ElementsAreMatcher10 {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
include/gmock/gmock-generated-matchers.h.pump
View file @
02f71065
...
...
@@ -44,7 +44,6 @@ $$ }} This line fixes auto-indentation of the following code in Emacs.
#include <string>
#include <vector>
#include <gmock/gmock-matchers.h>
#include <gmock/gmock-printers.h>
namespace
testing
{
namespace
internal
{
...
...
@@ -108,7 +107,7 @@ template <class ArgsTuple$for i [[, int k$i = -1]]>
class
ArgsMatcherImpl
:
public
MatcherInterface
<
ArgsTuple
>
{
public:
// ArgsTuple may have top-level const or reference modifiers.
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
ArgsTuple
))
RawArgsTuple
;
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
ArgsTuple
))
RawArgsTuple
;
typedef
typename
internal
::
TupleFields
<
RawArgsTuple
,
$
ks
>::
type
SelectedArgs
;
typedef
Matcher
<
const
SelectedArgs
&>
MonomorphicInnerMatcher
;
...
...
@@ -201,7 +200,7 @@ class ElementsAreMatcher$i {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
include/gmock/gmock-matchers.h
View file @
02f71065
...
...
@@ -45,7 +45,6 @@
#include <string>
#include <vector>
#include <gmock/gmock-printers.h>
#include <gmock/internal/gmock-internal-utils.h>
#include <gmock/internal/gmock-port.h>
#include <gtest/gtest.h>
...
...
@@ -419,20 +418,20 @@ class SafeMatcherCastImpl {
template
<
typename
U
>
static
inline
Matcher
<
T
>
Cast
(
const
Matcher
<
U
>&
matcher
)
{
// Enforce that T can be implicitly converted to U.
G
MOCK
_COMPILE_ASSERT_
((
internal
::
ImplicitlyConvertible
<
T
,
U
>::
value
),
G
TEST
_COMPILE_ASSERT_
((
internal
::
ImplicitlyConvertible
<
T
,
U
>::
value
),
T_must_be_implicitly_convertible_to_U
);
// Enforce that we are not converting a non-reference type T to a reference
// type U.
G
MOCK
_COMPILE_ASSERT_
(
G
TEST
_COMPILE_ASSERT_
(
internal
::
is_reference
<
T
>::
value
||
!
internal
::
is_reference
<
U
>::
value
,
cannot_convert_non_referentce_arg_to_reference
);
// In case both T and U are arithmetic types, enforce that the
// conversion is not lossy.
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
T
))
RawT
;
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
U
))
RawU
;
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
T
))
RawT
;
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
U
))
RawU
;
const
bool
kTIsOther
=
GMOCK_KIND_OF_
(
RawT
)
==
internal
::
kOther
;
const
bool
kUIsOther
=
GMOCK_KIND_OF_
(
RawU
)
==
internal
::
kOther
;
G
MOCK
_COMPILE_ASSERT_
(
G
TEST
_COMPILE_ASSERT_
(
kTIsOther
||
kUIsOther
||
(
internal
::
LosslessArithmeticConvertible
<
RawT
,
RawU
>::
value
),
conversion_of_arithmetic_types_must_be_lossless
);
...
...
@@ -566,7 +565,7 @@ bool TupleMatches(const MatcherTuple& matcher_tuple,
using
::
std
::
tr1
::
tuple_size
;
// Makes sure that matcher_tuple and value_tuple have the same
// number of fields.
G
MOCK
_COMPILE_ASSERT_
(
tuple_size
<
MatcherTuple
>::
value
==
G
TEST
_COMPILE_ASSERT_
(
tuple_size
<
MatcherTuple
>::
value
==
tuple_size
<
ValueTuple
>::
value
,
matcher_and_value_have_different_numbers_of_fields
);
return
TuplePrefix
<
tuple_size
<
ValueTuple
>::
value
>::
...
...
@@ -1604,8 +1603,8 @@ class PointeeMatcher {
template
<
typename
Pointer
>
class
Impl
:
public
MatcherInterface
<
Pointer
>
{
public:
typedef
typename
PointeeOf
<
G
MOCK
_REMOVE_CONST_
(
// NOLINT
G
MOCK
_REMOVE_REFERENCE_
(
Pointer
))
>::
type
Pointee
;
typedef
typename
PointeeOf
<
G
TEST
_REMOVE_CONST_
(
// NOLINT
G
TEST
_REMOVE_REFERENCE_
(
Pointer
))
>::
type
Pointee
;
explicit
Impl
(
const
InnerMatcher
&
matcher
)
:
matcher_
(
MatcherCast
<
const
Pointee
&>
(
matcher
))
{}
...
...
@@ -1663,7 +1662,7 @@ class FieldMatcher {
bool
MatchAndExplain
(
const
T
&
value
,
MatchResultListener
*
listener
)
const
{
return
MatchAndExplainImpl
(
typename
::
testing
::
internal
::
is_pointer
<
G
MOCK
_REMOVE_CONST_
(
T
)
>::
type
(),
is_pointer
<
G
TEST
_REMOVE_CONST_
(
T
)
>::
type
(),
value
,
listener
);
}
...
...
@@ -1702,9 +1701,9 @@ class PropertyMatcher {
public:
// The property may have a reference type, so 'const PropertyType&'
// may cause double references and fail to compile. That's why we
// need G
MOCK
_REFERENCE_TO_CONST, which works regardless of
// need G
TEST
_REFERENCE_TO_CONST, which works regardless of
// PropertyType being a reference or not.
typedef
G
MOCK
_REFERENCE_TO_CONST_
(
PropertyType
)
RefToConstProperty
;
typedef
G
TEST
_REFERENCE_TO_CONST_
(
PropertyType
)
RefToConstProperty
;
PropertyMatcher
(
PropertyType
(
Class
::*
property
)()
const
,
const
Matcher
<
RefToConstProperty
>&
matcher
)
...
...
@@ -1724,7 +1723,7 @@ class PropertyMatcher {
bool
MatchAndExplain
(
const
T
&
value
,
MatchResultListener
*
listener
)
const
{
return
MatchAndExplainImpl
(
typename
::
testing
::
internal
::
is_pointer
<
G
MOCK
_REMOVE_CONST_
(
T
)
>::
type
(),
is_pointer
<
G
TEST
_REMOVE_CONST_
(
T
)
>::
type
(),
value
,
listener
);
}
...
...
@@ -1875,7 +1874,7 @@ class ContainerEqMatcher {
// Makes sure the user doesn't instantiate this class template
// with a const or reference type.
testing
::
StaticAssertTypeEq
<
Container
,
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
>
();
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
>
();
}
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
...
...
@@ -1890,9 +1889,9 @@ class ContainerEqMatcher {
template
<
typename
LhsContainer
>
bool
MatchAndExplain
(
const
LhsContainer
&
lhs
,
MatchResultListener
*
listener
)
const
{
// G
MOCK
_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug
// G
TEST
_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug
// that causes LhsContainer to be a const type sometimes.
typedef
internal
::
StlContainerView
<
G
MOCK
_REMOVE_CONST_
(
LhsContainer
)
>
typedef
internal
::
StlContainerView
<
G
TEST
_REMOVE_CONST_
(
LhsContainer
)
>
LhsView
;
typedef
typename
LhsView
::
type
LhsStlContainer
;
StlContainerReference
lhs_stl_container
=
LhsView
::
ConstReference
(
lhs
);
...
...
@@ -1951,7 +1950,7 @@ class ContainerEqMatcher {
template
<
typename
Container
>
class
QuantifierMatcherImpl
:
public
MatcherInterface
<
Container
>
{
public:
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
StlContainerView
<
RawContainer
>
View
;
typedef
typename
View
::
type
StlContainer
;
typedef
typename
View
::
const_reference
StlContainerReference
;
...
...
@@ -2090,7 +2089,7 @@ class EachMatcher {
template
<
typename
PairType
>
class
KeyMatcherImpl
:
public
MatcherInterface
<
PairType
>
{
public:
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
PairType
))
RawPairType
;
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
PairType
))
RawPairType
;
typedef
typename
RawPairType
::
first_type
KeyType
;
template
<
typename
InnerMatcher
>
...
...
@@ -2152,7 +2151,7 @@ class KeyMatcher {
template
<
typename
PairType
>
class
PairMatcherImpl
:
public
MatcherInterface
<
PairType
>
{
public:
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
PairType
))
RawPairType
;
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
PairType
))
RawPairType
;
typedef
typename
RawPairType
::
first_type
FirstType
;
typedef
typename
RawPairType
::
second_type
SecondType
;
...
...
@@ -2259,7 +2258,7 @@ class PairMatcher {
template
<
typename
Container
>
class
ElementsAreMatcherImpl
:
public
MatcherInterface
<
Container
>
{
public:
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
internal
::
StlContainerView
<
RawContainer
>
View
;
typedef
typename
View
::
type
StlContainer
;
typedef
typename
View
::
const_reference
StlContainerReference
;
...
...
@@ -2378,7 +2377,7 @@ class ElementsAreMatcher0 {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
@@ -2397,7 +2396,7 @@ class ElementsAreArrayMatcher {
template
<
typename
Container
>
operator
Matcher
<
Container
>
()
const
{
typedef
G
MOCK
_REMOVE_CONST_
(
G
MOCK
_REMOVE_REFERENCE_
(
Container
))
typedef
G
TEST
_REMOVE_CONST_
(
G
TEST
_REMOVE_REFERENCE_
(
Container
))
RawContainer
;
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
...
...
@@ -2609,7 +2608,7 @@ inline PolymorphicMatcher<
return
MakePolymorphicMatcher
(
internal
::
PropertyMatcher
<
Class
,
PropertyType
>
(
property
,
MatcherCast
<
G
MOCK
_REFERENCE_TO_CONST_
(
PropertyType
)
>
(
matcher
)));
MatcherCast
<
G
TEST
_REFERENCE_TO_CONST_
(
PropertyType
)
>
(
matcher
)));
// The call to MatcherCast() is required for supporting inner
// matchers of compatible types. For example, it allows
// Property(&Foo::bar, m)
...
...
@@ -2893,11 +2892,11 @@ Truly(Predicate pred) {
// values and order differences are not explained.)
template
<
typename
Container
>
inline
PolymorphicMatcher
<
internal
::
ContainerEqMatcher
<
// NOLINT
G
MOCK
_REMOVE_CONST_
(
Container
)
>
>
G
TEST
_REMOVE_CONST_
(
Container
)
>
>
ContainerEq
(
const
Container
&
rhs
)
{
// This following line is for working around a bug in MSVC 8.0,
// which causes Container to be a const type sometimes.
typedef
G
MOCK
_REMOVE_CONST_
(
Container
)
RawContainer
;
typedef
G
TEST
_REMOVE_CONST_
(
Container
)
RawContainer
;
return
MakePolymorphicMatcher
(
internal
::
ContainerEqMatcher
<
RawContainer
>
(
rhs
));
}
...
...
include/gmock/gmock-more-actions.h
View file @
02f71065
...
...
@@ -162,7 +162,7 @@ ACTION_TEMPLATE(SetArgReferee,
// Ensures that argument #k is a reference. If you get a compiler
// error on the next line, you are using SetArgReferee<k>(value) in
// a mock function whose k-th (0-based) argument is not a reference.
G
MOCK
_COMPILE_ASSERT_
(
internal
::
is_reference
<
argk_type
>::
value
,
G
TEST
_COMPILE_ASSERT_
(
internal
::
is_reference
<
argk_type
>::
value
,
SetArgReferee_must_be_used_with_a_reference_argument
);
::
std
::
tr1
::
get
<
k
>
(
args
)
=
value
;
}
...
...
include/gmock/gmock-printers.h
deleted
100644 → 0
View file @
76c1c612
This diff is collapsed.
Click to expand it.
include/gmock/gmock-spec-builders.h
View file @
02f71065
...
...
@@ -69,7 +69,6 @@
#include <gmock/gmock-actions.h>
#include <gmock/gmock-cardinalities.h>
#include <gmock/gmock-matchers.h>
#include <gmock/gmock-printers.h>
#include <gmock/internal/gmock-internal-utils.h>
#include <gmock/internal/gmock-port.h>
#include <gtest/gtest.h>
...
...
include/gmock/gmock.h
View file @
02f71065
...
...
@@ -63,7 +63,6 @@
#include <gmock/gmock-more-actions.h>
#include <gmock/gmock-generated-nice-strict.h>
#include <gmock/gmock-matchers.h>
#include <gmock/gmock-printers.h>
#include <gmock/internal/gmock-internal-utils.h>
namespace
testing
{
...
...
include/gmock/internal/gmock-internal-utils.h
View file @
02f71065
...
...
@@ -57,9 +57,6 @@
#define GMOCK_ATTRIBUTE_UNUSED_
#endif // __GNUC__
class
ProtocolMessage
;
namespace
proto2
{
class
Message
;
}
namespace
testing
{
namespace
internal
{
...
...
@@ -69,77 +66,6 @@ namespace internal {
// "foo_bar_123" are converted to "foo bar 123".
string
ConvertIdentifierNameToWords
(
const
char
*
id_name
);
// Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
// compiler error iff T1 and T2 are different types.
template
<
typename
T1
,
typename
T2
>
struct
CompileAssertTypesEqual
;
template
<
typename
T
>
struct
CompileAssertTypesEqual
<
T
,
T
>
{
};
// Removes the reference from a type if it is a reference type,
// otherwise leaves it unchanged. This is the same as
// tr1::remove_reference, which is not widely available yet.
template
<
typename
T
>
struct
RemoveReference
{
typedef
T
type
;
};
// NOLINT
template
<
typename
T
>
struct
RemoveReference
<
T
&>
{
typedef
T
type
;
};
// NOLINT
// A handy wrapper around RemoveReference that works when the argument
// T depends on template parameters.
#define GMOCK_REMOVE_REFERENCE_(T) \
typename ::testing::internal::RemoveReference<T>::type
// Removes const from a type if it is a const type, otherwise leaves
// it unchanged. This is the same as tr1::remove_const, which is not
// widely available yet.
template
<
typename
T
>
struct
RemoveConst
{
typedef
T
type
;
};
// NOLINT
template
<
typename
T
>
struct
RemoveConst
<
const
T
>
{
typedef
T
type
;
};
// NOLINT
// MSVC 8.0 has a bug which causes the above definition to fail to
// remove the const in 'const int[3]'. The following specialization
// works around the bug. However, it causes trouble with gcc and thus
// needs to be conditionally compiled.
#ifdef _MSC_VER
template
<
typename
T
,
size_t
N
>
struct
RemoveConst
<
T
[
N
]
>
{
typedef
typename
RemoveConst
<
T
>::
type
type
[
N
];
};
#endif // _MSC_VER
// A handy wrapper around RemoveConst that works when the argument
// T depends on template parameters.
#define GMOCK_REMOVE_CONST_(T) \
typename ::testing::internal::RemoveConst<T>::type
// Adds reference to a type if it is not a reference type,
// otherwise leaves it unchanged. This is the same as
// tr1::add_reference, which is not widely available yet.
template
<
typename
T
>
struct
AddReference
{
typedef
T
&
type
;
};
// NOLINT
template
<
typename
T
>
struct
AddReference
<
T
&>
{
typedef
T
&
type
;
};
// NOLINT
// A handy wrapper around AddReference that works when the argument T
// depends on template parameters.
#define GMOCK_ADD_REFERENCE_(T) \
typename ::testing::internal::AddReference<T>::type
// Adds a reference to const on top of T as necessary. For example,
// it transforms
//
// char ==> const char&
// const char ==> const char&
// char& ==> const char&
// const char& ==> const char&
//
// The argument T must depend on some template parameters.
#define GMOCK_REFERENCE_TO_CONST_(T) \
GMOCK_ADD_REFERENCE_(const GMOCK_REMOVE_REFERENCE_(T))
// PointeeOf<Pointer>::type is the type of a value pointed to by a
// Pointer, which can be either a smart pointer or a raw pointer. The
// following default implementation is for the case where Pointer is a
...
...
@@ -174,53 +100,6 @@ struct LinkedPtrLessThan {
}
};
// ImplicitlyConvertible<From, To>::value is a compile-time bool
// constant that's true iff type From can be implicitly converted to
// type To.
template
<
typename
From
,
typename
To
>
class
ImplicitlyConvertible
{
private:
// We need the following helper functions only for their types.
// They have no implementations.
// MakeFrom() is an expression whose type is From. We cannot simply
// use From(), as the type From may not have a public default
// constructor.
static
From
MakeFrom
();
// These two functions are overloaded. Given an expression
// Helper(x), the compiler will pick the first version if x can be
// implicitly converted to type To; otherwise it will pick the
// second version.
//
// The first version returns a value of size 1, and the second
// version returns a value of size 2. Therefore, by checking the
// size of Helper(x), which can be done at compile time, we can tell
// which version of Helper() is used, and hence whether x can be
// implicitly converted to type To.
static
char
Helper
(
To
);
static
char
(
&
Helper
(...))[
2
];
// NOLINT
// We have to put the 'public' section after the 'private' section,
// or MSVC refuses to compile the code.
public:
// MSVC warns about implicitly converting from double to int for
// possible loss of data, so we need to temporarily disable the
// warning.
#ifdef _MSC_VER
#pragma warning(push) // Saves the current warning state.
#pragma warning(disable:4244) // Temporarily disables warning 4244.
static
const
bool
value
=
sizeof
(
Helper
(
ImplicitlyConvertible
::
MakeFrom
()))
==
1
;
#pragma warning(pop) // Restores the warning state.
#else
static
const
bool
value
=
sizeof
(
Helper
(
ImplicitlyConvertible
::
MakeFrom
()))
==
1
;
#endif // _MSV_VER
};
template
<
typename
From
,
typename
To
>
const
bool
ImplicitlyConvertible
<
From
,
To
>::
value
;
// Symbian compilation can be done with wchar_t being either a native
// type or a typedef. Using Google Mock with OpenC without wchar_t
// should require the definition of _STLP_NO_WCHAR_T.
...
...
@@ -385,32 +264,6 @@ struct LosslessArithmeticConvertible
:
public
LosslessArithmeticConvertibleImpl
<
GMOCK_KIND_OF_
(
From
),
From
,
GMOCK_KIND_OF_
(
To
),
To
>
{};
// NOLINT
// IsAProtocolMessage<T>::value is a compile-time bool constant that's
// true iff T is type ProtocolMessage, proto2::Message, or a subclass
// of those.
template
<
typename
T
>
struct
IsAProtocolMessage
:
public
bool_constant
<
ImplicitlyConvertible
<
const
T
*
,
const
::
ProtocolMessage
*>::
value
||
ImplicitlyConvertible
<
const
T
*
,
const
::
proto2
::
Message
*>::
value
>
{
};
// When the compiler sees expression IsContainerTest<C>(0), the first
// overload of IsContainerTest will be picked if C is an STL-style
// container class (since C::const_iterator* is a valid type and 0 can
// be converted to it), while the second overload will be picked
// otherwise (since C::const_iterator will be an invalid type in this
// case). Therefore, we can determine whether C is a container class
// by checking the type of IsContainerTest<C>(0). The value of the
// expression is insignificant.
typedef
int
IsContainer
;
template
<
class
C
>
IsContainer
IsContainerTest
(
typename
C
::
const_iterator
*
)
{
return
0
;
}
typedef
char
IsNotContainer
;
template
<
class
C
>
IsNotContainer
IsContainerTest
(...)
{
return
'\0'
;
}
// This interface knows how to report a Google Mock failure (either
// non-fatal or fatal).
class
FailureReporterInterface
{
...
...
@@ -514,149 +367,6 @@ inline T Invalid() {
template
<
>
inline
void
Invalid
<
void
>
()
{}
// Utilities for native arrays.
// ArrayEq() compares two k-dimensional native arrays using the
// elements' operator==, where k can be any integer >= 0. When k is
// 0, ArrayEq() degenerates into comparing a single pair of values.
template
<
typename
T
,
typename
U
>
bool
ArrayEq
(
const
T
*
lhs
,
size_t
size
,
const
U
*
rhs
);
// This generic version is used when k is 0.
template
<
typename
T
,
typename
U
>
inline
bool
ArrayEq
(
const
T
&
lhs
,
const
U
&
rhs
)
{
return
lhs
==
rhs
;
}
// This overload is used when k >= 1.
template
<
typename
T
,
typename
U
,
size_t
N
>
inline
bool
ArrayEq
(
const
T
(
&
lhs
)[
N
],
const
U
(
&
rhs
)[
N
])
{
return
internal
::
ArrayEq
(
lhs
,
N
,
rhs
);
}
// This helper reduces code bloat. If we instead put its logic inside
// the previous ArrayEq() function, arrays with different sizes would
// lead to different copies of the template code.
template
<
typename
T
,
typename
U
>
bool
ArrayEq
(
const
T
*
lhs
,
size_t
size
,
const
U
*
rhs
)
{
for
(
size_t
i
=
0
;
i
!=
size
;
i
++
)
{
if
(
!
internal
::
ArrayEq
(
lhs
[
i
],
rhs
[
i
]))
return
false
;
}
return
true
;
}
// Finds the first element in the iterator range [begin, end) that
// equals elem. Element may be a native array type itself.
template
<
typename
Iter
,
typename
Element
>
Iter
ArrayAwareFind
(
Iter
begin
,
Iter
end
,
const
Element
&
elem
)
{
for
(
Iter
it
=
begin
;
it
!=
end
;
++
it
)
{
if
(
internal
::
ArrayEq
(
*
it
,
elem
))
return
it
;
}
return
end
;
}
// CopyArray() copies a k-dimensional native array using the elements'
// operator=, where k can be any integer >= 0. When k is 0,
// CopyArray() degenerates into copying a single value.
template
<
typename
T
,
typename
U
>
void
CopyArray
(
const
T
*
from
,
size_t
size
,
U
*
to
);
// This generic version is used when k is 0.
template
<
typename
T
,
typename
U
>
inline
void
CopyArray
(
const
T
&
from
,
U
*
to
)
{
*
to
=
from
;
}
// This overload is used when k >= 1.
template
<
typename
T
,
typename
U
,
size_t
N
>
inline
void
CopyArray
(
const
T
(
&
from
)[
N
],
U
(
*
to
)[
N
])
{
internal
::
CopyArray
(
from
,
N
,
*
to
);
}
// This helper reduces code bloat. If we instead put its logic inside
// the previous CopyArray() function, arrays with different sizes
// would lead to different copies of the template code.
template
<
typename
T
,
typename
U
>
void
CopyArray
(
const
T
*
from
,
size_t
size
,
U
*
to
)
{
for
(
size_t
i
=
0
;
i
!=
size
;
i
++
)
{
internal
::
CopyArray
(
from
[
i
],
to
+
i
);
}
}
// The relation between an NativeArray object (see below) and the
// native array it represents.
enum
RelationToSource
{
kReference
,
// The NativeArray references the native array.
kCopy
// The NativeArray makes a copy of the native array and
// owns the copy.
};
// Adapts a native array to a read-only STL-style container. Instead
// of the complete STL container concept, this adaptor only implements
// members useful for Google Mock's container matchers. New members
// should be added as needed. To simplify the implementation, we only
// support Element being a raw type (i.e. having no top-level const or
// reference modifier). It's the client's responsibility to satisfy
// this requirement. Element can be an array type itself (hence
// multi-dimensional arrays are supported).
template
<
typename
Element
>
class
NativeArray
{
public:
// STL-style container typedefs.
typedef
Element
value_type
;
typedef
const
Element
*
const_iterator
;
// Constructs from a native array.
NativeArray
(
const
Element
*
array
,
size_t
count
,
RelationToSource
relation
)
{
Init
(
array
,
count
,
relation
);
}
// Copy constructor.
NativeArray
(
const
NativeArray
&
rhs
)
{
Init
(
rhs
.
array_
,
rhs
.
size_
,
rhs
.
relation_to_source_
);
}
~
NativeArray
()
{
// Ensures that the user doesn't instantiate NativeArray with a
// const or reference type.
testing
::
StaticAssertTypeEq
<
Element
,
GMOCK_REMOVE_CONST_
(
GMOCK_REMOVE_REFERENCE_
(
Element
))
>
();
if
(
relation_to_source_
==
kCopy
)
delete
[]
array_
;
}
// STL-style container methods.
size_t
size
()
const
{
return
size_
;
}
const_iterator
begin
()
const
{
return
array_
;
}
const_iterator
end
()
const
{
return
array_
+
size_
;
}
bool
operator
==
(
const
NativeArray
&
rhs
)
const
{
return
size
()
==
rhs
.
size
()
&&
ArrayEq
(
begin
(),
size
(),
rhs
.
begin
());
}
private:
// Not implemented as we don't want to support assignment.
void
operator
=
(
const
NativeArray
&
rhs
);
// Initializes this object; makes a copy of the input array if
// 'relation' is kCopy.
void
Init
(
const
Element
*
array
,
size_t
a_size
,
RelationToSource
relation
)
{
if
(
relation
==
kReference
)
{
array_
=
array
;
}
else
{
Element
*
const
copy
=
new
Element
[
a_size
];
CopyArray
(
array
,
a_size
,
copy
);
array_
=
copy
;
}
size_
=
a_size
;
relation_to_source_
=
relation
;
}
const
Element
*
array_
;
size_t
size_
;
RelationToSource
relation_to_source_
;
};
// Given a raw type (i.e. having no top-level reference or const
// modifier) RawContainer that's either an STL-style container or a
// native array, class StlContainerView<RawContainer> has the
...
...
@@ -682,7 +392,7 @@ class StlContainerView {
static
const_reference
ConstReference
(
const
RawContainer
&
container
)
{
// Ensures that RawContainer is not a const type.
testing
::
StaticAssertTypeEq
<
RawContainer
,
G
MOCK
_REMOVE_CONST_
(
RawContainer
)
>
();
G
TEST
_REMOVE_CONST_
(
RawContainer
)
>
();
return
container
;
}
static
type
Copy
(
const
RawContainer
&
container
)
{
return
container
;
}
...
...
@@ -692,7 +402,7 @@ class StlContainerView {
template
<
typename
Element
,
size_t
N
>
class
StlContainerView
<
Element
[
N
]
>
{
public:
typedef
G
MOCK
_REMOVE_CONST_
(
Element
)
RawElement
;
typedef
G
TEST
_REMOVE_CONST_
(
Element
)
RawElement
;
typedef
internal
::
NativeArray
<
RawElement
>
type
;
// NativeArray<T> can represent a native array either by value or by
// reference (selected by a constructor argument), so 'const type'
...
...
@@ -737,7 +447,7 @@ class StlContainerView<Element[N]> {
template
<
typename
ElementPointer
,
typename
Size
>
class
StlContainerView
<
::
std
::
tr1
::
tuple
<
ElementPointer
,
Size
>
>
{
public:
typedef
G
MOCK
_REMOVE_CONST_
(
typedef
G
TEST
_REMOVE_CONST_
(
typename
internal
::
PointeeOf
<
ElementPointer
>::
type
)
RawElement
;
typedef
internal
::
NativeArray
<
RawElement
>
type
;
typedef
const
type
const_reference
;
...
...
include/gmock/internal/gmock-port.h
View file @
02f71065
...
...
@@ -50,149 +50,12 @@
// tr1/tuple. gmock-port.h does this via gtest-port.h, which is
// guaranteed to pull in the tuple header.
#if GTEST_OS_LINUX
#endif // GTEST_OS_LINUX
namespace
testing
{
namespace
internal
{
// For MS Visual C++, check the compiler version. At least VS 2003 is
// required to compile Google Mock.
#if defined(_MSC_VER) && _MSC_VER < 1310
#error "At least Visual C++ 2003 (7.1) is required to compile Google Mock."
#endif
// Use implicit_cast as a safe version of static_cast for upcasting in
// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
// const Foo*). When you use implicit_cast, the compiler checks that
// the cast is safe. Such explicit implicit_casts are necessary in
// surprisingly many situations where C++ demands an exact type match
// instead of an argument type convertable to a target type.
//
// The syntax for using implicit_cast is the same as for static_cast:
//
// implicit_cast<ToType>(expr)
//
// implicit_cast would have been part of the C++ standard library,
// but the proposal was submitted too late. It will probably make
// its way into the language in the future.
template
<
typename
To
>
inline
To
implicit_cast
(
To
x
)
{
return
x
;
}
// When you upcast (that is, cast a pointer from type Foo to type
// SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts
// always succeed. When you downcast (that is, cast a pointer from
// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
// how do you know the pointer is really of type SubclassOfFoo? It
// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus,
// when you downcast, you should use this macro. In debug mode, we
// use dynamic_cast<> to double-check the downcast is legal (we die
// if it's not). In normal mode, we do the efficient static_cast<>
// instead. Thus, it's important to test in debug mode to make sure
// the cast is legal!
// This is the only place in the code we should use dynamic_cast<>.
// In particular, you SHOULDN'T be using dynamic_cast<> in order to
// do RTTI (eg code like this:
// if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
// if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
// You should design the code some other way not to need this.
template
<
typename
To
,
typename
From
>
// use like this: down_cast<T*>(foo);
inline
To
down_cast
(
From
*
f
)
{
// so we only accept pointers
// Ensures that To is a sub-type of From *. This test is here only
// for compile-time type checking, and has no overhead in an
// optimized build at run-time, as it will be optimized away
// completely.
if
(
false
)
{
const
To
to
=
NULL
;
::
testing
::
internal
::
implicit_cast
<
From
*>
(
to
);
}
#if GTEST_HAS_RTTI
assert
(
f
==
NULL
||
dynamic_cast
<
To
>
(
f
)
!=
NULL
);
// RTTI: debug mode only!
#endif
return
static_cast
<
To
>
(
f
);
}
// The GMOCK_COMPILE_ASSERT_ macro can be used to verify that a compile time
// expression is true. For example, you could use it to verify the
// size of a static array:
//
// GMOCK_COMPILE_ASSERT_(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
// content_type_names_incorrect_size);
//
// or to make sure a struct is smaller than a certain size:
//
// GMOCK_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
//
// The second argument to the macro is the name of the variable. If
// the expression is false, most compilers will issue a warning/error
// containing the name of the variable.
template
<
bool
>
struct
CompileAssert
{
};
#define GMOCK_COMPILE_ASSERT_(expr, msg) \
typedef ::testing::internal::CompileAssert<(bool(expr))> \
msg[bool(expr) ? 1 : -1]
// Implementation details of GMOCK_COMPILE_ASSERT_:
//
// - GMOCK_COMPILE_ASSERT_ works by defining an array type that has -1
// elements (and thus is invalid) when the expression is false.
//
// - The simpler definition
//
// #define GMOCK_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
//
// does not work, as gcc supports variable-length arrays whose sizes
// are determined at run-time (this is gcc's extension and not part
// of the C++ standard). As a result, gcc fails to reject the
// following code with the simple definition:
//
// int foo;
// GMOCK_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
// // not a compile-time constant.
//
// - By using the type CompileAssert<(bool(expr))>, we ensures that
// expr is a compile-time constant. (Template arguments must be
// determined at compile-time.)
//
// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
//
// CompileAssert<bool(expr)>
//
// instead, these compilers will refuse to compile
//
// GMOCK_COMPILE_ASSERT_(5 > 0, some_message);
//
// (They seem to think the ">" in "5 > 0" marks the end of the
// template argument list.)
//
// - The array size is (bool(expr) ? 1 : -1), instead of simply
//
// ((expr) ? 1 : -1).
//
// This is to avoid running into a bug in MS VC 7.1, which
// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
#if GTEST_HAS_GLOBAL_STRING
typedef
::
string
string
;
#else
typedef
::
std
::
string
string
;
#endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_GLOBAL_WSTRING
typedef
::
wstring
wstring
;
#elif GTEST_HAS_STD_WSTRING
typedef
::
std
::
wstring
wstring
;
#endif // GTEST_HAS_GLOBAL_WSTRING
}
// namespace internal
}
// namespace testing
// Macro for referencing flags. This is public as we want the user to
// use this syntax to reference Google Mock flags.
#define GMOCK_FLAG(name) FLAGS_gmock_##name
...
...
scons/SConscript
View file @
02f71065
...
...
@@ -186,7 +186,6 @@ GtestTest(env, 'gmock-matchers_test', [gtest, gmock_main])
GtestTest
(
env
,
'gmock-more-actions_test'
,
[
gtest
,
gmock_main
])
GtestTest
(
env
,
'gmock-nice-strict_test'
,
[
gtest
,
gmock_main
])
GtestTest
(
env
,
'gmock-port_test'
,
[
gtest
,
gmock_main
])
GtestTest
(
env
,
'gmock-printers_test'
,
[
gtest
,
gmock_main
])
GtestTest
(
env
,
'gmock-spec-builders_test'
,
[
gtest
,
gmock_main
])
GtestTest
(
env
,
'gmock_leak_test_'
,
[
gtest
,
gmock_main
])
GtestTest
(
env
,
'gmock_link_test'
,
[
gtest
,
gmock_main
],
...
...
scripts/gmock_doctor.py
View file @
02f71065
...
...
@@ -203,7 +203,7 @@ def _IncompleteByReferenceArgumentDiagnoser(msg):
"""Diagnoses the IBRA disease, given the error messages by gcc."""
regex
=
(
_FILE_LINE_RE
+
r
'instantiated from here\n'
r
'.*g
mock
-printers\.h.*error: invalid application of '
r
'.*g
test
-printers\.h.*error: invalid application of '
r
'\'sizeof\' to incomplete type \'(?P<type>.*)\''
)
diagnosis
=
"""
In order to mock this function, Google Mock needs to see the definition
...
...
src/gmock-all.cc
View file @
02f71065
...
...
@@ -43,6 +43,5 @@
#include "src/gmock-cardinalities.cc"
#include "src/gmock-internal-utils.cc"
#include "src/gmock-matchers.cc"
#include "src/gmock-printers.cc"
#include "src/gmock-spec-builders.cc"
#include "src/gmock.cc"
src/gmock-printers.cc
deleted
100644 → 0
View file @
76c1c612
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
// This file implements a universal value printer that can print a
// value of any type T:
//
// void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
//
// It uses the << operator when possible, and prints the bytes in the
// object otherwise. A user can override its behavior for a class
// type Foo by defining either operator<<(::std::ostream&, const Foo&)
// or void PrintTo(const Foo&, ::std::ostream*) in the namespace that
// defines Foo.
#include <gmock/gmock-printers.h>
#include <ctype.h>
#include <stdio.h>
#include <ostream> // NOLINT
#include <string>
#include <gmock/internal/gmock-port.h>
namespace
testing
{
namespace
{
using
::
std
::
ostream
;
#if GTEST_OS_WINDOWS_MOBILE // Windows CE does not define _snprintf_s.
#define snprintf _snprintf
#elif _MSC_VER >= 1400 // VC 8.0 and later deprecate snprintf and _snprintf.
#define snprintf _snprintf_s
#elif _MSC_VER
#define snprintf _snprintf
#endif // GTEST_OS_WINDOWS_MOBILE
// Prints a segment of bytes in the given object.
void
PrintByteSegmentInObjectTo
(
const
unsigned
char
*
obj_bytes
,
size_t
start
,
size_t
count
,
ostream
*
os
)
{
char
text
[
5
]
=
""
;
for
(
size_t
i
=
0
;
i
!=
count
;
i
++
)
{
const
size_t
j
=
start
+
i
;
if
(
i
!=
0
)
{
// Organizes the bytes into groups of 2 for easy parsing by
// human.
if
((
j
%
2
)
==
0
)
{
*
os
<<
" "
;
}
}
snprintf
(
text
,
sizeof
(
text
),
"%02X"
,
obj_bytes
[
j
]);
*
os
<<
text
;
}
}
// Prints the bytes in the given value to the given ostream.
void
PrintBytesInObjectToImpl
(
const
unsigned
char
*
obj_bytes
,
size_t
count
,
ostream
*
os
)
{
// Tells the user how big the object is.
*
os
<<
count
<<
"-byte object <"
;
const
size_t
kThreshold
=
132
;
const
size_t
kChunkSize
=
64
;
// If the object size is bigger than kThreshold, we'll have to omit
// some details by printing only the first and the last kChunkSize
// bytes.
// TODO(wan): let the user control the threshold using a flag.
if
(
count
<
kThreshold
)
{
PrintByteSegmentInObjectTo
(
obj_bytes
,
0
,
count
,
os
);
}
else
{
PrintByteSegmentInObjectTo
(
obj_bytes
,
0
,
kChunkSize
,
os
);
*
os
<<
" ... "
;
// Rounds up to 2-byte boundary.
const
size_t
resume_pos
=
(
count
-
kChunkSize
+
1
)
/
2
*
2
;
PrintByteSegmentInObjectTo
(
obj_bytes
,
resume_pos
,
count
-
resume_pos
,
os
);
}
*
os
<<
">"
;
}
}
// namespace
namespace
internal2
{
// Delegates to PrintBytesInObjectToImpl() to print the bytes in the
// given object. The delegation simplifies the implementation, which
// uses the << operator and thus is easier done outside of the
// ::testing::internal namespace, which contains a << operator that
// sometimes conflicts with the one in STL.
void
PrintBytesInObjectTo
(
const
unsigned
char
*
obj_bytes
,
size_t
count
,
ostream
*
os
)
{
PrintBytesInObjectToImpl
(
obj_bytes
,
count
,
os
);
}
}
// namespace internal2
namespace
internal
{
// Prints a wide char as a char literal without the quotes, escaping it
// when necessary.
static
void
PrintAsWideCharLiteralTo
(
wchar_t
c
,
ostream
*
os
)
{
switch
(
c
)
{
case
L'\0'
:
*
os
<<
"
\\
0"
;
break
;
case
L'\''
:
*
os
<<
"
\\
'"
;
break
;
case
L'\?'
:
*
os
<<
"
\\
?"
;
break
;
case
L'\\'
:
*
os
<<
"
\\\\
"
;
break
;
case
L'\a'
:
*
os
<<
"
\\
a"
;
break
;
case
L'\b'
:
*
os
<<
"
\\
b"
;
break
;
case
L'\f'
:
*
os
<<
"
\\
f"
;
break
;
case
L'\n'
:
*
os
<<
"
\\
n"
;
break
;
case
L'\r'
:
*
os
<<
"
\\
r"
;
break
;
case
L'\t'
:
*
os
<<
"
\\
t"
;
break
;
case
L'\v'
:
*
os
<<
"
\\
v"
;
break
;
default:
// Checks whether c is printable or not. Printable characters are in
// the range [0x20,0x7E].
// We test the value of c directly instead of calling isprint(), as
// isprint() is buggy on Windows mobile.
if
(
0x20
<=
c
&&
c
<=
0x7E
)
{
*
os
<<
static_cast
<
char
>
(
c
);
}
else
{
// Buffer size enough for the maximum number of digits and \0.
char
text
[
2
*
sizeof
(
unsigned
long
)
+
1
]
=
""
;
snprintf
(
text
,
sizeof
(
text
),
"%lX"
,
static_cast
<
unsigned
long
>
(
c
));
*
os
<<
"
\\
x"
<<
text
;
}
}
}
// Prints a char as if it's part of a string literal, escaping it when
// necessary.
static
void
PrintAsWideStringLiteralTo
(
wchar_t
c
,
ostream
*
os
)
{
switch
(
c
)
{
case
L'\''
:
*
os
<<
"'"
;
break
;
case
L'"'
:
*
os
<<
"
\\\"
"
;
break
;
default:
PrintAsWideCharLiteralTo
(
c
,
os
);
}
}
// Prints a char as a char literal without the quotes, escaping it
// when necessary.
static
void
PrintAsCharLiteralTo
(
char
c
,
ostream
*
os
)
{
PrintAsWideCharLiteralTo
(
static_cast
<
unsigned
char
>
(
c
),
os
);
}
// Prints a char as if it's part of a string literal, escaping it when
// necessary.
static
void
PrintAsStringLiteralTo
(
char
c
,
ostream
*
os
)
{
PrintAsWideStringLiteralTo
(
static_cast
<
unsigned
char
>
(
c
),
os
);
}
// Prints a char and its code. The '\0' char is printed as "'\\0'",
// other unprintable characters are also properly escaped using the
// standard C++ escape sequence.
void
PrintCharTo
(
char
c
,
int
char_code
,
ostream
*
os
)
{
*
os
<<
"'"
;
PrintAsCharLiteralTo
(
c
,
os
);
*
os
<<
"'"
;
if
(
c
!=
'\0'
)
*
os
<<
" ("
<<
char_code
<<
")"
;
}
// Prints a wchar_t as a symbol if it is printable or as its internal
// code otherwise and also as its decimal code (except for L'\0').
// The L'\0' char is printed as "L'\\0'". The decimal code is printed
// as signed integer when wchar_t is implemented by the compiler
// as a signed type and is printed as an unsigned integer when wchar_t
// is implemented as an unsigned type.
void
PrintTo
(
wchar_t
wc
,
ostream
*
os
)
{
*
os
<<
"L'"
;
PrintAsWideCharLiteralTo
(
wc
,
os
);
*
os
<<
"'"
;
if
(
wc
!=
L'\0'
)
{
// Type Int64 is used because it provides more storage than wchar_t thus
// when the compiler converts signed or unsigned implementation of wchar_t
// to Int64 it fills higher bits with either zeros or the sign bit
// passing it to operator <<() as either signed or unsigned integer.
*
os
<<
" ("
<<
static_cast
<
Int64
>
(
wc
)
<<
")"
;
}
}
// Prints the given array of characters to the ostream.
// The array starts at *begin, the length is len, it may include '\0' characters
// and may not be null-terminated.
static
void
PrintCharsAsStringTo
(
const
char
*
begin
,
size_t
len
,
ostream
*
os
)
{
*
os
<<
"
\"
"
;
for
(
size_t
index
=
0
;
index
<
len
;
++
index
)
{
PrintAsStringLiteralTo
(
begin
[
index
],
os
);
}
*
os
<<
"
\"
"
;
}
// Prints a (const) char array of 'len' elements, starting at address 'begin'.
void
UniversalPrintArray
(
const
char
*
begin
,
size_t
len
,
ostream
*
os
)
{
PrintCharsAsStringTo
(
begin
,
len
,
os
);
}
// Prints the given array of wide characters to the ostream.
// The array starts at *begin, the length is len, it may include L'\0'
// characters and may not be null-terminated.
static
void
PrintWideCharsAsStringTo
(
const
wchar_t
*
begin
,
size_t
len
,
ostream
*
os
)
{
*
os
<<
"L
\"
"
;
for
(
size_t
index
=
0
;
index
<
len
;
++
index
)
{
PrintAsWideStringLiteralTo
(
begin
[
index
],
os
);
}
*
os
<<
"
\"
"
;
}
// Prints the given C string to the ostream.
void
PrintTo
(
const
char
*
s
,
ostream
*
os
)
{
if
(
s
==
NULL
)
{
*
os
<<
"NULL"
;
}
else
{
*
os
<<
implicit_cast
<
const
void
*>
(
s
)
<<
" pointing to "
;
PrintCharsAsStringTo
(
s
,
strlen
(
s
),
os
);
}
}
// MSVC compiler can be configured to define whar_t as a typedef
// of unsigned short. Defining an overload for const wchar_t* in that case
// would cause pointers to unsigned shorts be printed as wide strings,
// possibly accessing more memory than intended and causing invalid
// memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when
// wchar_t is implemented as a native type.
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
// Prints the given wide C string to the ostream.
void
PrintTo
(
const
wchar_t
*
s
,
ostream
*
os
)
{
if
(
s
==
NULL
)
{
*
os
<<
"NULL"
;
}
else
{
*
os
<<
implicit_cast
<
const
void
*>
(
s
)
<<
" pointing to "
;
PrintWideCharsAsStringTo
(
s
,
wcslen
(
s
),
os
);
}
}
#endif // wchar_t is native
// Prints a ::string object.
#if GTEST_HAS_GLOBAL_STRING
void
PrintStringTo
(
const
::
string
&
s
,
ostream
*
os
)
{
PrintCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
);
}
#endif // GTEST_HAS_GLOBAL_STRING
void
PrintStringTo
(
const
::
std
::
string
&
s
,
ostream
*
os
)
{
PrintCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
);
}
// Prints a ::wstring object.
#if GTEST_HAS_GLOBAL_WSTRING
void
PrintWideStringTo
(
const
::
wstring
&
s
,
ostream
*
os
)
{
PrintWideCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
);
}
#endif // GTEST_HAS_GLOBAL_WSTRING
#if GTEST_HAS_STD_WSTRING
void
PrintWideStringTo
(
const
::
std
::
wstring
&
s
,
ostream
*
os
)
{
PrintWideCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
);
}
#endif // GTEST_HAS_STD_WSTRING
}
// namespace internal
}
// namespace testing
test/gmock-actions_test.cc
View file @
02f71065
...
...
@@ -74,9 +74,9 @@ using testing::SetArgumentPointee;
using
testing
::
SetErrnoAndReturn
;
#endif
#if G
MOCK
_HAS_PROTOBUF_
#if G
TEST
_HAS_PROTOBUF_
using
testing
::
internal
::
TestMessage
;
#endif // G
MOCK
_HAS_PROTOBUF_
#endif // G
TEST
_HAS_PROTOBUF_
// Tests that BuiltInDefaultValue<T*>::Get() returns NULL.
TEST
(
BuiltInDefaultValueTest
,
IsNullForPointerTypes
)
{
...
...
@@ -689,7 +689,7 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointee) {
EXPECT_EQ
(
'a'
,
ch
);
}
#if G
MOCK
_HAS_PROTOBUF_
#if G
TEST
_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.
...
...
@@ -786,7 +786,7 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProto2BufferBaseType) {
EXPECT_EQ
(
"hi"
,
dest
.
string_field
());
}
#endif // G
MOCK
_HAS_PROTOBUF_
#endif // G
TEST
_HAS_PROTOBUF_
// Sample functions and functors for testing Invoke() and etc.
int
Nullary
()
{
return
1
;
}
...
...
test/gmock-internal-utils_test.cc
View file @
02f71065
...
...
@@ -96,102 +96,6 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
ConvertIdentifierNameToWords
(
"_Chapter11Section_1_"
));
}
// Tests that CompileAssertTypesEqual compiles when the type arguments are
// equal.
TEST
(
CompileAssertTypesEqual
,
CompilesWhenTypesAreEqual
)
{
CompileAssertTypesEqual
<
void
,
void
>
();
CompileAssertTypesEqual
<
int
*
,
int
*>
();
}
// Tests that RemoveReference does not affect non-reference types.
TEST
(
RemoveReferenceTest
,
DoesNotAffectNonReferenceType
)
{
CompileAssertTypesEqual
<
int
,
RemoveReference
<
int
>::
type
>
();
CompileAssertTypesEqual
<
const
char
,
RemoveReference
<
const
char
>::
type
>
();
}
// Tests that RemoveReference removes reference from reference types.
TEST
(
RemoveReferenceTest
,
RemovesReference
)
{
CompileAssertTypesEqual
<
int
,
RemoveReference
<
int
&>::
type
>
();
CompileAssertTypesEqual
<
const
char
,
RemoveReference
<
const
char
&>::
type
>
();
}
// Tests GMOCK_REMOVE_REFERENCE_.
template
<
typename
T1
,
typename
T2
>
void
TestGMockRemoveReference
()
{
CompileAssertTypesEqual
<
T1
,
GMOCK_REMOVE_REFERENCE_
(
T2
)
>
();
}
TEST
(
RemoveReferenceTest
,
MacroVersion
)
{
TestGMockRemoveReference
<
int
,
int
>
();
TestGMockRemoveReference
<
const
char
,
const
char
&>
();
}
// Tests that RemoveConst does not affect non-const types.
TEST
(
RemoveConstTest
,
DoesNotAffectNonConstType
)
{
CompileAssertTypesEqual
<
int
,
RemoveConst
<
int
>::
type
>
();
CompileAssertTypesEqual
<
char
&
,
RemoveConst
<
char
&>::
type
>
();
}
// Tests that RemoveConst removes const from const types.
TEST
(
RemoveConstTest
,
RemovesConst
)
{
CompileAssertTypesEqual
<
int
,
RemoveConst
<
const
int
>::
type
>
();
CompileAssertTypesEqual
<
char
[
2
],
RemoveConst
<
const
char
[
2
]
>::
type
>
();
CompileAssertTypesEqual
<
char
[
2
][
3
],
RemoveConst
<
const
char
[
2
][
3
]
>::
type
>
();
}
// Tests GMOCK_REMOVE_CONST_.
template
<
typename
T1
,
typename
T2
>
void
TestGMockRemoveConst
()
{
CompileAssertTypesEqual
<
T1
,
GMOCK_REMOVE_CONST_
(
T2
)
>
();
}
TEST
(
RemoveConstTest
,
MacroVersion
)
{
TestGMockRemoveConst
<
int
,
int
>
();
TestGMockRemoveConst
<
double
&
,
double
&>
();
TestGMockRemoveConst
<
char
,
const
char
>
();
}
// Tests that AddReference does not affect reference types.
TEST
(
AddReferenceTest
,
DoesNotAffectReferenceType
)
{
CompileAssertTypesEqual
<
int
&
,
AddReference
<
int
&>::
type
>
();
CompileAssertTypesEqual
<
const
char
&
,
AddReference
<
const
char
&>::
type
>
();
}
// Tests that AddReference adds reference to non-reference types.
TEST
(
AddReferenceTest
,
AddsReference
)
{
CompileAssertTypesEqual
<
int
&
,
AddReference
<
int
>::
type
>
();
CompileAssertTypesEqual
<
const
char
&
,
AddReference
<
const
char
>::
type
>
();
}
// Tests GMOCK_ADD_REFERENCE_.
template
<
typename
T1
,
typename
T2
>
void
TestGMockAddReference
()
{
CompileAssertTypesEqual
<
T1
,
GMOCK_ADD_REFERENCE_
(
T2
)
>
();
}
TEST
(
AddReferenceTest
,
MacroVersion
)
{
TestGMockAddReference
<
int
&
,
int
>
();
TestGMockAddReference
<
const
char
&
,
const
char
&>
();
}
// Tests GMOCK_REFERENCE_TO_CONST_.
template
<
typename
T1
,
typename
T2
>
void
TestGMockReferenceToConst
()
{
CompileAssertTypesEqual
<
T1
,
GMOCK_REFERENCE_TO_CONST_
(
T2
)
>
();
}
TEST
(
GMockReferenceToConstTest
,
Works
)
{
TestGMockReferenceToConst
<
const
char
&
,
char
>
();
TestGMockReferenceToConst
<
const
int
&
,
const
int
>
();
TestGMockReferenceToConst
<
const
double
&
,
double
>
();
TestGMockReferenceToConst
<
const
string
&
,
const
string
&>
();
}
TEST
(
PointeeOfTest
,
WorksForSmartPointers
)
{
CompileAssertTypesEqual
<
const
char
,
PointeeOf
<
internal
::
linked_ptr
<
const
char
>
>::
type
>
();
...
...
@@ -217,38 +121,11 @@ TEST(GetRawPointerTest, WorksForRawPointers) {
EXPECT_EQ
(
&
n
,
GetRawPointer
(
&
n
));
}
// Tests KindOf<T>.
class
Base
{};
class
Derived
:
public
Base
{};
// Tests that ImplicitlyConvertible<T1, T2>::value is a compile-time constant.
TEST
(
ImplicitlyConvertibleTest
,
ValueIsCompileTimeConstant
)
{
GMOCK_COMPILE_ASSERT_
((
ImplicitlyConvertible
<
int
,
int
>::
value
),
const_true
);
GMOCK_COMPILE_ASSERT_
((
!
ImplicitlyConvertible
<
void
*
,
int
*>::
value
),
const_false
);
}
// Tests that ImplicitlyConvertible<T1, T2>::value is true when T1 can
// be implicitly converted to T2.
TEST
(
ImplicitlyConvertibleTest
,
ValueIsTrueWhenConvertible
)
{
EXPECT_TRUE
((
ImplicitlyConvertible
<
int
,
double
>::
value
));
EXPECT_TRUE
((
ImplicitlyConvertible
<
double
,
int
>::
value
));
EXPECT_TRUE
((
ImplicitlyConvertible
<
int
*
,
void
*>::
value
));
EXPECT_TRUE
((
ImplicitlyConvertible
<
int
*
,
const
int
*>::
value
));
EXPECT_TRUE
((
ImplicitlyConvertible
<
Derived
&
,
const
Base
&>::
value
));
EXPECT_TRUE
((
ImplicitlyConvertible
<
const
Base
,
Base
>::
value
));
}
// Tests that ImplicitlyConvertible<T1, T2>::value is false when T1
// cannot be implicitly converted to T2.
TEST
(
ImplicitlyConvertibleTest
,
ValueIsFalseWhenNotConvertible
)
{
EXPECT_FALSE
((
ImplicitlyConvertible
<
double
,
int
*>::
value
));
EXPECT_FALSE
((
ImplicitlyConvertible
<
void
*
,
int
*>::
value
));
EXPECT_FALSE
((
ImplicitlyConvertible
<
const
int
*
,
int
*>::
value
));
EXPECT_FALSE
((
ImplicitlyConvertible
<
Base
&
,
Derived
&>::
value
));
}
// Tests KindOf<T>.
TEST
(
KindOfTest
,
Bool
)
{
EXPECT_EQ
(
kBool
,
GMOCK_KIND_OF_
(
bool
));
// NOLINT
}
...
...
@@ -382,46 +259,6 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
}
}
// Tests that IsAProtocolMessage<T>::value is a compile-time constant.
TEST
(
IsAProtocolMessageTest
,
ValueIsCompileTimeConstant
)
{
GMOCK_COMPILE_ASSERT_
(
IsAProtocolMessage
<
ProtocolMessage
>::
value
,
const_true
);
GMOCK_COMPILE_ASSERT_
(
!
IsAProtocolMessage
<
int
>::
value
,
const_false
);
}
// Tests that IsAProtocolMessage<T>::value is true when T is
// ProtocolMessage or a sub-class of it.
TEST
(
IsAProtocolMessageTest
,
ValueIsTrueWhenTypeIsAProtocolMessage
)
{
EXPECT_TRUE
(
IsAProtocolMessage
<
::
proto2
::
Message
>::
value
);
EXPECT_TRUE
(
IsAProtocolMessage
<
ProtocolMessage
>::
value
);
#if GMOCK_HAS_PROTOBUF_
EXPECT_TRUE
(
IsAProtocolMessage
<
const
TestMessage
>::
value
);
#endif // GMOCK_HAS_PROTOBUF_
}
// Tests that IsAProtocolMessage<T>::value is false when T is neither
// ProtocolMessage nor a sub-class of it.
TEST
(
IsAProtocolMessageTest
,
ValueIsFalseWhenTypeIsNotAProtocolMessage
)
{
EXPECT_FALSE
(
IsAProtocolMessage
<
int
>::
value
);
EXPECT_FALSE
(
IsAProtocolMessage
<
const
Base
>::
value
);
}
// Tests IsContainerTest.
class
NonContainer
{};
TEST
(
IsContainerTestTest
,
WorksForNonContainer
)
{
EXPECT_EQ
(
sizeof
(
IsNotContainer
),
sizeof
(
IsContainerTest
<
int
>
(
0
)));
EXPECT_EQ
(
sizeof
(
IsNotContainer
),
sizeof
(
IsContainerTest
<
char
[
5
]
>
(
0
)));
EXPECT_EQ
(
sizeof
(
IsNotContainer
),
sizeof
(
IsContainerTest
<
NonContainer
>
(
0
)));
}
TEST
(
IsContainerTestTest
,
WorksForContainer
)
{
EXPECT_EQ
(
sizeof
(
IsContainer
),
sizeof
(
IsContainerTest
<
std
::
vector
<
bool
>
>
(
0
)));
EXPECT_EQ
(
sizeof
(
IsContainer
),
sizeof
(
IsContainerTest
<
std
::
map
<
int
,
double
>
>
(
0
)));
}
// Tests the TupleMatches() template function.
TEST
(
TupleMatchesTest
,
WorksForSize0
)
{
...
...
@@ -737,148 +574,6 @@ TEST(OnCallTest, LogsAnythingArgument) {
#endif // GTEST_HAS_STREAM_REDIRECTION_
// Tests ArrayEq().
TEST
(
ArrayEqTest
,
WorksForDegeneratedArrays
)
{
EXPECT_TRUE
(
ArrayEq
(
5
,
5L
));
EXPECT_FALSE
(
ArrayEq
(
'a'
,
0
));
}
TEST
(
ArrayEqTest
,
WorksForOneDimensionalArrays
)
{
const
int
a
[]
=
{
0
,
1
};
long
b
[]
=
{
0
,
1
};
EXPECT_TRUE
(
ArrayEq
(
a
,
b
));
EXPECT_TRUE
(
ArrayEq
(
a
,
2
,
b
));
b
[
0
]
=
2
;
EXPECT_FALSE
(
ArrayEq
(
a
,
b
));
EXPECT_FALSE
(
ArrayEq
(
a
,
1
,
b
));
}
TEST
(
ArrayEqTest
,
WorksForTwoDimensionalArrays
)
{
const
char
a
[][
3
]
=
{
"hi"
,
"lo"
};
const
char
b
[][
3
]
=
{
"hi"
,
"lo"
};
const
char
c
[][
3
]
=
{
"hi"
,
"li"
};
EXPECT_TRUE
(
ArrayEq
(
a
,
b
));
EXPECT_TRUE
(
ArrayEq
(
a
,
2
,
b
));
EXPECT_FALSE
(
ArrayEq
(
a
,
c
));
EXPECT_FALSE
(
ArrayEq
(
a
,
2
,
c
));
}
// Tests ArrayAwareFind().
TEST
(
ArrayAwareFindTest
,
WorksForOneDimensionalArray
)
{
const
char
a
[]
=
"hello"
;
EXPECT_EQ
(
a
+
4
,
ArrayAwareFind
(
a
,
a
+
5
,
'o'
));
EXPECT_EQ
(
a
+
5
,
ArrayAwareFind
(
a
,
a
+
5
,
'x'
));
}
TEST
(
ArrayAwareFindTest
,
WorksForTwoDimensionalArray
)
{
int
a
[][
2
]
=
{
{
0
,
1
},
{
2
,
3
},
{
4
,
5
}
};
const
int
b
[
2
]
=
{
2
,
3
};
EXPECT_EQ
(
a
+
1
,
ArrayAwareFind
(
a
,
a
+
3
,
b
));
const
int
c
[
2
]
=
{
6
,
7
};
EXPECT_EQ
(
a
+
3
,
ArrayAwareFind
(
a
,
a
+
3
,
c
));
}
// Tests CopyArray().
TEST
(
CopyArrayTest
,
WorksForDegeneratedArrays
)
{
int
n
=
0
;
CopyArray
(
'a'
,
&
n
);
EXPECT_EQ
(
'a'
,
n
);
}
TEST
(
CopyArrayTest
,
WorksForOneDimensionalArrays
)
{
const
char
a
[
3
]
=
"hi"
;
int
b
[
3
];
CopyArray
(
a
,
&
b
);
EXPECT_TRUE
(
ArrayEq
(
a
,
b
));
int
c
[
3
];
CopyArray
(
a
,
3
,
c
);
EXPECT_TRUE
(
ArrayEq
(
a
,
c
));
}
TEST
(
CopyArrayTest
,
WorksForTwoDimensionalArrays
)
{
const
int
a
[
2
][
3
]
=
{
{
0
,
1
,
2
},
{
3
,
4
,
5
}
};
int
b
[
2
][
3
];
CopyArray
(
a
,
&
b
);
EXPECT_TRUE
(
ArrayEq
(
a
,
b
));
int
c
[
2
][
3
];
CopyArray
(
a
,
2
,
c
);
EXPECT_TRUE
(
ArrayEq
(
a
,
c
));
}
// Tests NativeArray.
TEST
(
NativeArrayTest
,
ConstructorFromArrayWorks
)
{
const
int
a
[
3
]
=
{
0
,
1
,
2
};
NativeArray
<
int
>
na
(
a
,
3
,
kReference
);
EXPECT_EQ
(
3U
,
na
.
size
());
EXPECT_EQ
(
a
,
na
.
begin
());
}
TEST
(
NativeArrayTest
,
CreatesAndDeletesCopyOfArrayWhenAskedTo
)
{
typedef
int
Array
[
2
];
Array
*
a
=
new
Array
[
1
];
(
*
a
)[
0
]
=
0
;
(
*
a
)[
1
]
=
1
;
NativeArray
<
int
>
na
(
*
a
,
2
,
kCopy
);
EXPECT_NE
(
*
a
,
na
.
begin
());
delete
[]
a
;
EXPECT_EQ
(
0
,
na
.
begin
()[
0
]);
EXPECT_EQ
(
1
,
na
.
begin
()[
1
]);
// We rely on the heap checker to verify that na deletes the copy of
// array.
}
TEST
(
NativeArrayTest
,
TypeMembersAreCorrect
)
{
StaticAssertTypeEq
<
char
,
NativeArray
<
char
>::
value_type
>
();
StaticAssertTypeEq
<
int
[
2
],
NativeArray
<
int
[
2
]
>::
value_type
>
();
StaticAssertTypeEq
<
const
char
*
,
NativeArray
<
char
>::
const_iterator
>
();
StaticAssertTypeEq
<
const
bool
(
*
)[
2
],
NativeArray
<
bool
[
2
]
>::
const_iterator
>
();
}
TEST
(
NativeArrayTest
,
MethodsWork
)
{
const
int
a
[
3
]
=
{
0
,
1
,
2
};
NativeArray
<
int
>
na
(
a
,
3
,
kCopy
);
ASSERT_EQ
(
3U
,
na
.
size
());
EXPECT_EQ
(
3
,
na
.
end
()
-
na
.
begin
());
NativeArray
<
int
>::
const_iterator
it
=
na
.
begin
();
EXPECT_EQ
(
0
,
*
it
);
++
it
;
EXPECT_EQ
(
1
,
*
it
);
it
++
;
EXPECT_EQ
(
2
,
*
it
);
++
it
;
EXPECT_EQ
(
na
.
end
(),
it
);
EXPECT_THAT
(
na
,
Eq
(
na
));
NativeArray
<
int
>
na2
(
a
,
3
,
kReference
);
EXPECT_THAT
(
na
,
Eq
(
na2
));
const
int
b1
[
3
]
=
{
0
,
1
,
1
};
const
int
b2
[
4
]
=
{
0
,
1
,
2
,
3
};
EXPECT_THAT
(
na
,
Not
(
Eq
(
NativeArray
<
int
>
(
b1
,
3
,
kReference
))));
EXPECT_THAT
(
na
,
Not
(
Eq
(
NativeArray
<
int
>
(
b2
,
4
,
kCopy
))));
}
TEST
(
NativeArrayTest
,
WorksForTwoDimensionalArray
)
{
const
char
a
[
2
][
3
]
=
{
"hi"
,
"lo"
};
NativeArray
<
char
[
3
]
>
na
(
a
,
2
,
kReference
);
ASSERT_EQ
(
2U
,
na
.
size
());
EXPECT_EQ
(
a
,
na
.
begin
());
}
// Tests StlContainerView.
TEST
(
StlContainerViewTest
,
WorksForStlContainer
)
{
...
...
test/gmock-port_test.cc
View file @
02f71065
...
...
@@ -39,126 +39,5 @@
// NOTE: if this file is left without tests for some reason, put a dummy
// test here to make references to symbols in the gtest library and avoid
// 'undefined symbol' linker errors in gmock_main:
//
// TEST(DummyTest, Dummy) {}
namespace
testing
{
namespace
internal
{
// Needed to avoid name collisions in gmock_all_test.cc.
namespace
gmock_port_test
{
class
Base
{
public:
// Copy constructor and assignment operator do exactly what we need, so we
// use them.
Base
()
:
member_
(
0
)
{}
explicit
Base
(
int
n
)
:
member_
(
n
)
{}
virtual
~
Base
()
{}
int
member
()
{
return
member_
;
}
private:
int
member_
;
};
class
Derived
:
public
Base
{
public:
explicit
Derived
(
int
n
)
:
Base
(
n
)
{}
};
TEST
(
ImplicitCastTest
,
ConvertsPointers
)
{
Derived
derived
(
0
);
EXPECT_TRUE
(
&
derived
==
::
testing
::
internal
::
implicit_cast
<
Base
*>
(
&
derived
));
}
TEST
(
ImplicitCastTest
,
CanUseInheritance
)
{
Derived
derived
(
1
);
Base
base
=
::
testing
::
internal
::
implicit_cast
<
Base
>
(
derived
);
EXPECT_EQ
(
derived
.
member
(),
base
.
member
());
}
class
Castable
{
public:
Castable
(
bool
*
converted
)
:
converted_
(
converted
)
{}
operator
Base
()
{
*
converted_
=
true
;
return
Base
();
}
private:
bool
*
converted_
;
};
TEST
(
ImplicitCastTest
,
CanUseNonConstCastOperator
)
{
bool
converted
=
false
;
Castable
castable
(
&
converted
);
Base
base
=
::
testing
::
internal
::
implicit_cast
<
Base
>
(
castable
);
EXPECT_TRUE
(
converted
);
}
class
ConstCastable
{
public:
ConstCastable
(
bool
*
converted
)
:
converted_
(
converted
)
{}
operator
Base
()
const
{
*
converted_
=
true
;
return
Base
();
}
private:
bool
*
converted_
;
};
TEST
(
ImplicitCastTest
,
CanUseConstCastOperatorOnConstValues
)
{
bool
converted
=
false
;
const
ConstCastable
const_castable
(
&
converted
);
Base
base
=
::
testing
::
internal
::
implicit_cast
<
Base
>
(
const_castable
);
EXPECT_TRUE
(
converted
);
}
class
ConstAndNonConstCastable
{
public:
ConstAndNonConstCastable
(
bool
*
converted
,
bool
*
const_converted
)
:
converted_
(
converted
),
const_converted_
(
const_converted
)
{}
operator
Base
()
{
*
converted_
=
true
;
return
Base
();
}
operator
Base
()
const
{
*
const_converted_
=
true
;
return
Base
();
}
private:
bool
*
converted_
;
bool
*
const_converted_
;
};
TEST
(
ImplicitCastTest
,
CanSelectBetweenConstAndNonConstCasrAppropriately
)
{
bool
converted
=
false
;
bool
const_converted
=
false
;
ConstAndNonConstCastable
castable
(
&
converted
,
&
const_converted
);
Base
base
=
::
testing
::
internal
::
implicit_cast
<
Base
>
(
castable
);
EXPECT_TRUE
(
converted
);
EXPECT_FALSE
(
const_converted
);
converted
=
false
;
const_converted
=
false
;
const
ConstAndNonConstCastable
const_castable
(
&
converted
,
&
const_converted
);
base
=
::
testing
::
internal
::
implicit_cast
<
Base
>
(
const_castable
);
EXPECT_FALSE
(
converted
);
EXPECT_TRUE
(
const_converted
);
}
class
To
{
public:
To
(
bool
*
converted
)
{
*
converted
=
true
;
}
// NOLINT
};
TEST
(
ImplicitCastTest
,
CanUseImplicitConstructor
)
{
bool
converted
=
false
;
To
to
=
::
testing
::
internal
::
implicit_cast
<
To
>
(
&
converted
);
EXPECT_TRUE
(
converted
);
}
}
// namespace gmock_port_test
}
// namespace internal
}
// namespace testing
TEST
(
DummyTest
,
Dummy
)
{}
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment