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:
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 describes any further calls that have not been described. Moreover, this key word allows to not check the sub call number. A <call_num> value of 0 means that there are no calls.
If <call_range> is not specified, then the next call number is assumed.
<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:
Numeric (integer or floating-point), character, or character string literal values. Strings can be delimited by single or double inverted commas
Constants which can be numeric, characters, or character strings
Constants defined in the test script
Variables belonging to the test program or the module to be tested
C functions
The keyword NIL to designate a null pointer
Pseudo-variables I, I1, I2 ..., J, J1, J2 ..., where In is the current index of the nth dimension of the parameter and Jm the current number of the subtest generated by the test scenario's mth INIT IN, INIT FROM or LOOP; the I and I1 variables are therefore equivalent as are J and J1; the subtest numbers begin at 1 and are incremented by 1 at each iteration
An expression with one or more of the above elements combined using any of the C operators (+, -, *, /, %, &, |, ^, &&, ||, <<, >>) and casting, with all required levels of parentheses, and conforming to C rules of syntax and semantics, the + operator being allowed to concatenate character string variables
For arrays and structures, a list of expressions between braces ('{' and '}') or brackets ('[' and ']') with, where appropriate:
For an array element, part of an array or a structure field, its index, interval or name followed by '=>' and by the value of the array element, common to all elements of the array portion or structure field
The keyword others (written in lower case) followed by '=>' and the default value of any array elements or structure fields not yet mentioned.
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 open_file ("file1")3
STUB create_file ("file2")4
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)1