VAR, ARRAY and STR <expected> Parameter
C Test Script Language
Purpose
In this documentation, the Component Testing <expected value> parameters for C specify the expected value of a variable.
Syntax
EV = <exp>
EV = <exp> , DELTA = <delta>
MIN = <exp>, MAX = <exp>
EV IN { <exp>, <exp>, ... }
EV ( <variable> ) IN { <exp>, <exp>, ... }
EV ==
where:
<exp> can be any of the expressions of the Initialization Parameters, plus the following expressions:
<delta> is the acceptable tolerance of the expected value and can be expressed:
<variable> is a C variable
Description
The <expected value> expressions are used to specify a test criteria by comparison with the value of a variable. The test is considered Passed when the actual value matches the <expected value> expression.
The EV value is calculated during the preprocessing phase, not dynamically during test execution.
An acceptable tolerance <delta> can be expressed:
As an absolute value, by a numerical expression in the form described above
As a percentage of the expected value. Tolerance is then written in the form <exp>%.
Expected values can be expressed in the following ways:
EV = <exp> specifies the expected value of the variable when it is known in advance. The value of variable is considered correct if it is equal to <exp>.
EV = <exp>, DELTA = <tolerance> allows a tolerance for the expected value. The value of variable is considered correct if it lies between <exp> - <tolerance> and <exp> + <tolerance>.
MIN = <exp> and MAX = <exp> specify an interval delimited by an upper and lower limit. The value of the variable is considered correct if it lies between the two expressions. Characters and character strings are treated in dictionary order.
EV IN { <exp>, <exp>, ... } specifies the values expected successively, in accordance with the initial values, for a variable that is declared in INIT IN. It is therefore essential that the two lists have an identical number of values.
EV ( <variable> ) IN is identical to EV IN, but the expected values are a function of another variable that has previously been declared in INIT IN. As for EV IN, the two lists must have an identical number of values.
EV == allows the value of <variable> not to be checked at the end of the test. Instead, this value is read and displayed. The value of <variable> is always considered correct.
Expressions
The initialization expressions <exp> can be among any of the following values:
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
C or Ada functions
The keyword NIL to designate a null pointer
The keyword NONIL, which tests if a pointer is non-null
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
A C or 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 braces ('{}') for C, 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:
{<value>,,<value>}
The keyword others (written in lower case) followed by '=>' and the default value of any array elements or structure fields not yet mentioned.
The pseudo-variable INIT, which copies the initialization expression. You cannot use the pseudo-variable INIT inside an array or structure. The keyword INIT applies to the entire expression.
Additional Rules
EV with DELTA is only allowed for numeric variables. The STR statement does not support DELTA.
MIN = <exp> and MAX = <exp> are only allowed for alphanumeric variables that use lexicographical order for characters and character strings.
MIN = <exp> and MAX = <exp> are not allowed for pointers.
Only EV = and EV == are allowed for structured variables.
In some cases, in order to avoid generated code compilation warnings, the word CAST must be inserted before the NIL or NONIL keywords.
All Euclidian divisions performed by the Test Script Compiler round to the inferior integer. Therefore, writing -a/b returns a different result than -(a/b), as in the following examples:
-(9/2) returns -4
-9/2 returns -5
Not a number and infinite float values
Component testing can handle not a number and infinite float values as MIN and MAX parameters. Such values must be assigned through a variable. The test produces a verdict depending on the nature of the values.
The following table describes the verdict to be expected for each combination of MIN and MAX values. For example, if the MIN is a real float value and the MAX is +infinite, then the test will fail if the actual return value is not a number or +infinite and will pass if the value is +infinite or greater that MIN.
Expected values |
Actual return values |
||||
MIN |
MAX |
Not a number |
-infinite |
float value |
+infinite |
Not a number |
Not a number |
Pass |
Fail |
Fail |
Fail |
Not a number |
-infinite |
Pass |
Pass |
Fail |
Fail |
Not a number |
float value |
Pass |
Fail |
x==MAX |
Fail |
Not a number |
+infinite |
Pass |
Fail |
Fail |
Pass |
-infinite |
Not a number |
Pass |
Pass |
Fail |
Fail |
-infinite |
-infinite |
Fail |
Pass |
Fail |
Fail |
-infinite |
float value |
Fail |
Pass |
x<=MAX |
Fail |
-infinite |
+infinite |
Fail |
Pass |
Pass |
Pass |
float value |
Not a number |
Pass |
Fail |
x==MIN |
Fail |
float value |
-infinite |
Fail |
Fail |
Fail |
Fail |
float value |
float value |
Fail |
Fail |
MIN<=x<=MAX |
Fail |
float value |
+infinite |
Fail |
Fail |
x>=MIN |
Pass |
+infinite |
Not a number |
Pass |
Fail |
Fail |
Pass |
+infinite |
-infinite |
Fail |
Fail |
Fail |
Fail |
+infinite |
float value |
Fail |
Fail |
Fail |
Fail |
+infinite |
+infinite |
Fail |
Fail |
Fail |
Pass |
Example
VAR x, ..., EV = pi/4-1
VAR y[4], ..., EV IN { 0, 1, 2, 3 }
VAR y[5], ..., EV(y[4]) IN { 10, 11, 12, 13 }
VAR z.field, ..., MIN = 0, MAX = 100
VAR p->value, ..., EV ==
ARRAY y[0..100], ..., EV = cos(I)
ARRAY y, ..., EV = {50=>10,others=>0}
STR z, ..., EV = {0, "", NIL}
STR *p, ..., EV = {value=>4.9, valid=>1}
Related Topics
Initialization Expressions | VAR, ARRAY and STR | C Variables