text
stringlengths 0
2.2M
|
---|
const size_t DATA_LEN = sizeof DATA / sizeof *DATA;
|
for (size_t i = 0; i < DATA_LEN; ++i ) {
|
const int LINE = DATA[i].d_line;
|
const int FINAL_POS = (0 <= DATA[i].d_retVal ?
|
DATA[i].d_retVal :
|
DATA[i].d_initialPosition);
|
char buffer[INIT_BUFSIZE];
|
memset(buffer, 'Z', INIT_BUFSIZE);
|
Obj mSB(buffer, INIT_BUFSIZE);
|
const Obj& SB = mSB;
|
Obj::pos_type ret;
|
mSB.sputn(mFILL, DATA[i].d_initialPosition);
|
ret = mSB.pubseekoff(DATA[i].d_offset, CUR, PUT);
|
if (veryVerbose) P(ret);
|
ASSERTV(LINE, DATA[i].d_retVal == ret);
|
ASSERTV(LINE, FINAL_POS == SB.length());
|
ASSERTV(LINE, 0 == bsl::memcmp(mFILL, buffer, SB.length()));
|
}
|
}
|
if (verbose) cout << "\nTesting seekpos."
|
<< endl;
|
{
|
static const struct {
|
int d_line; // line number
|
int d_offset; // seek offset
|
int d_initialPosition; // where to set pptr() first
|
int d_retVal; // expected return value
|
} DATA[] = {
|
//LINE OFFSET STARTPOS RETVAL
|
//---- -------------- -------------- ---------------
|
{ L_, INIT_BUFSIZE/2, 0, -1 },
|
{ L_, INIT_BUFSIZE/2, INIT_BUFSIZE/2, INIT_BUFSIZE/2 },
|
{ L_, INIT_BUFSIZE/2, INIT_BUFSIZE, INIT_BUFSIZE/2 },
|
};
|
const size_t DATA_LEN = sizeof DATA / sizeof *DATA;
|
for (size_t i = 0; i < DATA_LEN; ++i ) {
|
const int LINE = DATA[i].d_line;
|
const int FINAL_POS = (0 <= DATA[i].d_retVal ?
|
DATA[i].d_retVal :
|
DATA[i].d_initialPosition);
|
char buffer[INIT_BUFSIZE];
|
memset(buffer, 'Z', INIT_BUFSIZE);
|
Obj mSB(buffer, INIT_BUFSIZE);
|
const Obj& SB = mSB;
|
Obj::pos_type ret;
|
mSB.sputn(mFILL, DATA[i].d_initialPosition);
|
ret = mSB.pubseekpos(DATA[i].d_offset, PUT);
|
if (veryVerbose) P(ret);
|
ASSERTV(LINE, DATA[i].d_retVal == ret);
|
ASSERTV(LINE, FINAL_POS == SB.length());
|
}
|
}
|
} break;
|
case 5: {
|
// --------------------------------------------------------------------
|
// TESTING 'sputn' METHOD
|
//
|
// Concerns:
|
//: 1 Strings of varying length are written correctly.
|
//:
|
//: 2 Writing strings does not overwrite existing buffer content.
|
//:
|
//: 3 No more than the specified number of characters are written.
|
//:
|
//: 4 No writing happens beyond existing capacity.
|
//
|
// Plan:
|
//: 1 Write out representative strings from the categories 0
|
//: characters, 1 character, and > 1 character, into streambufs with
|
//: representative contents "empty", substantially less than
|
//: capacity, and almost-full-so-that-next-write-exceeds-capacity.
|
//: (C-1..4)
|
//
|
// Testing:
|
// streamsize sputn(const char_type, streamsize);
|
// --------------------------------------------------------------------
|
if (verbose) cout << endl
|
<< "TESTING 'sputn' METHOD" << endl
|
<< "======================" << endl;
|
if (verbose) cout << "\nTesting sputn with no buffer." << endl;
|
{
|
Obj mSB(0, 0);
|
const Obj& SB = mSB;
|
const char *source = "a";
|
bsl::streamsize retResult;
|
ASSERT(0 == SB.capacity());
|
retResult = mSB.sputn(source, strlen(source));
|
ASSERT(0 == retResult);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.