diff options
author | Vincent Do <do.vincent@live.com> | 2016-05-19 14:41:49 -0400 |
---|---|---|
committer | Vincent Do <vincent.do@10gen.com> | 2016-05-24 15:24:58 -0400 |
commit | 6369be976c5b3188e2bbafd9d7513f6808ac5595 (patch) | |
tree | 9110c67e693cb378d386d70433cffd9e505a47ec /src/mongo/platform/decimal128_test.cpp | |
parent | 96841731d86f761dd8862ebed64d3f97e86b748c (diff) | |
download | mongo-6369be976c5b3188e2bbafd9d7513f6808ac5595.tar.gz |
SERVER-23702 Fix server crashing on invalid decimal toString invariant check
Diffstat (limited to 'src/mongo/platform/decimal128_test.cpp')
-rw-r--r-- | src/mongo/platform/decimal128_test.cpp | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/mongo/platform/decimal128_test.cpp b/src/mongo/platform/decimal128_test.cpp index 7846ef58bf0..0632de053e6 100644 --- a/src/mongo/platform/decimal128_test.cpp +++ b/src/mongo/platform/decimal128_test.cpp @@ -661,13 +661,6 @@ TEST(Decimal128Test, TestDecimal128ToStringNeg) { ASSERT_EQUALS(result, "-2.087015E-278"); } -TEST(Decimal128Test, TestDecimal128ToStringPosNaN) { - std::string s = "+NaN"; - Decimal128 d(s); - std::string result = d.toString(); - ASSERT_EQUALS(result, "NaN"); -} - TEST(Decimal128Test, TestDecimal128ToStringInRangeZero1) { std::string s = "0"; Decimal128 d(s); @@ -823,25 +816,38 @@ TEST(Decimal128Test, TestDecimal128ToStringOutRangePos3) { ASSERT_EQUALS(result, "1.234567890123456789012345678901234E+33"); } -TEST(Decimal128Test, TestDecimal128ToStringNegNaN) { - std::string s = "-NaN"; +TEST(Decimal128Test, TestDecimal128ToStringInvalidToNaN) { + std::string s = "Some garbage string"; Decimal128 d(s); - std::string result = d.toString(); - ASSERT_EQUALS(result, "NaN"); + ASSERT_EQUALS(d.toString(), "NaN"); +} + +TEST(Decimal128Test, TestDecimal128ToStringNaN) { + std::string s[3] = {"-NaN", "+NaN", "NaN"}; + for (auto& item : s) { + Decimal128 d(item); + ASSERT_EQUALS(d.toString(), "NaN"); + } + + // Testing a NaN with a payload + Decimal128 payloadNaN(Decimal128::Value({/*payload*/ 0x1, 0x7cull << 56})); + ASSERT_EQUALS(payloadNaN.toString(), "NaN"); } TEST(Decimal128Test, TestDecimal128ToStringPosInf) { - std::string s = "+Infinity"; - Decimal128 d(s); - std::string result = d.toString(); - ASSERT_EQUALS(result, "Inf"); + std::string s[3] = {"Inf", "Infinity", "+Inf"}; + for (auto& item : s) { + Decimal128 d(item); + ASSERT_EQUALS(d.toString(), "Infinity"); + } } TEST(Decimal128Test, TestDecimal128ToStringNegInf) { - std::string s = "-Infinity"; - Decimal128 d(s); - std::string result = d.toString(); - ASSERT_EQUALS(result, "-Inf"); + std::string s[2] = {"-Infinity", "-Inf"}; + for (auto& item : s) { + Decimal128 d(item); + ASSERT_EQUALS(d.toString(), "-Infinity"); + } } // Tests for Decimal128 operations that use a signaling flag |