Testing Arrays

Component Testing for C

With Component Testing for C, you can test arrays in quite the same way as you test variables. In the C Test Script Language, this is done with the ARRAY statement.

The ARRAY statement specifies both the test start-up procedure and the post-execution test for simple variables. This instruction uses three parameters:

  • Name of the variable under test: species the name of the array in any of the following ways:

    • To test one array element, conform to the C syntax: histo[0].

    • To test the entire array without specifying its bounds, the size of the array is deduced by analyzing its declaration. This can only be done for well-defined arrays.

    • To test a part of the array, specify the lower and upper bounds within which the test will be run, separated with two periods (..), as in: histo[1..SIZE_HISTO]

  • Initial value of the array: identified by the keyword INIT.

  • Expected value of the array after the procedure has been executed: identified by the keyword EV.

Declare variables under test with the ARRAY statement, followed by the declaration keywords:

  • INIT = for an assignment

  • INIT == for no initialization

  • EV = for a simple test.

It does not matter where the ARRAY instructions are located with respect to the test procedure call since the C code generator separates ARRAY instructions into two parts :

  • The array test is initialized with the ELEMENT instruction

  • The actual test against the expected value is done with the END ELEMENT instruction

To initialize and test an array, specify the same value for all the array elements.

You can use the same expressions for initial and expected values as those used for simple variables (literal values, constants, variables, functions, and C operators).

Use the ARRAY instruction to run simple tests on all or only some of the elements in an array.

Testing Arrays with C Expressions

To initialize and test an array, specify the same value for all the array elements. The following two examples illustrate this simple form.

ARRAY image, INIT = 0, EV = INIT

ARRAY histo[1..SIZE_HISTO-1], INIT = 0, EV = 0

You can use the same expressions for initial and expected values as those used for simple variables (literal values, constants, variables, functions, and C operators).

Example

The following example highlights the ARRAY instruction syntax for C:

HEADER histo, 1, 1

##include "histo.h"

BEGIN

SERVICE COMPUTE_HISTO

#int x1, x2, y1, y2;

#int status;

#T_HISTO histo;

TEST 1

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 = 0, ev = init

VAR histo[0], init = 0, ev = SIZE_IMAGE*SIZE_IMAGE

ARRAY histo[1..SIZE_HISTO-1], init = 0, ev = 0

VAR status, init = 0, ev = 0

#status = compute_histo(x1, y1, x2, y2, histo);

END ELEMENT

END TEST

END SERVICE

Related Topics

Testing arrays with pseudo-variables | Testing large arrays | Testing arrays with lists | Testing character arrays | Testing arrays with other arrays | Testing an array of union elements