| Index: base/strings/string_number_conversions_unittest.cc
|
| diff --git a/base/strings/string_number_conversions_unittest.cc b/base/strings/string_number_conversions_unittest.cc
|
| index ac74e9f0a89b9cbbc6de0831cef795e7a393393f..9bd81c78ab49af0f3ee81bedba8677a967eddeb0 100644
|
| --- a/base/strings/string_number_conversions_unittest.cc
|
| +++ b/base/strings/string_number_conversions_unittest.cc
|
| @@ -309,6 +309,68 @@ TEST(StringNumberConversionsTest, HexStringToInt64) {
|
| EXPECT_EQ(0xc0ffee, output);
|
| }
|
|
|
| +TEST(StringNumberConversionsTest, HexStringToUInt64) {
|
| + static const struct {
|
| + std::string input;
|
| + uint64 output;
|
| + bool success;
|
| + } cases[] = {
|
| + {"0", 0, true},
|
| + {"42", 66, true},
|
| + {"-42", -66, true},
|
| + {"+42", 66, true},
|
| + {"40acd88557b", GG_INT64_C(4444444448123), true},
|
| + {"7fffffff", INT_MAX, true},
|
| + {"-80000000", INT_MIN, true},
|
| + {"ffffffff", 0xffffffff, true},
|
| + {"DeadBeef", 0xdeadbeef, true},
|
| + {"0x42", 66, true},
|
| + {"-0x42", -66, true},
|
| + {"+0x42", 66, true},
|
| + {"0x40acd88557b", GG_INT64_C(4444444448123), true},
|
| + {"0x7fffffff", INT_MAX, true},
|
| + {"-0x80000000", INT_MIN, true},
|
| + {"0xffffffff", 0xffffffff, true},
|
| + {"0XDeadBeef", 0xdeadbeef, true},
|
| + {"0x7fffffffffffffff", kint64max, true},
|
| + {"-0x8000000000000000", 0x8000000000000000L, true},
|
| + {"0x8000000000000000", 0x8000000000000000L, true},
|
| + {"-0x8000000000000001", 0x7fffffffffffffffL, true},
|
| + {"0xFFFFFFFFFFFFFFFF", kuint64max, true},
|
| + {"FFFFFFFFFFFFFFFF", kuint64max, true},
|
| + {"0x0000000000000000", 0, true},
|
| + {"0000000000000000", 0, true},
|
| + {"1FFFFFFFFFFFFFFFF", kuint64max, false}, // Overflow test.
|
| + {"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},
|
| + {"-", 0, false},
|
| + {"", 0, false},
|
| + {"0x", 0, false},
|
| + };
|
| +
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
|
| + uint64 output = 0;
|
| + EXPECT_EQ(cases[i].success, HexStringToUInt64(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);
|
| + uint64 output;
|
| + EXPECT_FALSE(HexStringToUInt64(input_string, &output));
|
| + EXPECT_EQ(0xc0ffeeU, output);
|
| +}
|
| +
|
| TEST(StringNumberConversionsTest, HexStringToBytes) {
|
| static const struct {
|
| const std::string input;
|
|
|