piotr

About

Username
piotr
Joined
Visits
39
Last Active
Roles
Members, Staff
Points
6
Posts
8
Badges
1
  • Re: How to use Parasoft Dynamic stubs #4

    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); 
    
  • Re: Setting Environment variables and supply arguments

    Hello,

    1. Setting environment variables

    You should set-up all required environment variables before launching C++test/Eclipse IDE (in the console shell etc.)

    In addition, if your project is of "CDT Managed C/C++ Project" type*, then you can configure environment variables directly in the IDE:
    Project Properties> C/C++ Build> Environment

    (*) Be sure Project Properties> Parasoft> C++test> Build Settings> Options Source is set to "Use options from Managed C/C++ project"

    2. Setting application command line arguments

    When "Unit Testing" your code, C++test will call functions under tests directly - the application's main entry point will not be executed - so command line arguments are not relevant here.

    When "Application Monitoring" your app, the command line arguments can be configured in Test Configuration> Execution> General> Execution Details> Application command line.

    3. "Cannot find test log file" message

    The test binary was not executed successfully - most probably because of "[...] error while loading shared libraries", so the test log could not be created. Please be sure the environment is set-up correctly (see #1).