| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 {"\t\n\v\f\r 0x45", 0x45, false}, | 299 {"\t\n\v\f\r 0x45", 0x45, false}, |
| 300 {" 45", 0x45, false}, | 300 {" 45", 0x45, false}, |
| 301 {"45 ", 0x45, false}, | 301 {"45 ", 0x45, false}, |
| 302 {"45:", 0x45, false}, | 302 {"45:", 0x45, false}, |
| 303 {"efgh", 0xef, false}, | 303 {"efgh", 0xef, false}, |
| 304 {"0xefgh", 0xef, false}, | 304 {"0xefgh", 0xef, false}, |
| 305 {"hgfe", 0, false}, | 305 {"hgfe", 0, false}, |
| 306 {"100000000", -1, false}, // don't care about |output|, just |success| | 306 {"100000000", -1, false}, // don't care about |output|, just |success| |
| 307 {"-", 0, false}, | 307 {"-", 0, false}, |
| 308 {"", 0, false}, | 308 {"", 0, false}, |
| 309 {"0x", 0, false}, |
| 309 }; | 310 }; |
| 310 | 311 |
| 311 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 312 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 312 const char* ascii_chars = cases[i].input.c_str(); | 313 const char* ascii_chars = cases[i].input.c_str(); |
| 313 int output = 0; | 314 int output = 0; |
| 314 EXPECT_EQ(cases[i].success, HexStringToInt(cases[i].input, &output)); | 315 EXPECT_EQ(cases[i].success, HexStringToInt(cases[i].input, &output)); |
| 315 EXPECT_EQ(cases[i].output, output); | 316 EXPECT_EQ(cases[i].output, output); |
| 316 output = 0; | 317 output = 0; |
| 317 EXPECT_EQ(cases[i].success, HexStringToInt(cases[i].input.begin(), | 318 EXPECT_EQ(cases[i].success, HexStringToInt(cases[i].input.begin(), |
| 318 cases[i].input.end(), | 319 cases[i].input.end(), |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 436 |
| 436 TEST(StringNumberConversionsTest, HexEncode) { | 437 TEST(StringNumberConversionsTest, HexEncode) { |
| 437 std::string hex(HexEncode(NULL, 0)); | 438 std::string hex(HexEncode(NULL, 0)); |
| 438 EXPECT_EQ(hex.length(), 0U); | 439 EXPECT_EQ(hex.length(), 0U); |
| 439 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; | 440 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; |
| 440 hex = HexEncode(bytes, sizeof(bytes)); | 441 hex = HexEncode(bytes, sizeof(bytes)); |
| 441 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); | 442 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); |
| 442 } | 443 } |
| 443 | 444 |
| 444 } // namespace base | 445 } // namespace base |
| OLD | NEW |