diff options
Diffstat (limited to 'googlemock/test/gmock-function-mocker_test.cc')
-rw-r--r-- | googlemock/test/gmock-function-mocker_test.cc | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc index 007e86c..fbc5d5b 100644 --- a/googlemock/test/gmock-function-mocker_test.cc +++ b/googlemock/test/gmock-function-mocker_test.cc @@ -45,13 +45,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -// There is a bug in MSVC (fixed in VS 2008) that prevents creating a -// mock for a function with const arguments, so we don't test such -// cases for MSVC versions older than 2008. -#if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500) -# define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS -#endif // !GTEST_OS_WINDOWS || (_MSC_VER >= 1500) - namespace testing { namespace gmock_function_mocker_test { @@ -69,6 +62,15 @@ using testing::Return; using testing::ReturnRef; using testing::TypedEq; +template<typename T> +class TemplatedCopyable { + public: + TemplatedCopyable() {} + + template <typename U> + TemplatedCopyable(const U& other) {} // NOLINT +}; + class FooInterface { public: virtual ~FooInterface() {} @@ -84,9 +86,7 @@ class FooInterface { virtual bool TakesNonConstReference(int& n) = 0; // NOLINT virtual std::string TakesConstReference(const int& n) = 0; -#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS virtual bool TakesConst(const int x) = 0; -#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS virtual int OverloadedOnArgumentNumber() = 0; virtual int OverloadedOnArgumentNumber(int n) = 0; @@ -99,6 +99,7 @@ class FooInterface { virtual int TypeWithHole(int (*func)()) = 0; virtual int TypeWithComma(const std::map<int, std::string>& a_map) = 0; + virtual int TypeWithTemplatedCopyCtor(const TemplatedCopyable<int>&) = 0; #if GTEST_OS_WINDOWS STDMETHOD_(int, CTNullary)() = 0; @@ -137,10 +138,7 @@ class MockFoo : public FooInterface { MOCK_METHOD(bool, TakesNonConstReference, (int&)); // NOLINT MOCK_METHOD(std::string, TakesConstReference, (const int&)); - -#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS MOCK_METHOD(bool, TakesConst, (const int)); // NOLINT -#endif // Tests that the function return type can contain unprotected comma. MOCK_METHOD((std::map<int, std::string>), ReturnTypeWithComma, (), ()); @@ -158,6 +156,8 @@ class MockFoo : public FooInterface { MOCK_METHOD(int, TypeWithHole, (int (*)()), ()); // NOLINT MOCK_METHOD(int, TypeWithComma, ((const std::map<int, std::string>&))); + MOCK_METHOD(int, TypeWithTemplatedCopyCtor, + (const TemplatedCopyable<int>&)); // NOLINT #if GTEST_OS_WINDOWS MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE))); @@ -248,7 +248,6 @@ TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstReferenceArgument) { EXPECT_EQ("Hello", foo_->TakesConstReference(a)); } -#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS // Tests mocking a function that takes a const variable. TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstArgument) { EXPECT_CALL(mock_foo_, TakesConst(Lt(10))) @@ -256,7 +255,6 @@ TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstArgument) { EXPECT_FALSE(foo_->TakesConst(5)); } -#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS // Tests mocking functions overloaded on the number of arguments. TEST_F(MockMethodFunctionMockerTest, MocksFunctionsOverloadedOnArgumentNumber) { @@ -302,6 +300,11 @@ TEST_F(MockMethodFunctionMockerTest, MocksReturnTypeWithComma) { EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma(42)); } +TEST_F(MockMethodFunctionMockerTest, MocksTypeWithTemplatedCopyCtor) { + EXPECT_CALL(mock_foo_, TypeWithTemplatedCopyCtor(_)).WillOnce(Return(true)); + EXPECT_TRUE(foo_->TypeWithTemplatedCopyCtor(TemplatedCopyable<int>())); +} + #if GTEST_OS_WINDOWS // Tests mocking a nullary function with calltype. TEST_F(MockMethodFunctionMockerTest, MocksNullaryFunctionWithCallType) { @@ -533,7 +536,7 @@ TEST(MockMethodOverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) { #define MY_MOCK_METHODS2_ \ MOCK_CONST_METHOD1(Overloaded, int(int n)); \ - MOCK_METHOD1(Overloaded, int(int n)); + MOCK_METHOD1(Overloaded, int(int n)) class MockOverloadedOnConstness { public: @@ -598,7 +601,6 @@ TEST(MockMethodMockFunctionTest, WorksFor10Arguments) { EXPECT_EQ(2, foo.Call(true, 'a', 0, 0, 0, 0, 0, 'b', 1, false)); } -#if GTEST_HAS_STD_FUNCTION_ TEST(MockMethodMockFunctionTest, AsStdFunction) { MockFunction<int(int)> foo; auto call = [](const std::function<int(int)> &f, int i) { @@ -630,7 +632,6 @@ TEST(MockMethodMockFunctionTest, AsStdFunctionWithReferenceParameter) { EXPECT_EQ(-1, call(foo.AsStdFunction(), i)); } -#endif // GTEST_HAS_STD_FUNCTION_ struct MockMethodSizes0 { MOCK_METHOD(void, func, ()); |