how to use Parasoft Dynamic stubs #1

wsuberswsubers Posts: 6

Hello Community,

I am a first time user of Parasoft's dynamic stubs. I am evaluating this feature as an alternate to using Google mock.

If I have a function:

void Func1()
{
int a = 1;
Func2(a);
a++;
Func2(a);
}

In my test case for testing Func1, what is the appropriate Dynamic Stubs calls to validate the first time Func2 was called, the input parameter a was equal to 1 and the second time Func2 was called, the input parameter a was equal to 2?

Tagged:

Comments

  • MirekMirek Posts: 24

    Hello,

    The simplest solution is to add the following two lines to the test case:

    CPPTEST_ON_CALL("Func2")->If()->LP()->RunId()->Equal()->Value(1)->RP()->If()->LP()->Arg("a")->NotEqual()->Value(1)->RP()->Fail("Argument \"a\" not equal 1");
    
    CPPTEST_ON_CALL("Func2")->If()->LP()->RunId()->Equal()->Value(2)->RP()->If()->LP()->Arg("a")->NotEqual()->Value(2)->RP()->Fail("Argument \"a\" not equal 2");
    

    I will discuss only the first one since the second one is exactly the same, there are 3 parts:

    1.
    CPPTEST_ON_CALL("Func2")->
    Register operation for the "Func2" stub id

    1. If()->LP()->RunId()->Equal()->Value(1)->RP()->
      Check the stub call number. Counting starts from 1.
      Remaining part will be executed only if this evaluates to true.

    3.
    If()->LP()->Arg("a")->NotEqual()->Value(1)->RP()->
    Check the value of parameter (this action is executed only if "RunId" condition evaluated to true)

    4.
    Fail("Argument \"a\"~~~~ not equal 1");
    Report failure (executed only if parameter check evaluated to true)

    Hope this helps

Sign In or Register to comment.