background image
<< Testing an Array with an Enumerated List | Read_image and extern_image >>
<< Testing an Array with an Enumerated List | Read_image and extern_image >>

Testing Character Arrays

Test RealTime - User Guide
You can also specify a value for all the as yet undefined elements by using the
keyword others, as the following example illustrates:
TEST 2
FAMILY nominal
ELEMENT
VAR x1, init = 0, ev = init
VAR x2, init = SIZE_IMAGE-1, ev = init
VAR y1, init = 0, ev = init
VAR y2, init = SIZE_IMAGE-1, ev = init
ARRAY image, init = {others=>{others=>100}}, ev = init
ARRAY histo, init = 0,
& ev = {100=>SIZE_IMAGE*SIZE_IMAGE, others=>0}
VAR status, init ==, ev = 0
#status = compute_histo(x1, y1, x2, y2, histo);
END ELEMENT
END TEST
Note The form {others =>
<expression>
} is equivalent to initializing and
testing all array elements with the same expression.
You can also initialize and test multidimensional arrays with a list of expressions, as
follows. In this case, the previously mentioned rules apply to each dimension.
ARRAY image, init = {0, 1=>4, others=>{1, 2, others=>100}} ...
Note Some C compilers allow you to omit levels of brackets when initializing
a multidimensional array. The Unit Testing Scripting Language does not
accept this non-standard extension to the language.
Testing Character Arrays
Character arrays are a special case. Variables of this type are processed as character
strings delimited by quotes.
You therefore need to initialize and test character arrays using character strings, as
the following list example illustrates.
If you want to test character arrays like other arrays, you must use a format
modification declaration (FORMAT instruction) to change them to arrays of integers.
Example
The following list example illustrates this type of modification:
TEST 2
FAMILY nominal
FORMAT T_LIST.str[] = int
ELEMENT
VAR l, init = NIL, ev = NONIL
VAR s, init = "myfoo", ev = init
VAR l·>str[0..5], init == , ev = {'m','y','f','o','o',0}
#l = push(l,s);
END ELEMENT
END TEST
Testing an Array with Another Array
The following example illustrates a form of initialization that consists of initializing
or comparing an array with another array that has the same declaration:
140