text
stringlengths 0
2.2M
|
---|
ASSERT(0 == SB.length());
|
ASSERT(0 == SB.capacity());
|
}
|
if (verbose) cout << "\nTesting sputn." << endl;
|
{
|
const struct TestData {
|
int d_line; // line number
|
const char *d_outStr; // string 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 put chars
|
int d_returnVal; // 'sputn' return val
|
} DATA[] = {
|
//LINE OUT STREAM INIT RESULT STREAM RET
|
// STRNG CPCITY CONTNT CONTNT LENGTH VAL
|
//---- ----- ------ ------ ------ ------ ---
|
{ L_, "", 0, "", "", 0, 0 }, // N = 0
|
{ L_, "s", 0, "", "", 0, 0 },
|
{ L_, "abc", 0, "", "", 0, 0 },
|
{ L_, "", 1, "", "", 0, 0 }, // N = 1
|
{ L_, "s", 1, "a", "a", 1, 0 },
|
{ L_, "abc", 1, "a", "a", 1, 0 },
|
{ L_, "", 2, "", "", 0, 0 }, // N = 2
|
{ L_, "abc", 2, "", "ab", 2, 2 },
|
{ L_, "s", 2, "a", "as", 2, 1 },
|
{ L_, "abc", 2, "a", "aa", 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)};
|
bsl::streamsize retResult;
|
retResult = mSB.sputn(DATA[i].d_outStr,
|
strlen(DATA[i].d_outStr));
|
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());
|
delete [] bytes;
|
}
|
}
|
} break;
|
case 4: {
|
// --------------------------------------------------------------------
|
// BASIC ACCESSORS
|
// Verify the basic accessors of the 'bdlsb::FixedMemOutput'
|
// object. Note that none of the accessors are strictly needed for
|
// followup tests, but simplify the overall test logic.
|
//
|
// Concerns:
|
//: 1 Accessors work off of a references to 'const' objects.
|
//:
|
//: 2 The address of the user provided buffer is correctly reported.
|
//:
|
//: 3 The capacity of the stream buffer is correctly reported.
|
//:
|
//: 4 The number of characters written to the stream buffer is
|
//: correctly reported.
|
//
|
// Plan:
|
//: 1 Verify accessors for corner cases. (C-1..4)
|
//:
|
//: 2 Fill the stream buffer with data and verify that all accessors
|
//: report expected values. (C-1..4)
|
//
|
// Testing:
|
// const char_type *data() const;
|
// streamsize length() const;
|
// streamsize capacity() const;
|
// --------------------------------------------------------------------
|
if (verbose) cout << endl
|
<< "BASIC ACCESSORS" << endl
|
<< "===============" << endl;
|
if (verbose) cout << "\nTesting streambuf with no buffer." << endl;
|
{
|
Obj mSB(0, 0);
|
ASSERT(0 == mSB.data());
|
ASSERT(0 == mSB.length());
|
ASSERT(0 == mSB.capacity());
|
const Obj& SB = mSB;
|
ASSERT(0 == SB.data());
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.