Skip to content

Commit a757a2a

Browse files
committed
Add more tests
Some more need to be fixed.
1 parent 1792778 commit a757a2a

File tree

1 file changed

+84
-57
lines changed

1 file changed

+84
-57
lines changed

test/unittest/readertest.cpp

Lines changed: 84 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -410,28 +410,29 @@ static void TestParseDouble() {
410410
TEST_DOUBLE(fullPrecision, "0e-9223372036854775808", 0.0);
411411
#endif
412412

413-
#if 0
414-
// Slightly above max-normal
415-
// Fails with "normal" precision
416-
TEST_DOUBLE(fullPrecision, "1.7976931348623158e+308", 1.7976931348623158e+308);
417-
#endif
413+
if (fullPrecision)
414+
{
415+
// Slightly above max-normal
416+
TEST_DOUBLE(fullPrecision, "1.7976931348623158e+308", 1.7976931348623158e+308);
417+
418+
TEST_DOUBLE(fullPrecision,
419+
"17976931348623157081452742373170435679807056752584499659891747680315726"
420+
"07800285387605895586327668781715404589535143824642343213268894641827684"
421+
"67546703537516986049910576551282076245490090389328944075868508455133942"
422+
"30458323690322294816580855933212334827479782620414472316873817718091929"
423+
"9881250404026184124858368",
424+
std::numeric_limits<double>::max());
425+
426+
TEST_DOUBLE(fullPrecision,
427+
"243546080556034731077856379609316893158278902575447060151047"
428+
"212703405344938119816206067372775299130836050315842578309818"
429+
"316450894337978612745889730079163798234256495613858256849283"
430+
"467066859489192118352020514036083287319232435355752493038825"
431+
"828481044358810649108367633313557305310641892225870327827273"
432+
"41408256.000000",
433+
2.4354608055603473e+307);
434+
}
418435

419-
#if 0
420-
TEST_DOUBLE(fullPrecision,
421-
"17976931348623157081452742373170435679807056752584499659891747680315726"
422-
"07800285387605895586327668781715404589535143824642343213268894641827684"
423-
"67546703537516986049910576551282076245490090389328944075868508455133942"
424-
"30458323690322294816580855933212334827479782620414472316873817718091929"
425-
"9881250404026184124858368",
426-
std::numeric_limits<double>::max());
427-
TEST_DOUBLE(fullPrecision,
428-
"243546080556034731077856379609316893158278902575447060151047"
429-
"212703405344938119816206067372775299130836050315842578309818"
430-
"316450894337978612745889730079163798234256495613858256849283"
431-
"467066859489192118352020514036083287319232435355752493038825"
432-
"828481044358810649108367633313557305310641892225870327827273"
433-
"41408256.000000",
434-
2.4354608055603473e+307);
435436
// 9007199254740991 * 2^971 (max normal)
436437
TEST_DOUBLE(fullPrecision,
437438
"1.797693134862315708145274237317043567980705675258449965989174768031572607800285"
@@ -440,6 +441,9 @@ static void TestParseDouble() {
440441
"9332123348274797826204144723168738177180919299881250404026184124858368e+308",
441442
1.797693134862315708e+308 // 0x1.fffffffffffffp1023
442443
);
444+
#if 0
445+
// TODO:
446+
// Should work at least in full-precision mode...
443447
TEST_DOUBLE(fullPrecision,
444448
"0.00000000000000000000000000000000000000000000000000000000000"
445449
"0000000000000000000000000000000000000000000000000000000000000"
@@ -460,6 +464,7 @@ static void TestParseDouble() {
460464
"9083625477918694866799496832404970582102851318545139621383772"
461465
"2826145437693412532098591327667236328125",
462466
0.0);
467+
#endif
463468
// 9007199254740991 * 2^-1074 = (2^53 - 1) * 2^-1074
464469
TEST_DOUBLE(fullPrecision,
465470
"4.450147717014402272114819593418263951869639092703291296046852219449644444042153"
@@ -518,7 +523,10 @@ static void TestParseDouble() {
518523
"00000000000000000000000000000000000000000000000000000000000000000000000000000000e-308",
519524
4.450147717014401778e-308 // 0x1.ffffffffffffep-1022
520525
);
526+
#if 0
521527
// ... round up
528+
// TODO:
529+
// Should work at least in full-precision mode...
522530
TEST_DOUBLE(fullPrecision,
523531
"4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
524532
"64069530541271189424317838013700808305231545782515453032382772695923684574304409"
@@ -534,6 +542,7 @@ static void TestParseDouble() {
534542
"00000000000000000000000000000000000000000000000000000000000000000000000000000001e-308",
535543
4.450147717014402272e-308 // 0x1.fffffffffffffp-1022
536544
);
545+
#endif
537546
// ... round down
538547
TEST_DOUBLE(fullPrecision,
539548
"4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
@@ -571,7 +580,6 @@ static void TestParseDouble() {
571580
"99999999999999999999999999999999999999999999999999999999999999999999999999999999e+308",
572581
1.797693134862315708e+308 // 0x1.fffffffffffffp1023
573582
);
574-
#endif
575583

576584
#undef TEST_DOUBLE
577585
}
@@ -618,7 +626,8 @@ TEST(Reader, ParseNumber_NormalPrecisionError) {
618626
printf("ULP Average = %g, Max = %g \n", ulpSum / count, ulpMax);
619627
}
620628

621-
TEST(Reader, ParseNumber_Error) {
629+
template<bool fullPrecision>
630+
static void TestParseNumberError() {
622631
#define TEST_NUMBER_ERROR(errorCode, str, errorOffset, streamPos) \
623632
{ \
624633
char buffer[2048]; \
@@ -627,7 +636,7 @@ TEST(Reader, ParseNumber_Error) {
627636
InsituStringStream s(buffer); \
628637
BaseReaderHandler<> h; \
629638
Reader reader; \
630-
EXPECT_FALSE(reader.Parse(s, h)); \
639+
EXPECT_FALSE(reader.Parse<fullPrecision ? kParseFullPrecisionFlag : 0>(s, h)); \
631640
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
632641
EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
633642
EXPECT_EQ(streamPos, s.Tell());\
@@ -686,45 +695,63 @@ TEST(Reader, ParseNumber_Error) {
686695
"76789342486548527630221960124609411945308295208500576883815068234246288147391311"
687696
"0540827237163350510684586298239947245938479716304835356329624224137216e+308", 0, 315);
688697

689-
#if 0
690-
// Half way between max-normal and infinity
691-
// Should round to infinity in nearest-even mode.
692-
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
693-
"1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
694-
"50946649017977587207096330286416692887910946555547851940402630657488671505820681"
695-
"90890200070838367627385484581771153176447573027006985557136695962284291481986083"
696-
"49364752927190741684443655107043427115596995080930428801779041744977920000000000"
697-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
698-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
699-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
700-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
701-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
702-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
703-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
704-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
705-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
706-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000e+308", 0, 1125);
707-
// ...round up
698+
// TODO:
699+
// These tests (currently) fail in normal-precision mode
700+
if (fullPrecision)
701+
{
702+
// Half way between max-normal and infinity
703+
// Should round to infinity in nearest-even mode.
704+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
705+
"1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
706+
"50946649017977587207096330286416692887910946555547851940402630657488671505820681"
707+
"90890200070838367627385484581771153176447573027006985557136695962284291481986083"
708+
"49364752927190741684443655107043427115596995080930428801779041744977920000000000"
709+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
710+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
711+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
712+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
713+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
714+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
715+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
716+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
717+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
718+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000e+308", 0, 1125);
719+
// ...round up
720+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
721+
"1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
722+
"50946649017977587207096330286416692887910946555547851940402630657488671505820681"
723+
"90890200070838367627385484581771153176447573027006985557136695962284291481986083"
724+
"49364752927190741684443655107043427115596995080930428801779041744977920000000000"
725+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
726+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
727+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
728+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
729+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
730+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
731+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
732+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
733+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
734+
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
735+
"00000000000000000000000000000000000000000000000000000000000000000000000000000001e+308", 0, 1205);
736+
}
737+
708738
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
709-
"1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
710-
"50946649017977587207096330286416692887910946555547851940402630657488671505820681"
711-
"90890200070838367627385484581771153176447573027006985557136695962284291481986083"
712-
"49364752927190741684443655107043427115596995080930428801779041744977920000000000"
713-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
714-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
739+
"10000000000000000000000000000000000000000000000000000000000000000000000000000000"
715740
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
716741
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
717-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
718-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
719-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
720-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
721-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
722-
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
723-
"00000000000000000000000000000000000000000000000000000000000000000000000000000001e+308", 0, 1125);
724-
#endif
742+
"0000000000000000000000000000000000000000000000000000000000000000000001", 0, 310);
743+
725744
#undef TEST_NUMBER_ERROR
726745
}
727746

747+
TEST(Reader, ParseNumberError_NormalPrecisionDouble) {
748+
TestParseNumberError<false>();
749+
}
750+
751+
TEST(Reader, ParseNumberError_FullPrecisionDouble) {
752+
TestParseNumberError<true>();
753+
}
754+
728755
template <typename Encoding>
729756
struct ParseStringHandler : BaseReaderHandler<Encoding, ParseStringHandler<Encoding> > {
730757
ParseStringHandler() : str_(0), length_(0), copy_() {}

0 commit comments

Comments
 (0)