From f3aa4d2934a485d756d5709feb97ea6146fe08d6 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 25 Sep 2009 22:34:47 +0000 Subject: Implements the MockFunction class. --- include/gmock/gmock-generated-function-mockers.h | 111 +++++++++++++++++++++ .../gmock/gmock-generated-function-mockers.h.pump | 49 +++++++++ 2 files changed, 160 insertions(+) (limited to 'include/gmock') diff --git a/include/gmock/gmock-generated-function-mockers.h b/include/gmock/gmock-generated-function-mockers.h index b6c1d82e..3002b6c5 100644 --- a/include/gmock/gmock-generated-function-mockers.h +++ b/include/gmock/gmock-generated-function-mockers.h @@ -712,6 +712,117 @@ using internal::FunctionMocker; #define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, F) \ GMOCK_METHOD10_(typename, const, ct, m, F) +// A MockFunction class has one mock method whose type is F. It is +// useful when you just want your test code to emit some messages and +// have Google Mock verify the right messages are sent (and perhaps at +// the right times). For example, if you are exercising code: +// +// Foo(1); +// Foo(2); +// Foo(3); +// +// and want to verify that Foo(1) and Foo(3) both invoke +// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: +// +// TEST(FooTest, InvokesBarCorrectly) { +// MyMock mock; +// MockFunction check; +// { +// InSequence s; +// +// EXPECT_CALL(mock, Bar("a")); +// EXPECT_CALL(check, Call("1")); +// EXPECT_CALL(check, Call("2")); +// EXPECT_CALL(mock, Bar("a")); +// } +// Foo(1); +// check.Call("1"); +// Foo(2); +// check.Call("2"); +// Foo(3); +// } +// +// The expectation spec says that the first Bar("a") must happen +// before check point "1", the second Bar("a") must happen after check +// point "2", and nothing should happen between the two check +// points. The explicit check points make it easy to tell which +// Bar("a") is called by which call to Foo(). +template +class MockFunction; + +template +class MockFunction { + public: + MOCK_METHOD0_T(Call, R()); +}; + +template +class MockFunction { + public: + MOCK_METHOD1_T(Call, R(A0)); +}; + +template +class MockFunction { + public: + MOCK_METHOD2_T(Call, R(A0, A1)); +}; + +template +class MockFunction { + public: + MOCK_METHOD3_T(Call, R(A0, A1, A2)); +}; + +template +class MockFunction { + public: + MOCK_METHOD4_T(Call, R(A0, A1, A2, A3)); +}; + +template +class MockFunction { + public: + MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4)); +}; + +template +class MockFunction { + public: + MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5)); +}; + +template +class MockFunction { + public: + MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6)); +}; + +template +class MockFunction { + public: + MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7)); +}; + +template +class MockFunction { + public: + MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8)); +}; + +template +class MockFunction { + public: + MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)); +}; + } // namespace testing #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ diff --git a/include/gmock/gmock-generated-function-mockers.h.pump b/include/gmock/gmock-generated-function-mockers.h.pump index 54b848f6..3c845632 100644 --- a/include/gmock/gmock-generated-function-mockers.h.pump +++ b/include/gmock/gmock-generated-function-mockers.h.pump @@ -198,6 +198,55 @@ $for i [[ ]] +// A MockFunction class has one mock method whose type is F. It is +// useful when you just want your test code to emit some messages and +// have Google Mock verify the right messages are sent (and perhaps at +// the right times). For example, if you are exercising code: +// +// Foo(1); +// Foo(2); +// Foo(3); +// +// and want to verify that Foo(1) and Foo(3) both invoke +// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: +// +// TEST(FooTest, InvokesBarCorrectly) { +// MyMock mock; +// MockFunction check; +// { +// InSequence s; +// +// EXPECT_CALL(mock, Bar("a")); +// EXPECT_CALL(check, Call("1")); +// EXPECT_CALL(check, Call("2")); +// EXPECT_CALL(mock, Bar("a")); +// } +// Foo(1); +// check.Call("1"); +// Foo(2); +// check.Call("2"); +// Foo(3); +// } +// +// The expectation spec says that the first Bar("a") must happen +// before check point "1", the second Bar("a") must happen after check +// point "2", and nothing should happen between the two check +// points. The explicit check points make it easy to tell which +// Bar("a") is called by which call to Foo(). +template +class MockFunction; + + +$for i [[ +$range j 0..i-1 +template +class MockFunction { + public: + MOCK_METHOD$i[[]]_T(Call, R($for j, [[A$j]])); +}; + + +]] } // namespace testing #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ -- cgit v1.2.3