text
stringlengths 0
2.2M
|
---|
Obj mSB(buffer1, INIT_BUFSIZE);
|
const Obj& SB = mSB;
|
ASSERT(buffer1 == SB.data());
|
ASSERT(INIT_BUFSIZE == SB.capacity());
|
ASSERT(0 == SB.length());
|
mSB.sputc('a');
|
ASSERT(1 == SB.length());
|
mSB.pubsetbuf(buffer2, INIT_BUFSIZE/2);
|
ASSERT(buffer2 == SB.data());
|
ASSERT(INIT_BUFSIZE/2 == SB.capacity());
|
ASSERT(0 == SB.length());
|
}
|
if (verbose) cout << "\nNegative Testing." << endl;
|
{
|
char buffer[INIT_BUFSIZE];
|
Obj mSB(buffer, INIT_BUFSIZE);
|
bsls::AssertTestHandlerGuard hG;
|
ASSERT_SAFE_FAIL(mSB.pubsetbuf( 0, INIT_BUFSIZE));
|
ASSERT_SAFE_FAIL(mSB.pubsetbuf( 0, -1));
|
ASSERT_SAFE_FAIL(mSB.pubsetbuf(buffer, -1));
|
ASSERT_SAFE_PASS(mSB.pubsetbuf( 0, 0));
|
ASSERT_SAFE_PASS(mSB.pubsetbuf(buffer, 0));
|
ASSERT_SAFE_PASS(mSB.pubsetbuf(buffer, INIT_BUFSIZE));
|
}
|
} break;
|
case 6: {
|
// --------------------------------------------------------------------
|
// TESTING 'seek' METHODS
|
// As the only action performed in 'pubseekpos' is the call for
|
// 'pubseekoff' with predetermined second parameter, then we can test
|
// 'pubseekpos' superficially.
|
//
|
// Concerns:
|
//: 1 Seeking is correct for:
|
//: - all relative positions.
|
//: - positive, 0, and negative values.
|
//: - out of buffer boundaries.
|
//:
|
//: 2 Seeking into the "get" area has no effect.
|
//:
|
//: 3 'pubseekpos' calls 'pubseekoff' with correctly predetermined
|
//: second parameter (bsl::ios_base::beg)
|
//
|
// Plan:
|
//: 1 Perform a variety of seeks, using representative test vectors
|
//: from the cross-product of offset categories beginning-pointer,
|
//: current-pointer and end-pointer, with direction categories
|
//: negative-forcing-past-beginning, negative-falling-within-bounds,
|
//: 0, positive-falling-within bounds, and positive-forcing-past-end.
|
//: (C-1..2)
|
//:
|
//: 2 Perform several seeks with different initial states of the
|
//: tested object. (C-3)
|
//
|
// Testing:
|
// pos_type pubseekoff(off_type, seekdir, openmode);
|
// pos_type pubseekpos(pos_type, openmode);
|
// --------------------------------------------------------------------
|
if (verbose) cout << endl
|
<< "TESTING 'seek' METHODS" << endl
|
<< "======================" << endl;
|
const io_openmode PUT = bsl::ios_base::out;
|
const io_openmode GET = bsl::ios_base::in;
|
const io_seekdir CUR = bsl::ios_base::cur;
|
const io_seekdir BEG = bsl::ios_base::beg;
|
const io_seekdir END = bsl::ios_base::end;
|
char mFILL[INIT_BUFSIZE];
|
memset(mFILL, 'a', sizeof mFILL);
|
if (verbose) cout << "\nTesting seekoff with no buffer." << endl;
|
{
|
Obj mSB(0, 0);
|
Obj::pos_type ret;
|
ret = mSB.pubseekoff(1, BEG, PUT);
|
ASSERT(-1 == ret);
|
}
|
if (verbose) cout << "\nTesting seekoff from beginning and end."
|
<< endl;
|
{
|
static const struct {
|
int d_line; // line number
|
io_openmode d_areaFlags; // "put"/"get" area flag
|
Obj::off_type d_amount; // seek offset
|
io_seekdir d_base; // relative position
|
int d_retVal; // expected return from seekoff
|
} DATA[] = {
|
//LINE AREA OFFSET POS RETVAL
|
//---- ---- --------------------- ---- -------------------
|
// seekoff from the start of the streambuf
|
{ L_, PUT, 0, BEG, 0 },
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.