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

Unified Diff: base/string_number_conversions_unittest.cc

Issue 11293078: Integrating Online Wallet into Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes from latest code review Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: base/string_number_conversions_unittest.cc
diff --git a/base/string_number_conversions_unittest.cc b/base/string_number_conversions_unittest.cc
index 30b9b8c06ea416ee82820521f9b6f69ec5e16b1e..af4b75897aa81262cd7f21267a73e3d715903012 100644
--- a/base/string_number_conversions_unittest.cc
+++ b/base/string_number_conversions_unittest.cc
@@ -252,6 +252,63 @@ TEST(StringNumberConversionsTest, HexStringToInt) {
EXPECT_EQ(0xc0ffee, output);
}
+TEST(StringNumberConversionsTest, HexStringToInt64) {
+ static const struct {
+ std::string input;
+ int64 output;
+ bool success;
+ } cases[] = {
+ {"0", 0, true},
+ {"42", 66, true},
+ {"-42", -66, true},
+ {"+42", 66, true},
+ {"7fffffff", INT_MAX, true},
+ {"80000000", 0x80000000, true},
+ {"ffffffff", 0xffffffff, true},
+ {"DeadBeef", 0xdeadbeef, true},
+ {"0x40acd88557b", 0x40acd88557b, true},
+ {"0x42", 66, true},
+ {"-0x42", -66, true},
+ {"+0x42", 66, true},
+ {"0x7fffffff", INT_MAX, true},
+ {"0x80000000", 0x80000000, true},
+ {"0xffffffff", 0xffffffff, true},
+ {"0XDeadBeef", 0xdeadbeef, true},
+ {"100000000", 0x100000000, true},
+ {"0xffffffffffffffff", -1, true},
+ {"0x7fffffffffffffff", kint64max, true},
+ {"0x8000000000000000", kint64min, true},
+ {"0x0f", 15, true},
+ {"0f", 15, true},
+ {" 45", 0x45, false},
+ {"\t\n\v\f\r 0x45", 0x45, false},
+ {" 45", 0x45, false},
+ {"45 ", 0x45, false},
+ {"45:", 0x45, false},
+ {"efgh", 0xef, false},
+ {"0xefgh", 0xef, false},
+ {"hgfe", 0, false},
+ {"10000000000000000", -1, false},
+ {"-", 0, false},
+ {"", 0, false},
+ {"0x", 0, false},
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ int64 output = 0;
+ EXPECT_EQ(cases[i].success, HexStringToInt64(cases[i].input, &output));
+ EXPECT_EQ(cases[i].output, output);
+ }
+ // One additional test to verify that conversion of numbers in strings with
+ // embedded NUL characters. The NUL and extra data after it should be
+ // interpreted as junk after the number.
+ const char input[] = "0xc0ffee\09";
+ std::string input_string(input, arraysize(input) - 1);
+ int64 output;
+ EXPECT_FALSE(HexStringToInt64(input_string, &output));
+ EXPECT_EQ(0xc0ffee, output);
+}
+
TEST(StringNumberConversionsTest, HexStringToBytes) {
static const struct {
const std::string input;

Powered by Google App Engine
This is Rietveld 408576698