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:

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

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 :

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-variablesTesting large arraysTesting arrays with listsTesting character arraysTesting arrays with other arraysTesting an array of union elements