mirror of
https://github.com/openappsec/openappsec.git
synced 2025-10-01 20:17:43 +03:00
First release of open-appsec source code
This commit is contained in:
50
external/C-Mock/test/cmock-function-mockers_test.cc
vendored
Normal file
50
external/C-Mock/test/cmock-function-mockers_test.cc
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <cmock/cmock.h>
|
||||
|
||||
#include "math.h"
|
||||
|
||||
using namespace ::testing;
|
||||
|
||||
DECLARE_FUNCTION_MOCK2(AddFunctionMock, add, int(int, int));
|
||||
DECLARE_FUNCTION_MOCK1(NegateFunctionMock, negate, int(int));
|
||||
|
||||
IMPLEMENT_FUNCTION_MOCK2(AddFunctionMock, add, int(int, int));
|
||||
IMPLEMENT_FUNCTION_MOCK1(NegateFunctionMock, negate, int(int));
|
||||
|
||||
/**
|
||||
* Function add is mocked as long as AddFunctionMock instance exists.
|
||||
* Once mock function is destroyed, a call directs to a real function.
|
||||
*/
|
||||
TEST(FunctionMockersTest, MocksFunctionAsLongAsMockInstanceExists) {
|
||||
|
||||
{
|
||||
AddFunctionMock mock;
|
||||
|
||||
EXPECT_FUNCTION_CALL(mock, (1, 2)).WillOnce(Return(12));
|
||||
ASSERT_EQ(12, add(1, 2));
|
||||
}
|
||||
|
||||
ASSERT_EQ(3, add(1, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* real static mock class field holds pointer to a real function.
|
||||
*/
|
||||
TEST(FunctionMockersTest, FunctionMockExportsRealFunctionPointer) {
|
||||
EXPECT_EQ(3, AddFunctionMock::real(1, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Function negate doesn't exist, but can be mocked.
|
||||
*/
|
||||
TEST(FunctionMockersTest, ThrowsExceptionIfRealFunctionNotFound)
|
||||
{
|
||||
{
|
||||
NegateFunctionMock mock;
|
||||
|
||||
EXPECT_FUNCTION_CALL(mock, (9)).WillOnce(Return(3));
|
||||
|
||||
ASSERT_EQ(3, negate(9));
|
||||
}
|
||||
|
||||
EXPECT_THROW(negate(9), std::logic_error);
|
||||
}
|
Reference in New Issue
Block a user