C++ contract check script structure

A C++ Contract Check Script (.otc script) describes assertions for a set of classes. Each C++ class can be associated to a Contract Check CLASS block. When built, the script instruments the source code under test.

The scripts, being descriptions, are made of statements only. As a consequence, the order of execution is irrelevant. There is no hierarchical structure.

The Contract Check CLASS block describes assertions for a C++ class.

Note The evaluation of the contract should not have any side effects. The contract evaluation does not alter the state of the corresponding system. For more specific information refer to REQUIRE, ENSURE, INVARIANT and STATE sections.

Basic structure

A typical Component Testing .otc contract check script structure looks like this:

CLASS VCR {

STATE Empty {

(media_present() == false)

}

STATE Loaded {

(media_present() == true)

(mode () == m_stop;)

}

STATE Playing {

(media_present() == true)

(mode() == m_play || mode() == m_pause)

}

TRANSITION Empty TO Loaded;

TRANSITION Loaded TO Playing;

TRANSITION Playing TO Loaded;

TRANSITION Playing TO Empty;

TRANSITION Loaded TO Empty;

}

All instructions in a test script have the following characteristics:

  • A CLASS block contains all the assertions for a C++ class.

  • All statements begin with a keyword.

  • Statements are not case sensitive (except when C expressions are used).

  • Statements start at the beginning of a line and end at the end of a line. You can, however, write an instruction over several lines using the ampersand (&) continuation character at the beginning of additional lines. In this case, the ampersand must be the very first character on that line; no spaces or tabs should precede it.

  • Statements must be shorter than 2048 characters, although this limit may be lower on some platforms.

Related Topics

C++ contract check script (.otc) | C++ test script keywords