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

Side by Side Diff: base/strings/string_number_conversions_unittest.cc

Issue 1212653005: [ADANDONED] Helper code for finding problematic uses of IntToString variants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@int_to_string_cleanup_net
Patch Set: Disable warnings on IntToString's own tests. Created 5 years, 3 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
« no previous file with comments | « base/strings/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) 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 "base/strings/string_number_conversions.h" 5 #include "base/strings/string_number_conversions.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <stdio.h> 9 #include <stdio.h>
10 10
(...skipping 11 matching lines...) Expand all
22 22
23 template <typename INT> 23 template <typename INT>
24 struct IntToStringTest { 24 struct IntToStringTest {
25 INT num; 25 INT num;
26 const char* sexpected; 26 const char* sexpected;
27 const char* uexpected; 27 const char* uexpected;
28 }; 28 };
29 29
30 } // namespace 30 } // namespace
31 31
32 #if !defined(STRING_NUMBER_CONVERSIONS_DETECT_RISKY_CONVERSIONS)
33
32 TEST(StringNumberConversionsTest, IntToString) { 34 TEST(StringNumberConversionsTest, IntToString) {
33 static const IntToStringTest<int> int_tests[] = { 35 static const IntToStringTest<int> int_tests[] = {
34 { 0, "0", "0" }, 36 { 0, "0", "0" },
35 { -1, "-1", "4294967295" }, 37 { -1, "-1", "4294967295" },
36 { std::numeric_limits<int>::max(), "2147483647", "2147483647" }, 38 { std::numeric_limits<int>::max(), "2147483647", "2147483647" },
37 { std::numeric_limits<int>::min(), "-2147483648", "2147483648" }, 39 { std::numeric_limits<int>::min(), "-2147483648", "2147483648" },
38 }; 40 };
39 static const IntToStringTest<int64> int64_tests[] = { 41 static const IntToStringTest<int64> int64_tests[] = {
40 { 0, "0", "0" }, 42 { 0, "0", "0" },
41 { -1, "-1", "18446744073709551615" }, 43 { -1, "-1", "18446744073709551615" },
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 uint64 output; 355 uint64 output;
354 EXPECT_FALSE(StringToUint64(input_string, &output)); 356 EXPECT_FALSE(StringToUint64(input_string, &output));
355 EXPECT_EQ(6U, output); 357 EXPECT_EQ(6U, output);
356 358
357 string16 utf16_input = UTF8ToUTF16(input_string); 359 string16 utf16_input = UTF8ToUTF16(input_string);
358 output = 0; 360 output = 0;
359 EXPECT_FALSE(StringToUint64(utf16_input, &output)); 361 EXPECT_FALSE(StringToUint64(utf16_input, &output));
360 EXPECT_EQ(6U, output); 362 EXPECT_EQ(6U, output);
361 } 363 }
362 364
365 #endif // !defined(STRING_NUMBER_CONVERSIONS_DETECT_RISKY_CONVERSIONS)
366
363 TEST(StringNumberConversionsTest, StringToSizeT) { 367 TEST(StringNumberConversionsTest, StringToSizeT) {
364 size_t size_t_max = std::numeric_limits<size_t>::max(); 368 size_t size_t_max = std::numeric_limits<size_t>::max();
365 std::string size_t_max_string = StringPrintf("%" PRIuS, size_t_max); 369 std::string size_t_max_string = StringPrintf("%" PRIuS, size_t_max);
366 370
367 static const struct { 371 static const struct {
368 std::string input; 372 std::string input;
369 size_t output; 373 size_t output;
370 bool success; 374 bool success;
371 } cases[] = { 375 } cases[] = {
372 {"0", 0, true}, 376 {"0", 0, true},
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 791
788 TEST(StringNumberConversionsTest, HexEncode) { 792 TEST(StringNumberConversionsTest, HexEncode) {
789 std::string hex(HexEncode(NULL, 0)); 793 std::string hex(HexEncode(NULL, 0));
790 EXPECT_EQ(hex.length(), 0U); 794 EXPECT_EQ(hex.length(), 0U);
791 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; 795 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81};
792 hex = HexEncode(bytes, sizeof(bytes)); 796 hex = HexEncode(bytes, sizeof(bytes));
793 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); 797 EXPECT_EQ(hex.compare("01FF02FE038081"), 0);
794 } 798 }
795 799
796 } // namespace base 800 } // namespace base
OLDNEW
« no previous file with comments | « base/strings/string_number_conversions.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698