text
stringlengths 0
2.2M
|
---|
ASSERT(0 == SB.length());
|
}
|
if (verbose) cout << "\nNegative Testing." << endl;
|
{
|
char buffer[INIT_BUFSIZE];
|
bsls::AssertTestHandlerGuard hG;
|
ASSERT_SAFE_FAIL(Obj( 0, INIT_BUFSIZE));
|
ASSERT_SAFE_FAIL(Obj( 0, -1));
|
ASSERT_SAFE_FAIL(Obj(buffer, -1));
|
ASSERT_SAFE_PASS(Obj( 0, 0));
|
ASSERT_SAFE_PASS(Obj(buffer, 0));
|
ASSERT_SAFE_PASS(Obj(buffer, INIT_BUFSIZE));
|
}
|
if (verbose) cout << "\nTesting sputc." << endl;
|
{
|
if (verbose) { cout << "\tBasic sputc test." << endl; }
|
{
|
typedef Obj::char_type T;
|
static const struct {
|
int d_line; // line number
|
T d_outChar; // character to output
|
const char *d_result; // expected content
|
} DATA[] = {
|
//LINE OUTPUT RESULT
|
//---- ------ ------
|
{ L_, 's', "s" }, // Add ordinary ASCII character
|
{ L_, 10, "\xA" }, // Add non-printing character
|
{ L_, 127, "\x7F" }, // Add <= 127
|
{ L_, (T)128, "\x80" } // Add >= 128
|
}; // end table DATA
|
const size_t DATA_LEN = sizeof DATA / sizeof *DATA;
|
// This loop verifies that 'sputc' both:
|
// 1. Adds the character, and
|
// 2. Does not overwrite beyond the character.
|
if (verbose) { T_ cout << "Testing different character types."
|
<< endl; }
|
for (size_t i = 0; i < DATA_LEN; ++i ) {
|
const int LINE = DATA[i].d_line;
|
char buffer[INIT_BUFSIZE];
|
memset(buffer, 'Z', INIT_BUFSIZE);
|
Obj mSB(buffer, INIT_BUFSIZE - 1);
|
mSB.sputc(DATA[i].d_outChar);
|
ASSERTV(LINE, 0 == strncmp(buffer, DATA[i].d_result, 1));
|
ASSERTV(LINE, 'Z' == buffer[1]);
|
}
|
}
|
if (verbose) { cout << "\tTesting 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 content
|
int d_returnVal; // 'sputc' return val
|
} DATA[] = {
|
//LINE OUT STREAM INIT RESULT RET
|
// CHAR CPCITY CONTNT CONTNT VAL
|
//---- ---- ------ ------ ------ ----
|
{ L_, 's', 0, "", "", -1 }, // N = 0
|
{ L_, 's', 1, "", "s", 's' }, // N = 1
|
{ L_, 's', 1, "a", "a", -1 },
|
{ L_, 's', 2, "", "s", 's' }, // N = 2
|
{ L_, 's', 2, "a", "as", 's' },
|
{ L_, 's', 2, "ab", "ab", -1 },
|
{ L_, 's', 3, "", "s", 's' }, // N = 3
|
{ L_, 's', 3, "ab", "abs", 's' },
|
{ L_, 's', 3, "abc", "abc", -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 + 1];
|
memset(bytes, 'Z', DATA[i].d_strCap + 1);
|
Obj mSB(bytes, DATA[i].d_strCap);
|
for (size_t j = 0; j < strlen(DATA[i].d_initCont); ++j) {
|
mSB.sputc(DATA[i].d_initCont[j]);
|
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.