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> :

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

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) }

}