STUB

C++ Test Script Language

Syntax

STUB <stub name> : <native routine signature>

[ REQUIRE ( <require native expression> ) ]

{<stub item>... <stub item>}

[ ENSURE ( <ensure native expression> ) ]

Location

C++ Test Driver Script

Description

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

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:

<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:

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:

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.