text
stringlengths
0
2.2M
//: to invoke the value constructor and verify the values of the
//: resulting objects. (C-1..5)
//:
//: 3 Verify that, in appropriate build modes, defensive checks are
//: triggered for invalid attribute values, but not triggered for
//: adjacent valid ones (using the 'BSLS_ASSERTTEST_*' macros).
//: (C-6)
//
// Testing:
// RateLimiter(sR, sRW, pR, pRW, currentTime);
// --------------------------------------------------------------------
if (verbose) cout << endl
<< "VALUE CTOR" << endl
<< "==========" << endl;
// Testing value constructor.
{
const Uint64 BIG_VAL = 0xFFFFFFFFULL * 2;
const Uint64 MAX_RT = ULLONG_MAX/1000000;
struct {
int d_line;
Uint64 d_sustRate;
Ti d_sustWindow;
Uint64 d_peakRate;
Ti d_peakWindow;
Ti d_creationTime;
Ti d_expSustWnd;
Ti d_expPeakWnd;
} DATA[] = {
// LINE S_RATE S_WND P_RATE P_WND TCREATE EXP_S_WND EXP_P_WND
// ---- --------- --------- -------- ---------- -------- --------- ---------
{L_, 100, Ti( 1), 1000, Ti(0.001), Ti( 0), Ti( 1), Ti(0.001)},
{L_, 10, Ti( 0.5), 150, Ti( 0.1), Ti( 0), Ti( 0.5), Ti( 0.1)},
{L_, BIG_VAL, Ti(1000), MAX_RT, Ti( 50), Ti(999), Ti(1000), Ti( 50)},
{L_, MAX_RT/2, Ti( 100), MAX_RT, Ti( 90), Ti(500), Ti( 100), Ti( 90)},
{L_, 5, Ti( 0.3), 1000, Ti( 0.1), Ti( 0), Ti( 0.2), Ti( 0.1)},
{L_, 1, Ti( 10), 10, Ti( 1.55), Ti( 0), Ti( 10), Ti( 1.5)},
{L_, 1, Ti( 0.1), 100, Ti( 0.05), Ti( 0), Ti( 1), Ti( 0.05)}
};
const int NUM_DATA = sizeof(DATA)/sizeof(*DATA);
for (int ti = 0; ti < NUM_DATA; ++ti) {
const Uint64 LINE = DATA[ti].d_line;
const Uint64 S_RATE = DATA[ti].d_sustRate;
const Ti S_WND = DATA[ti].d_sustWindow;
const Uint64 P_RATE = DATA[ti].d_peakRate;
const Ti P_WND = DATA[ti].d_peakWindow;
const Ti CREATION_TIME = DATA[ti].d_creationTime;
const Ti EXP_S_WND = DATA[ti].d_expSustWnd;
const Ti EXP_P_WND = DATA[ti].d_expPeakWnd;
Obj x(S_RATE, S_WND, P_RATE, P_WND, CREATION_TIME);
const Obj& X = x;
LOOP_ASSERT(LINE, 0 == X.unitsReserved());
LOOP_ASSERT(LINE, S_RATE == X.sustainedRateLimit());
LOOP_ASSERT(LINE, P_RATE == X.peakRateLimit());
LOOP_ASSERT(LINE, CREATION_TIME == X.lastUpdateTime());
LOOP_ASSERT(LINE,
CREATION_TIME ==
X.statisticsCollectionStartTime());
Ti delta = EXP_S_WND - X.sustainedRateWindow();
LOOP_ASSERT(LINE,
0 == delta.seconds() &&
delta.nanoseconds() >= 0 &&
delta.nanoseconds() <= 1 );
delta = EXP_P_WND - X.peakRateWindow();
LOOP_ASSERT(LINE,
0 == delta.seconds() &&
delta.nanoseconds() >= 0 &&
delta.nanoseconds() <= 1 );
}
// Testing Coexistence
{
Obj y(DATA[0].d_sustRate,
DATA[0].d_sustWindow,
DATA[0].d_peakRate,
DATA[0].d_peakWindow,
DATA[0].d_creationTime);
Obj z(DATA[1].d_sustRate,
DATA[1].d_sustWindow,
DATA[1].d_peakRate,
DATA[1].d_peakWindow,
DATA[1].d_creationTime);
ASSERT(DATA[0].d_sustRate == y.sustainedRateLimit());
ASSERT(DATA[0].d_peakRate == y.peakRateLimit());
ASSERT(DATA[0].d_creationTime == y.lastUpdateTime());
ASSERT(DATA[0].d_creationTime ==
y.statisticsCollectionStartTime());
Ti delta = DATA[0].d_sustWindow - y.sustainedRateWindow();
ASSERT(0 == delta.seconds() &&