I'm trying to test some cpp code with cpputest. There is the code I would test:
void TA_MotRunng(rte_MotRunng_t_iArgs_t *args)
{
MotRunngLocalVariables_t lv;
InpGetAndChk(args, &lv);
std::cout << "lv.ip.drvEna_HW = " << lv.ip.drvEna_HW << std::endl;
/* motor running */
if ((ON == lv.ip.drvEna_HW) &&
(ON == lv.ip.drvEnaSW) &&
((drv_ENABLED == lv.ip.drvSts) || (drv_RESTARTING == lv.ip.drvSts)) &&
(lv.ip.drvSpd > 500.0f))
{
lv.sts.motRunng_sts = ON;
}
/* motor not running */
if ((OFF == lv.ip.drvEna_HW) ||
(OFF == lv.ip.drvEnaSW) ||
((drv_ENABLED != lv.ip.drvSts ) && (drv_RESTARTING != lv.ip.drvSts)) ||
(lv.ip.drvSpd < 50.0f ))
{
lv.sts.motRunng_sts = OFF;
}
// write output
lv.op.motRunng = lv.sts.motRunng_sts;
SetOutp(args, &lv);
}
And I wrote a test code like this
#include "../includes/TestMotRunng.hpp"
#include <iostream>
TEST_GROUP(TA_MotRunngTest)
{
TA_MotRunngTest test;
void setup()
{
test.setUp();
}
void teardown()
{
test.tearDown();
}
};
TEST(TA_MotRunngTest, testMotRunning)
{
test.testMotRunning();
}
TEST(TA_MotRunngTest, testMotNotRunning)
{
test.testMotNotRunning();
}
TA_MotRunngTest::TA_MotRunngTest() {}
void TA_MotRunngTest::setUp()
{
// Set up
// ...
mock().clear();
}
void TA_MotRunngTest::tearDown()
{
std::cout << "teardown" << std::endl;
mock().checkExpectations();
mock().clear();
}
void TA_MotRunngTest::testMotRunning()
{
rte_MotRunng_t_iArgs_t args;
MotRunngLocalVariables_t lv;
MockSupport mock;
// Set the input values to make the motor running
lv.ip.drvEna_HW = ON;
lv.ip.drvEnaSW = ON;
lv.ip.drvSts = drv_ENABLED;
lv.ip.drvSpd = 501.0f;
mock.expectOneCall("InpGetAndChk")
.withOutputParameterReturning("args", &args, sizeof(args))
.withOutputParameterReturning("lv", &lv, sizeof(lv));
TA_MotRunng(&args);
// Verify that the output value for motor running is ON
mock.checkExpectations();
CHECK_EQUAL(ON, lv.sts.motRunng_sts);
}
void TA_MotRunngTest::testMotNotRunning()
{
}
static void __wrap_InpGetAndChk(rte_MotRunng_t_iArgs_t const *args,
MotRunngLocalVariables_t *lv)
{
// mock the InpGetAndChk function and set the input values
mock().actualCall("InpGetAndChk").withOutputParameter("args",
(void*)args).withOutputParameter("lv", lv);
lv->ip.drvEna_HW = ON;
lv->ip.drvEnaSW = ON;
lv->ip.drvSts = drv_ENABLED;
lv->ip.drvSpd = 600.0f;
}
I'm trying to mock the inpGetAndChk function but I've an error:
/usr/src/app/tests/src/TestMotRunng.cpp:17: error: Failure in TEST(TA_MotRunngTest, testMotRunning) Mock Failure: Expected call WAS NOT fulfilled. EXPECTED calls that WERE NOT fulfilled: InpGetAndChk -> const void* args: , const void* lv: (expected 1 call, called 0 times) EXPECTED calls that WERE fulfilled:
I search on stackoverflow and I found this
I tried to use --wrap like that
--wrap=InpGetAndChk
but it's doesn't work I have the same error.
Thanks for reading me.
Cheers