Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3137)

Unified Diff: base/string_number_conversions_unittest.cc

Issue 10332159: Add some unittests for DoubleToString. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_number_conversions_unittest.cc
diff --git a/base/string_number_conversions_unittest.cc b/base/string_number_conversions_unittest.cc
index 438db077a953225adac1d4bf9c8881aca750cb5b..7fbf94e2a73c0648d05a8173664ef4cdb715f4f7 100644
--- a/base/string_number_conversions_unittest.cc
+++ b/base/string_number_conversions_unittest.cc
@@ -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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698