Was könnte Seien Sie die wahrscheinlichen Ursachen der Kürzung der Zeigeradresse, die ich sehe? -Override ">
Code: Select all
#include "CppUTest/TestHarness.h"
#include "CppUTestExt/MockSupport.h"
#include "CppUTest/CommandLineTestRunner.h"
extern "C"
{
#include "includes.h"
#include
DivStruct_t* GetDivPtr()
{
void* retVal = mock().actualCall("GetDivPtr").returnPointerValue();
printf("fake div in mock %p \n", retVal);
return (DivStruct_t*)retVal;
}
}
TEST_GROUP( mockTest )
{
void setup()
{
// Initialize before each test
}
void teardown()
{
// Deinitialize after each test
mock().clear();
}
};
TEST ( mockTest, passingPointer )
{
DivStruct_t fakeDiv;
fakeDiv.f1 = 8.0;
fakeDiv.f2 = 6.0;
printf("fake div addr %p \n", (void*)&fakeDiv);
mock().expectOneCall("GetDivPtr").andReturnValue(&fakeDiv);
Cfunction();
mock().checkExpectations();
}
< /code>
Function.c
#include "includes.h"
void Cfunction()
{
DivStruct_t* div = GetDivPtr();
// seg fault happens here
printf("div addr %p \n", (void*)&div);
float f1Val = div->f1;
return;
}
< /code>
Includes.h
typedef struct
{
float f1;
float f2;
} DivStruct_t;
DivStruct_t* GetDivPtr();
void Cfunction();
< /code>
Main.cpp
#include "CppUTest/CommandLineTestRunner.h"
int main( int ac, char ** av )
{
return CommandLineTestRunner::RunAllTests( ac, av );
}