STUB

The STUB statement defines a stub for a function or method. A stub defines or replaces the initial routine.

C++ Test Script Language

Syntax
STUB <stub name> : <native routine signature>
[ REQUIRE ( <require native expression> ) ]
{<stub item>... <stub item>}
[ ENSURE ( <ensure native expression> ) ]

Note The use of stubs requires instrumentation.

<stub name> is a unique C++ Test Script Language identifier.

<native routine signature> is a C++ signature matching the routine to stub. Unlike WRAP signatures, the signature must be complete; the return type and parameters (type and name) must be specified. If the routine is a class member or belongs to a namespace, its name must be qualified. If the routine is a template function or a template class member, the usual template<...> prefix must be used. If it is a generic template, any instance of this template is stubbed. If it is a template specialization, only the corresponding instance is stubbed.

<require native expression> is a C++ expression that can be evaluated to a Boolean. It is evaluated before the stub execution. It can refer to:

  • The global variables defined in the test script.

  • The stubbed routine's parameters.

<ensure native expression> is a C++ expression which can be evaluated to a Boolean. It is evaluated after the stub execution. It can refer to:

  • The global variables defined in the test script.

  • The stubbed routine's parameters.

  • The_ATO_resultvariable that contains the routine return value, if any. Its type is that of the routine return type. Its value may be undefined if no value is returned (because an exception was thrown, or a return without a value is executed, or the function implicitly returns).

  • The_ATO_in_exceptionBoolean variable, which isTrueif the post-condition is executed because an exception has been thrown. This variable is available only if the Target Deployment Package is configured to support exceptions.

If one of these expressions is False, the stub is failed but not the CHECK STUB, which could still have been defined to ensure the stub is called.

<stub item> may be one the following entities:

  • CHECK

  • COMMENT

  • PRINT

  • Native statement

The "..." zone is optional and is replaced by the code provided through the CHECK STUB statement. If not specified, it is implicitly defined at the end of the STUB block.

You cannot define several stubs for the same method. However you can define a stub for each instance of a template function or a template class member.

If a statement of the STUB generates an error, the stub is declared failed, but its execution continues (there is always an implicit ON ERROR CONTINUE in stubs).

An error in a STUB does not imply an error in the TEST CASE containing the corresponding CHECK STUB. The CHECK STUB statement only checks that the stub is called, not that its execution is correct.

Example : STUB ModifyCell : int IntArray::Modify (int Cell)

REQUIRE (Cell != 128)

{

#int Nb = random(10000);

... // this part is completed by the code of CHECK STUB

#return (Nb);

}

In this example, a number Nb is randomly chosen. If no additional code is provided by a CHECK STUB, then this number is returned. If a CHECK STUB is provided, assign the expected return value to Nb on a case-by-case basis.