VAR, ARRAY and STR

Purpose

The VAR, ARRAY, and STR instructions declare the test of a simple variable, a variable array or a variable structure. It applies to C Test Script Language.

Syntax

VAR <variable>, [<format>], <initialization>, <expected_value> 
ARRAY <variable>, [<format>], <initialization>, <expected_value> 
STR <variable>, [<format>], <initialization>, <expected_value> 

where:

  • <variable> is a variable

  • <format> optionally defines the format of the variable.

  • <initialization> is a Component Testing initialization parameter for C

  • <expected value> is a Component Testing expected_value parameter for C

Description

Use the VAR, ARRAY, and STR instructions to declare a variable test. During test execution, if the value of the variable is out of the bounds specified in the <expected_value> expression, the test is Failed.

The usage of VAR, ARRAY or STR does not change the behavior of the test, but each keyword specify how the result is displayed in the test report. Use:

  • VAR: for simple variables.

  • ARRAY: for variable arrays.

  • STR: for variable structures.

If you use a VAR statement to test an array or structure, the report lists each element of the array or structure.

If you use a STR in an ENVIRONMENT block, then all elements of the structure are shown in the report, regardless of whether the test passes or fails. If the STR is in an ELEMENT block, then only the failed elements of the structure are displayed.

The VAR, ARRAY, and STR instructions must be located in an ELEMENT or an ENVIRONMENT block.

Note:
  • The initialization expressions must not use '--' or '++' operators, as these may be interpreted as comments in some environments.

The optional <format> parameter allows you to modify the type of the tested element. This parameter uses the same syntax as a the FORMAT statement. See FORMAT for more information.

In addition the following formats are available in a VAR, ARRAY, or STR statement only:

  • pointer: Initialize and test as a pointer, with pointer cast (void*).

  • string_ptr: Initialize as a pointer and test as a string.

  • string: Initialize and test as a string.

Example

#char *ar;

#char *ar1;

#char ar2[50];

#unsigned char t;

VAR t, #h, init=200, ev =init -- display as hexadecimal

VAR ar1,string_ptr, init ="defg", ev =INIT -- init as a pointer and test as a string

VAR ar2,string, init ="defgh", ev =INIT -- init and test as a string

VAR ar,pointer#b, init =0x12345678, ev =NONIL -- init and test as a pointer and display in binary

Related Topics

Initialization Expressions for C | Expected Value Expression for C | C Variables | FORMAT