diff options
author | Abseil Team <absl-team@google.com> | 2019-01-17 20:56:41 (GMT) |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2019-01-18 19:06:03 (GMT) |
commit | 9518a57428ae0a7ed450c1361768e84a2a38af5a (patch) | |
tree | 7e50bf47b6258b000a67e8882075f4743d072917 /googlemock/test | |
parent | 0adeadd2830211f827fd2908e4621f6a4afa810c (diff) | |
download | googletest-9518a57428ae0a7ed450c1361768e84a2a38af5a.zip googletest-9518a57428ae0a7ed450c1361768e84a2a38af5a.tar.gz googletest-9518a57428ae0a7ed450c1361768e84a2a38af5a.tar.bz2 |
Googletest export
Fix mocking method arguments with templated copy constructors.
A previous change removed workarounds for old compilers from googletest and googlemock. Unfortunately, a bit of code that started as a workaround for Symbian's C++ compiler is still needed to avoid copy/move constructor ambiguity when mocking functions with certain argument types.
The test case added by this CL is extracted from Chrome's codebase, and was discovered while attempting to roll googletest.
PiperOrigin-RevId: 229801765
Diffstat (limited to 'googlemock/test')
-rw-r--r-- | googlemock/test/gmock-function-mocker_test.cc | 17 | ||||
-rw-r--r-- | googlemock/test/gmock-generated-function-mockers_test.cc | 18 |
2 files changed, 35 insertions, 0 deletions
diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc index f29433f..d16006f 100644 --- a/googlemock/test/gmock-function-mocker_test.cc +++ b/googlemock/test/gmock-function-mocker_test.cc @@ -62,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() {} @@ -90,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; @@ -146,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))); @@ -288,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) { diff --git a/googlemock/test/gmock-generated-function-mockers_test.cc b/googlemock/test/gmock-generated-function-mockers_test.cc index 52d9b8b..f07226c 100644 --- a/googlemock/test/gmock-generated-function-mockers_test.cc +++ b/googlemock/test/gmock-generated-function-mockers_test.cc @@ -63,6 +63,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() {} @@ -91,6 +100,8 @@ 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>& a_vector) = 0; #if GTEST_OS_WINDOWS STDMETHOD_(int, CTNullary)() = 0; @@ -146,6 +157,8 @@ class MockFoo : public FooInterface { MOCK_METHOD1(TypeWithHole, int(int (*)())); // NOLINT MOCK_METHOD1(TypeWithComma, int(const std::map<int, std::string>&)); // NOLINT + MOCK_METHOD1(TypeWithTemplatedCopyCtor, + int(const TemplatedCopyable<int>&)); // NOLINT #if GTEST_OS_WINDOWS MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int()); @@ -288,6 +301,11 @@ TEST_F(FunctionMockerTest, MocksReturnTypeWithComma) { EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma(42)); } +TEST_F(FunctionMockerTest, 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(FunctionMockerTest, MocksNullaryFunctionWithCallType) { |