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

Macros

#define BSLS_PRECONDITIONS_BEGIN_IMP()
 
#define BSLS_PRECONDITIONS_END_IMP()
 
#define BSLS_PRECONDITIONS_BEGIN()   do {} while(false)
 
#define BSLS_PRECONDITIONS_END()   do {} while(false)
 

Detailed Description

Outline

Purpose

Provide macros for use in fuzz testing narrow contract functions.

Classes

Macros

See also
bsls_fuzztest

Description

This component provides macros, BSLS_PRECONDITIONS_BEGIN and BSLS_PRECONDITIONS_END, to facilitate fuzz testing narrow contract functions. When fuzz testing is not enabled, the macros expand to nothing. When fuzz testing is enabled, the macros invoke a dynamic handler function via bsls::PreconditionsHandler.

BSLS_PRECONDITIONS_BEGIN is used as a marker to identify where precondition checks are begun, while BSLS_PRECONDITIONS_END is used as a marker to identify where precondition checks are complete. These macros should always be used as a pair, and always at the very beginning of a function, surrounding the function preconditions.

Usage

Since the macros contained in this component are intended to be used in conjunction with the macros defined in bsls_fuzztest , this test driver contains only the simplest USAGE EXAMPLE. See the USAGE EXAMPLE in bsls_fuzztest for a fuller treatment.

The following example shows the use of BSLS_PRECONDITIONS_BEGIN and BSLS_PRECONDITIONS_END in the definition of a narrow contract function. These macros are to be placed around the function precondition checks, immediately before and after.

double mySqrt(double x)
// Return the square root of the specified 'x'. The behavior is
// undefined unless 'x >= 0'.
{
BSLS_ASSERT(0 <= x);
return sqrt(x);
}
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_PRECONDITIONS_END()
Definition bsls_preconditions.h:131
#define BSLS_PRECONDITIONS_BEGIN()
Definition bsls_preconditions.h:130

In a fuzz-enabled build, we would invoke this function inside the fuzz loop with BSLS_FUZZTEST_EVALUATE.

Macro Definition Documentation

◆ BSLS_PRECONDITIONS_BEGIN

#define BSLS_PRECONDITIONS_BEGIN ( )    do {} while(false)

◆ BSLS_PRECONDITIONS_BEGIN_IMP

#define BSLS_PRECONDITIONS_BEGIN_IMP ( )
Value:
do { \
bsls::PreconditionsHandler::invokeBeginHandler(); \
} while (false)

◆ BSLS_PRECONDITIONS_END

#define BSLS_PRECONDITIONS_END ( )    do {} while(false)

◆ BSLS_PRECONDITIONS_END_IMP

#define BSLS_PRECONDITIONS_END_IMP ( )
Value:
do { \
bsls::PreconditionsHandler::invokeEndHandler(); \
} while (false)