Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <math.h> | 5 #include <math.h> |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 // One additional test to verify that conversion of numbers in strings with | 337 // One additional test to verify that conversion of numbers in strings with |
| 338 // embedded NUL characters. The NUL and extra data after it should be | 338 // embedded NUL characters. The NUL and extra data after it should be |
| 339 // interpreted as junk after the number. | 339 // interpreted as junk after the number. |
| 340 const char input[] = "3.14\0159"; | 340 const char input[] = "3.14\0159"; |
| 341 std::string input_string(input, arraysize(input) - 1); | 341 std::string input_string(input, arraysize(input) - 1); |
| 342 double output; | 342 double output; |
| 343 EXPECT_FALSE(StringToDouble(input_string, &output)); | 343 EXPECT_FALSE(StringToDouble(input_string, &output)); |
| 344 EXPECT_DOUBLE_EQ(3.14, output); | 344 EXPECT_DOUBLE_EQ(3.14, output); |
| 345 } | 345 } |
| 346 | 346 |
| 347 TEST(StringNumberConversionsTest, DoubleToString) { | |
| 348 static const struct { | |
| 349 double input; | |
| 350 std::string expected; | |
|
eroman
2012/05/14 22:52:39
I would suggest making this a |const char*| instea
Mark Mentovai
2012/05/14 23:20:32
eroman wrote:
| |
| 351 } cases[] = { | |
| 352 {0.0, "0"}, | |
| 353 {1.25, "1.25"}, | |
| 354 {1.33518e+012, "1.33518e+12"}, | |
|
eroman
2012/05/14 22:52:39
Note that these are NOT the exact same values as I
| |
| 355 {1.33489e+012, "1.33489e+12"}, | |
| 356 {1.33505e+012, "1.33505e+12"}, | |
| 357 {1.33545e+009, "1335450000"}, | |
| 358 {1.33503e+009, "1335030000"}, | |
| 359 }; | |
| 360 | |
| 361 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | |
| 362 EXPECT_EQ(cases[i].expected, DoubleToString(cases[i].input)); | |
| 363 } | |
| 364 } | |
| 365 | |
| 347 TEST(StringNumberConversionsTest, HexEncode) { | 366 TEST(StringNumberConversionsTest, HexEncode) { |
| 348 std::string hex(HexEncode(NULL, 0)); | 367 std::string hex(HexEncode(NULL, 0)); |
| 349 EXPECT_EQ(hex.length(), 0U); | 368 EXPECT_EQ(hex.length(), 0U); |
| 350 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; | 369 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; |
| 351 hex = HexEncode(bytes, sizeof(bytes)); | 370 hex = HexEncode(bytes, sizeof(bytes)); |
| 352 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); | 371 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); |
| 353 } | 372 } |
| 354 | 373 |
| 355 } // namespace base | 374 } // namespace base |
| OLD | NEW |