how to validate a reference argument on CPPTEST_ON_CALL?

I'm using gcc compiler MinGW version 6.3.0 with Parasoft 10.4 under eclipse.

I have a C++ function which expects an argument passed as reference, I want to validate on my test that I'm not passing that argument as null. I tried several ways to use the .Equal() on the stub, but I always get errors.
My simplified code is below:

/* My C++ function is */
void MainClass::Enable(ClassA_t &obj, bool enable) { // code }

/* My autogenerate stub from parasoft for MainClass::Enable */
void (::MainCode::CppTest_Auto_Stub_Enable) (::ClassA_t & obj, ::bool enable)
{
CPPTEST_ACTUAL_CALL("MainClass::Enable")
->WithPtrArg("this", this, tgr_void_type())
->WithRefArg("obj", &obj, tgr_void_type())
->WithRefArg("enable", &enable, tgr_bool_type())
->WithRefArg("__callOrig", &__callOrig, tgr_int_type())
->End();
/* rest of the stub code*/
}

/* in my test evaluation I want to assure that my argument obj is not null, obj is a reference not a pointer /
CPPTEST_ON_CALL("MainClass::Enable")
.If().Arg("obj").Equal(nullptr) /
<--- HOW DO I COMPARE WITH REFERENCE ARGUMENT? /
.Fail("Enable(): Object Not Inititialized")
.If().Arg("enable").Equal(true)/
<- if I only compare this argument it works fine */
.Fail("Enable(): Obj Incorrectly Enabled");

Tagged:

Comments

  • MirekMirek Posts: 119 ✭✭✭

    Hi @celsostryker,

    This case is not trivial. To implement the check you described, you will need to slightly modify the body of auto-generated stub. In place of

    WithRefArg("obj", &obj, tgr_void_type())

    insert the following:

    WithPtrArg("obj", &obj, tgr_void_type())

    This should allow you to compare the "obj" against the null in the test case.
    To preserve this modification you will need to check in the file with the modified stub body so that you can rely on it in your test cases.

    Thank,
    Mirek

Sign In or Register to comment.