diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-21 05:35:36 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-21 05:35:36 +0000 |
commit | 2f98e25a97f5b824e110f8c0e5d95d76b4abf42b (patch) | |
tree | 84ee1ed4a9f3aa1604de5b12d3324ccadfc9234a /base/strings | |
parent | 7e1dab5af73dba19753166358cc0e0813aa8a436 (diff) | |
download | chromium_src-2f98e25a97f5b824e110f8c0e5d95d76b4abf42b.zip chromium_src-2f98e25a97f5b824e110f8c0e5d95d76b4abf42b.tar.gz chromium_src-2f98e25a97f5b824e110f8c0e5d95d76b4abf42b.tar.bz2 |
Revert 201204 "add more string -> unsigned number conversion uni..."
This change generates "integer constant is too large for 'unsigned long' type" compile error on "Google Chrome Linux" buildbot
> add more string -> unsigned number conversion unit tests
>
> Add unit tests for the following functions in base:
> StringToUint
> StringToUint64
> StringToSizeT
>
> Review URL: https://chromiumcodereview.appspot.com/14794002
TBR=mostynb@opera.com
Review URL: https://codereview.chromium.org/15464016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201237 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/strings')
-rw-r--r-- | base/strings/string_number_conversions_unittest.cc | 197 |
1 files changed, 0 insertions, 197 deletions
diff --git a/base/strings/string_number_conversions_unittest.cc b/base/strings/string_number_conversions_unittest.cc index a347022..5ae59d3 100644 --- a/base/strings/string_number_conversions_unittest.cc +++ b/base/strings/string_number_conversions_unittest.cc @@ -4,7 +4,6 @@ #include <errno.h> #include <math.h> -#include <stdint.h> #include <limits> @@ -137,70 +136,6 @@ TEST(StringNumberConversionsTest, StringToInt) { EXPECT_EQ(0, output); } -TEST(StringNumberConversionsTest, StringToUint) { - static const struct { - std::string input; - unsigned output; - bool success; - } cases[] = { - {"0", 0, true}, - {"42", 42, true}, - {"42\x99", 42, false}, - {"\x99" "42\x99", 0, false}, - {"-2147483648", 0, false}, - {"2147483647", INT_MAX, true}, - {"", 0, false}, - {" 42", 42, false}, - {"42 ", 42, false}, - {"\t\n\v\f\r 42", 42, false}, - {"blah42", 0, false}, - {"42blah", 42, false}, - {"blah42blah", 0, false}, - {"-273.15", 0, false}, - {"+98.6", 98, false}, - {"--123", 0, false}, - {"++123", 0, false}, - {"-+123", 0, false}, - {"+-123", 0, false}, - {"-", 0, false}, - {"-2147483649", 0, false}, - {"-99999999999", 0, false}, - {"4294967295", UINT_MAX, true}, - {"4294967296", UINT_MAX, false}, - {"99999999999", UINT_MAX, false}, - }; - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { - unsigned output = 0; - EXPECT_EQ(cases[i].success, StringToUint(cases[i].input, &output)); - EXPECT_EQ(cases[i].output, output); - - string16 utf16_input = UTF8ToUTF16(cases[i].input); - output = 0; - EXPECT_EQ(cases[i].success, StringToUint(utf16_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[] = "6\06"; - std::string input_string(input, arraysize(input) - 1); - unsigned output; - EXPECT_FALSE(StringToUint(input_string, &output)); - EXPECT_EQ(6U, output); - - string16 utf16_input = UTF8ToUTF16(input_string); - output = 0; - EXPECT_FALSE(StringToUint(utf16_input, &output)); - EXPECT_EQ(6U, output); - - output = 0; - const char16 negative_wide_input[] = { 0xFF4D, '4', '2', 0}; - EXPECT_FALSE(StringToUint(string16(negative_wide_input), &output)); - EXPECT_EQ(0U, output); -} - TEST(StringNumberConversionsTest, StringToInt64) { static const struct { std::string input; @@ -266,138 +201,6 @@ TEST(StringNumberConversionsTest, StringToInt64) { EXPECT_EQ(6, output); } -TEST(StringNumberConversionsTest, StringToUint64) { - static const struct { - std::string input; - uint64 output; - bool success; - } cases[] = { - {"0", 0, true}, - {"42", 42, true}, - {"-2147483648", 0, false}, - {"2147483647", INT_MAX, true}, - {"-2147483649", 0, false}, - {"-99999999999", 0, false}, - {"2147483648", GG_INT64_C(2147483648), true}, - {"99999999999", GG_INT64_C(99999999999), true}, - {"9223372036854775807", kint64max, true}, - {"-9223372036854775808", 0, false}, - {"09", 9, true}, - {"-09", 0, false}, - {"", 0, false}, - {" 42", 42, false}, - {"42 ", 42, false}, - {"0x42", 0, false}, - {"\t\n\v\f\r 42", 42, false}, - {"blah42", 0, false}, - {"42blah", 42, false}, - {"blah42blah", 0, false}, - {"-273.15", 0, false}, - {"+98.6", 98, false}, - {"--123", 0, false}, - {"++123", 0, false}, - {"-+123", 0, false}, - {"+-123", 0, false}, - {"-", 0, false}, - {"-9223372036854775809", 0, false}, - {"-99999999999999999999", 0, false}, - {"9223372036854775808", 9223372036854775808U, true}, - {"99999999999999999999", kuint64max, false}, - {"18446744073709551615", kuint64max, true}, - {"18446744073709551616", kuint64max, false}, - }; - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { - uint64 output = 0; - EXPECT_EQ(cases[i].success, StringToUint64(cases[i].input, &output)); - EXPECT_EQ(cases[i].output, output); - - string16 utf16_input = UTF8ToUTF16(cases[i].input); - output = 0; - EXPECT_EQ(cases[i].success, StringToUint64(utf16_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[] = "6\06"; - std::string input_string(input, arraysize(input) - 1); - uint64 output; - EXPECT_FALSE(StringToUint64(input_string, &output)); - EXPECT_EQ(6U, output); - - string16 utf16_input = UTF8ToUTF16(input_string); - output = 0; - EXPECT_FALSE(StringToUint64(utf16_input, &output)); - EXPECT_EQ(6U, output); -} - -TEST(StringNumberConversionsTest, StringToSizeT) { - static const struct { - std::string input; - size_t output; - bool success; - } cases[] = { - {"0", 0, true}, - {"42", 42, true}, - {"-2147483648", 0, false}, - {"2147483647", INT_MAX, true}, - {"-2147483649", 0, false}, - {"-99999999999", 0, false}, - {"2147483648", 2147483648U, true}, -#if SIZE_MAX > 4294967295U - {"99999999999", 99999999999U, true}, -#endif - {"-9223372036854775808", 0, false}, - {"09", 9, true}, - {"-09", 0, false}, - {"", 0, false}, - {" 42", 42, false}, - {"42 ", 42, false}, - {"0x42", 0, false}, - {"\t\n\v\f\r 42", 42, false}, - {"blah42", 0, false}, - {"42blah", 42, false}, - {"blah42blah", 0, false}, - {"-273.15", 0, false}, - {"+98.6", 98, false}, - {"--123", 0, false}, - {"++123", 0, false}, - {"-+123", 0, false}, - {"+-123", 0, false}, - {"-", 0, false}, - {"-9223372036854775809", 0, false}, - {"-99999999999999999999", 0, false}, - {"999999999999999999999999", std::numeric_limits<size_t>::max(), false}, - }; - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { - size_t output = 0; - EXPECT_EQ(cases[i].success, StringToSizeT(cases[i].input, &output)); - EXPECT_EQ(cases[i].output, output); - - string16 utf16_input = UTF8ToUTF16(cases[i].input); - output = 0; - EXPECT_EQ(cases[i].success, StringToSizeT(utf16_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[] = "6\06"; - std::string input_string(input, arraysize(input) - 1); - size_t output; - EXPECT_FALSE(StringToSizeT(input_string, &output)); - EXPECT_EQ(6U, output); - - string16 utf16_input = UTF8ToUTF16(input_string); - output = 0; - EXPECT_FALSE(StringToSizeT(utf16_input, &output)); - EXPECT_EQ(6U, output); -} - TEST(StringNumberConversionsTest, HexStringToInt) { static const struct { std::string input; |