Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

Stub API require the Enable Stub API option option to be enabled in the Stubs view (see see Configuring Stub Options in the Stubs View) or directly in your test configuration (see Execution Tab Settings - Defining How Tests are Executed) before the stub is created.

...

  1. You can enforce the returning integer value 5 for all calls to the stub.

    Code Block
    [C++] CPPTEST_ON_CALL("foo").Arg("__return").Assign(5);
    [C] CPPTEST_ON_CALL("foo")->Arg("__return").Assign()->Int(5);

     

  2. You can enforce the return value depending on the stub parameter value. In the following example, the returning integer value 5 for the calls to the stub where parameter param1 is equal to the integer value 0 is enforced. For all other cases, the default value is returned (0 for numerical types).

    Code Block
    [C++] CPPTEST_ON_CALL("foo").If().Arg("param1").Equal(0).Arg("__return").Assign(5);
    [C] CPPTEST_ON_CALL("foo")->If()->Arg("param1")->Equal()->Int(0)->Arg("__return")->Assign()->Int(5);
  3. You can call the original function and modify return values. In the following example, the original function is called and the return value is modified to the integer value of 5.

    Code Block
    [C++] CPPTEST_ON_CALL("foo").Arg("__callOrig").Assign(1).Arg("__return").Assign(5);
    [C] CPPTEST_ON_CALL("foo")->Arg("__callOrig")->Assign()->Int(1)->Arg("__return")->Assign()->Int(5);

...