STUB

C Test Script Language

Purpose

The STUB instruction for C describes all calls to a simulated function in a test script.

Syntax

STUB [<stub_name>.] <function> [<call_range> =>] ([<param_val> {, <param_val> }]) [<return_val>] {, [<call_range> =>] ([<param_val> {, <param_val> }]) [<return_val>] }

Description

The following is described for every parameter of this function and for every expected call:

  1. For _in parameters, the values passed to the function; these values will be stored and then tested during execution,

    For _out parameters and, where appropriate, the return value, the values returned by the function; these values will be stored in order to be returned during execution,

    For _inout parameters, both the previous two values are required,

    For _no parameters, any parameter is ignored.

The optional <call_range> describes one or several successive calls as follows:

<call_num> =>

<call_num> .. <call_num> =>

others =>

 

where <call_num> is the number of the stub call. The keyword others specifies the behavior of any further calls that have not been described. A <call_num> value of 0 means that no calls are expected to the stub. For example, the following line specifies that test will pass if there are 0 or more calls to the stub:

STUB close_file others=>(5)1

 

Moreover, you can use others to specify that the calls are optional. Combining others with a list of call numbers, enables you to check the minimum number of calls. For example, the following line specifies that test will pass if there are at least 4 calls to the stub:

STUB close_file 1=>(3)1, 2..4=>(4)1, others=>(5)1

 

If <call_range> is not specified, then the next call number is assumed. For example, the following lines specify that the test will pass if there are 2 calls to the stub:

STUB open_file ("file1")3

STUB open_file ("file2")4

 

<function> is the name of the simulated function. It is obligatory. You must previously have described this function in a DEFINE STUB ... END DEFINE STUB block. You can specify in which stub (<stub_name>) the declaration was made.

<param_val> is an expression describing the test values for _in parameters and the returned values for _out parameters. For _inout parameters, <param_val> is expressed in the following way:

(<in_param_val>, <out_param_val>)

<return_val> is an expression describing the value returned by the function if its type is not void. Otherwise, no value is provided.

You must give values for every _in, _out and _inout parameter; otherwise, a warning message is generated. You must not give a value for any _no parameters; otherwise, a warning message is generated.

<param_val> and <return_val> are expressions that can contain:

You must describe at least one call in the STUB instruction. There can be several descriptions, separated by commas (','). STUB instructions can appear in ELEMENT or ENVIRONMENT blocks.

Type Modifier '@' Syntax

In a STUB definition you can use a @ before a type modifier to indicate that this type modifier should be used when generating variable that test the correct execution of STUBs. For example:

DEFINE STUB Example

#void ConstParam (@const int _in *a);

END DEFINE

 

Without the @ symbol, the variables are of const int type and therefore are not modified by the test harness.

Example

STUB read_file (3,"line 1")1, (3,"line 2")1, (3,"")0

STUB write_file (4,"line 1")1, (4,"line 2")1

STUB close_file 1=>(3)1, 2..4=>(4)1, others=>(5)1