1 #include <cmock/cmock.h>
5 using namespace ::testing;
7 class MathMocker : public CMockMocker<MathMocker>
10 MOCK_METHOD2(add, int(int, int));
11 MOCK_METHOD2(substract, int(int, int));
12 MOCK_METHOD1(negate, int(int));
15 CMOCK_MOCK_FUNCTION2(MathMocker, add, int(int, int));
16 CMOCK_MOCK_FUNCTION2(MathMocker, substract, int(int, int));
17 CMOCK_MOCK_FUNCTION1(MathMocker, negate, int(int));
20 * Functions add and substract are mocked as long as MathMocker instance exists.
21 * Once a mock function is destroyed, a call directs to a real function.
23 TEST(FunctionClassMockersOldStyleTest, MocksFunctionAsLongAsMockerInstanceExists) {
28 EXPECT_CALL(mock, add(1, 1)).WillOnce(Return(11));
29 ASSERT_EQ(11, add(1, 1));
31 EXPECT_CALL(mock, substract(1, 2)).WillOnce(Return(12));
32 ASSERT_EQ(12, substract(1, 2));
35 ASSERT_EQ(2, add(1, 1));
36 ASSERT_EQ(-1, substract(1, 2));
39 TEST(FunctionClassMockersOldStyleTest, ThrowsExceptionIfRealFunctionNotFound) {
44 EXPECT_CALL(mock, negate(3)).WillOnce(Return(-3));
45 ASSERT_EQ(-3, negate(3));
48 EXPECT_THROW(negate(3), std::logic_error);