STUB

Ada Test Script Language

Purpose

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

Syntax

STUB <stub_name> [<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 are stored and tested during execution.

    For out parameters and, where appropriate, the return value, the values returned by the function. These values are stored in order to be returned during execution.

    For in out and in access parameters, both the previous two values are required.

    For no parameters, no expression is required.

<stub_name> is the name of the simulated procedure or function. It is obligatory. You must previously have described this procedure or function in a DEFINE STUB block.

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 2 calls to the stub:

STUB close_file 1=>(3)1, 2=>(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

<param_val> is an expression describing the test values for in parameters and the returned values for out parameters. If named, parameters can be in any order. For in out parameters, <param_val> is expressed in the following way:

( [IN =>]<in_param_val> , [OUT =>]<out_param_val> )

If you use the optional IN => and OUT => specifiers, you can invert the order of the parameters.

<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 in out parameter; otherwise, a warning message is generated. The no parameters are ignored.

<param_val> and <return_val> are Ada 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, in the Ada sense of the word, which can be numeric, characters, or character strings

    Variables belonging to the test program or the module to be tested

    Ada functions

    The keyword NIL to designate a null pointer

    Pseudo-variables I, I1, I2 ..., J, J1, J2 ..., where I n is the current index of the nth dimension of the parameter and J m 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 Ada expression with one or more of the above elements combined using any of the Ada operators and casting, with all required levels of parentheses, and conforming to Ada rules of syntax and semantics

    For arrays and structures, aggregates between parentheses ('( )') or brackets ('[ ]').

<param_val> can contain for an in value:

  • The <-> expression to specify that the parameter should be ignored

    The < value> <-> < value> expression to specify a range of values for the parameter

<param_val> can contain for an out value or return value:

  • The == expression to specify that the parameter should not be set

If are using one of the above expressions, you can specify the type of parameter by using the ==: <type> syntax for the out and return value or <->: <type> for the in value.

<return_val> can also refer to an Ada exception name introduced by the following syntax:

[ : <return_type> ] RAISE <exception_name>

where : <return_type> is used to specify the function returned type in case of overloading.

You must describe at least one call in the STUB instruction. Several descriptions can occur separated by commas.

STUB instructions can appear in ELEMENT blocks.

Example

STUB open_file ("file1")3

STUB create_file ("file2")4

STUB read_file 1..2 =>(3,"line 1",1)1,(3,"line 2",2<->3)1,

& 4..7 =>(3,"",0)0

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

STUB close_file (3)1,(4)1, (<->) RAISE DEVICE_ERROR

Related Topics

DEFINE STUB ... END DEFINE