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
b93d0f10
Commit
b93d0f10
authored
Jan 13, 2014
by
kosak
Browse files
Make Google Mock build cleanly on Visual Studio 2010, 2012, 2013.
parent
04ce8521
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
23 deletions
+59
-23
CMakeLists.txt
CMakeLists.txt
+20
-5
include/gmock/gmock-more-actions.h
include/gmock/gmock-more-actions.h
+17
-7
test/gmock-generated-function-mockers_test.cc
test/gmock-generated-function-mockers_test.cc
+11
-0
test/gmock-more-actions_test.cc
test/gmock-more-actions_test.cc
+11
-11
No files found.
CMakeLists.txt
View file @
b93d0f10
...
@@ -63,6 +63,16 @@ include_directories("${gmock_SOURCE_DIR}/include"
...
@@ -63,6 +63,16 @@ include_directories("${gmock_SOURCE_DIR}/include"
# Test sources.
# Test sources.
"
${
gtest_SOURCE_DIR
}
"
)
"
${
gtest_SOURCE_DIR
}
"
)
# Summary of tuple support for Microsoft Visual Studio:
# Compiler version(MS) version(cmake) Support
# ---------- ----------- -------------- -----------------------------
# <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple.
# VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10
# VS 2013 12 1800 std::tr1::tuple
if
(
MSVC AND MSVC_VERSION EQUAL 1700
)
add_definitions
(
/D _VARIADIC_MAX=10
)
endif
()
########################################################################
########################################################################
#
#
# Defines the gmock & gmock_main libraries. User tests should link
# Defines the gmock & gmock_main libraries. User tests should link
...
@@ -134,8 +144,16 @@ if (gmock_build_tests)
...
@@ -134,8 +144,16 @@ if (gmock_build_tests)
cxx_library
(
gmock_main_no_rtti
"
${
cxx_no_rtti
}
"
cxx_library
(
gmock_main_no_rtti
"
${
cxx_no_rtti
}
"
"
${
gtest_dir
}
/src/gtest-all.cc"
src/gmock-all.cc src/gmock_main.cc
)
"
${
gtest_dir
}
/src/gtest-all.cc"
src/gmock-all.cc src/gmock_main.cc
)
cxx_library
(
gmock_main_use_own_tuple
"
${
cxx_use_own_tuple
}
"
if
(
NOT MSVC OR MSVC_VERSION LESS 1600
)
# 1600 is Visual Studio 2010.
"
${
gtest_dir
}
/src/gtest-all.cc"
src/gmock-all.cc src/gmock_main.cc
)
# Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
# conflict with our own definitions. Therefore using our own tuple does not
# work on those compilers.
cxx_library
(
gmock_main_use_own_tuple
"
${
cxx_use_own_tuple
}
"
"
${
gtest_dir
}
/src/gtest-all.cc"
src/gmock-all.cc src/gmock_main.cc
)
cxx_test_with_flags
(
gmock_use_own_tuple_test
"
${
cxx_use_own_tuple
}
"
gmock_main_use_own_tuple test/gmock-spec-builders_test.cc
)
endif
()
cxx_test_with_flags
(
gmock-more-actions_no_exception_test
"
${
cxx_no_exception
}
"
cxx_test_with_flags
(
gmock-more-actions_no_exception_test
"
${
cxx_no_exception
}
"
gmock_main_no_exception test/gmock-more-actions_test.cc
)
gmock_main_no_exception test/gmock-more-actions_test.cc
)
...
@@ -143,9 +161,6 @@ if (gmock_build_tests)
...
@@ -143,9 +161,6 @@ if (gmock_build_tests)
cxx_test_with_flags
(
gmock_no_rtti_test
"
${
cxx_no_rtti
}
"
cxx_test_with_flags
(
gmock_no_rtti_test
"
${
cxx_no_rtti
}
"
gmock_main_no_rtti test/gmock-spec-builders_test.cc
)
gmock_main_no_rtti test/gmock-spec-builders_test.cc
)
cxx_test_with_flags
(
gmock_use_own_tuple_test
"
${
cxx_use_own_tuple
}
"
gmock_main_use_own_tuple test/gmock-spec-builders_test.cc
)
cxx_shared_library
(
shared_gmock_main
"
${
cxx_default
}
"
cxx_shared_library
(
shared_gmock_main
"
${
cxx_default
}
"
"
${
gtest_dir
}
/src/gtest-all.cc"
src/gmock-all.cc src/gmock_main.cc
)
"
${
gtest_dir
}
/src/gtest-all.cc"
src/gmock-all.cc src/gmock_main.cc
)
...
...
include/gmock/gmock-more-actions.h
View file @
b93d0f10
...
@@ -87,6 +87,20 @@ class InvokeMethodAction {
...
@@ -87,6 +87,20 @@ class InvokeMethodAction {
GTEST_DISALLOW_ASSIGN_
(
InvokeMethodAction
);
GTEST_DISALLOW_ASSIGN_
(
InvokeMethodAction
);
};
};
// An internal replacement for std::copy which mimics its behavior. This is
// necessary because Visual Studio deprecates ::std::copy, issuing warning 4996.
// However Visual Studio 2010 and later do not honor #pragmas which disable that
// warning.
template
<
typename
InputIterator
,
typename
OutputIterator
>
inline
OutputIterator
CopyElements
(
InputIterator
first
,
InputIterator
last
,
OutputIterator
output
)
{
for
(;
first
!=
last
;
++
first
,
++
output
)
{
*
output
=
*
first
;
}
return
output
;
}
}
// namespace internal
}
// namespace internal
// Various overloads for Invoke().
// Various overloads for Invoke().
...
@@ -185,15 +199,11 @@ ACTION_TEMPLATE(SetArgReferee,
...
@@ -185,15 +199,11 @@ ACTION_TEMPLATE(SetArgReferee,
ACTION_TEMPLATE
(
SetArrayArgument
,
ACTION_TEMPLATE
(
SetArrayArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_2_VALUE_PARAMS
(
first
,
last
))
{
AND_2_VALUE_PARAMS
(
first
,
last
))
{
// Microsoft compiler deprecates ::std::copy, so we want to suppress warning
// Visual Studio deprecates ::std::copy, so we use our own copy in that case.
// 4996 (Function call with parameters that may be unsafe) there.
#ifdef _MSC_VER
#ifdef _MSC_VER
# pragma warning(push) // Saves the current warning state.
internal
::
CopyElements
(
first
,
last
,
::
std
::
tr1
::
get
<
k
>
(
args
));
# pragma warning(disable:4996) // Temporarily disables warning 4996.
#else
#endif
::
std
::
copy
(
first
,
last
,
::
std
::
tr1
::
get
<
k
>
(
args
));
::
std
::
copy
(
first
,
last
,
::
std
::
tr1
::
get
<
k
>
(
args
));
#ifdef _MSC_VER
# pragma warning(pop) // Restores the warning state.
#endif
#endif
}
}
...
...
test/gmock-generated-function-mockers_test.cc
View file @
b93d0f10
...
@@ -112,6 +112,14 @@ class FooInterface {
...
@@ -112,6 +112,14 @@ class FooInterface {
#endif // GTEST_OS_WINDOWS
#endif // GTEST_OS_WINDOWS
};
};
// Const qualifiers on arguments were once (incorrectly) considered
// significant in determining whether two virtual functions had the same
// signature. This was fixed in Visual Studio 2008. However, the compiler
// still emits a warning that alerts about this change in behavior.
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4373)
#endif
class
MockFoo
:
public
FooInterface
{
class
MockFoo
:
public
FooInterface
{
public:
public:
MockFoo
()
{}
MockFoo
()
{}
...
@@ -167,6 +175,9 @@ class MockFoo : public FooInterface {
...
@@ -167,6 +175,9 @@ class MockFoo : public FooInterface {
private:
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockFoo
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockFoo
);
};
};
#ifdef _MSC_VER
# pragma warning(pop)
#endif
class
FunctionMockerTest
:
public
testing
::
Test
{
class
FunctionMockerTest
:
public
testing
::
Test
{
protected:
protected:
...
...
test/gmock-more-actions_test.cc
View file @
b93d0f10
...
@@ -668,17 +668,17 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
...
@@ -668,17 +668,17 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
// Tests SetArrayArgument<N>(first, last) where *first is convertible
// Tests SetArrayArgument<N>(first, last) where *first is convertible
// (but not equal) to the argument type.
// (but not equal) to the argument type.
TEST
(
SetArrayArgumentTest
,
SetsTheNthArrayWithConvertibleType
)
{
TEST
(
SetArrayArgumentTest
,
SetsTheNthArrayWithConvertibleType
)
{
typedef
void
MyFunction
(
bool
,
char
*
);
typedef
void
MyFunction
(
bool
,
int
*
);
int
code
s
[]
=
{
97
,
98
,
99
};
char
char
s
[]
=
{
97
,
98
,
99
};
Action
<
MyFunction
>
a
=
SetArrayArgument
<
1
>
(
c
ode
s
,
c
ode
s
+
3
);
Action
<
MyFunction
>
a
=
SetArrayArgument
<
1
>
(
c
har
s
,
c
har
s
+
3
);
char
ch
[
4
]
=
{
};
int
codes
[
4
]
=
{
111
,
222
,
333
,
444
};
char
*
pch
=
ch
;
int
*
pcodes
=
codes
;
a
.
Perform
(
make_tuple
(
true
,
pc
h
));
a
.
Perform
(
make_tuple
(
true
,
pc
odes
));
EXPECT_EQ
(
'a'
,
ch
[
0
]);
EXPECT_EQ
(
97
,
codes
[
0
]);
EXPECT_EQ
(
'b'
,
ch
[
1
]);
EXPECT_EQ
(
98
,
codes
[
1
]);
EXPECT_EQ
(
'c'
,
ch
[
2
]);
EXPECT_EQ
(
99
,
codes
[
2
]);
EXPECT_EQ
(
'\0'
,
ch
[
3
]);
EXPECT_EQ
(
444
,
codes
[
3
]);
}
}
// Test SetArrayArgument<N>(first, last) with iterator as argument.
// Test SetArrayArgument<N>(first, last) with iterator as argument.
...
...
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