Chromium Code Reviews| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 } | 73 } |
| 74 | 74 |
| 75 TEST(StringNumberConversionsTest, StringToInt) { | 75 TEST(StringNumberConversionsTest, StringToInt) { |
| 76 static const struct { | 76 static const struct { |
| 77 std::string input; | 77 std::string input; |
| 78 int output; | 78 int output; |
| 79 bool success; | 79 bool success; |
| 80 } cases[] = { | 80 } cases[] = { |
| 81 {"0", 0, true}, | 81 {"0", 0, true}, |
| 82 {"42", 42, true}, | 82 {"42", 42, true}, |
| 83 {"42\x99", 42, false}, | |
| 84 {"\x99" "42\x99", 0, false}, | |
| 83 {"-2147483648", INT_MIN, true}, | 85 {"-2147483648", INT_MIN, true}, |
| 84 {"2147483647", INT_MAX, true}, | 86 {"2147483647", INT_MAX, true}, |
| 85 {"", 0, false}, | 87 {"", 0, false}, |
| 86 {" 42", 42, false}, | 88 {" 42", 42, false}, |
| 87 {"42 ", 42, false}, | 89 {"42 ", 42, false}, |
| 88 {"\t\n\v\f\r 42", 42, false}, | 90 {"\t\n\v\f\r 42", 42, false}, |
| 89 {"blah42", 0, false}, | 91 {"blah42", 0, false}, |
| 90 {"42blah", 42, false}, | 92 {"42blah", 42, false}, |
| 91 {"blah42blah", 0, false}, | 93 {"blah42blah", 0, false}, |
| 92 {"-273.15", -273, false}, | 94 {"-273.15", -273, false}, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 EXPECT_FALSE(StringToInt(utf16_input, &output)); | 156 EXPECT_FALSE(StringToInt(utf16_input, &output)); |
| 155 EXPECT_EQ(6, output); | 157 EXPECT_EQ(6, output); |
| 156 output = 0; | 158 output = 0; |
| 157 EXPECT_FALSE(StringToInt(utf16_input.begin(), utf16_input.end(), &output)); | 159 EXPECT_FALSE(StringToInt(utf16_input.begin(), utf16_input.end(), &output)); |
| 158 EXPECT_EQ(6, output); | 160 EXPECT_EQ(6, output); |
| 159 output = 0; | 161 output = 0; |
| 160 EXPECT_FALSE(StringToInt(utf16_chars, | 162 EXPECT_FALSE(StringToInt(utf16_chars, |
| 161 utf16_chars + utf16_input.length(), | 163 utf16_chars + utf16_input.length(), |
| 162 &output)); | 164 &output)); |
| 163 EXPECT_EQ(6, output); | 165 EXPECT_EQ(6, output); |
| 166 | |
| 167 output = 0; | |
| 168 const char16 negative_wide_input[] = { 0xFF4D, '4', '2', 0}; | |
|
MAD
2010/11/02 18:53:25
I was wondering about that... But didn't mention s
erikwright (departed)
2010/11/02 19:32:22
The other one did build on Win (locally), but I wa
| |
| 169 EXPECT_FALSE(StringToInt(string16(negative_wide_input), &output)); | |
| 170 EXPECT_EQ(0, output); | |
| 164 } | 171 } |
| 165 | 172 |
| 166 TEST(StringNumberConversionsTest, StringToInt64) { | 173 TEST(StringNumberConversionsTest, StringToInt64) { |
| 167 static const struct { | 174 static const struct { |
| 168 std::string input; | 175 std::string input; |
| 169 int64 output; | 176 int64 output; |
| 170 bool success; | 177 bool success; |
| 171 } cases[] = { | 178 } cases[] = { |
| 172 {"0", 0, true}, | 179 {"0", 0, true}, |
| 173 {"42", 42, true}, | 180 {"42", 42, true}, |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 428 | 435 |
| 429 TEST(StringNumberConversionsTest, HexEncode) { | 436 TEST(StringNumberConversionsTest, HexEncode) { |
| 430 std::string hex(HexEncode(NULL, 0)); | 437 std::string hex(HexEncode(NULL, 0)); |
| 431 EXPECT_EQ(hex.length(), 0U); | 438 EXPECT_EQ(hex.length(), 0U); |
| 432 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; | 439 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; |
| 433 hex = HexEncode(bytes, sizeof(bytes)); | 440 hex = HexEncode(bytes, sizeof(bytes)); |
| 434 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); | 441 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); |
| 435 } | 442 } |
| 436 | 443 |
| 437 } // namespace base | 444 } // namespace base |
| OLD | NEW |