-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1ec02b
commit bbbbdc0
Showing
17 changed files
with
207 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include "add_function_mock.h" | ||
|
||
IMPLEMENT_FUNCTION_MOCK2(AddFunctionMock, add, int(int, int)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef CMOCK_TEST_ADD_FUNCTION_MOCK_H_ | ||
#define CMOCK_TEST_ADD_FUNCTION_MOCK_H_ | ||
|
||
#include "cmock/cmock.h" | ||
|
||
#include "math.h" | ||
|
||
DECLARE_FUNCTION_MOCK2(AddFunctionMock, add, int(int, int)); | ||
|
||
#endif /* CMOCK_TEST_ADD_FUNCTION_MOCK_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
#include <cmock/cmock.h> | ||
|
||
#include "foo_mock_class.h" | ||
#include "math_mocker.h" | ||
|
||
using namespace ::testing; | ||
|
||
/** | ||
* Function foo is mocked as long as FooFunctionMock instance exists. | ||
* Functions add and substract are mocked as long as MathMocker instance exists. | ||
* Once mock function is destroyed, call directs to real function. | ||
*/ | ||
TEST(FunctionClassMockersTest, FunctionIsMockedAsLongAsMockInstanceExists) { | ||
TEST(FunctionClassMockersTest, FunctionsAreMockedAsLongAsMockerInstanceExists) { | ||
|
||
{ | ||
FooMocker mock; | ||
MathMocker mock; | ||
|
||
EXPECT_CALL(mock, add(1, 1)).WillOnce(Return(11)); | ||
ASSERT_EQ(11, add(1, 1)); | ||
EXPECT_CALL(mock, divide(1, 1)).WillOnce(Return(11)); | ||
ASSERT_EQ(11, divide(1, 1)); | ||
|
||
EXPECT_CALL(mock, sub(1, 1)).WillOnce(Return(7)); | ||
ASSERT_EQ(7, sub(1, 1)); | ||
EXPECT_CALL(mock, substract(1, 2)).WillOnce(Return(12)); | ||
ASSERT_EQ(12, substract(1, 2)); | ||
} | ||
|
||
ASSERT_EQ(2, add(1, 1)); | ||
ASSERT_EQ(0, sub(1, 1)); | ||
ASSERT_EQ(1, divide(1, 1)); | ||
ASSERT_EQ(-1, substract(1, 2)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
#include <cmock/cmock.h> | ||
|
||
#include "foo_mock.h" | ||
#include "add_function_mock.h" | ||
|
||
using namespace ::testing; | ||
|
||
/** | ||
* Function foo is mocked as long as FooFunctionMock instance exists. | ||
* Once mock function is destroyed, call directs to real function. | ||
* Function add is mocked as long as AddFunctionMock instance exists. | ||
* Once mock function is destroyed, a call directs to a real function. | ||
*/ | ||
TEST(FunctionMockersTest, FunctionIsMockedAsLongAsMockInstanceExists) { | ||
|
||
{ | ||
FooFunctionMock mock; | ||
AddFunctionMock mock; | ||
|
||
EXPECT_FUNCTION_CALL(mock, (1, 2)).WillOnce(Return(3)); | ||
ASSERT_EQ(3, foo(1, 2)); | ||
EXPECT_FUNCTION_CALL(mock, (1, 2)).WillOnce(Return(12)); | ||
ASSERT_EQ(12, add(1, 2)); | ||
} | ||
|
||
ASSERT_EQ(2, foo(1, 2)); | ||
ASSERT_EQ(3, add(1, 2)); | ||
} | ||
|
||
/** | ||
* real static mock class field holds pointer to real function. | ||
* real static mock class field holds pointer to a real function. | ||
*/ | ||
TEST(FunctionMockersTest, FunctionMockExportsRealFunctionPointer) { | ||
EXPECT_EQ(2, FooFunctionMock::real(1, 2)); | ||
EXPECT_EQ(3, AddFunctionMock::real(1, 2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
#include <cmock/cmock.h> | ||
|
||
#include "foo_mock.h" | ||
#include "add_function_mock.h" | ||
|
||
TEST(SpecBuildersTest, ExpectFunctionCallCompiles) { | ||
FooFunctionMock mock; | ||
AddFunctionMock mock; | ||
EXPECT_FUNCTION_CALL(mock, (1, 2)).Times(0); | ||
} | ||
|
||
TEST(SpecBuildersTest, OnFunctionCallCompiles) { | ||
FooFunctionMock mock; | ||
AddFunctionMock mock; | ||
ON_FUNCTION_CALL(mock, (1, 2)); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.