text
stringlengths
0
2.2M
const int NUM_DATA = sizeof DATA / sizeof *DATA;
for (int i = 0; i < NUM_DATA; ++i) {
const int LINE = DATA[i].d_lineNum;
const char *INPUT = DATA[i].d_input;
const int INPUT_LENGTH =
static_cast<int>(bsl::strlen(INPUT)) - 1;
const Type EXPECTED_RESULT = DATA[i].d_result;
Type mX(!EXPECTED_RESULT); const Type& X = mX;
int retCode = Util::parseDecimal(&mX, INPUT, INPUT_LENGTH);
LOOP2_ASSERT(LINE, retCode, 0 == retCode);
LOOP2_ASSERT(LINE, X, EXPECTED_RESULT == X);
}
}
if (verbose) cout << "\nUsing 'short'." << endl;
{
typedef short Type;
static const struct {
int d_lineNum;
const char *d_input;
Type d_result;
} DATA[] = {
//line input result
//---- ----- ------
{ L_, "-32768X", -32768 },
{ L_, "-32767X", -32767 },
{ L_, "-1X", -1 },
{ L_, "0X", 0 },
{ L_, "1X", 1 },
{ L_, "32766X", 32766 },
{ L_, "32767X", 32767 },
};
const int NUM_DATA = sizeof DATA / sizeof *DATA;
for (int i = 0; i < NUM_DATA; ++i) {
const int LINE = DATA[i].d_lineNum;
const char *INPUT = DATA[i].d_input;
const int INPUT_LENGTH =
static_cast<int>(bsl::strlen(INPUT)) - 1;
const Type EXPECTED_RESULT = DATA[i].d_result;
Type mX(!EXPECTED_RESULT); const Type& X = mX;
int retCode = Util::parseDecimal(&mX, INPUT, INPUT_LENGTH);
LOOP2_ASSERT(LINE, retCode, 0 == retCode);
LOOP2_ASSERT(LINE, X, EXPECTED_RESULT == X);
}
}
if (verbose) cout << "\nUsing 'int'." << endl;
{
typedef int Type;
static const struct {
int d_lineNum;
const char *d_input;
Type d_result;
} DATA[] = {
//line input result
//---- ----- ------
{ L_, "-2147483648X", -2147483647-1 },
{ L_, "-2147483647X", -2147483647 },
{ L_, "-1X", -1 },
{ L_, "0X", 0 },
{ L_, "1X", 1 },
{ L_, "2147483646X", 2147483646 },
{ L_, "2147483647X", 2147483647 },
};
const int NUM_DATA = sizeof DATA / sizeof *DATA;
for (int i = 0; i < NUM_DATA; ++i) {
const int LINE = DATA[i].d_lineNum;
const char *INPUT = DATA[i].d_input;
const int INPUT_LENGTH =
static_cast<int>(bsl::strlen(INPUT)) - 1;
const Type EXPECTED_RESULT = DATA[i].d_result;
Type mX(!EXPECTED_RESULT); const Type& X = mX;
int retCode = Util::parseDecimal(&mX, INPUT, INPUT_LENGTH);
LOOP2_ASSERT(LINE, retCode, 0 == retCode);
LOOP2_ASSERT(LINE, X, EXPECTED_RESULT == X);
}
}
if (verbose) cout << "\nUsing 'bsls::Types::Int64'." << endl;
{
typedef bsls::Types::Int64 Type;
static const struct {
int d_lineNum;
const char *d_input;
Type d_result;