diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-15 23:34:58 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-15 23:34:58 +0000 |
commit | cc8a935c9a2cf55f59d0f08993b4718b89dc26a0 (patch) | |
tree | 2c8960bab5ba1c73996598319edfb4e4d30cb7e9 /base | |
parent | a86a3f9d9e6392f9ad39a59019ba2b1618cf78d5 (diff) | |
download | chromium_src-cc8a935c9a2cf55f59d0f08993b4718b89dc26a0.zip chromium_src-cc8a935c9a2cf55f59d0f08993b4718b89dc26a0.tar.gz chromium_src-cc8a935c9a2cf55f59d0f08993b4718b89dc26a0.tar.bz2 |
Add some unittests for DoubleToString.
Some of these test cases are causing crashes in the wild. They don't
crash on my machine, with or without the dtoa patch, but we may as
well check in the test cases.
BUG=123157
Review URL: https://chromiumcodereview.appspot.com/10332159
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137301 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/string_number_conversions_unittest.cc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/base/string_number_conversions_unittest.cc b/base/string_number_conversions_unittest.cc index 438db07..30b9b8c 100644 --- a/base/string_number_conversions_unittest.cc +++ b/base/string_number_conversions_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -344,6 +344,36 @@ TEST(StringNumberConversionsTest, StringToDouble) { EXPECT_DOUBLE_EQ(3.14, output); } +TEST(StringNumberConversionsTest, DoubleToString) { + static const struct { + double input; + const char* expected; + } cases[] = { + {0.0, "0"}, + {1.25, "1.25"}, + {1.33518e+012, "1.33518e+12"}, + {1.33489e+012, "1.33489e+12"}, + {1.33505e+012, "1.33505e+12"}, + {1.33545e+009, "1335450000"}, + {1.33503e+009, "1335030000"}, + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { + EXPECT_EQ(cases[i].expected, DoubleToString(cases[i].input)); + } + + // The following two values were seen in crashes in the wild. + const char input_bytes[8] = {0, 0, 0, 0, '\xee', '\x6d', '\x73', '\x42'}; + double input = 0; + memcpy(&input, input_bytes, arraysize(input_bytes)); + EXPECT_EQ("1335179083776", DoubleToString(input)); + const char input_bytes2[8] = + {0, 0, 0, '\xa0', '\xda', '\x6c', '\x73', '\x42'}; + input = 0; + memcpy(&input, input_bytes2, arraysize(input_bytes2)); + EXPECT_EQ("1334890332160", DoubleToString(input)); +} + TEST(StringNumberConversionsTest, HexEncode) { std::string hex(HexEncode(NULL, 0)); EXPECT_EQ(hex.length(), 0U); |