text
stringlengths
0
2.2M
x.cancelReserved(UNITS_TO_CANCEL);
x.submit(freeUnits-1);
LOOP_ASSERT(LINE, false == x.wouldExceedBandwidth(Ti(0)));
}
else {
}
}
if (verbose) cout << endl << "Negative Testing" << endl;
{
bsls::AssertTestHandlerGuard hG;
Obj y(100, Ti(10), 1000, Ti(1), Ti(0));
y.submit(100);
y.reserve(100);
ASSERT_PASS(y.cancelReserved(100));
ASSERT_FAIL(y.cancelReserved(1));
y.reserve(100);
ASSERT_FAIL(y.cancelReserved(101));
}
} break;
case 11: {
// --------------------------------------------------------------------
// CLASS METHOD 'reset'
//
// Concerns:
//: 1 The object parameters are not affected by the 'reset'
//: method.
//:
//: 2 The object state is set to initial state and 'lastUpdateTime'
//: is recorded correctly when 'reset' is invoked
//:
//: 3 'reset' method invokes 'resetStatistics' method and
//: 'statisticsCollectionStartTime' is updated
//
// Testing:
// void reset(const bsls::TimeInterval& currentTime);
// --------------------------------------------------------------------
if (verbose) cout << endl
<< "CLASS METHOD 'reset'" << endl
<< "====================" << endl;
Uint64 usedUnits = 0;
Uint64 unusedUnits = 0;
const Uint64 S_RATE = 1000;
const Ti S_WND = Ti(10);
const Uint64 P_RATE = 10000;
const Ti P_WND = Ti(0.1);
struct {
int d_line;
Ti d_creationTime;
Uint64 d_units;
Ti d_resetTime;
} DATA[] = {
//LINE CTIME UNITS TRESET
//---- ------- ----- ------
{ L_, Ti( 0), 0, Ti( 0) },
{ L_, Ti( 0), 1000, Ti( 0) },
{ L_, Ti( 0), 2000, Ti( 0) },
{ L_, Ti(50), 0, Ti(60) },
{ L_, Ti(50), 1000, Ti(60) },
{ L_, Ti(50), 0, Ti( 0) },
{ L_, Ti(50), 1000, Ti( 0) }
};
const int NUM_DATA = sizeof(DATA)/sizeof(*DATA);
for(int ti = 0; ti < NUM_DATA; ti++) {
const int LINE = DATA[ti].d_line;
const Ti CREATION_TIME = DATA[ti].d_creationTime;
const Uint64 UNITS = DATA[ti].d_units;
const Ti RESET_TIME = DATA[ti].d_resetTime;
Obj x(S_RATE, S_WND, P_RATE, P_WND, CREATION_TIME);
x.submit(UNITS);
x.reserve(UNITS);
x.updateState(RESET_TIME);
x.reset(RESET_TIME);
// C-1
ASSERT(S_RATE == x.sustainedRateLimit());
ASSERT(S_WND == x.sustainedRateWindow());
ASSERT(P_RATE == x.peakRateLimit());
ASSERT(P_WND == x.peakRateWindow());
// C-2
LOOP_ASSERT(LINE, 0 == x.unitsReserved());
LOOP_ASSERT(LINE, RESET_TIME == x.lastUpdateTime());
// C-3
x.getStatistics(&usedUnits, &unusedUnits);
LOOP_ASSERT(LINE, 0 == usedUnits);
LOOP_ASSERT(LINE, 0 == unusedUnits);
LOOP_ASSERT(LINE, RESET_TIME == x.statisticsCollectionStartTime());
}
} break;
case 10: {