Quick Links: |
Provide test utilities for components in bdl
and above.
More...
bdl
and above. BDLS_TESTUTIL_ASSERT(X) | record and print error if !X |
BDLS_TESTUTIL_LOOP_ASSERT(I, X) | print args if !X |
BDLS_TESTUTIL_LOOP2_ASSERT(I, J, X) | print args if !X |
BDLS_TESTUTIL_LOOP3_ASSERT(I, J, K, X) | print args if !X |
BDLS_TESTUTIL_LOOP4_ASSERT(I, J, K, L, X) | print args if !X |
BDLS_TESTUTIL_LOOP5_ASSERT(I, J, K, L, M, X) | print args if !X |
BDLS_TESTUTIL_LOOP6_ASSERT(I, J, K, L, M, N, X) | print args if !X |
BDLS_TESTUTIL_ASSERTV(..., X) | generic print args if !X |
BDLS_TESTUTIL_Q(X) | quote identifier literally |
BDLS_TESTUTIL_P(X) | print identifier and value |
BDLS_TESTUTIL_P_(X) | print identifier and value without \n |
BDLS_TESTUTIL_L_ | current line number |
BDLS_TESTUTIL_T_ | print tab without \n |
ASSERT
, LOOP_ASSERT
, ASSERTV
, P
, Q
, L
, and T
) for components in the bdl
package group and above. <<
) to support the streaming of test types defined in the bsltf
package. This is required for test drivers in the bdl
package group and above to print the objects of these types to bsl::cout
. bsltf
package resides below bsl+bslhdrs
, in which bsl::cout
is defined; therefore, the components in bsltf
cannot directly define the overloads of the insertion operator to support printing the test types. Instead, an alternate method supplied in bsls_bsltestutil
is used for test drivers in the bsl
package group. namespace bdlabc { struct BdlExampleUtil { // This utility class provides sample functionality to demonstrate how // a test driver might be written validating its only method. static int fortyTwo(); // Return the integer value '42'. }; inline int BdlExampleUtil::fortyTwo() { return 42; } } // close package namespace
//========================================================================= // STANDARD BDE ASSERT TEST MACRO //------------------------------------------------------------------------- static int testStatus = 0; static void aSsErT(bool b, const char *s, int i) { if (b) { printf("Error " __FILE__ "(%d): %s (failed)\n", i, s); if (testStatus >= 0 && testStatus <= 100) ++testStatus; } }
LOOP_ASSERT
macros, as aliases to the macros defined by this component: //========================================================================= // STANDARD BDE TEST DRIVER MACROS //------------------------------------------------------------------------- #define ASSERT BDLS_TESTUTIL_ASSERT #define LOOP_ASSERT BDLS_TESTUTIL_LOOP_ASSERT #define LOOP0_ASSERT BDLS_TESTUTIL_LOOP0_ASSERT #define LOOP1_ASSERT BDLS_TESTUTIL_LOOP1_ASSERT #define LOOP2_ASSERT BDLS_TESTUTIL_LOOP2_ASSERT #define LOOP3_ASSERT BDLS_TESTUTIL_LOOP3_ASSERT #define LOOP4_ASSERT BDLS_TESTUTIL_LOOP4_ASSERT #define LOOP5_ASSERT BDLS_TESTUTIL_LOOP5_ASSERT #define LOOP6_ASSERT BDLS_TESTUTIL_LOOP6_ASSERT #define ASSERTV BDLS_TESTUTIL_ASSERTV #define Q BDLS_TESTUTIL_Q // Quote identifier literally. #define P BDLS_TESTUTIL_P // Print identifier and value. #define P_ BDLS_TESTUTIL_P_ // P(X) without '\n'. #define T_ BDLS_TESTUTIL_T_ // Print a tab (w/o newline). #define L_ BDLS_TESTUTIL_L_ // current Line number
static
fortyTwo
method, to be called from a test case in a test driver. void testFortyTwo(bool verbose) { const int value = bdlabc::BdlExampleUtil::fortyTwo(); if (verbose) P(value); LOOP_ASSERT(value, 42 == value); }
testFortyTwo
is called from a test case in verbose mode we observe the console output: value = 42
bsltf
package using bsl::cout
. This component supplies the necessary overloads of the insertion operator for this to be done directly. #include <bdls_testutil.h>
SimpleTestType
object and stream its value to bsl::cout
using the <<
operator: bsltf::SimpleTestType a(10); bsl::cout << a;
10