text
stringlengths
0
2.2M
#define LOOP5_ASSERT BSLS_BSLTESTUTIL_LOOP5_ASSERT
#define LOOP6_ASSERT BSLS_BSLTESTUTIL_LOOP6_ASSERT
#define Q BSLS_BSLTESTUTIL_Q // Quote identifier literally.
#define P BSLS_BSLTESTUTIL_P // Print identifier and value.
#define P_ BSLS_BSLTESTUTIL_P_ // P(X) without '\n'.
#define T_ BSLS_BSLTESTUTIL_T_ // Print a tab (w/o newline).
#define L_ BSLS_BSLTESTUTIL_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)
// ============================================================================
// PRINTF FORMAT MACRO ABBREVIATIONS
// ----------------------------------------------------------------------------
#define ZU BSLS_BSLTESTUTIL_FORMAT_ZU
//=============================================================================
// GLOBAL TYPEDEFS, HELPER FUNCTIONS, AND CLASSES FOR TESTING
//-----------------------------------------------------------------------------
class MockRNG {
// This class provides a predictable mock random number generator for use
// in testing.
public:
// PUBLIC TYPES
typedef unsigned int result_type;
// The type of the random data that 'operator()' will return.
private:
// DATA
result_type d_counter;
// Counter that provides some variance in the random numbers returned.
public:
// CREATORS
MockRNG();
// Create a 'MockRNG' that will return predictable "random" values.
//! MockRNG(const MockRNG& original) = default;
// Create a 'MockRNG' object with a copy of 'd_counter' from the
// specified 'original'.
//! ~MockRNG() = default;
// Destroy this object.
// MANIPULATORS
//! MockRNG& operator=(const MockRNG& rhs) = default;
// Assign to this object the value of 'd_counter' from the specified
// 'rhs' object, and return a reference providing modifiable access to
// this object.
result_type operator()();
// Return a predictable "random" number of 'result_type'.
// ACCESSORS
result_type numberOfCalls() const;
// Return the number of times that 'operator()' has been called
};
// CREATORS
MockRNG::MockRNG() : d_counter(0) { }
// MANIPULATORS
MockRNG::result_type MockRNG::operator()() {
return ++d_counter;
}
// ACCESSORS
MockRNG::result_type MockRNG::numberOfCalls() const {
return d_counter;
}
void verifyResultMatchesRNG(const char *result, size_t length)
// Compare the specified 'length' bytes of 'result' to the expected output
// of 'MockRNG' using 'ASSERT's
{
MockRNG rng = MockRNG();
const size_t rngSize = sizeof(MockRNG::result_type);
MockRNG::result_type rand;
const char *randPtr = reinterpret_cast<const char *>(&rand);
for (size_t i = 0; i < length; ++i) {
if (i % rngSize == 0) {
rand = rng();
}
ASSERT(result[i] == randPtr[i % rngSize]);
}
}