VAR, ARRAY and STR <initialization> Parameter
In conjunction with the VAR, ARRAY and STR keywords, the <initialization> parameters for Ada Test Script Language specify the initial value of the variable.
Syntax
INIT = <exp>
INIT IN ( <exp>, <exp>, ... )
INIT ( <variable> ) WITH ( <exp>, <exp>, ... )
INIT FROM <exp> TO <exp> [STEP <exp> | NB_TIMES <nb> | NB_RANDOM <nb>[+ BOUNDS]]
INIT FROM <exp> TO <exp> [STEP <exp> | NB_VALUE <nb> | NB_RANDOM <nb>[+ BOUNDS]]
INIT ==
where:
-
<exp> is an expression as described below.
-
<nb> is an integer constant that is either literal or derived from an expression containing native constants.
-
<variable> is an Ada variable.
Description
The <initialization> expressions are used to assign an initial value to a variable. The initial value is displayed in the Component Testing report for Ada.
The INIT value is calculated during the pre-processing phase, not dynamically during test execution.
Initializations can be expressed in the following ways:
-
INIT = <exp> initializes a variable before the test with the value <expression>.
-
INIT IN { <exp> , <exp> , ...} declares a list of initial values. This is a condensed form of writing that enables several tests to be contained within a single instruction.
-
INIT ( <variable> ) WITH { <exp> , <exp> , ...} declares a list of initial values that is assigned in correlation with those of the variable initialized by an INIT IN instruction. There must be the same number of initial values.
-
INIT FROM <lower> TO <upper> allows the initial value of a numeric variable (integer or floating-point) to vary between lower and upper boundary limits:
-
STEP: the value varies by successive steps.
-
NB_TIMES <nb> or NB_VALUE <nb>: the value varies by a number <nb> of values that are equidistant between the two boundaries, where <nb> >= 2 (NB_TIMES and NB_VALUE are equivalent keywords). This option requires that the target platform supports floating point numbers.
-
NB_RANDOM <nb>: the value varies by generating random values between the 2 boundaries, including, when appropriate, the boundaries, where <nb> >= 1.
- BOUNDS: When you enter the ‘+ BOUNDS’ instruction after ‘NB_RANDOM nb’, two numerical values are added to the nb (number) values.
- The INIT IN and INIT ( <variable> ) WITH expressions cannot be used with for arrays that were initialized in extended mode or for structures.
- The INIT FROM expression can only be used for numeric variables.
- The STEP syntax cannot be used when the same variable is tested by another VAR, ARRAY or STR statement.
- The NB_TIMES, NB_VALUE, and NB_RANDOM keywords require that the target platform supports floating point numbers.
- An initialization expression can still be used (INIT == <expression>) to include of expected value expression when using the INIT pseudo-variable is used. See Expected_Value Expressions.
- The following syntaxes cannot be used in an ARRAY instruction:
- INIT FROM <exp> TO <exp> STEP <exp>,
- INIT FROM <exp> TO <exp> NB_TIMES <nb>,
- INIT FROM <exp> TO <exp> NB_VALUE <nb>,
- INIT FROM <exp> TO <exp>NB_RANDOM <nb>,
- INIT FROM <exp> TO <exp>NB_RANDOM <nb>[+ BOUNDS]
Expressions
- Numeric (integer or floating-point), character, or character string literal values. Strings can be delimited by single or double quotes.
-
Native constants, 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 operators and casting, with all required levels of parentheses, the + operator being allowed to concatenate character string variables.
-
For arrays and structures, any of the above-mentioned expressions between brackets ('[]') for Ada, including when 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.
- For structures you can test some fields only, by using the following
syntax:
[ <fieldname> => <value> , <fieldname> => <value> ]
-
The keyword others (written in lower case) followed by '=>' and the default value of any array elements or structure fields not yet mentioned.
-
For INIT IN and INIT WITH only, a list of values delimited by brackets ('[]') for Ada composed of any of the previously defined expressions.
Additional Rules
- Any integers contained in an expression must be written either in accordance with
native lexical rules, or under the form:
- <hex_integer> H for hexadecimal values. In this case, the integer must be preceded by 0 if it begins with a letter.
- <binary_integer> B for binary values.
- The number of values inside an INIT IN parameter is limited to 100 elements in a single VAR statement.
- The number of INIT IN parameters per TEST LOOP block is limited to 7.
- The number of INIT IN parameters per TEST block is limited to 8.
- In Component Testing for Ada, if variables are used in the expression, then the test evaluate the the INIT value with variable values from before the execution.
Examples
VAR x, INIT = pi/4-1, ...
VAR y[4], INIT IN ( 0, 1, 2, 3 ), ...
VAR y[5], INIT(y[4]) WITH ( 10, 11, 12, 13 ), ...
VAR z.field, INIT FROM 0 TO 100 NB_RANDOM 3, ...
VAR p->value, INIT ==, ...
ARRAY y[0..100], INIT = sin(I), ...
ARRAY y, INIT = (50=>10,others=>0), ...
STR z, INIT = (0, "", NIL), ...
STR *p, INIT = (value=>4.9, valid=>1), ...
In the following example, the Ada test Script Compiler generates code that tests x against a then b before the execution of the code under test:
VAR y, init in (1,2), ev = init
VAR a, init(y) with ( 10, 20 ), ev = 50
VAR b, init(y) with ( 30, 40 ), ev = 70
VAR x, init(y) with (a, b), ev = init
#a := 50;
#b := 70;
Related Topics
VAR, ARRAY and STR | VAR, ARRAY and STR <variable> Parameter | VAR, ARRAY and STR <expected> Parameter