Messages and Data Management

System Testing for C

The instruction VAR allows you to initialize and check the contents of simple or complex variables.

The process of initializing or checking variables is performed independently by the following two sub-instructions:

VAR <variable> , INIT = <init_expr>

or

VAR <variable> , EV = <expec_expr>

This instruction allows you to initialize and check the contents of structured variables, such as messages.

The field <variable> represents a variable or part of a structured variable.

<init_expr> and <expec_expr> let you describe the contents of structured variables using a simple syntax.

To describe a sequence of fields at the same level in a structured variable, you enclose the sequence in braces '{}' or brackets '[]' and separate the fields with a comma ','.

You can reference members of a structured variable in the following ways:

  • Reference by name

  • Reference by position

You cannot however mix both methods.

The System Testing report does not show VAR instructions relating to initializations. Only VAR instructions relating to content checks on variables or messages are recorded in the test report.

The DEF_MESSAGE instruction allows you to define reference messages using the DEF_MESSAGE instruction, using exactly the same syntax. The following examples are presented using the VAR instruction, but are also applicable to DEF_MESSAGE.

The report does not show DEF_MESSAGE instruction as they appear in the test script, but only when they are used within a WAITTIL instruction.

Reference by Name

You can describe the contents of a structure by naming each field in the structure. This is very useful if you do not know the order of the fields in the declaration of the structure.

When referencing by name, a parameter is described by the name of the field in the structure followed by the arrow symbol (=>) and the initialization or checking expression.

#typedef struct

# {

# int Integer;

# char String [ 15 ];

# float Real;

# } block;

# block variable;

VAR variable, INIT={Real=>2.0, Integer=>26, String=>"foo"}

You can omit the specification of structure elements by name if you know the order of the fields within the structure. For the block type defined above, you can write the following VAR statement:

VAR variable, INIT={ 26, "foo", 2.0 }

Reference by Position

You can describe the contents of an array by giving the position of elements within the array.

When referencing by position, define a parameter by giving the position of the field in the array followed by the arrow symbol (=>) and the initialization or checking expression.

Note that numbering begins at zero.

#int array[5];

VAR array, EV=[4=>5, 1=>12, 2=>-18, 5=>15-26, 3=>0, 0=>123]

You can use ranges of positions when referencing by position. These ranges are specified by two bounds separated by the symbol double full-stop (..).

#typedef int matrix[3][150];

VAR matrix, EV= [

& 2=>[0..99=>1, 100..149=>2],

& 0=>[99..0=>2, 100..149=>1],

& 1=>[0..80=>-1, 81..149=>0]]

Note that the bounds of an interval can be reversed.

When referencing by position, you must reference an entire sequence at a given level.

Partial Initialization and Checks

With a VAR instruction, you can partially initialize and check a structured variable.

#float array[10];

VAR array, INIT=[5..7=>2.1]

The array elements 5, 6 and 7 are initialized to 2.1. Other elements are not initialized.

Multi-dimension Initialization and Checks

With a VAR instruction, you can initialize and check multi-dimension variables with judicious use of bracket '[]' and brace '{}' separators.

The separators delimit the description of a structured variable to a given dimension. The absence of separators at a given level indicates that the initialization or checking value is valid for all the sub-dimensions of the variable.

In the following example:

  • Ex. 1: The set of 300 integer values of the matrix variable are initialized to zero.

  • Ex. 2: The 100 integer values contained in matrix[0] are initialized to 1, the 100 values of matrix[1] are initialized to 2, and the 100 values of matrix[2] are initialized to 3.

  • Ex. 3: Only the matrix[0][0] is initialized to zero.

  • Ex. 4: Only the first 100 values of matrix[0] are initialized to zero.

#int matrix[3][100];

-- -Ex. 1- Global initialization

VAR matrix, INIT=0

-- -Ex. 2- Global initialization of lines

VAR matrix, INIT=[1,2,3]

-- -Ex. 3- Initialization of only one element

VAR matrix, INIT=[[0]]

-- -Ex. 4- Initialization of only one line

VAR matrix, INIT=[0]

The following example provides a set of VAR instructions that are semantically identical:

#int matrix[3][3];

VAR matrix, EV=0

VAR matrix, EV=[0,0,0]

VAR matrix, EV=[[0,0,0],[0,0,0],[0,0,0]]

In the three VAR instructions above, all the matrix elements are checked against zero.

Array Indices

With a VAR instruction, you can initialize and check array elements according to their index at a given level.

The index is specified by a capital I followed by the level number. Levels begin at 1. You can use I1, I2, I3, etc. as implicit variables.

#int matrix[3][100];

VAR matrix, EV=I1*I2

Each element of the above matrix is checked against the product of variables I1 and I2, which indicate, respectively, a range from 0 to 2 and a range from 0 to 99. The above matrix is checked against the 3 by 100 multiplication table.

Reference by Default

You can reference the remaining set of fields in an array, structure, or object in a VAR instruction. To do this, use the keyword OTHERS, followed by the arrow symbol =>, and an expression in C or C++.

Note: To use OTHERS, the remaining fields must be the same type and must be compatible with the expression following OTHERS.

#typedef struct {

# char String[25];

# int Value;

# int Value2;

# int Array[30];

#} block;

# block variable;

VAR variable, INIT=[

& String=>"chaine",

& Array=>[0..10=>0, OTHERS=>1] ,

& OTHERS=>2]

In the previous example, OTHERS has two functions:

  • When initializing the array, the values indexed from 11 to 29 begin at 1.

  • When initializing the structure, the value and value2 fields begin at 2.

Checking Pointers

With a VAR instruction, you may use NIL and NONIL, to check for null and non-null pointers.

#typedef struct {

# int a;

# float b;

#} block, *PT_block;

#PT_block addr[10];

VAR addr, EV=[0..5=>NIL, OTHERS=>NONIL]

In the above example, the pointers indexed from 0 to 5 of the addr array are compared with the null address. The test of the pointers indexed from 6 to 9 is correct if these pointers are different from the null address.

Checking Ranges

You may use ranges of acceptable values instead of immediate values. To do this, use the following syntax:

VAR <variable>, EV=[Min..Max]

DEF_MESSAGE <variable>, EV=[Min..Max]

The following example demonstrates this syntax:

#typedef struct {

# int a;

# float b;

#} block, *PT_block;

#PT_block addr[10];

VAR addr, EV=[0..5=>{a=>[0..100]}, OTHERS=>NONIL]

In the previous example, the elements indexed from 0 to 5 of the addr array are checked with the following constraint:

a should be greater than 0 and lower than 100.

The test of the pointers indexed from 6 to 9 is correct if these pointers are different from null address

Character Strings

When you use the VAR instruction for character strings, you may alter it. In C, a character string can also be an array. This flexibility is retained in the VAR instruction.

In the following example, the first variable String initializes as in C (null-terminated). The second String initializes as an array of characters (not null-terminated).

#char String[15];

VAR String, INIT="abcdef"

VAR String, INIT=['a', 'b', 'c', 'd', 'e', 'f']

Note You must define the VAR instruction either as a character string or an array of characters.