text
stringlengths 0
2.2M
|
---|
#define ASSERT BSLIM_TESTUTIL_ASSERT
|
#define ASSERTV BSLIM_TESTUTIL_ASSERTV
|
#define LOOP_ASSERT BSLIM_TESTUTIL_LOOP_ASSERT
|
#define LOOP0_ASSERT BSLIM_TESTUTIL_LOOP0_ASSERT
|
#define LOOP1_ASSERT BSLIM_TESTUTIL_LOOP1_ASSERT
|
#define LOOP2_ASSERT BSLIM_TESTUTIL_LOOP2_ASSERT
|
#define LOOP3_ASSERT BSLIM_TESTUTIL_LOOP3_ASSERT
|
#define LOOP4_ASSERT BSLIM_TESTUTIL_LOOP4_ASSERT
|
#define LOOP5_ASSERT BSLIM_TESTUTIL_LOOP5_ASSERT
|
#define LOOP6_ASSERT BSLIM_TESTUTIL_LOOP6_ASSERT
|
#define Q BSLIM_TESTUTIL_Q // Quote identifier literally.
|
#define P BSLIM_TESTUTIL_P // Print identifier and value.
|
#define P_ BSLIM_TESTUTIL_P_ // P(X) without '\n'.
|
#define T_ BSLIM_TESTUTIL_T_ // Print a tab (w/o newline).
|
#define L_ BSLIM_TESTUTIL_L_ // current Line number
|
// ============================================================================
|
// NEGATIVE-TEST MACRO ABBREVIATIONS
|
// ----------------------------------------------------------------------------
|
#define ASSERT_SAFE_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_SAFE_PASS(EXPR)
|
#define ASSERT_SAFE_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_SAFE_FAIL(EXPR)
|
#define ASSERT_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_PASS(EXPR)
|
#define ASSERT_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_FAIL(EXPR)
|
#define ASSERT_OPT_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_OPT_PASS(EXPR)
|
#define ASSERT_OPT_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_OPT_FAIL(EXPR)
|
//=============================================================================
|
// GLOBAL TYPEDEFS FOR TESTING
|
//-----------------------------------------------------------------------------
|
typedef bdlb::RandomDevice Util;
|
#if defined(BSLS_PLATFORM_OS_WINDOWS)
|
#define sleep(x) Sleep((x))
|
#else
|
#define sleep(x) usleep((x) * 100)
|
#endif
|
//=============================================================================
|
// MAIN PROGRAM
|
//-----------------------------------------------------------------------------
|
int main(int argc, char *argv[])
|
{
|
int test = argc > 1 ? atoi(argv[1]) : 0;
|
bool verbose = argc > 2;
|
bool veryVerbose = argc > 3;
|
cout << "TEST " << __FILE__ << " CASE " << test << endl;
|
switch (test) { case 0:
|
case 3: {
|
// --------------------------------------------------------------------
|
// USAGE EXAMPLE TEST
|
//
|
// Concerns:
|
// The usage example provided in the component header file must
|
// compile, link, and run on all platforms as shown.
|
//
|
// Plan:
|
// Incorporate usage example from header into driver, remove leading
|
// comment characters, and replace 'assert' with 'ASSERT'.
|
//
|
// Testing:
|
// USAGE EXAMPLE
|
// --------------------------------------------------------------------
|
if (verbose) cout << endl << "USAGE EXAMPLE TEST" << endl
|
<< "==================" << endl;
|
///Usage
|
///-----
|
// This section illustrates intended use of this component.
|
//..
|
///Example 1: Seeding the Random-Number Generator
|
/// - - - - - - - - - - - - - - - - - - - - - - -
|
// System-provided random-number generators generally must be initialized with
|
// a seed value from which they go on to produce their stream of pseudo-random
|
// numbers. We can use 'RandomDevice' to provide such a seed.
|
//
|
// First, we obtain the results of invoking the random-number generator without
|
// having seeded it:
|
//..
|
int unseededR1 = rand();
|
int unseededR2 = rand();
|
//..
|
// Then, we obtain a random number:
|
//..
|
int seed = 0;
|
int status = bdlb::RandomDevice::getRandomBytes(
|
reinterpret_cast<unsigned char *>(&seed), sizeof(seed));
|
ASSERT(0 == status);
|
ASSERT(0 != seed); // This will fail every few billion attempts...
|
//..
|
// Next, we seed the random-number generator with our seed:
|
//..
|
srand(seed);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.