| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <errno.h> |
| 5 #include <math.h> | 6 #include <math.h> |
| 6 | 7 |
| 7 #include <limits> | 8 #include <limits> |
| 8 | 9 |
| 9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 | 15 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 {" 2.99", 2.99, false}, | 443 {" 2.99", 2.99, false}, |
| 443 {"1e3.4", 1000.0, false}, | 444 {"1e3.4", 1000.0, false}, |
| 444 {"nothing", 0.0, false}, | 445 {"nothing", 0.0, false}, |
| 445 {"-", 0.0, false}, | 446 {"-", 0.0, false}, |
| 446 {"+", 0.0, false}, | 447 {"+", 0.0, false}, |
| 447 {"", 0.0, false}, | 448 {"", 0.0, false}, |
| 448 }; | 449 }; |
| 449 | 450 |
| 450 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 451 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 451 double output; | 452 double output; |
| 453 errno = 1; |
| 452 EXPECT_EQ(cases[i].success, StringToDouble(cases[i].input, &output)); | 454 EXPECT_EQ(cases[i].success, StringToDouble(cases[i].input, &output)); |
| 455 if (cases[i].success) |
| 456 EXPECT_EQ(1, errno) << i; // confirm that errno is unchanged. |
| 453 EXPECT_DOUBLE_EQ(cases[i].output, output); | 457 EXPECT_DOUBLE_EQ(cases[i].output, output); |
| 454 } | 458 } |
| 455 | 459 |
| 456 // One additional test to verify that conversion of numbers in strings with | 460 // One additional test to verify that conversion of numbers in strings with |
| 457 // embedded NUL characters. The NUL and extra data after it should be | 461 // embedded NUL characters. The NUL and extra data after it should be |
| 458 // interpreted as junk after the number. | 462 // interpreted as junk after the number. |
| 459 const char input[] = "3.14\0159"; | 463 const char input[] = "3.14\0159"; |
| 460 std::string input_string(input, arraysize(input) - 1); | 464 std::string input_string(input, arraysize(input) - 1); |
| 461 double output; | 465 double output; |
| 462 EXPECT_FALSE(StringToDouble(input_string, &output)); | 466 EXPECT_FALSE(StringToDouble(input_string, &output)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 | 499 |
| 496 TEST(StringNumberConversionsTest, HexEncode) { | 500 TEST(StringNumberConversionsTest, HexEncode) { |
| 497 std::string hex(HexEncode(NULL, 0)); | 501 std::string hex(HexEncode(NULL, 0)); |
| 498 EXPECT_EQ(hex.length(), 0U); | 502 EXPECT_EQ(hex.length(), 0U); |
| 499 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; | 503 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; |
| 500 hex = HexEncode(bytes, sizeof(bytes)); | 504 hex = HexEncode(bytes, sizeof(bytes)); |
| 501 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); | 505 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); |
| 502 } | 506 } |
| 503 | 507 |
| 504 } // namespace base | 508 } // namespace base |
| OLD | NEW |