Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
95b12332
Commit
95b12332
authored
Sep 25, 2009
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Makes gmock work on Symbian (both 3rd & 5th editions), original patch contributed by Mika Raento.
parent
2d970ee3
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
165 additions
and
72 deletions
+165
-72
gmock-actions.h
include/gmock/gmock-actions.h
+1
-20
gmock-generated-matchers.h
include/gmock/gmock-generated-matchers.h
+9
-5
gmock-generated-matchers.h.pump
include/gmock/gmock-generated-matchers.h.pump
+15
-0
gmock-matchers.h
include/gmock/gmock-matchers.h
+30
-18
gmock-internal-utils.h
include/gmock/internal/gmock-internal-utils.h
+50
-4
gmock-actions_test.cc
test/gmock-actions_test.cc
+15
-4
gmock-internal-utils_test.cc
test/gmock-internal-utils_test.cc
+2
-1
gmock-matchers_test.cc
test/gmock-matchers_test.cc
+39
-16
gmock-printers_test.cc
test/gmock-printers_test.cc
+4
-4
No files found.
include/gmock/gmock-actions.h
View file @
95b12332
...
@@ -125,32 +125,13 @@ GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
...
@@ -125,32 +125,13 @@ GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
(
signed
char
,
'\0'
);
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
(
signed
char
,
'\0'
);
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
(
char
,
'\0'
);
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
(
char
,
'\0'
);
// signed wchar_t and unsigned wchar_t are NOT in the C++ standard.
// Using them is a bad practice and not portable. So don't use them.
//
// Still, Google Mock is designed to work even if the user uses signed
// wchar_t or unsigned wchar_t (obviously, assuming the compiler
// supports them).
//
// To gcc,
//
// wchar_t == signed wchar_t != unsigned wchar_t == unsigned int
//
// MSVC does not recognize signed wchar_t or unsigned wchar_t. It
// treats wchar_t as a native type usually, but treats it as the same
// as unsigned short when the compiler option /Zc:wchar_t- is
// specified.
//
// Therefore we provide a default action for wchar_t when compiled
// with gcc or _NATIVE_WCHAR_T_DEFINED is defined.
//
// There's no need for a default action for signed wchar_t, as that
// There's no need for a default action for signed wchar_t, as that
// type is the same as wchar_t for gcc, and invalid for MSVC.
// type is the same as wchar_t for gcc, and invalid for MSVC.
//
//
// There's also no need for a default action for unsigned wchar_t, as
// There's also no need for a default action for unsigned wchar_t, as
// that type is the same as unsigned int for gcc, and invalid for
// that type is the same as unsigned int for gcc, and invalid for
// MSVC.
// MSVC.
#if
defined(__GNUC__) || defined(_NATIVE_WCHAR_T_DEFINED)
#if
GMOCK_WCHAR_T_IS_NATIVE_
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
(
wchar_t
,
0U
);
// NOLINT
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
(
wchar_t
,
0U
);
// NOLINT
#endif
#endif
...
...
include/gmock/gmock-generated-matchers.h
View file @
95b12332
...
@@ -304,11 +304,15 @@ class ElementsAreMatcher1 {
...
@@ -304,11 +304,15 @@ class ElementsAreMatcher1 {
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
Element
;
const
Matcher
<
const
Element
&>
matchers
[]
=
{
// Nokia's Symbian Compiler has a nasty bug where the object put
MatcherCast
<
const
Element
&>
(
e1_
),
// in a one-element local array is not destructed when the array
};
// goes out of scope. This leads to obvious badness as we've
// added the linked_ptr in it to our other linked_ptrs list.
return
MakeMatcher
(
new
ElementsAreMatcherImpl
<
Container
>
(
matchers
,
1
));
// Hence we implement ElementsAreMatcher1 specially to avoid using
// a local array.
const
Matcher
<
const
Element
&>
matcher
=
MatcherCast
<
const
Element
&>
(
e1_
);
return
MakeMatcher
(
new
ElementsAreMatcherImpl
<
Container
>
(
&
matcher
,
1
));
}
}
private
:
private
:
...
...
include/gmock/gmock-generated-matchers.h.pump
View file @
95b12332
...
@@ -192,6 +192,19 @@ class ElementsAreMatcher$i {
...
@@ -192,6 +192,19 @@ class ElementsAreMatcher$i {
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
typedef
typename
internal
::
StlContainerView
<
RawContainer
>::
type
::
value_type
Element
;
Element
;
$
if
i
==
1
[[
// Nokia's Symbian Compiler has a nasty bug where the object put
// in a one-element local array is not destructed when the array
// goes out of scope. This leads to obvious badness as we've
// added the linked_ptr in it to our other linked_ptrs list.
// Hence we implement ElementsAreMatcher1 specially to avoid using
// a local array.
const
Matcher
<
const
Element
&>
matcher
=
MatcherCast
<
const
Element
&>
(
e1_
);
return
MakeMatcher
(
new
ElementsAreMatcherImpl
<
Container
>
(
&
matcher
,
1
));
]]
$
else
[[
const
Matcher
<
const
Element
&>
matchers
[]
=
{
const
Matcher
<
const
Element
&>
matchers
[]
=
{
$
for
j
[[
$
for
j
[[
...
@@ -201,6 +214,8 @@ $for j [[
...
@@ -201,6 +214,8 @@ $for j [[
};
};
return
MakeMatcher
(
new
ElementsAreMatcherImpl
<
Container
>
(
matchers
,
$
i
));
return
MakeMatcher
(
new
ElementsAreMatcherImpl
<
Container
>
(
matchers
,
$
i
));
]]
}
}
private
:
private
:
...
...
include/gmock/gmock-matchers.h
View file @
95b12332
...
@@ -320,28 +320,34 @@ inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) {
...
@@ -320,28 +320,34 @@ inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) {
template
<
typename
T
,
typename
M
>
template
<
typename
T
,
typename
M
>
Matcher
<
T
>
MatcherCast
(
M
m
);
Matcher
<
T
>
MatcherCast
(
M
m
);
// TODO(vladl@google.com): Modify the implementation to reject casting
// Matcher<int> to Matcher<double>.
// Implements SafeMatcherCast().
// Implements SafeMatcherCast().
//
//
// This overload handles polymorphic matchers only since monomorphic
// We use an intermediate class to do the actual safe casting as Nokia's
// matchers are handled by the next one.
// Symbian compiler cannot decide between
template
<
typename
T
,
typename
M
>
// template <T, M> ... (M) and
inline
Matcher
<
T
>
SafeMatcherCast
(
M
polymorphic_matcher
)
{
// template <T, U> ... (const Matcher<U>&)
// for function templates but can for member function templates.
template
<
typename
T
>
class
SafeMatcherCastImpl
{
public
:
// This overload handles polymorphic matchers only since monomorphic
// matchers are handled by the next one.
template
<
typename
M
>
static
inline
Matcher
<
T
>
Cast
(
M
polymorphic_matcher
)
{
return
Matcher
<
T
>
(
polymorphic_matcher
);
return
Matcher
<
T
>
(
polymorphic_matcher
);
}
}
// This overload handles monomorphic matchers.
// This overload handles monomorphic matchers.
//
//
// In general, if type T can be implicitly converted to type U, we can
// In general, if type T can be implicitly converted to type U, we can
// safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
// safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
// contravariant): just keep a copy of the original Matcher<U>, convert the
// contravariant): just keep a copy of the original Matcher<U>, convert the
// argument from type T to U, and then pass it to the underlying Matcher<U>.
// argument from type T to U, and then pass it to the underlying Matcher<U>.
// The only exception is when U is a reference and T is not, as the
// The only exception is when U is a reference and T is not, as the
// underlying Matcher<U> may be interested in the argument's address, which
// underlying Matcher<U> may be interested in the argument's address, which
// is not preserved in the conversion from T to U.
// is not preserved in the conversion from T to U.
template
<
typename
T
,
typename
U
>
template
<
typename
U
>
Matcher
<
T
>
SafeMatcher
Cast
(
const
Matcher
<
U
>&
matcher
)
{
static
inline
Matcher
<
T
>
Cast
(
const
Matcher
<
U
>&
matcher
)
{
// Enforce that T can be implicitly converted to U.
// Enforce that T can be implicitly converted to U.
GMOCK_COMPILE_ASSERT_
((
internal
::
ImplicitlyConvertible
<
T
,
U
>::
value
),
GMOCK_COMPILE_ASSERT_
((
internal
::
ImplicitlyConvertible
<
T
,
U
>::
value
),
T_must_be_implicitly_convertible_to_U
);
T_must_be_implicitly_convertible_to_U
);
...
@@ -361,6 +367,12 @@ Matcher<T> SafeMatcherCast(const Matcher<U>& matcher) {
...
@@ -361,6 +367,12 @@ Matcher<T> SafeMatcherCast(const Matcher<U>& matcher) {
(
internal
::
LosslessArithmeticConvertible
<
RawT
,
RawU
>::
value
),
(
internal
::
LosslessArithmeticConvertible
<
RawT
,
RawU
>::
value
),
conversion_of_arithmetic_types_must_be_lossless
);
conversion_of_arithmetic_types_must_be_lossless
);
return
MatcherCast
<
T
>
(
matcher
);
return
MatcherCast
<
T
>
(
matcher
);
}
};
template
<
typename
T
,
typename
M
>
inline
Matcher
<
T
>
SafeMatcherCast
(
const
M
&
polymorphic_matcher
)
{
return
SafeMatcherCastImpl
<
T
>::
Cast
(
polymorphic_matcher
);
}
}
// A<T>() returns a matcher that matches any value of type T.
// A<T>() returns a matcher that matches any value of type T.
...
...
include/gmock/internal/gmock-internal-utils.h
View file @
95b12332
...
@@ -221,6 +221,34 @@ class ImplicitlyConvertible {
...
@@ -221,6 +221,34 @@ class ImplicitlyConvertible {
template
<
typename
From
,
typename
To
>
template
<
typename
From
,
typename
To
>
const
bool
ImplicitlyConvertible
<
From
,
To
>::
value
;
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.
//
// MSVC treats wchar_t as a native type usually, but treats it as the
// same as unsigned short when the compiler option /Zc:wchar_t- is
// specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
// is a native type.
#if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \
(defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED))
// wchar_t is a typedef.
#else
#define GMOCK_WCHAR_T_IS_NATIVE_ 1
#endif
// signed wchar_t and unsigned wchar_t are NOT in the C++ standard.
// Using them is a bad practice and not portable. So DON'T use them.
//
// Still, Google Mock is designed to work even if the user uses signed
// wchar_t or unsigned wchar_t (obviously, assuming the compiler
// supports them).
//
// To gcc,
// wchar_t == signed wchar_t != unsigned wchar_t == unsigned int
#ifdef __GNUC__
#define GMOCK_HAS_SIGNED_WCHAR_T_ 1 // signed/unsigned wchar_t are valid types.
#endif
// In what follows, we use the term "kind" to indicate whether a type
// In what follows, we use the term "kind" to indicate whether a type
// is bool, an integer type (excluding bool), a floating-point type,
// is bool, an integer type (excluding bool), a floating-point type,
// or none of them. This categorization is useful for determining
// or none of them. This categorization is useful for determining
...
@@ -252,10 +280,7 @@ GMOCK_DECLARE_KIND_(unsigned int, kInteger);
...
@@ -252,10 +280,7 @@ GMOCK_DECLARE_KIND_(unsigned int, kInteger);
GMOCK_DECLARE_KIND_
(
long
,
kInteger
);
// NOLINT
GMOCK_DECLARE_KIND_
(
long
,
kInteger
);
// NOLINT
GMOCK_DECLARE_KIND_
(
unsigned
long
,
kInteger
);
// NOLINT
GMOCK_DECLARE_KIND_
(
unsigned
long
,
kInteger
);
// NOLINT
// MSVC can be configured to define wchar_t as a typedef of unsigned
#if GMOCK_WCHAR_T_IS_NATIVE_
// short. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t is a
// native type.
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
GMOCK_DECLARE_KIND_
(
wchar_t
,
kInteger
);
GMOCK_DECLARE_KIND_
(
wchar_t
,
kInteger
);
#endif
#endif
...
@@ -679,10 +704,31 @@ class StlContainerView<Element[N]> {
...
@@ -679,10 +704,31 @@ class StlContainerView<Element[N]> {
static
const_reference
ConstReference
(
const
Element
(
&
array
)[
N
])
{
static
const_reference
ConstReference
(
const
Element
(
&
array
)[
N
])
{
// Ensures that Element is not a const type.
// Ensures that Element is not a const type.
testing
::
StaticAssertTypeEq
<
Element
,
RawElement
>
();
testing
::
StaticAssertTypeEq
<
Element
,
RawElement
>
();
#if GTEST_OS_SYMBIAN
// The Nokia Symbian compiler confuses itself in template instantiation
// for this call without the cast to Element*:
// function call '[testing::internal::NativeArray<char *>].NativeArray(
// {lval} const char *[4], long, testing::internal::RelationToSource)'
// does not match
// 'testing::internal::NativeArray<char *>::NativeArray(
// char *const *, unsigned int, testing::internal::RelationToSource)'
// (instantiating: 'testing::internal::ContainsMatcherImpl
// <const char * (&)[4]>::Matches(const char * (&)[4]) const')
// (instantiating: 'testing::internal::StlContainerView<char *[4]>::
// ConstReference(const char * (&)[4])')
// (and though the N parameter type is mismatched in the above explicit
// conversion of it doesn't help - only the conversion of the array).
return
type
(
const_cast
<
Element
*>
(
&
array
[
0
]),
N
,
kReference
);
#else
return
type
(
array
,
N
,
kReference
);
return
type
(
array
,
N
,
kReference
);
#endif // GTEST_OS_SYMBIAN
}
}
static
type
Copy
(
const
Element
(
&
array
)[
N
])
{
static
type
Copy
(
const
Element
(
&
array
)[
N
])
{
#if GTEST_OS_SYMBIAN
return
type
(
const_cast
<
Element
*>
(
&
array
[
0
]),
N
,
kCopy
);
#else
return
type
(
array
,
N
,
kCopy
);
return
type
(
array
,
N
,
kCopy
);
#endif // GTEST_OS_SYMBIAN
}
}
};
};
...
...
test/gmock-actions_test.cc
View file @
95b12332
...
@@ -98,11 +98,13 @@ TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) {
...
@@ -98,11 +98,13 @@ TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) {
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
unsigned
char
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
unsigned
char
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
signed
char
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
signed
char
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
char
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
char
>::
Get
());
#if
!GTEST_OS_WINDOWS
#if
GMOCK_HAS_SIGNED_WCHAR_T_
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
unsigned
wchar_t
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
unsigned
wchar_t
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
signed
wchar_t
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
signed
wchar_t
>::
Get
());
#endif // !GTEST_OS_WINDOWS
#endif
#if GMOCK_WCHAR_T_IS_NATIVE_
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
wchar_t
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
wchar_t
>::
Get
());
#endif
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
unsigned
short
>::
Get
());
// NOLINT
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
unsigned
short
>::
Get
());
// NOLINT
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
signed
short
>::
Get
());
// NOLINT
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
signed
short
>::
Get
());
// NOLINT
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
short
>::
Get
());
// NOLINT
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
short
>::
Get
());
// NOLINT
...
@@ -124,11 +126,13 @@ TEST(BuiltInDefaultValueTest, ExistsForNumericTypes) {
...
@@ -124,11 +126,13 @@ TEST(BuiltInDefaultValueTest, ExistsForNumericTypes) {
EXPECT_TRUE
(
BuiltInDefaultValue
<
unsigned
char
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
unsigned
char
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
signed
char
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
signed
char
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
char
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
char
>::
Exists
());
#if
!GTEST_OS_WINDOWS
#if
GMOCK_HAS_SIGNED_WCHAR_T_
EXPECT_TRUE
(
BuiltInDefaultValue
<
unsigned
wchar_t
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
unsigned
wchar_t
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
signed
wchar_t
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
signed
wchar_t
>::
Exists
());
#endif // !GTEST_OS_WINDOWS
#endif
#if GMOCK_WCHAR_T_IS_NATIVE_
EXPECT_TRUE
(
BuiltInDefaultValue
<
wchar_t
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
wchar_t
>::
Exists
());
#endif
EXPECT_TRUE
(
BuiltInDefaultValue
<
unsigned
short
>::
Exists
());
// NOLINT
EXPECT_TRUE
(
BuiltInDefaultValue
<
unsigned
short
>::
Exists
());
// NOLINT
EXPECT_TRUE
(
BuiltInDefaultValue
<
signed
short
>::
Exists
());
// NOLINT
EXPECT_TRUE
(
BuiltInDefaultValue
<
signed
short
>::
Exists
());
// NOLINT
EXPECT_TRUE
(
BuiltInDefaultValue
<
short
>::
Exists
());
// NOLINT
EXPECT_TRUE
(
BuiltInDefaultValue
<
short
>::
Exists
());
// NOLINT
...
@@ -395,12 +399,19 @@ class IsNotZero : public ActionInterface<bool(int)> { // NOLINT
...
@@ -395,12 +399,19 @@ class IsNotZero : public ActionInterface<bool(int)> { // NOLINT
}
}
};
};
#if !GTEST_OS_SYMBIAN
// Compiling this test on Nokia's Symbian compiler fails with:
// 'Result' is not a member of class 'testing::internal::Function<int>'
// (point of instantiation: '@unnamed@gmock_actions_test_cc@::
// ActionTest_CanBeConvertedToOtherActionType_Test::TestBody()')
// with no obvious fix.
TEST
(
ActionTest
,
CanBeConvertedToOtherActionType
)
{
TEST
(
ActionTest
,
CanBeConvertedToOtherActionType
)
{
const
Action
<
bool
(
int
)
>
a1
(
new
IsNotZero
);
// NOLINT
const
Action
<
bool
(
int
)
>
a1
(
new
IsNotZero
);
// NOLINT
const
Action
<
int
(
char
)
>
a2
=
Action
<
int
(
char
)
>
(
a1
);
// NOLINT
const
Action
<
int
(
char
)
>
a2
=
Action
<
int
(
char
)
>
(
a1
);
// NOLINT
EXPECT_EQ
(
1
,
a2
.
Perform
(
make_tuple
(
'a'
)));
EXPECT_EQ
(
1
,
a2
.
Perform
(
make_tuple
(
'a'
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
make_tuple
(
'\0'
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
make_tuple
(
'\0'
)));
}
}
#endif // !GTEST_OS_SYMBIAN
// The following two classes are for testing MakePolymorphicAction().
// The following two classes are for testing MakePolymorphicAction().
...
...
test/gmock-internal-utils_test.cc
View file @
95b12332
...
@@ -211,7 +211,8 @@ TEST(GetRawPointerTest, WorksForSmartPointers) {
...
@@ -211,7 +211,8 @@ TEST(GetRawPointerTest, WorksForSmartPointers) {
TEST
(
GetRawPointerTest
,
WorksForRawPointers
)
{
TEST
(
GetRawPointerTest
,
WorksForRawPointers
)
{
int
*
p
=
NULL
;
int
*
p
=
NULL
;
EXPECT_EQ
(
NULL
,
GetRawPointer
(
p
));
// Don't use EXPECT_EQ as no NULL-testing magic on Symbian.
EXPECT_TRUE
(
NULL
==
GetRawPointer
(
p
));
int
n
=
1
;
int
n
=
1
;
EXPECT_EQ
(
&
n
,
GetRawPointer
(
&
n
));
EXPECT_EQ
(
&
n
,
GetRawPointer
(
&
n
));
}
}
...
...
test/gmock-matchers_test.cc
View file @
95b12332
...
@@ -699,10 +699,20 @@ TEST(IsNullTest, MatchesNullPointer) {
...
@@ -699,10 +699,20 @@ TEST(IsNullTest, MatchesNullPointer) {
EXPECT_TRUE
(
m2
.
Matches
(
p2
));
EXPECT_TRUE
(
m2
.
Matches
(
p2
));
EXPECT_FALSE
(
m2
.
Matches
(
"hi"
));
EXPECT_FALSE
(
m2
.
Matches
(
"hi"
));
#if !GTEST_OS_SYMBIAN
// Nokia's Symbian compiler generates:
// gmock-matchers.h: ambiguous access to overloaded function
// gmock-matchers.h: 'testing::Matcher<void *>::Matcher(void *)'
// gmock-matchers.h: 'testing::Matcher<void *>::Matcher(const testing::
// MatcherInterface<void *> *)'
// gmock-matchers.h: (point of instantiation: 'testing::
// gmock_matchers_test::IsNullTest_MatchesNullPointer_Test::TestBody()')
// gmock-matchers.h: (instantiating: 'testing::PolymorphicMatc
Matcher
<
void
*>
m3
=
IsNull
();
Matcher
<
void
*>
m3
=
IsNull
();
void
*
p3
=
NULL
;
void
*
p3
=
NULL
;
EXPECT_TRUE
(
m3
.
Matches
(
p3
));
EXPECT_TRUE
(
m3
.
Matches
(
p3
));
EXPECT_FALSE
(
m3
.
Matches
(
reinterpret_cast
<
void
*>
(
0xbeef
)));
EXPECT_FALSE
(
m3
.
Matches
(
reinterpret_cast
<
void
*>
(
0xbeef
)));
#endif
}
}
// Tests that IsNull() describes itself properly.
// Tests that IsNull() describes itself properly.
...
@@ -933,24 +943,24 @@ TEST(KeyTest, SafelyCastsInnerMatcher) {
...
@@ -933,24 +943,24 @@ TEST(KeyTest, SafelyCastsInnerMatcher) {
}
}
TEST
(
KeyTest
,
InsideContainsUsingMap
)
{
TEST
(
KeyTest
,
InsideContainsUsingMap
)
{
std
::
map
<
int
,
std
::
string
>
container
;
std
::
map
<
int
,
char
>
container
;
container
.
insert
(
std
::
make_pair
(
1
,
"foo"
));
container
.
insert
(
std
::
make_pair
(
1
,
'a'
));
container
.
insert
(
std
::
make_pair
(
2
,
"bar"
));
container
.
insert
(
std
::
make_pair
(
2
,
'b'
));
container
.
insert
(
std
::
make_pair
(
4
,
"baz"
));
container
.
insert
(
std
::
make_pair
(
4
,
'c'
));
EXPECT_THAT
(
container
,
Contains
(
Key
(
1
)));
EXPECT_THAT
(
container
,
Contains
(
Key
(
1
)));
EXPECT_THAT
(
container
,
Not
(
Contains
(
Key
(
3
))));
EXPECT_THAT
(
container
,
Not
(
Contains
(
Key
(
3
))));
}
}
TEST
(
KeyTest
,
InsideContainsUsingMultimap
)
{
TEST
(
KeyTest
,
InsideContainsUsingMultimap
)
{
std
::
multimap
<
int
,
std
::
string
>
container
;
std
::
multimap
<
int
,
char
>
container
;
container
.
insert
(
std
::
make_pair
(
1
,
"foo"
));
container
.
insert
(
std
::
make_pair
(
1
,
'a'
));
container
.
insert
(
std
::
make_pair
(
2
,
"bar"
));
container
.
insert
(
std
::
make_pair
(
2
,
'b'
));
container
.
insert
(
std
::
make_pair
(
4
,
"baz"
));
container
.
insert
(
std
::
make_pair
(
4
,
'c'
));
EXPECT_THAT
(
container
,
Not
(
Contains
(
Key
(
25
))));
EXPECT_THAT
(
container
,
Not
(
Contains
(
Key
(
25
))));
container
.
insert
(
std
::
make_pair
(
25
,
"more foo"
));
container
.
insert
(
std
::
make_pair
(
25
,
'd'
));
EXPECT_THAT
(
container
,
Contains
(
Key
(
25
)));
EXPECT_THAT
(
container
,
Contains
(
Key
(
25
)));
container
.
insert
(
std
::
make_pair
(
25
,
"more bar"
));
container
.
insert
(
std
::
make_pair
(
25
,
'e'
));
EXPECT_THAT
(
container
,
Contains
(
Key
(
25
)));
EXPECT_THAT
(
container
,
Contains
(
Key
(
25
)));
EXPECT_THAT
(
container
,
Contains
(
Key
(
1
)));
EXPECT_THAT
(
container
,
Contains
(
Key
(
1
)));
...
@@ -1031,13 +1041,13 @@ TEST(PairTest, SafelyCastsInnerMatchers) {
...
@@ -1031,13 +1041,13 @@ TEST(PairTest, SafelyCastsInnerMatchers) {
}
}
TEST
(
PairTest
,
InsideContainsUsingMap
)
{
TEST
(
PairTest
,
InsideContainsUsingMap
)
{
std
::
map
<
int
,
std
::
string
>
container
;
std
::
map
<
int
,
char
>
container
;
container
.
insert
(
std
::
make_pair
(
1
,
"foo"
));
container
.
insert
(
std
::
make_pair
(
1
,
'a'
));
container
.
insert
(
std
::
make_pair
(
2
,
"bar"
));
container
.
insert
(
std
::
make_pair
(
2
,
'b'
));
container
.
insert
(
std
::
make_pair
(
4
,
"baz"
));
container
.
insert
(
std
::
make_pair
(
4
,
'c'
));
EXPECT_THAT
(
container
,
Contains
(
Pair
(
1
,
"foo"
)));
EXPECT_THAT
(
container
,
Contains
(
Pair
(
1
,
'a'
)));
EXPECT_THAT
(
container
,
Contains
(
Pair
(
1
,
_
)));
EXPECT_THAT
(
container
,
Contains
(
Pair
(
1
,
_
)));
EXPECT_THAT
(
container
,
Contains
(
Pair
(
_
,
"foo"
)));
EXPECT_THAT
(
container
,
Contains
(
Pair
(
_
,
'a'
)));
EXPECT_THAT
(
container
,
Not
(
Contains
(
Pair
(
3
,
_
))));
EXPECT_THAT
(
container
,
Not
(
Contains
(
Pair
(
3
,
_
))));
}
}
...
@@ -1961,8 +1971,20 @@ TEST(MatcherAssertionTest, WorksForByRefArguments) {
...
@@ -1961,8 +1971,20 @@ TEST(MatcherAssertionTest, WorksForByRefArguments) {
"Actual: 0 (is located @"
);
"Actual: 0 (is located @"
);
}
}
#if !GTEST_OS_SYMBIAN
// Tests that ASSERT_THAT() and EXPECT_THAT() work when the matcher is
// Tests that ASSERT_THAT() and EXPECT_THAT() work when the matcher is
// monomorphic.
// monomorphic.
// ASSERT_THAT("hello", starts_with_he) fails to compile with Nokia's
// Symbian compiler: it tries to compile
// template<T, U> class MatcherCastImpl { ...
// virtual bool Matches(T x) const {
// return source_matcher_.Matches(static_cast<U>(x));
// with U == string and T == const char*
// With ASSERT_THAT("hello"...) changed to ASSERT_THAT(string("hello") ... )
// the compiler silently crashes with no output.
// If MatcherCastImpl is changed to use U(x) instead of static_cast<U>(x)
// the code compiles but the converted string is bogus.
TEST
(
MatcherAssertionTest
,
WorksForMonomorphicMatcher
)
{
TEST
(
MatcherAssertionTest
,
WorksForMonomorphicMatcher
)
{
Matcher
<
const
char
*>
starts_with_he
=
StartsWith
(
"he"
);
Matcher
<
const
char
*>
starts_with_he
=
StartsWith
(
"he"
);
ASSERT_THAT
(
"hello"
,
starts_with_he
);
ASSERT_THAT
(
"hello"
,
starts_with_he
);
...
@@ -1976,6 +1998,7 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
...
@@ -1976,6 +1998,7 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
"Expected: is greater than 5
\n
"
"Expected: is greater than 5
\n
"
" Actual: 5"
);
" Actual: 5"
);
}
}
#endif // !GTEST_OS_SYMBIAN
// Tests floating-point matchers.
// Tests floating-point matchers.
template
<
typename
RawType
>
template
<
typename
RawType
>
...
...
test/gmock-printers_test.cc
View file @
95b12332
...
@@ -840,16 +840,16 @@ TEST(PrintTupleTest, VariousSizes) {
...
@@ -840,16 +840,16 @@ TEST(PrintTupleTest, VariousSizes) {
const
char
*
const
str
=
"8"
;
const
char
*
const
str
=
"8"
;
tuple
<
bool
,
char
,
short
,
testing
::
internal
::
Int32
,
// NOLINT
tuple
<
bool
,
char
,
short
,
testing
::
internal
::
Int32
,
// NOLINT
testing
::
internal
::
Int64
,
float
,
double
,
const
char
*
,
void
*
,
string
>
testing
::
internal
::
Int64
,
float
,
double
,
const
char
*
,
void
*
,
string
>
t10
(
false
,
'a'
,
3
,
4
,
5
,
6.5
F
,
7
.5
,
str
,
NULL
,
"10"
);
t10
(
false
,
'a'
,
3
,
4
,
5
,
1.5
F
,
-
2
.5
,
str
,
NULL
,
"10"
);
EXPECT_EQ
(
"(false, 'a' (97), 3, 4, 5,
6.5, 7
.5, "
+
PrintPointer
(
str
)
+
EXPECT_EQ
(
"(false, 'a' (97), 3, 4, 5,
1.5, -2
.5, "
+
PrintPointer
(
str
)
+
" pointing to
\"
8
\"
, NULL,
\"
10
\"
)"
,
" pointing to
\"
8
\"
, NULL,
\"
10
\"
)"
,
Print
(
t10
));
Print
(
t10
));
}
}
// Nested tuples.
// Nested tuples.
TEST
(
PrintTupleTest
,
NestedTuple
)
{
TEST
(
PrintTupleTest
,
NestedTuple
)
{
tuple
<
tuple
<
int
,
double
>
,
char
>
nested
(
make_tuple
(
5
,
9.5
),
'a'
);
tuple
<
tuple
<
int
,
bool
>
,
char
>
nested
(
make_tuple
(
5
,
true
),
'a'
);
EXPECT_EQ
(
"((5,
9.5
), 'a' (97))"
,
Print
(
nested
));
EXPECT_EQ
(
"((5,
true
), 'a' (97))"
,
Print
(
nested
));
}
}
// Tests printing user-defined unprintable types.
// Tests printing user-defined unprintable types.
...
...
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