diff options
Diffstat (limited to 'test/gmock-generated-function-mockers_test.cc')
-rw-r--r-- | test/gmock-generated-function-mockers_test.cc | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/test/gmock-generated-function-mockers_test.cc b/test/gmock-generated-function-mockers_test.cc index 2087f991..ea49b9c1 100644 --- a/test/gmock-generated-function-mockers_test.cc +++ b/test/gmock-generated-function-mockers_test.cc @@ -129,9 +129,16 @@ class MockFoo : public FooInterface { MOCK_METHOD1(TakesNonConstReference, bool(int&)); // NOLINT MOCK_METHOD1(TakesConstReference, string(const int&)); + #ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS MOCK_METHOD1(TakesConst, bool(const int)); // NOLINT -#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS +#endif + + // Tests that the function return type can contain unprotected comma. + MOCK_METHOD0(ReturnTypeWithComma, std::map<int, string>()); + MOCK_CONST_METHOD1(ReturnTypeWithComma, + std::map<int, string>(int)); // NOLINT + MOCK_METHOD0(OverloadedOnArgumentNumber, int()); // NOLINT MOCK_METHOD1(OverloadedOnArgumentNumber, int(int)); // NOLINT @@ -143,6 +150,7 @@ class MockFoo : public FooInterface { MOCK_METHOD1(TypeWithHole, int(int (*)())); // NOLINT MOCK_METHOD1(TypeWithComma, int(const std::map<int, string>&)); // NOLINT + #if GTEST_OS_WINDOWS MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int()); MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int)); @@ -150,6 +158,10 @@ class MockFoo : public FooInterface { short d, int e, long f, float g, double h, unsigned i, char* j, const string& k)); MOCK_CONST_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTConst, char(int)); + + // Tests that the function return type can contain unprotected comma. + MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTReturnTypeWithComma, + std::map<int, string>()); #endif // GTEST_OS_WINDOWS private: @@ -267,6 +279,17 @@ TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) { EXPECT_EQ('a', Const(*foo_).OverloadedOnConstness()); } +TEST_F(FunctionMockerTest, MocksReturnTypeWithComma) { + const std::map<int, string> a_map; + EXPECT_CALL(mock_foo_, ReturnTypeWithComma()) + .WillOnce(Return(a_map)); + EXPECT_CALL(mock_foo_, ReturnTypeWithComma(42)) + .WillOnce(Return(a_map)); + + EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma()); + EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma(42)); +} + #if GTEST_OS_WINDOWS // Tests mocking a nullary function with calltype. TEST_F(FunctionMockerTest, MocksNullaryFunctionWithCallType) { @@ -306,6 +329,14 @@ TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) { EXPECT_EQ('a', Const(*foo_).CTConst(0)); } +TEST_F(FunctionMockerTest, MocksReturnTypeWithCommaAndCallType) { + const std::map<int, string> a_map; + EXPECT_CALL(mock_foo_, CTReturnTypeWithComma()) + .WillOnce(Return(a_map)); + + EXPECT_EQ(a_map, mock_foo_.CTReturnTypeWithComma()); +} + #endif // GTEST_OS_WINDOWS class MockB { @@ -362,6 +393,10 @@ class MockStack : public StackInterface<T> { MOCK_CONST_METHOD0_T(GetSize, int()); // NOLINT MOCK_CONST_METHOD0_T(GetTop, const T&()); + // Tests that the function return type can contain unprotected comma. + MOCK_METHOD0_T(ReturnTypeWithComma, std::map<int, int>()); + MOCK_CONST_METHOD1_T(ReturnTypeWithComma, std::map<int, int>(int)); // NOLINT + private: GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStack); }; @@ -389,6 +424,19 @@ TEST(TemplateMockTest, Works) { EXPECT_EQ(0, mock.GetSize()); } +TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) { + MockStack<int> mock; + + const std::map<int, int> a_map; + EXPECT_CALL(mock, ReturnTypeWithComma()) + .WillOnce(Return(a_map)); + EXPECT_CALL(mock, ReturnTypeWithComma(1)) + .WillOnce(Return(a_map)); + + EXPECT_EQ(a_map, mock.ReturnTypeWithComma()); + EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1)); +} + #if GTEST_OS_WINDOWS // Tests mocking template interfaces with calltype. |