STATE

C++ Test Script Language

Syntax

STATE <state name> { (<native expression>)}

Location

CLASS

Description

The STATE statement describes a state for the current class, which is defined by the conjunction of one or several Boolean expression.

Notes STATE by itself does not generate any source code instrumentation. STATE should be used along with the TRANSITION statement.

<state name> is a C++ Test Script Language identifier.

<native expression> is a C++ Boolean expression (or an expression that can be converted to a Boolean).

The following symbols can be used in <native expression> :

  • Any of the class members.

  • Any of the global variables declared in every file where a method of the class (or a method of descendant if it is not a single class contract) is defined.

The following symbols cannot be accessed in <native expression>:

  • Local variables of any methods.

  • Macros.

  • Global variables that are not defined in at least one file where a method of the class (or one of its descendants if it is not a single class contract) is defined.

Evaluation

<native expression> may be evaluated at the end of the execution of class constructors (except for implicitly defined copy constructors), at the beginning of class destructors, and both at the beginning and the end of other non-static non-implicitly defined methods.

Warning: You can call methods in <native expression>, but you must ensure that these calls do not modify the object's state by writing to any fields. You can ensure this by using const methods only. If you want the compiler to check this, see the ATO_AC_STRICT_CHECKING Target Package option .

Example

C++ source code example:

class Stack {

int count;

Stack () : count(0) {}

void push (void *);

void *pop ();

};

C++ Contract Check Script code example:

CLASS Stack {

STATE Empty { (count == 0) }

STATE NotEmpty { (count > 0) }

}