text
stringlengths 0
2.2M
|
|---|
ASSERT(0 == SB.length());
|
ASSERT(0 == SB.capacity());
|
if(veryVerbose) P(SB);
|
}
|
if (verbose) cout << "\nTesting empty streambuf." << endl;
|
{
|
char buffer[INIT_BUFSIZE];
|
Obj mSB(buffer, INIT_BUFSIZE - 1);
|
const Obj& SB = mSB;
|
ASSERT(buffer == SB.data());
|
ASSERT(0 == SB.length());
|
ASSERT(INIT_BUFSIZE - 1 == SB.capacity());
|
if(veryVerbose) P(SB);
|
}
|
if (verbose) { cout << "\nTesting different initial buffer states."
|
<< endl; }
|
{
|
const struct TestData {
|
int d_line; // line number
|
char d_outChar; // character to output
|
int d_strCap; // stream capacity
|
const char *d_initCont; // initial contents of stream
|
const char *d_result; // expected contents after 'sputc'
|
int d_length; // number of chars in stream
|
// buffer after 'sputc'
|
int d_returnVal; // 'sputc' return val
|
} DATA[] = {
|
//LINE OUT STREAM INIT RESULT STREAM RET
|
// CHAR CPCITY CONTNT CONTNT LENGTH VAL
|
//---- ---- ------ ------ ------ ------ ---
|
{ L_, 's', 0, "", "", 0, -1 }, // N = 0
|
{ L_, 's', 1, "", "s", 1, 's' }, // N = 1
|
{ L_, 's', 1, "a", "a", 1, -1 },
|
{ L_, 's', 2, "", "s", 1, 's' }, // N = 2
|
{ L_, 's', 2, "a", "as", 2, 's' },
|
{ L_, 's', 2, "ab", "ab", 2, -1 },
|
};
|
const size_t DATA_LEN = sizeof DATA / sizeof *DATA;
|
// This segment verifies correct behavior across different initial
|
// buffer states (buffer length x buffer contents.)
|
for(size_t i = 0; i < DATA_LEN; ++i ) {
|
const int LINE = DATA[i].d_line;
|
char *bytes = new char[DATA[i].d_strCap];
|
Obj mSB(bytes, DATA[i].d_strCap);
|
const Obj& SB = mSB;
|
for (unsigned j = 0; j < strlen(DATA[i].d_initCont); ++j) {
|
mSB.sputc(DATA[i].d_initCont[j]);
|
}
|
if (veryVerbose) { cout << "\tInitial contents: "; P(SB)};
|
int retResult = mSB.sputc(DATA[i].d_outChar);
|
ASSERTV(LINE, 0 == strncmp(bytes,
|
DATA[i].d_result,
|
strlen(DATA[i].d_result)));
|
ASSERTV(LINE, DATA[i].d_returnVal == retResult);
|
ASSERTV(LINE, DATA[i].d_length == SB.length());
|
ASSERTV(LINE, DATA[i].d_strCap == SB.capacity());
|
delete [] bytes;
|
}
|
}
|
} break;
|
case 3: {
|
// --------------------------------------------------------------------
|
// TEST APPARATUS
|
// Verify the auxiliary function used in the test driver. Note that
|
// the tested function is not part of the component and use only to
|
// provide human readable test traces.
|
//
|
// Concerns:
|
//: 1 Output operator formats the stream buffer correctly.
|
//:
|
//: 2 Output operator does not produce any trailing characters.
|
//:
|
//: 3 Output operator works on references to 'const' object.
|
//
|
// Plan:
|
//: 1 For each of a small representative set of object values use
|
//: 'stringstream' to write that object's value to two separate
|
//: strings. Compare the contents of these strings with the literal
|
//: expected output format and verify that they are equal. (C-1..3)
|
//
|
// Testing:
|
// ostream& operator<<(ostream&, const FixedMemOutput&);
|
// --------------------------------------------------------------------
|
if (verbose) cout << endl
|
<< "TEST APPARATUS" << endl
|
<< "==============" << endl;
|
if (verbose) cout << "\nCreate stream buffers to be printed." << endl;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.