Difference between revisions of "Test Point (old)"

From STRIDE Wiki
Jump to: navigation, search
(Created page with 'Expectation testing is made possible by selective developer instrumentation of the source under test. The instrumentation is unobtrusive and powerful, supporting the ability to o…')
 
Line 19: Line 19:
 
| '''srTEST_POINT_STR'''(''label'', ''message'')
 
| '''srTEST_POINT_STR'''(''label'', ''message'')
 
| ''label'' is a pointer to a null-terminated string<br/>
 
| ''label'' is a pointer to a null-terminated string<br/>
''message'' is a pointer to a null-terminated string
+
''message'' is a pointer to a null-terminated string<br/>
 +
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)
  
 
|-valign="top"
 
|-valign="top"
Line 43: Line 44:
 
/* a test point with simple string payload */
 
/* a test point with simple string payload */
 
srTEST_POINT_STR("third test point", "payload with simple string");
 
srTEST_POINT_STR("third test point", "payload with simple string");
 +
 +
#ifdef __cplusplus
 +
srTEST_POINT_STR("third test point", "") << "stream input supported under c++";
 +
#endif
  
 
/* a test point with formatted string payload */
 
/* a test point with formatted string payload */

Revision as of 18:31, 27 January 2010

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.

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

srTEST_POINT_STR[1..4](label, message, ...) label is a pointer to a null-terminated string

message is a pointer to a null-terminated format string
... variable list (up to 4) matching the format string

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");

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

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

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.