Test Point (old): Difference between revisions
m (Marku moved page Test Point to Test Point (old)) |
|||
(6 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
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. | [[Expectations|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 <tt>STRIDE_ENABLED</tt> is <tt>#define</tt>d, therefore it is practical to place these macros in-line in production source. When <tt>STRIDE_ENABLED</tt> is not <tt>#define</tt>d, these macros evaluate to nothing. | 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 <tt>STRIDE_ENABLED</tt> is <tt>#define</tt>d, therefore it is practical to place these macros in-line in production source. When <tt>STRIDE_ENABLED</tt> is not <tt>#define</tt>d, these macros evaluate to nothing. | ||
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<br/> | ''message'' is a pointer to a null-terminated format string<br/> | ||
''...'' variable list matching the format 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) | 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 === | === 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. | 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 [[C%2B%2B_Only_Features|this]]. | ||
For more information please read [[C%2B%2B_Only_Features|this]]. | |||
== Code Snippets == | == Code Snippets == | ||
Line 55: | Line 43: | ||
/* a test point with formatted string payload */ | /* a test point with formatted string payload */ | ||
srTEST_POINT_STR("third test point", "payload with format string %d", myVar); | |||
#ifdef __cplusplus | #ifdef __cplusplus |
Latest revision as of 19:38, 6 July 2015
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 |
srTEST_POINT_STR(label, message) | label is a pointer to a null-terminated string message is a pointer to a null-terminated format string |
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.