BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdls_testutil

Macros

#define BDLS_TESTUTIL_ASSERT(X)    BSLIM_TESTUTIL_ASSERT(X)
 
#define BDLS_TESTUTIL_LOOP0_ASSERT    BSLIM_TESTUTIL_ASSERT
 
#define BDLS_TESTUTIL_LOOP_ASSERT(I, X)    BSLIM_TESTUTIL_LOOP_ASSERT(I,X)
 
#define BDLS_TESTUTIL_LOOP1_ASSERT    BSLIM_TESTUTIL_LOOP_ASSERT
 
#define BDLS_TESTUTIL_LOOP2_ASSERT(I, J, X)    BSLIM_TESTUTIL_LOOP2_ASSERT(I,J,X)
 
#define BDLS_TESTUTIL_LOOP3_ASSERT(I, J, K, X)    BSLIM_TESTUTIL_LOOP3_ASSERT(I,J,K,X)
 
#define BDLS_TESTUTIL_LOOP4_ASSERT(I, J, K, L, X)    BSLIM_TESTUTIL_LOOP4_ASSERT(I,J,K,L,X)
 
#define BDLS_TESTUTIL_LOOP5_ASSERT(I, J, K, L, M, X)    BSLIM_TESTUTIL_LOOP5_ASSERT(I,J,K,L,M,X)
 
#define BDLS_TESTUTIL_LOOP6_ASSERT(I, J, K, L, M, N, X)    BSLIM_TESTUTIL_LOOP6_ASSERT(I,J,K,L,M,N,X)
 
#define BDLS_TESTUTIL_ASSERTV    BSLIM_TESTUTIL_ASSERTV
 
#define BDLS_TESTUTIL_Q(X)    BSLIM_TESTUTIL_Q(X)
 
#define BDLS_TESTUTIL_P(X)    BSLIM_TESTUTIL_P(X)
 
#define BDLS_TESTUTIL_P_(X)    BSLIM_TESTUTIL_P_(X)
 
#define BDLS_TESTUTIL_L_    BSLIM_TESTUTIL_L_
 
#define BDLS_TESTUTIL_T_    BSLIM_TESTUTIL_T_
 

Detailed Description

Outline

Purpose

Provide test utilities for components in bdl and above.

Deprecated:
Use bslim_testutil instead.

Macros

See also
bslim_testutil

Description

This component provides the standard print macros used in BDE-style test drivers (ASSERT, LOOP_ASSERT, ASSERTV, P, Q, L, and T) for components in the bdl package group and above.

This component also define a set of overloads for the insertion operator (<<) 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.

Note that the 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.

Usage

This section illustrates intended use of this component.

Example 1: Writing a Test Driver

First, we write a component to test, which provides a utility class:

namespace bdlabc {
/// This utility class provides sample functionality to demonstrate how
/// a test driver might be written validating its only method.
struct BdlExampleUtil {
/// Return the integer value `42`.
static int fortyTwo();
};
inline
int BdlExampleUtil::fortyTwo()
{
return 42;
}
} // close package namespace

Then, we can write a test driver for this component. We start by providing the standard BDE assert test macro:

//=========================================================================
// 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;
}
}

Next, we define the standard print and 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

Now, using the (standard) abbreviated macro names we have just defined, we write a test function for the 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);
}

Finally, when testFortyTwo is called from a test case in verbose mode we observe the console output:

value = 42

Example 2: Print the Value of a Test Type

Suppose we want to print the value of an object of a test type defined the bsltf package using bsl::cout. This component supplies the necessary overloads of the insertion operator for this to be done directly.

First, include the header of this component:

Now, we construct a SimpleTestType object and stream its value to bsl::cout using the << operator:

bsl::cout << a;
Definition bsltf_simpletesttype.h:130

Finally, we observe the following console output:

10

Macro Definition Documentation

◆ BDLS_TESTUTIL_ASSERT

#define BDLS_TESTUTIL_ASSERT (   X)     BSLIM_TESTUTIL_ASSERT(X)

◆ BDLS_TESTUTIL_ASSERTV

#define BDLS_TESTUTIL_ASSERTV    BSLIM_TESTUTIL_ASSERTV

◆ BDLS_TESTUTIL_L_

#define BDLS_TESTUTIL_L_    BSLIM_TESTUTIL_L_

◆ BDLS_TESTUTIL_LOOP0_ASSERT

#define BDLS_TESTUTIL_LOOP0_ASSERT    BSLIM_TESTUTIL_ASSERT

◆ BDLS_TESTUTIL_LOOP1_ASSERT

#define BDLS_TESTUTIL_LOOP1_ASSERT    BSLIM_TESTUTIL_LOOP_ASSERT

◆ BDLS_TESTUTIL_LOOP2_ASSERT

#define BDLS_TESTUTIL_LOOP2_ASSERT (   I,
  J,
 
)     BSLIM_TESTUTIL_LOOP2_ASSERT(I,J,X)

◆ BDLS_TESTUTIL_LOOP3_ASSERT

#define BDLS_TESTUTIL_LOOP3_ASSERT (   I,
  J,
  K,
 
)     BSLIM_TESTUTIL_LOOP3_ASSERT(I,J,K,X)

◆ BDLS_TESTUTIL_LOOP4_ASSERT

#define BDLS_TESTUTIL_LOOP4_ASSERT (   I,
  J,
  K,
  L,
 
)     BSLIM_TESTUTIL_LOOP4_ASSERT(I,J,K,L,X)

◆ BDLS_TESTUTIL_LOOP5_ASSERT

#define BDLS_TESTUTIL_LOOP5_ASSERT (   I,
  J,
  K,
  L,
  M,
 
)     BSLIM_TESTUTIL_LOOP5_ASSERT(I,J,K,L,M,X)

◆ BDLS_TESTUTIL_LOOP6_ASSERT

#define BDLS_TESTUTIL_LOOP6_ASSERT (   I,
  J,
  K,
  L,
  M,
  N,
 
)     BSLIM_TESTUTIL_LOOP6_ASSERT(I,J,K,L,M,N,X)

◆ BDLS_TESTUTIL_LOOP_ASSERT

#define BDLS_TESTUTIL_LOOP_ASSERT (   I,
 
)     BSLIM_TESTUTIL_LOOP_ASSERT(I,X)

◆ BDLS_TESTUTIL_P

#define BDLS_TESTUTIL_P (   X)     BSLIM_TESTUTIL_P(X)

◆ BDLS_TESTUTIL_P_

#define BDLS_TESTUTIL_P_ (   X)     BSLIM_TESTUTIL_P_(X)

◆ BDLS_TESTUTIL_Q

#define BDLS_TESTUTIL_Q (   X)     BSLIM_TESTUTIL_Q(X)

◆ BDLS_TESTUTIL_T_

#define BDLS_TESTUTIL_T_    BSLIM_TESTUTIL_T_