mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-03-06 04:55:50 +01:00
Add more tests
Some more need to be fixed.
This commit is contained in:
parent
179277817d
commit
a757a2aeb8
@ -410,28 +410,29 @@ static void TestParseDouble() {
|
||||
TEST_DOUBLE(fullPrecision, "0e-9223372036854775808", 0.0);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// Slightly above max-normal
|
||||
// Fails with "normal" precision
|
||||
TEST_DOUBLE(fullPrecision, "1.7976931348623158e+308", 1.7976931348623158e+308);
|
||||
#endif
|
||||
if (fullPrecision)
|
||||
{
|
||||
// Slightly above max-normal
|
||||
TEST_DOUBLE(fullPrecision, "1.7976931348623158e+308", 1.7976931348623158e+308);
|
||||
|
||||
TEST_DOUBLE(fullPrecision,
|
||||
"17976931348623157081452742373170435679807056752584499659891747680315726"
|
||||
"07800285387605895586327668781715404589535143824642343213268894641827684"
|
||||
"67546703537516986049910576551282076245490090389328944075868508455133942"
|
||||
"30458323690322294816580855933212334827479782620414472316873817718091929"
|
||||
"9881250404026184124858368",
|
||||
std::numeric_limits<double>::max());
|
||||
|
||||
TEST_DOUBLE(fullPrecision,
|
||||
"243546080556034731077856379609316893158278902575447060151047"
|
||||
"212703405344938119816206067372775299130836050315842578309818"
|
||||
"316450894337978612745889730079163798234256495613858256849283"
|
||||
"467066859489192118352020514036083287319232435355752493038825"
|
||||
"828481044358810649108367633313557305310641892225870327827273"
|
||||
"41408256.000000",
|
||||
2.4354608055603473e+307);
|
||||
}
|
||||
|
||||
#if 0
|
||||
TEST_DOUBLE(fullPrecision,
|
||||
"17976931348623157081452742373170435679807056752584499659891747680315726"
|
||||
"07800285387605895586327668781715404589535143824642343213268894641827684"
|
||||
"67546703537516986049910576551282076245490090389328944075868508455133942"
|
||||
"30458323690322294816580855933212334827479782620414472316873817718091929"
|
||||
"9881250404026184124858368",
|
||||
std::numeric_limits<double>::max());
|
||||
TEST_DOUBLE(fullPrecision,
|
||||
"243546080556034731077856379609316893158278902575447060151047"
|
||||
"212703405344938119816206067372775299130836050315842578309818"
|
||||
"316450894337978612745889730079163798234256495613858256849283"
|
||||
"467066859489192118352020514036083287319232435355752493038825"
|
||||
"828481044358810649108367633313557305310641892225870327827273"
|
||||
"41408256.000000",
|
||||
2.4354608055603473e+307);
|
||||
// 9007199254740991 * 2^971 (max normal)
|
||||
TEST_DOUBLE(fullPrecision,
|
||||
"1.797693134862315708145274237317043567980705675258449965989174768031572607800285"
|
||||
@ -440,6 +441,9 @@ static void TestParseDouble() {
|
||||
"9332123348274797826204144723168738177180919299881250404026184124858368e+308",
|
||||
1.797693134862315708e+308 // 0x1.fffffffffffffp1023
|
||||
);
|
||||
#if 0
|
||||
// TODO:
|
||||
// Should work at least in full-precision mode...
|
||||
TEST_DOUBLE(fullPrecision,
|
||||
"0.00000000000000000000000000000000000000000000000000000000000"
|
||||
"0000000000000000000000000000000000000000000000000000000000000"
|
||||
@ -460,6 +464,7 @@ static void TestParseDouble() {
|
||||
"9083625477918694866799496832404970582102851318545139621383772"
|
||||
"2826145437693412532098591327667236328125",
|
||||
0.0);
|
||||
#endif
|
||||
// 9007199254740991 * 2^-1074 = (2^53 - 1) * 2^-1074
|
||||
TEST_DOUBLE(fullPrecision,
|
||||
"4.450147717014402272114819593418263951869639092703291296046852219449644444042153"
|
||||
@ -518,7 +523,10 @@ static void TestParseDouble() {
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000e-308",
|
||||
4.450147717014401778e-308 // 0x1.ffffffffffffep-1022
|
||||
);
|
||||
#if 0
|
||||
// ... round up
|
||||
// TODO:
|
||||
// Should work at least in full-precision mode...
|
||||
TEST_DOUBLE(fullPrecision,
|
||||
"4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
|
||||
"64069530541271189424317838013700808305231545782515453032382772695923684574304409"
|
||||
@ -534,6 +542,7 @@ static void TestParseDouble() {
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000001e-308",
|
||||
4.450147717014402272e-308 // 0x1.fffffffffffffp-1022
|
||||
);
|
||||
#endif
|
||||
// ... round down
|
||||
TEST_DOUBLE(fullPrecision,
|
||||
"4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
|
||||
@ -571,7 +580,6 @@ static void TestParseDouble() {
|
||||
"99999999999999999999999999999999999999999999999999999999999999999999999999999999e+308",
|
||||
1.797693134862315708e+308 // 0x1.fffffffffffffp1023
|
||||
);
|
||||
#endif
|
||||
|
||||
#undef TEST_DOUBLE
|
||||
}
|
||||
@ -618,7 +626,8 @@ TEST(Reader, ParseNumber_NormalPrecisionError) {
|
||||
printf("ULP Average = %g, Max = %g \n", ulpSum / count, ulpMax);
|
||||
}
|
||||
|
||||
TEST(Reader, ParseNumber_Error) {
|
||||
template<bool fullPrecision>
|
||||
static void TestParseNumberError() {
|
||||
#define TEST_NUMBER_ERROR(errorCode, str, errorOffset, streamPos) \
|
||||
{ \
|
||||
char buffer[2048]; \
|
||||
@ -627,7 +636,7 @@ TEST(Reader, ParseNumber_Error) {
|
||||
InsituStringStream s(buffer); \
|
||||
BaseReaderHandler<> h; \
|
||||
Reader reader; \
|
||||
EXPECT_FALSE(reader.Parse(s, h)); \
|
||||
EXPECT_FALSE(reader.Parse<fullPrecision ? kParseFullPrecisionFlag : 0>(s, h)); \
|
||||
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
|
||||
EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
|
||||
EXPECT_EQ(streamPos, s.Tell());\
|
||||
@ -686,45 +695,63 @@ TEST(Reader, ParseNumber_Error) {
|
||||
"76789342486548527630221960124609411945308295208500576883815068234246288147391311"
|
||||
"0540827237163350510684586298239947245938479716304835356329624224137216e+308", 0, 315);
|
||||
|
||||
#if 0
|
||||
// Half way between max-normal and infinity
|
||||
// Should round to infinity in nearest-even mode.
|
||||
// TODO:
|
||||
// These tests (currently) fail in normal-precision mode
|
||||
if (fullPrecision)
|
||||
{
|
||||
// Half way between max-normal and infinity
|
||||
// Should round to infinity in nearest-even mode.
|
||||
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
|
||||
"1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
|
||||
"50946649017977587207096330286416692887910946555547851940402630657488671505820681"
|
||||
"90890200070838367627385484581771153176447573027006985557136695962284291481986083"
|
||||
"49364752927190741684443655107043427115596995080930428801779041744977920000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000e+308", 0, 1125);
|
||||
// ...round up
|
||||
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
|
||||
"1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
|
||||
"50946649017977587207096330286416692887910946555547851940402630657488671505820681"
|
||||
"90890200070838367627385484581771153176447573027006985557136695962284291481986083"
|
||||
"49364752927190741684443655107043427115596995080930428801779041744977920000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000001e+308", 0, 1205);
|
||||
}
|
||||
|
||||
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
|
||||
"1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
|
||||
"50946649017977587207096330286416692887910946555547851940402630657488671505820681"
|
||||
"90890200070838367627385484581771153176447573027006985557136695962284291481986083"
|
||||
"49364752927190741684443655107043427115596995080930428801779041744977920000000000"
|
||||
"10000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000e+308", 0, 1125);
|
||||
// ...round up
|
||||
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
|
||||
"1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
|
||||
"50946649017977587207096330286416692887910946555547851940402630657488671505820681"
|
||||
"90890200070838367627385484581771153176447573027006985557136695962284291481986083"
|
||||
"49364752927190741684443655107043427115596995080930428801779041744977920000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000001e+308", 0, 1125);
|
||||
#endif
|
||||
"0000000000000000000000000000000000000000000000000000000000000000000001", 0, 310);
|
||||
|
||||
#undef TEST_NUMBER_ERROR
|
||||
}
|
||||
|
||||
TEST(Reader, ParseNumberError_NormalPrecisionDouble) {
|
||||
TestParseNumberError<false>();
|
||||
}
|
||||
|
||||
TEST(Reader, ParseNumberError_FullPrecisionDouble) {
|
||||
TestParseNumberError<true>();
|
||||
}
|
||||
|
||||
template <typename Encoding>
|
||||
struct ParseStringHandler : BaseReaderHandler<Encoding, ParseStringHandler<Encoding> > {
|
||||
ParseStringHandler() : str_(0), length_(0), copy_() {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user