C++ contract check Script

Component Testing for C++

The C++ Contract Check script allows you to test invariants and state charts as well as wraps for each method of the class.

The Contract Check script is contained in an .otc file, whose name matches the name of the file containing the class definition.

C++ Contract Check scripts are written in C++ Contract Check Language, which is part of the C++ Test Script language designed for Component Testing for C++.

A typical Contract Check .otc test script is structured as follows:

CLASS <class to wrap>

{

WRAP <method>

REQUIRE <expression>

ENSURE <expression>

WRAP <method>

REQUIRE <expression>

ENSURE <expression>

}

See the Reference section for the semantics of the C++ Contract Check Language.

Note When an .otc contract check script is used in a test node, the related source files are always instrumented even if they are displayed as not instrumented in Project Explorer.

Contract Check in a Component Test

You can use the Component Testing wizard to set up a test node and create the C++ contract-check script templates or you can manually create a Component Testing for C++ test node to reuse existing test scripts.

The .otc contract-check script must be executed before an .otd Test Driver script, therefore the order in which both script types appear in the Test node is critical. This is important if you are manually creating a test node.

Contract Check Runtime Analysis

C++ Contract Check scripts can also be used in a simple application node.

In this case, you can either copy the .otc contract from an existing C++ component test node, or you can create an .otc contract check script manually.

The .otc contract-check script must be placed before any other item in the application node.

Related Topics

C++ Test Driver Script | Component Testing Wizard | Manually Creating a Node | Using native C++ statements