Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How to use Parasoft Dynamic stubs #4

wsubers
wsubers Posts: 7

On https://docs.parasoft.com/display/CPPDESKE1033/Working+with+Complex+Types, can you provide an example of the stub for Line moveLine(Line line, int xoff, int yoff); but using the “Basic Approach to Working with Complex Types”?

Comments

  • piotr
    piotr Posts: 36
    edited January 2018

    Default stub for Line moveLine(Line line, int xoff, int yoff) will look similar to this:

    ::Line CppTest_Auto_Stub_moveLine (::Line line, int xoff, int yoff) 
    {
        ::Line __return = ::Line();
        int __callOrig = 0;
    
        CPPTEST_ACTUAL_CALL("moveLine")
            ->WithPtrArg("line", &line, tgr_void_type())
            ->WithRefArg("xoff", &xoff, tgr_int_type())
            ->WithRefArg("yoff", &yoff, tgr_int_type())
            ->WithPtrArg("__return", &__return, tgr_void_type())
            ->WithRefArg("__callOrig", &__callOrig, tgr_int_type())
            ->End();
        if (__callOrig) {
            ...
            ...
        }
        return __return;
    }
    

    In order to make the following complex type members available to test cases:

    IN: line._p1._x, line._p1._y, line._p2._x, line._p2._y
    OUT: return._p1._x, return._p1._y, return._p2._x, return._p2._y

    the CPPTEST_ACTUAL_CALL could be extended like this:

    ::Line CppTest_Auto_Stub_moveLine (::Line line, int xoff, int yoff) 
    {
        ::Line __return = ::Line();
        int __callOrig = 0;
    
    CPPTEST_ACTUAL_CALL("moveLine")
       ->WithRefArg("line_p1_x", &line._p1._x, tgr_int_type()) // expose line._p1._x
       ->WithRefArg("line_p1_y", &line._p1._y, tgr_int_type()) // expose line._p1._y
       ->WithRefArg("line_p2_x", &line._p2._x, tgr_int_type()) // expose line._p2._x
        ->WithRefArg("line_p2_y", &line._p2._y, tgr_int_type()) // expose line._p2._y
        ->WithRefArg("xoff", &xoff, tgr_int_type())
        ->WithRefArg("yoff", &yoff, tgr_int_type())
        ->WithRefArg("return_p1_x", &__return._p1._x, tgr_int_type()) // expose return._p1._x
        ->WithRefArg("return_p1_y", &__return._p1._y, tgr_int_type()) // expose return._p1._y
        ->WithRefArg("return_p2_x", &__return._p2._x, tgr_int_type()) // expose return._p2._x
        ->WithRefArg("return_p2_y", &__return._p2._y, tgr_int_type()) // expose return._p2._y
        ->WithRefArg("__callOrig", &__callOrig, tgr_int_type())
        ->End();
        if (__callOrig) {
            ...
            ...
        }
        return __return;
    }
    

    As a result, test cases could access those additional complex type members exposed from stub:

    CPPTEST_ON_CALL("moveLine")->Arg("return_p1_x")->Assign()->Value(0);
    CPPTEST_ON_CALL("moveLine")->Arg("line_p2_y")->Assign()->Value(12);