From e41f31f2af3a713e8652d1e091a13bed22781ec3 Mon Sep 17 00:00:00 2001 From: Adam Badura Date: Thu, 26 Dec 2019 01:32:37 +0100 Subject: Add tests for MockFunction deduction (#2277) Add tests checking that ::testing::MockFunction template argument can be deduced in a function call context. This is a property raised in the review, however, not checked before by any tests. --- googlemock/test/gmock-function-mocker_test.cc | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc index 019e3cb9..164c6b47 100644 --- a/googlemock/test/gmock-function-mocker_test.cc +++ b/googlemock/test/gmock-function-mocker_test.cc @@ -779,6 +779,36 @@ TEST(MockMethodMockFunctionTest, AsStdFunctionWithReferenceParameter) { } +namespace { + +template +static constexpr bool IsMockFunctionTemplateArgumentDeducedTo(const MockFunction&) { + return std::is_same::value; +} + +} // namespace + +template +class MockMethodMockFunctionSignatureTest : public Test { +}; + +using MockMethodMockFunctionSignatureTypes = Types< + void(), + int(), + void(int), + int(int), + int(bool, int), + int(bool, char, int, int, int, int, int, char, int, bool) +>; +TYPED_TEST_SUITE(MockMethodMockFunctionSignatureTest, MockMethodMockFunctionSignatureTypes); + +TYPED_TEST(MockMethodMockFunctionSignatureTest, IsMockFunctionTemplateArgumentDeduced) { + using Argument = TypeParam; + MockFunction foo; + EXPECT_TRUE(IsMockFunctionTemplateArgumentDeducedTo(foo)); +} + + struct MockMethodSizes0 { MOCK_METHOD(void, func, ()); }; -- cgit v1.2.3 From 53740ebc21d54f537f42fc565b0501e690c90dc4 Mon Sep 17 00:00:00 2001 From: Adam Badura Date: Thu, 11 Jul 2019 10:20:21 +0200 Subject: Add support for std::function in MockFunction (#2277) --- googlemock/test/gmock-function-mocker_test.cc | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc index 164c6b47..920b097f 100644 --- a/googlemock/test/gmock-function-mocker_test.cc +++ b/googlemock/test/gmock-function-mocker_test.cc @@ -40,6 +40,7 @@ # include #endif // GTEST_OS_WINDOWS +#include #include #include #include @@ -802,12 +803,30 @@ using MockMethodMockFunctionSignatureTypes = Types< >; TYPED_TEST_SUITE(MockMethodMockFunctionSignatureTest, MockMethodMockFunctionSignatureTypes); -TYPED_TEST(MockMethodMockFunctionSignatureTest, IsMockFunctionTemplateArgumentDeduced) { +TYPED_TEST(MockMethodMockFunctionSignatureTest, IsMockFunctionTemplateArgumentDeducedForRawSignature) { using Argument = TypeParam; MockFunction foo; EXPECT_TRUE(IsMockFunctionTemplateArgumentDeducedTo(foo)); } +TYPED_TEST(MockMethodMockFunctionSignatureTest, IsMockFunctionTemplateArgumentDeducedForStdFunction) { + using Argument = std::function; + MockFunction foo; + EXPECT_TRUE(IsMockFunctionTemplateArgumentDeducedTo(foo)); +} + +TYPED_TEST(MockMethodMockFunctionSignatureTest, IsMockFunctionCallMethodSignatureTheSameForRawSignatureAndStdFunction) { + using ForRawSignature = decltype(&MockFunction::Call); + using ForStdFunction = decltype(&MockFunction>::Call); + EXPECT_TRUE((std::is_same::value)); +} + +TYPED_TEST(MockMethodMockFunctionSignatureTest, IsMockFunctionAsStdFunctionMethodSignatureTheSameForRawSignatureAndStdFunction) { + using ForRawSignature = decltype(&MockFunction::AsStdFunction); + using ForStdFunction = decltype(&MockFunction>::AsStdFunction); + EXPECT_TRUE((std::is_same::value)); +} + struct MockMethodSizes0 { MOCK_METHOD(void, func, ()); -- cgit v1.2.3