Testing structured variables

Component Testing for C

To test all the fields of a structured variable, use a single instruction (STR) to define their initializations and expected values:

TEST 2

FAMILY nominal

ELEMENT

VAR l, init = NIL, ev = NONIL

STR *l, init == , ev = {"myfoo",NIL,NIL}

VAR s, init = "myfoo", ev = init

#l = push(l,s);

END ELEMENT

END TEST

You can only initialize and test structured variables with the following forms:

  • INIT =

  • INIT ==

  • EV =

  • EV ==

If a field of a structured variable needs to be initialized or tested in a different way, you can omit its initial and expected values from the global test of the structured variable, and run a separate test on this field.

The following example illustrates this:

TEST 4

FAMILY nominal

ELEMENT

VAR l, init = NIL, ev = NONIL

VAR *l, init == , ev = {,NIL,NIL}

VAR s, init in {"foo","bar"}, ev = init

VAR l->str, init ==, ev(s) in {"foo","bar"}

#l = push(l,s);

END ELEMENT

END TEST

Using field names, write this as follows:

VAR *l, init ==, ev = {next=>NIL,prev=>NIL}

Related Topics

Testing variables | Testing structured variables with C expressions | Testing structured variables with other structured variables | C Unions | Omitting a Field's Initial and Test Values