Test Point (old)

From STRIDE Wiki
Jump to navigation Jump to search

Expectation testing is made possible by selective developer instrumentation of the source under test. The instrumentation is unobtrusive and powerful, supporting the ability to optionally attach string or binary data to the Test Point.

Reference

To specify a test point you should include the srtest.h header file from the STRIDE Runtime in your compilation unit. The Test Point macros are active only when STRIDE_ENABLED is #defined, therefore it is practical to place these macros in-line in production source. When STRIDE_ENABLED is not #defined, these macros evaluate to nothing.

Test Point Macros
srTEST_POINT(label) label is a pointer to a null-terminated string
srTEST_POINT_DATA(label, data, size) label is a pointer to a null-terminated string

data is a pointer to a byte sequence
size is the size of the data in bytes

srTEST_POINT_STR(label, message) label is a pointer to a null-terminated string

message is a pointer to a null-terminated format string
... variable list matching the format string
When used in the context of a c++ compilation unit, this macro also supports the streaming operator to append to the message string (see example below)

C++ Only Features

In C++ source the string variants of the macros above support adding to other content to the message by using the << operator. For more information please read this.

Code Snippets

The source under test is instrumented simply by placing lines of the following form into the source code:

#include <srtest.h>
...
/* a test point with no payload */
srTEST_POINT("first test point");

/* a test point with binary payload */
srTEST_POINT_DATA("second test point", myData, sizeofMyData);

/* a test point with simple string payload */
srTEST_POINT_STR("third test point", "payload with simple string");

/* a test point with formatted string payload */
srTEST_POINT_STR("third test point", "payload with format string %d", myVar);

#ifdef __cplusplus
srTEST_POINT_STR("c++ test point", "") << "stream input supported under c++";
#endif

When this code is executed it broadcasts a message via the STRIDE Runtime which is detected by the test code if it is currently looking for test points in an expectation test. We refer to the receipt of a test point as a test point hit.