Declaring environments

Component Testing for C

A test environment consists of a list of variables for which you specify:

  • Default initialization conditions for before the test

  • Default expected results for after the test

Use the VAR, ARRAY, and STR instructions described previously to specify the status of the variables before and after the test.

You can only use an environment once you have defined it.

Delimit an environment using the instructions ENVIRONMENT <environment_name> and END ENVIRONMENT. You must place it after the BEGIN instruction. When you have declared it, an environment is visible to the block in which it was declared and to all blocks included therein.

Example

The following example illustrates the use of environments:

HEADER histo, 1, 1

##include <math.h>

##include "histo.h"

BEGIN

ENVIRONMENT image

ARRAY image, init = 0, ev = init

END ENVIRONMENT

USE image

SERVICE COMPUTE_HISTO

#int x1, x2, y1, y2;

#int status;

#T_HISTO histo;

#T_IMAGE image1;

ENVIRONMENT compute_histo

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

VAR status, init == , ev = 0

END ENVIRONMENT

USE compute_histo