C++ Test Script Language


ENSURE <native expression>




The ENSURE statement describes a method post-condition. It can be used in a WRAP, STUB or PROC block.

Note   The information below pertains to the use of ENSURE within a WRAP block. For more information about using the REQUIRE and ENSURE statement within a STUB or PROC block, please refer to the STUB and PROC.

<native expression> is a C++ Boolean expression (or an expression that can be converted into a Boolean), which can use:

The following symbols cannot be used in the <native expression> parameter of the ENSURE statement:


For performance purposes, the _ATO_old variable is generated only if it is used in the ENSURE expression.


When --postcondition_before_return option is set in the Target Deployment Package .opp file, <native expression> is evaluated before the return expression. If the return expression evaluation causes side-effects, they are not taken into account at the time the post-condition is checked. This option is provided for compatibility with limited C++ compilers, and its use should be avoided as much as possible.

Otherwise, <native expression> is evaluated after any code of the method (local variables are already popped).

Warning: you can call methods in <native expression>, but you must make sure that these calls do not modify the object's state (that is, they do not write to any field). You can ensure this by calling const methods only. If you want the compiler to check this, use the ATO_AC_STRICT_CHECKING Target Deployment Port option.


C++ source code example:

class Stack {


       int count;

       Stack () : count(0) {}

       void push (void *);

       void *pop ();



C++ Contract Check Script code example:

CLASS Stack {

       WRAP push
ENSURE (count == _ATO_old.count + 1)