Commit 5e24f358 authored by Roger Leigh's avatar Roger Leigh Committed by Jesse Beder
Browse files

test: Upgrade googlemock 1.7.0 to googletest 1.8.0

Note that with the release of 1.8.0, googlemock and
googletest are unified into a single release.
parent e2818c42
...@@ -81,6 +81,7 @@ using testing::Gt; ...@@ -81,6 +81,7 @@ using testing::Gt;
using testing::InSequence; using testing::InSequence;
using testing::Invoke; using testing::Invoke;
using testing::InvokeWithoutArgs; using testing::InvokeWithoutArgs;
using testing::IsNotSubstring;
using testing::IsSubstring; using testing::IsSubstring;
using testing::Lt; using testing::Lt;
using testing::Message; using testing::Message;
...@@ -134,14 +135,21 @@ void PrintTo(const Incomplete& /* x */, ::std::ostream* os) { ...@@ -134,14 +135,21 @@ void PrintTo(const Incomplete& /* x */, ::std::ostream* os) {
class Result {}; class Result {};
// A type that's not default constructible.
class NonDefaultConstructible {
public:
explicit NonDefaultConstructible(int /* dummy */) {}
};
class MockA { class MockA {
public: public:
MockA() {} MockA() {}
MOCK_METHOD1(DoA, void(int n)); // NOLINT MOCK_METHOD1(DoA, void(int n));
MOCK_METHOD1(ReturnResult, Result(int n)); // NOLINT MOCK_METHOD1(ReturnResult, Result(int n));
MOCK_METHOD2(Binary, bool(int x, int y)); // NOLINT MOCK_METHOD0(ReturnNonDefaultConstructible, NonDefaultConstructible());
MOCK_METHOD2(ReturnInt, int(int x, int y)); // NOLINT MOCK_METHOD2(Binary, bool(int x, int y));
MOCK_METHOD2(ReturnInt, int(int x, int y));
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockA); GTEST_DISALLOW_COPY_AND_ASSIGN_(MockA);
...@@ -1108,15 +1116,16 @@ TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) { ...@@ -1108,15 +1116,16 @@ TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
b.DoB(4); b.DoB(4);
} }
TEST(UndefinedReturnValueTest, ReturnValueIsMandatory) { TEST(UndefinedReturnValueTest,
ReturnValueIsMandatoryWhenNotDefaultConstructible) {
MockA a; MockA a;
// TODO(wan@google.com): We should really verify the output message, // TODO(wan@google.com): We should really verify the output message,
// but we cannot yet due to that EXPECT_DEATH only captures stderr // but we cannot yet due to that EXPECT_DEATH only captures stderr
// while Google Mock logs to stdout. // while Google Mock logs to stdout.
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
EXPECT_ANY_THROW(a.ReturnResult(1)); EXPECT_ANY_THROW(a.ReturnNonDefaultConstructible());
#else #else
EXPECT_DEATH_IF_SUPPORTED(a.ReturnResult(1), ""); EXPECT_DEATH_IF_SUPPORTED(a.ReturnNonDefaultConstructible(), "");
#endif #endif
} }
...@@ -1969,9 +1978,25 @@ class VerboseFlagPreservingFixture : public testing::Test { ...@@ -1969,9 +1978,25 @@ class VerboseFlagPreservingFixture : public testing::Test {
#if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
// Tests that an uninteresting mock function call on a naggy mock // Tests that an uninteresting mock function call on a naggy mock
// generates a warning containing the stack trace. // generates a warning without the stack trace when
// --gmock_verbose=warning is specified.
TEST(FunctionCallMessageTest, TEST(FunctionCallMessageTest,
UninterestingCallOnNaggyMockGeneratesFyiWithStackTrace) { UninterestingCallOnNaggyMockGeneratesNoStackTraceWhenVerboseWarning) {
GMOCK_FLAG(verbose) = kWarningVerbosity;
NaggyMock<MockC> c;
CaptureStdout();
c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable());
const std::string output = GetCapturedStdout();
EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", output);
EXPECT_PRED_FORMAT2(IsNotSubstring, "Stack trace:", output);
}
// Tests that an uninteresting mock function call on a naggy mock
// generates a warning containing the stack trace when
// --gmock_verbose=info is specified.
TEST(FunctionCallMessageTest,
UninterestingCallOnNaggyMockGeneratesFyiWithStackTraceWhenVerboseInfo) {
GMOCK_FLAG(verbose) = kInfoVerbosity;
NaggyMock<MockC> c; NaggyMock<MockC> c;
CaptureStdout(); CaptureStdout();
c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable()); c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable());
...@@ -2088,6 +2113,12 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { ...@@ -2088,6 +2113,12 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
// Tests how the flag affects uninteresting calls on a naggy mock. // Tests how the flag affects uninteresting calls on a naggy mock.
void TestUninterestingCallOnNaggyMock(bool should_print) { void TestUninterestingCallOnNaggyMock(bool should_print) {
NaggyMock<MockA> a; NaggyMock<MockA> a;
const string note =
"NOTE: You can safely ignore the above warning unless this "
"call should not happen. Do not suppress it by blindly adding "
"an EXPECT_CALL() if you don't mean to enforce the call. "
"See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#"
"knowing-when-to-expect for details.";
// A void-returning function. // A void-returning function.
CaptureStdout(); CaptureStdout();
...@@ -2097,8 +2128,8 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { ...@@ -2097,8 +2128,8 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
should_print, should_print,
"\nGMOCK WARNING:\n" "\nGMOCK WARNING:\n"
"Uninteresting mock function call - returning directly.\n" "Uninteresting mock function call - returning directly.\n"
" Function call: DoA(5)\n" " Function call: DoA(5)\n" +
"Stack trace:\n", note,
"DoA"); "DoA");
// A non-void-returning function. // A non-void-returning function.
...@@ -2110,8 +2141,8 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { ...@@ -2110,8 +2141,8 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
"\nGMOCK WARNING:\n" "\nGMOCK WARNING:\n"
"Uninteresting mock function call - returning default value.\n" "Uninteresting mock function call - returning default value.\n"
" Function call: Binary(2, 1)\n" " Function call: Binary(2, 1)\n"
" Returns: false\n" " Returns: false\n" +
"Stack trace:\n", note,
"Binary"); "Binary");
} }
}; };
......
...@@ -31,8 +31,11 @@ ...@@ -31,8 +31,11 @@
// //
// Tests for Google C++ Mocking Framework (Google Mock) // Tests for Google C++ Mocking Framework (Google Mock)
// //
// Sometimes it's desirable to build most of Google Mock's own tests // Some users use a build system that Google Mock doesn't support directly,
// by compiling a single file. This file serves this purpose. // yet they still want to build and run Google Mock's own tests. This file
// includes most such tests, making it easier for these users to maintain
// their build scripts (they just need to build this file, even though the
// below list of actual *_test.cc files might change).
#include "test/gmock-actions_test.cc" #include "test/gmock-actions_test.cc"
#include "test/gmock-cardinalities_test.cc" #include "test/gmock-cardinalities_test.cc"
#include "test/gmock-generated-actions_test.cc" #include "test/gmock-generated-actions_test.cc"
......
...@@ -39,14 +39,17 @@ namespace { ...@@ -39,14 +39,17 @@ namespace {
using testing::HasSubstr; using testing::HasSubstr;
using testing::internal::GoogleTestFailureException; using testing::internal::GoogleTestFailureException;
// A user-defined class. // A type that cannot be default constructed.
class Something {}; class NonDefaultConstructible {
public:
explicit NonDefaultConstructible(int /* dummy */) {}
};
class MockFoo { class MockFoo {
public: public:
// A mock method that returns a user-defined type. Google Mock // A mock method that returns a user-defined type. Google Mock
// doesn't know what the default value for this type is. // doesn't know what the default value for this type is.
MOCK_METHOD0(GetSomething, Something()); MOCK_METHOD0(GetNonDefaultConstructible, NonDefaultConstructible());
}; };
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
...@@ -59,9 +62,9 @@ TEST(DefaultValueTest, ThrowsRuntimeErrorWhenNoDefaultValue) { ...@@ -59,9 +62,9 @@ TEST(DefaultValueTest, ThrowsRuntimeErrorWhenNoDefaultValue) {
// nothing about the return type, it doesn't know what to return, // nothing about the return type, it doesn't know what to return,
// and has to throw (when exceptions are enabled) or abort // and has to throw (when exceptions are enabled) or abort
// (otherwise). // (otherwise).
mock.GetSomething(); mock.GetNonDefaultConstructible();
FAIL() << "GetSomething()'s return type has no default value, " FAIL() << "GetNonDefaultConstructible()'s return type has no default "
<< "so Google Mock should have thrown."; << "value, so Google Mock should have thrown.";
} catch (const GoogleTestFailureException& /* unused */) { } catch (const GoogleTestFailureException& /* unused */) {
FAIL() << "Google Test does not try to catch an exception of type " FAIL() << "Google Test does not try to catch an exception of type "
<< "GoogleTestFailureException, which is used for reporting " << "GoogleTestFailureException, which is used for reporting "
......
...@@ -75,14 +75,14 @@ GMOCK WARNING: ...@@ -75,14 +75,14 @@ GMOCK WARNING:
Uninteresting mock function call - returning default value. Uninteresting mock function call - returning default value.
Function call: Bar2(0, 1) Function call: Bar2(0, 1)
Returns: false Returns: false
Stack trace: NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#knowing-when-to-expect for details.
[ OK ] GMockOutputTest.UninterestingCall [ OK ] GMockOutputTest.UninterestingCall
[ RUN ] GMockOutputTest.UninterestingCallToVoidFunction [ RUN ] GMockOutputTest.UninterestingCallToVoidFunction
GMOCK WARNING: GMOCK WARNING:
Uninteresting mock function call - returning directly. Uninteresting mock function call - returning directly.
Function call: Bar3(0, 1) Function call: Bar3(0, 1)
Stack trace: NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#knowing-when-to-expect for details.
[ OK ] GMockOutputTest.UninterestingCallToVoidFunction [ OK ] GMockOutputTest.UninterestingCallToVoidFunction
[ RUN ] GMockOutputTest.RetiredExpectation [ RUN ] GMockOutputTest.RetiredExpectation
unknown file: Failure unknown file: Failure
...@@ -266,14 +266,14 @@ Uninteresting mock function call - taking default action specified at: ...@@ -266,14 +266,14 @@ Uninteresting mock function call - taking default action specified at:
FILE:#: FILE:#:
Function call: Bar2(2, 2) Function call: Bar2(2, 2)
Returns: true Returns: true
Stack trace: NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#knowing-when-to-expect for details.
GMOCK WARNING: GMOCK WARNING:
Uninteresting mock function call - taking default action specified at: Uninteresting mock function call - taking default action specified at:
FILE:#: FILE:#:
Function call: Bar2(1, 1) Function call: Bar2(1, 1)
Returns: false Returns: false
Stack trace: NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#knowing-when-to-expect for details.
[ OK ] GMockOutputTest.UninterestingCallWithDefaultAction [ OK ] GMockOutputTest.UninterestingCallWithDefaultAction
[ RUN ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction [ RUN ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction
......
...@@ -38,9 +38,10 @@ ...@@ -38,9 +38,10 @@
#include <string> #include <string>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
using testing::GMOCK_FLAG(verbose); using testing::GMOCK_FLAG(verbose);
using testing::InitGoogleMock; using testing::InitGoogleMock;
using testing::internal::g_init_gtest_count;
// Verifies that calling InitGoogleMock() on argv results in new_argv, // Verifies that calling InitGoogleMock() on argv results in new_argv,
// and the gmock_verbose flag's value is set to expected_gmock_verbose. // and the gmock_verbose flag's value is set to expected_gmock_verbose.
...@@ -135,25 +136,6 @@ TEST(InitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) { ...@@ -135,25 +136,6 @@ TEST(InitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
TestInitGoogleMock(argv, new_argv, "error"); TestInitGoogleMock(argv, new_argv, "error");
} }
TEST(InitGoogleMockTest, CallsInitGoogleTest) {
const int old_init_gtest_count = g_init_gtest_count;
const char* argv[] = {
"foo.exe",
"--non_gmock_flag=blah",
"--gmock_verbose=error",
NULL
};
const char* new_argv[] = {
"foo.exe",
"--non_gmock_flag=blah",
NULL
};
TestInitGoogleMock(argv, new_argv, "error");
EXPECT_EQ(old_init_gtest_count + 1, g_init_gtest_count);
}
TEST(WideInitGoogleMockTest, ParsesInvalidCommandLine) { TEST(WideInitGoogleMockTest, ParsesInvalidCommandLine) {
const wchar_t* argv[] = { const wchar_t* argv[] = {
NULL NULL
...@@ -228,24 +210,7 @@ TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) { ...@@ -228,24 +210,7 @@ TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
TestInitGoogleMock(argv, new_argv, "error"); TestInitGoogleMock(argv, new_argv, "error");
} }
TEST(WideInitGoogleMockTest, CallsInitGoogleTest) { #endif // !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
const int old_init_gtest_count = g_init_gtest_count;
const wchar_t* argv[] = {
L"foo.exe",
L"--non_gmock_flag=blah",
L"--gmock_verbose=error",
NULL
};
const wchar_t* new_argv[] = {
L"foo.exe",
L"--non_gmock_flag=blah",
NULL
};
TestInitGoogleMock(argv, new_argv, "error");
EXPECT_EQ(old_init_gtest_count + 1, g_init_gtest_count);
}
// Makes sure Google Mock flags can be accessed in code. // Makes sure Google Mock flags can be accessed in code.
TEST(FlagTest, IsAccessibleInCode) { TEST(FlagTest, IsAccessibleInCode) {
......
...@@ -22,6 +22,11 @@ option(gtest_build_samples "Build gtest's sample programs." OFF) ...@@ -22,6 +22,11 @@ option(gtest_build_samples "Build gtest's sample programs." OFF)
option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF) option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF)
option(
gtest_hide_internal_symbols
"Build gtest with internal symbols hidden in shared libraries."
OFF)
# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
include(cmake/hermetic_build.cmake OPTIONAL) include(cmake/hermetic_build.cmake OPTIONAL)
...@@ -46,6 +51,11 @@ if (COMMAND set_up_hermetic_build) ...@@ -46,6 +51,11 @@ if (COMMAND set_up_hermetic_build)
set_up_hermetic_build() set_up_hermetic_build()
endif() endif()
if (gtest_hide_internal_symbols)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
endif()
# Define helper functions and macros used by Google Test. # Define helper functions and macros used by Google Test.
include(cmake/internal_utils.cmake) include(cmake/internal_utils.cmake)
...@@ -59,6 +69,16 @@ include_directories( ...@@ -59,6 +69,16 @@ include_directories(
# Where Google Test's libraries can be found. # Where Google Test's libraries can be found.
link_directories(${gtest_BINARY_DIR}/src) link_directories(${gtest_BINARY_DIR}/src)
# 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 gtest & gtest_main libraries. User tests should link # Defines the gtest & gtest_main libraries. User tests should link
...@@ -71,6 +91,22 @@ cxx_library(gtest "${cxx_strict}" src/gtest-all.cc) ...@@ -71,6 +91,22 @@ cxx_library(gtest "${cxx_strict}" src/gtest-all.cc)
cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
target_link_libraries(gtest_main gtest) target_link_libraries(gtest_main gtest)
# If the CMake version supports it, attach header directory information
# to the targets for when we are part of a parent build (ie being pulled
# in via add_subdirectory() rather than being a standalone build).
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_include_directories(gtest INTERFACE "${gtest_SOURCE_DIR}/include")
target_include_directories(gtest_main INTERFACE "${gtest_SOURCE_DIR}/include")
endif()
########################################################################
#
# Install rules
install(TARGETS gtest gtest_main
DESTINATION lib)
install(DIRECTORY ${gtest_SOURCE_DIR}/include/gtest
DESTINATION include)
######################################################################## ########################################################################
# #
# Samples on how to link user tests with gtest or gtest_main. # Samples on how to link user tests with gtest or gtest_main.
...@@ -171,12 +207,10 @@ if (gtest_build_tests) ...@@ -171,12 +207,10 @@ if (gtest_build_tests)
PROPERTIES PROPERTIES
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
if (NOT MSVC OR NOT MSVC_VERSION EQUAL 1600) if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010.
# The C++ Standard specifies tuple_element<int, class>. # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
# Yet MSVC 10's <utility> declares tuple_element<size_t, class>. # conflict with our own definitions. Therefore using our own tuple does not
# That declaration conflicts with our own standard-conforming # work on those compilers.
# tuple implementation. Therefore using our own tuple with
# MSVC 10 doesn't compile.
cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}" cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}"
src/gtest-all.cc src/gtest_main.cc) src/gtest-all.cc src/gtest_main.cc)
...@@ -194,8 +228,8 @@ if (gtest_build_tests) ...@@ -194,8 +228,8 @@ if (gtest_build_tests)
cxx_executable(gtest_break_on_failure_unittest_ test gtest) cxx_executable(gtest_break_on_failure_unittest_ test gtest)
py_test(gtest_break_on_failure_unittest) py_test(gtest_break_on_failure_unittest)
# MSVC 7.1 does not support STL with exceptions disabled. # Visual Studio .NET 2003 does not support STL with exceptions disabled.
if (NOT MSVC OR MSVC_VERSION GREATER 1310) if (NOT MSVC OR MSVC_VERSION GREATER 1310) # 1310 is Visual Studio .NET 2003
cxx_executable_with_flags( cxx_executable_with_flags(
gtest_catch_exceptions_no_ex_test_ gtest_catch_exceptions_no_ex_test_
"${cxx_no_exception}" "${cxx_no_exception}"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment