Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: base/string_number_conversions_unittest.cc

Issue 7584031: base::HexStringToInt conversion function treats the string "0x" as a valid hex number (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/string_number_conversions.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « base/string_number_conversions.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698