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 <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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 string16 utf16_input = UTF8ToUTF16(input_string); | 197 string16 utf16_input = UTF8ToUTF16(input_string); |
198 output = 0; | 198 output = 0; |
199 EXPECT_FALSE(StringToInt64(utf16_input, &output)); | 199 EXPECT_FALSE(StringToInt64(utf16_input, &output)); |
200 EXPECT_EQ(6, output); | 200 EXPECT_EQ(6, output); |
201 } | 201 } |
202 | 202 |
203 TEST(StringNumberConversionsTest, HexStringToInt) { | 203 TEST(StringNumberConversionsTest, HexStringToInt) { |
204 static const struct { | 204 static const struct { |
205 std::string input; | 205 std::string input; |
206 int output; | 206 int64 output; |
207 bool success; | 207 bool success; |
208 } cases[] = { | 208 } cases[] = { |
209 {"0", 0, true}, | 209 {"0", 0, true}, |
210 {"42", 66, true}, | 210 {"42", 66, true}, |
211 {"-42", -66, true}, | 211 {"-42", -66, true}, |
212 {"+42", 66, true}, | 212 {"+42", 66, true}, |
213 {"7fffffff", INT_MAX, true}, | 213 {"7fffffff", INT_MAX, true}, |
214 {"80000000", INT_MIN, true}, | 214 {"80000000", INT_MIN, true}, |
215 {"ffffffff", -1, true}, | 215 {"ffffffff", -1, true}, |
216 {"DeadBeef", 0xdeadbeef, true}, | 216 {"DeadBeef", 0xdeadbeef, true}, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 376 |
377 TEST(StringNumberConversionsTest, HexEncode) { | 377 TEST(StringNumberConversionsTest, HexEncode) { |
378 std::string hex(HexEncode(NULL, 0)); | 378 std::string hex(HexEncode(NULL, 0)); |
379 EXPECT_EQ(hex.length(), 0U); | 379 EXPECT_EQ(hex.length(), 0U); |
380 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; | 380 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; |
381 hex = HexEncode(bytes, sizeof(bytes)); | 381 hex = HexEncode(bytes, sizeof(bytes)); |
382 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); | 382 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); |
383 } | 383 } |
384 | 384 |
385 } // namespace base | 385 } // namespace base |
OLD | NEW |