Skip to content

Commit

Permalink
Merge 92118fd into 5358c82
Browse files Browse the repository at this point in the history
  • Loading branch information
arstrube committed Mar 10, 2016
2 parents 5358c82 + 92118fd commit 70d515a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
1 change: 0 additions & 1 deletion platforms/CCStudio/CppUTestExtRunAllTests1.pjt
Expand Up @@ -38,7 +38,6 @@ Source="..\..\src\CppUTestExt\MockExpectedCallsList.cpp"
Source="..\..\src\CppUTestExt\MockFailure.cpp"
Source="..\..\src\CppUTestExt\MockNamedValue.cpp"
Source="..\..\src\CppUTestExt\MockSupport.cpp"
Source="..\..\src\CppUTestExt\MockSupport_c.cpp"
Source="..\..\src\CppUTestExt\MockSupportPlugin.cpp"
Source="..\..\src\CppUTestExt\OrderedTest.cpp"
Source="..\..\src\Platforms\C2000\UtestPlatform.cpp"
Expand Down
10 changes: 6 additions & 4 deletions src/CppUTestExt/MockSupport_c.cpp
Expand Up @@ -32,6 +32,8 @@
#include "CppUTestExt/MockSupport.h"
#include "CppUTestExt/MockSupport_c.h"

typedef void (*cpputest_cpp_function_pointer)(); /* Cl2000 requires cast to C++ function */

class MockFailureReporterTestTerminatorForInCOnlyCode : public TestTerminatorWithoutExceptions
{
public:
Expand Down Expand Up @@ -382,7 +384,7 @@ MockExpectedCall_c* withConstPointerParameters_c(const char* name, const void* v

MockExpectedCall_c* withFunctionPointerParameters_c(const char* name, void (*value)())
{
expectedCall = &expectedCall->withParameter(name, value);
expectedCall = &expectedCall->withParameter(name, (cpputest_cpp_function_pointer)value);
return &gExpectedCall;
}

Expand Down Expand Up @@ -466,7 +468,7 @@ MockExpectedCall_c* andReturnConstPointerValue_c(const void* value)

MockExpectedCall_c* andReturnFunctionPointerValue_c(void (*value)())
{
expectedCall = &expectedCall->andReturnValue(value);
expectedCall = &expectedCall->andReturnValue((cpputest_cpp_function_pointer)value);
return &gExpectedCall;
}

Expand Down Expand Up @@ -598,7 +600,7 @@ MockActualCall_c* withActualConstPointerParameters_c(const char* name, const voi

MockActualCall_c* withActualFunctionPointerParameters_c(const char* name, void (*value)())
{
actualCall = &actualCall->withParameter(name, value);
actualCall = &actualCall->withParameter(name, (cpputest_cpp_function_pointer) value);
return &gActualCall;
}

Expand Down Expand Up @@ -795,7 +797,7 @@ void setConstPointerData_c(const char* name, const void* value)

void setFunctionPointerData_c(const char* name, void (*value)())
{
currentMockSupport->setData(name, value);
currentMockSupport->setData(name, (cpputest_cpp_function_pointer) value);
}

void setDataObject_c(const char* name, const char* type, void* value)
Expand Down
24 changes: 14 additions & 10 deletions tests/CppUTestExt/MockSupport_cTest.cpp
Expand Up @@ -32,6 +32,10 @@
#include "MockSupport_cTestCFile.h"
#include "CppUTestExt/OrderedTest.h"

extern "C" { /* Cl2000 requires cast to C function */
typedef void (*cpputest_c_function_pointer)();
}

TEST_GROUP(MockSupport_c)
{
};
Expand Down Expand Up @@ -87,10 +91,10 @@ TEST(MockSupport_c, expectAndActualParameters)
{
mock_c()->expectOneCall("boo")->withIntParameters("integer", 1)->withDoubleParameters("double", 1.0)->
withStringParameters("string", "string")->withPointerParameters("pointer", (void*) 1)->
withFunctionPointerParameters("functionPointer", (void(*)()) 1);
withFunctionPointerParameters("functionPointer", (cpputest_c_function_pointer) 1);
mock_c()->actualCall("boo")->withIntParameters("integer", 1)->withDoubleParameters("double", 1.0)->
withStringParameters("string", "string")->withPointerParameters("pointer", (void*) 1)->
withFunctionPointerParameters("functionPointer", (void(*)()) 1);
withFunctionPointerParameters("functionPointer", (cpputest_c_function_pointer) 1);
}

extern "C"{
Expand Down Expand Up @@ -395,24 +399,24 @@ TEST(MockSupport_c, whenNoReturnValueIsGivenReturnConstPointerValueOrDefaultShou

TEST(MockSupport_c, returnFunctionPointerValue)
{
mock_c()->expectOneCall("boo")->andReturnFunctionPointerValue((void(*)()) 10);
FUNCTIONPOINTERS_EQUAL((void(*)()) 10, mock_c()->actualCall("boo")->functionPointerReturnValue());
FUNCTIONPOINTERS_EQUAL((void(*)()) 10, mock_c()->functionPointerReturnValue());
mock_c()->expectOneCall("boo")->andReturnFunctionPointerValue((cpputest_c_function_pointer) 10);
FUNCTIONPOINTERS_EQUAL((cpputest_c_function_pointer) 10, mock_c()->actualCall("boo")->returnValue().value.functionPointerValue);
FUNCTIONPOINTERS_EQUAL((cpputest_c_function_pointer) 10, mock_c()->functionPointerReturnValue());
LONGS_EQUAL(MOCKVALUETYPE_FUNCTIONPOINTER, mock_c()->returnValue().type);
}

TEST(MockSupport_c, whenReturnValueIsGivenReturnFunctionPointerValueOrDefaultShouldIgnoreTheDefault)
{
void (*defaultValue)() = (void (*)()) 10;
void (*expectedValue)() = (void (*)()) 14;
cpputest_c_function_pointer defaultValue = (cpputest_c_function_pointer) 10;
cpputest_c_function_pointer expectedValue = (cpputest_c_function_pointer) 14;
mock_c()->expectOneCall("foo")->andReturnFunctionPointerValue(expectedValue);
FUNCTIONPOINTERS_EQUAL(expectedValue, mock_c()->actualCall("foo")->returnFunctionPointerValueOrDefault(defaultValue));
FUNCTIONPOINTERS_EQUAL(expectedValue, mock_c()->returnFunctionPointerValueOrDefault(defaultValue));
}

TEST(MockSupport_c, whenNoReturnValueIsGivenReturnFunctionPointerValueOrDefaultShouldlUseTheDefaultValue)
{
void (*defaultValue)() = (void (*)()) 10;
cpputest_c_function_pointer defaultValue = (cpputest_c_function_pointer) 10;
mock_c()->expectOneCall("foo");
FUNCTIONPOINTERS_EQUAL(defaultValue, mock_c()->actualCall("foo")->returnFunctionPointerValueOrDefault(defaultValue));
FUNCTIONPOINTERS_EQUAL(defaultValue, mock_c()->returnFunctionPointerValueOrDefault(defaultValue));
Expand Down Expand Up @@ -465,8 +469,8 @@ TEST(MockSupport_c, MockSupportMemoryBufferData)

TEST(MockSupport_c, MockSupportSetFunctionPointerData)
{
mock_c()->setFunctionPointerData("functionPointer", (void(*)()) 1);
FUNCTIONPOINTERS_EQUAL((void(*)()) 1, mock_c()->getData("functionPointer").value.functionPointerValue);
mock_c()->setFunctionPointerData("functionPointer", (cpputest_c_function_pointer) 1);
FUNCTIONPOINTERS_EQUAL((cpputest_c_function_pointer) 1, mock_c()->getData("functionPointer").value.functionPointerValue);
}

TEST(MockSupport_c, MockSupportSetDataObject)
Expand Down

0 comments on commit 70d515a

Please sign in to comment.