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

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

Issue 656033009: Convert ARRAYSIZE_UNSAFE -> arraysize in base/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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/metrics/field_trial_unittest.cc ('k') | base/strings/string_split_unittest.cc » ('j') | 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 <errno.h> 5 #include <errno.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <limits> 10 #include <limits>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 static const struct { 66 static const struct {
67 uint64 input; 67 uint64 input;
68 std::string output; 68 std::string output;
69 } cases[] = { 69 } cases[] = {
70 {0, "0"}, 70 {0, "0"},
71 {42, "42"}, 71 {42, "42"},
72 {INT_MAX, "2147483647"}, 72 {INT_MAX, "2147483647"},
73 {kuint64max, "18446744073709551615"}, 73 {kuint64max, "18446744073709551615"},
74 }; 74 };
75 75
76 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) 76 for (size_t i = 0; i < arraysize(cases); ++i)
77 EXPECT_EQ(cases[i].output, Uint64ToString(cases[i].input)); 77 EXPECT_EQ(cases[i].output, Uint64ToString(cases[i].input));
78 } 78 }
79 79
80 TEST(StringNumberConversionsTest, SizeTToString) { 80 TEST(StringNumberConversionsTest, SizeTToString) {
81 size_t size_t_max = std::numeric_limits<size_t>::max(); 81 size_t size_t_max = std::numeric_limits<size_t>::max();
82 std::string size_t_max_string = StringPrintf("%" PRIuS, size_t_max); 82 std::string size_t_max_string = StringPrintf("%" PRIuS, size_t_max);
83 83
84 static const struct { 84 static const struct {
85 size_t input; 85 size_t input;
86 std::string output; 86 std::string output;
87 } cases[] = { 87 } cases[] = {
88 {0, "0"}, 88 {0, "0"},
89 {9, "9"}, 89 {9, "9"},
90 {42, "42"}, 90 {42, "42"},
91 {INT_MAX, "2147483647"}, 91 {INT_MAX, "2147483647"},
92 {2147483648U, "2147483648"}, 92 {2147483648U, "2147483648"},
93 #if SIZE_MAX > 4294967295U 93 #if SIZE_MAX > 4294967295U
94 {99999999999U, "99999999999"}, 94 {99999999999U, "99999999999"},
95 #endif 95 #endif
96 {size_t_max, size_t_max_string}, 96 {size_t_max, size_t_max_string},
97 }; 97 };
98 98
99 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) 99 for (size_t i = 0; i < arraysize(cases); ++i)
100 EXPECT_EQ(cases[i].output, Uint64ToString(cases[i].input)); 100 EXPECT_EQ(cases[i].output, Uint64ToString(cases[i].input));
101 } 101 }
102 102
103 TEST(StringNumberConversionsTest, StringToInt) { 103 TEST(StringNumberConversionsTest, StringToInt) {
104 static const struct { 104 static const struct {
105 std::string input; 105 std::string input;
106 int output; 106 int output;
107 bool success; 107 bool success;
108 } cases[] = { 108 } cases[] = {
109 {"0", 0, true}, 109 {"0", 0, true},
(...skipping 15 matching lines...) Expand all
125 {"++123", 0, false}, 125 {"++123", 0, false},
126 {"-+123", 0, false}, 126 {"-+123", 0, false},
127 {"+-123", 0, false}, 127 {"+-123", 0, false},
128 {"-", 0, false}, 128 {"-", 0, false},
129 {"-2147483649", INT_MIN, false}, 129 {"-2147483649", INT_MIN, false},
130 {"-99999999999", INT_MIN, false}, 130 {"-99999999999", INT_MIN, false},
131 {"2147483648", INT_MAX, false}, 131 {"2147483648", INT_MAX, false},
132 {"99999999999", INT_MAX, false}, 132 {"99999999999", INT_MAX, false},
133 }; 133 };
134 134
135 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 135 for (size_t i = 0; i < arraysize(cases); ++i) {
136 int output = 0; 136 int output = 0;
137 EXPECT_EQ(cases[i].success, StringToInt(cases[i].input, &output)); 137 EXPECT_EQ(cases[i].success, StringToInt(cases[i].input, &output));
138 EXPECT_EQ(cases[i].output, output); 138 EXPECT_EQ(cases[i].output, output);
139 139
140 string16 utf16_input = UTF8ToUTF16(cases[i].input); 140 string16 utf16_input = UTF8ToUTF16(cases[i].input);
141 output = 0; 141 output = 0;
142 EXPECT_EQ(cases[i].success, StringToInt(utf16_input, &output)); 142 EXPECT_EQ(cases[i].success, StringToInt(utf16_input, &output));
143 EXPECT_EQ(cases[i].output, output); 143 EXPECT_EQ(cases[i].output, output);
144 } 144 }
145 145
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 {"-+123", 0, false}, 189 {"-+123", 0, false},
190 {"+-123", 0, false}, 190 {"+-123", 0, false},
191 {"-", 0, false}, 191 {"-", 0, false},
192 {"-2147483649", 0, false}, 192 {"-2147483649", 0, false},
193 {"-99999999999", 0, false}, 193 {"-99999999999", 0, false},
194 {"4294967295", UINT_MAX, true}, 194 {"4294967295", UINT_MAX, true},
195 {"4294967296", UINT_MAX, false}, 195 {"4294967296", UINT_MAX, false},
196 {"99999999999", UINT_MAX, false}, 196 {"99999999999", UINT_MAX, false},
197 }; 197 };
198 198
199 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 199 for (size_t i = 0; i < arraysize(cases); ++i) {
200 unsigned output = 0; 200 unsigned output = 0;
201 EXPECT_EQ(cases[i].success, StringToUint(cases[i].input, &output)); 201 EXPECT_EQ(cases[i].success, StringToUint(cases[i].input, &output));
202 EXPECT_EQ(cases[i].output, output); 202 EXPECT_EQ(cases[i].output, output);
203 203
204 string16 utf16_input = UTF8ToUTF16(cases[i].input); 204 string16 utf16_input = UTF8ToUTF16(cases[i].input);
205 output = 0; 205 output = 0;
206 EXPECT_EQ(cases[i].success, StringToUint(utf16_input, &output)); 206 EXPECT_EQ(cases[i].success, StringToUint(utf16_input, &output));
207 EXPECT_EQ(cases[i].output, output); 207 EXPECT_EQ(cases[i].output, output);
208 } 208 }
209 209
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 {"++123", 0, false}, 259 {"++123", 0, false},
260 {"-+123", 0, false}, 260 {"-+123", 0, false},
261 {"+-123", 0, false}, 261 {"+-123", 0, false},
262 {"-", 0, false}, 262 {"-", 0, false},
263 {"-9223372036854775809", kint64min, false}, 263 {"-9223372036854775809", kint64min, false},
264 {"-99999999999999999999", kint64min, false}, 264 {"-99999999999999999999", kint64min, false},
265 {"9223372036854775808", kint64max, false}, 265 {"9223372036854775808", kint64max, false},
266 {"99999999999999999999", kint64max, false}, 266 {"99999999999999999999", kint64max, false},
267 }; 267 };
268 268
269 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 269 for (size_t i = 0; i < arraysize(cases); ++i) {
270 int64 output = 0; 270 int64 output = 0;
271 EXPECT_EQ(cases[i].success, StringToInt64(cases[i].input, &output)); 271 EXPECT_EQ(cases[i].success, StringToInt64(cases[i].input, &output));
272 EXPECT_EQ(cases[i].output, output); 272 EXPECT_EQ(cases[i].output, output);
273 273
274 string16 utf16_input = UTF8ToUTF16(cases[i].input); 274 string16 utf16_input = UTF8ToUTF16(cases[i].input);
275 output = 0; 275 output = 0;
276 EXPECT_EQ(cases[i].success, StringToInt64(utf16_input, &output)); 276 EXPECT_EQ(cases[i].success, StringToInt64(utf16_input, &output));
277 EXPECT_EQ(cases[i].output, output); 277 EXPECT_EQ(cases[i].output, output);
278 } 278 }
279 279
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 {"+-123", 0, false}, 326 {"+-123", 0, false},
327 {"-", 0, false}, 327 {"-", 0, false},
328 {"-9223372036854775809", 0, false}, 328 {"-9223372036854775809", 0, false},
329 {"-99999999999999999999", 0, false}, 329 {"-99999999999999999999", 0, false},
330 {"9223372036854775808", GG_UINT64_C(9223372036854775808), true}, 330 {"9223372036854775808", GG_UINT64_C(9223372036854775808), true},
331 {"99999999999999999999", kuint64max, false}, 331 {"99999999999999999999", kuint64max, false},
332 {"18446744073709551615", kuint64max, true}, 332 {"18446744073709551615", kuint64max, true},
333 {"18446744073709551616", kuint64max, false}, 333 {"18446744073709551616", kuint64max, false},
334 }; 334 };
335 335
336 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 336 for (size_t i = 0; i < arraysize(cases); ++i) {
337 uint64 output = 0; 337 uint64 output = 0;
338 EXPECT_EQ(cases[i].success, StringToUint64(cases[i].input, &output)); 338 EXPECT_EQ(cases[i].success, StringToUint64(cases[i].input, &output));
339 EXPECT_EQ(cases[i].output, output); 339 EXPECT_EQ(cases[i].output, output);
340 340
341 string16 utf16_input = UTF8ToUTF16(cases[i].input); 341 string16 utf16_input = UTF8ToUTF16(cases[i].input);
342 output = 0; 342 output = 0;
343 EXPECT_EQ(cases[i].success, StringToUint64(utf16_input, &output)); 343 EXPECT_EQ(cases[i].success, StringToUint64(utf16_input, &output));
344 EXPECT_EQ(cases[i].output, output); 344 EXPECT_EQ(cases[i].output, output);
345 } 345 }
346 346
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 {"++123", 0, false}, 395 {"++123", 0, false},
396 {"-+123", 0, false}, 396 {"-+123", 0, false},
397 {"+-123", 0, false}, 397 {"+-123", 0, false},
398 {"-", 0, false}, 398 {"-", 0, false},
399 {"-9223372036854775809", 0, false}, 399 {"-9223372036854775809", 0, false},
400 {"-99999999999999999999", 0, false}, 400 {"-99999999999999999999", 0, false},
401 {"999999999999999999999999", size_t_max, false}, 401 {"999999999999999999999999", size_t_max, false},
402 {size_t_max_string, size_t_max, true}, 402 {size_t_max_string, size_t_max, true},
403 }; 403 };
404 404
405 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 405 for (size_t i = 0; i < arraysize(cases); ++i) {
406 size_t output = 0; 406 size_t output = 0;
407 EXPECT_EQ(cases[i].success, StringToSizeT(cases[i].input, &output)); 407 EXPECT_EQ(cases[i].success, StringToSizeT(cases[i].input, &output));
408 EXPECT_EQ(cases[i].output, output); 408 EXPECT_EQ(cases[i].output, output);
409 409
410 string16 utf16_input = UTF8ToUTF16(cases[i].input); 410 string16 utf16_input = UTF8ToUTF16(cases[i].input);
411 output = 0; 411 output = 0;
412 EXPECT_EQ(cases[i].success, StringToSizeT(utf16_input, &output)); 412 EXPECT_EQ(cases[i].success, StringToSizeT(utf16_input, &output));
413 EXPECT_EQ(cases[i].output, output); 413 EXPECT_EQ(cases[i].output, output);
414 } 414 }
415 415
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 {"45 ", 0x45, false}, 458 {"45 ", 0x45, false},
459 {"45:", 0x45, false}, 459 {"45:", 0x45, false},
460 {"efgh", 0xef, false}, 460 {"efgh", 0xef, false},
461 {"0xefgh", 0xef, false}, 461 {"0xefgh", 0xef, false},
462 {"hgfe", 0, false}, 462 {"hgfe", 0, false},
463 {"-", 0, false}, 463 {"-", 0, false},
464 {"", 0, false}, 464 {"", 0, false},
465 {"0x", 0, false}, 465 {"0x", 0, false},
466 }; 466 };
467 467
468 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 468 for (size_t i = 0; i < arraysize(cases); ++i) {
469 int output = 0; 469 int output = 0;
470 EXPECT_EQ(cases[i].success, HexStringToInt(cases[i].input, &output)); 470 EXPECT_EQ(cases[i].success, HexStringToInt(cases[i].input, &output));
471 EXPECT_EQ(cases[i].output, output); 471 EXPECT_EQ(cases[i].output, output);
472 } 472 }
473 // One additional test to verify that conversion of numbers in strings with 473 // One additional test to verify that conversion of numbers in strings with
474 // embedded NUL characters. The NUL and extra data after it should be 474 // embedded NUL characters. The NUL and extra data after it should be
475 // interpreted as junk after the number. 475 // interpreted as junk after the number.
476 const char input[] = "0xc0ffee\0" "9"; 476 const char input[] = "0xc0ffee\0" "9";
477 std::string input_string(input, arraysize(input) - 1); 477 std::string input_string(input, arraysize(input) - 1);
478 int output; 478 int output;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 {"45 ", 0x45, false}, 518 {"45 ", 0x45, false},
519 {"45:", 0x45, false}, 519 {"45:", 0x45, false},
520 {"efgh", 0xef, false}, 520 {"efgh", 0xef, false},
521 {"0xefgh", 0xef, false}, 521 {"0xefgh", 0xef, false},
522 {"hgfe", 0, false}, 522 {"hgfe", 0, false},
523 {"-", 0, false}, 523 {"-", 0, false},
524 {"", 0, false}, 524 {"", 0, false},
525 {"0x", 0, false}, 525 {"0x", 0, false},
526 }; 526 };
527 527
528 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 528 for (size_t i = 0; i < arraysize(cases); ++i) {
529 uint32 output = 0; 529 uint32 output = 0;
530 EXPECT_EQ(cases[i].success, HexStringToUInt(cases[i].input, &output)); 530 EXPECT_EQ(cases[i].success, HexStringToUInt(cases[i].input, &output));
531 EXPECT_EQ(cases[i].output, output); 531 EXPECT_EQ(cases[i].output, output);
532 } 532 }
533 // One additional test to verify that conversion of numbers in strings with 533 // One additional test to verify that conversion of numbers in strings with
534 // embedded NUL characters. The NUL and extra data after it should be 534 // embedded NUL characters. The NUL and extra data after it should be
535 // interpreted as junk after the number. 535 // interpreted as junk after the number.
536 const char input[] = "0xc0ffee\0" "9"; 536 const char input[] = "0xc0ffee\0" "9";
537 std::string input_string(input, arraysize(input) - 1); 537 std::string input_string(input, arraysize(input) - 1);
538 uint32 output; 538 uint32 output;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 {"45 ", 0x45, false}, 575 {"45 ", 0x45, false},
576 {"45:", 0x45, false}, 576 {"45:", 0x45, false},
577 {"efgh", 0xef, false}, 577 {"efgh", 0xef, false},
578 {"0xefgh", 0xef, false}, 578 {"0xefgh", 0xef, false},
579 {"hgfe", 0, false}, 579 {"hgfe", 0, false},
580 {"-", 0, false}, 580 {"-", 0, false},
581 {"", 0, false}, 581 {"", 0, false},
582 {"0x", 0, false}, 582 {"0x", 0, false},
583 }; 583 };
584 584
585 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 585 for (size_t i = 0; i < arraysize(cases); ++i) {
586 int64 output = 0; 586 int64 output = 0;
587 EXPECT_EQ(cases[i].success, HexStringToInt64(cases[i].input, &output)); 587 EXPECT_EQ(cases[i].success, HexStringToInt64(cases[i].input, &output));
588 EXPECT_EQ(cases[i].output, output); 588 EXPECT_EQ(cases[i].output, output);
589 } 589 }
590 // One additional test to verify that conversion of numbers in strings with 590 // One additional test to verify that conversion of numbers in strings with
591 // embedded NUL characters. The NUL and extra data after it should be 591 // embedded NUL characters. The NUL and extra data after it should be
592 // interpreted as junk after the number. 592 // interpreted as junk after the number.
593 const char input[] = "0xc0ffee\0" "9"; 593 const char input[] = "0xc0ffee\0" "9";
594 std::string input_string(input, arraysize(input) - 1); 594 std::string input_string(input, arraysize(input) - 1);
595 int64 output; 595 int64 output;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 {"45 ", 0x45, false}, 637 {"45 ", 0x45, false},
638 {"45:", 0x45, false}, 638 {"45:", 0x45, false},
639 {"efgh", 0xef, false}, 639 {"efgh", 0xef, false},
640 {"0xefgh", 0xef, false}, 640 {"0xefgh", 0xef, false},
641 {"hgfe", 0, false}, 641 {"hgfe", 0, false},
642 {"-", 0, false}, 642 {"-", 0, false},
643 {"", 0, false}, 643 {"", 0, false},
644 {"0x", 0, false}, 644 {"0x", 0, false},
645 }; 645 };
646 646
647 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 647 for (size_t i = 0; i < arraysize(cases); ++i) {
648 uint64 output = 0; 648 uint64 output = 0;
649 EXPECT_EQ(cases[i].success, HexStringToUInt64(cases[i].input, &output)); 649 EXPECT_EQ(cases[i].success, HexStringToUInt64(cases[i].input, &output));
650 EXPECT_EQ(cases[i].output, output); 650 EXPECT_EQ(cases[i].output, output);
651 } 651 }
652 // One additional test to verify that conversion of numbers in strings with 652 // One additional test to verify that conversion of numbers in strings with
653 // embedded NUL characters. The NUL and extra data after it should be 653 // embedded NUL characters. The NUL and extra data after it should be
654 // interpreted as junk after the number. 654 // interpreted as junk after the number.
655 const char input[] = "0xc0ffee\0" "9"; 655 const char input[] = "0xc0ffee\0" "9";
656 std::string input_string(input, arraysize(input) - 1); 656 std::string input_string(input, arraysize(input) - 1);
657 uint64 output; 657 uint64 output;
(...skipping 21 matching lines...) Expand all
679 {"0f", "\xf", 1, true}, 679 {"0f", "\xf", 1, true},
680 {"45 ", "\x45", 1, false}, 680 {"45 ", "\x45", 1, false},
681 {"efgh", "\xef", 1, false}, 681 {"efgh", "\xef", 1, false},
682 {"", "", 0, false}, 682 {"", "", 0, false},
683 {"0123456789ABCDEF", "\x01\x23\x45\x67\x89\xAB\xCD\xEF", 8, true}, 683 {"0123456789ABCDEF", "\x01\x23\x45\x67\x89\xAB\xCD\xEF", 8, true},
684 {"0123456789ABCDEF012345", 684 {"0123456789ABCDEF012345",
685 "\x01\x23\x45\x67\x89\xAB\xCD\xEF\x01\x23\x45", 11, true}, 685 "\x01\x23\x45\x67\x89\xAB\xCD\xEF\x01\x23\x45", 11, true},
686 }; 686 };
687 687
688 688
689 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 689 for (size_t i = 0; i < arraysize(cases); ++i) {
690 std::vector<uint8> output; 690 std::vector<uint8> output;
691 std::vector<uint8> compare; 691 std::vector<uint8> compare;
692 EXPECT_EQ(cases[i].success, HexStringToBytes(cases[i].input, &output)) << 692 EXPECT_EQ(cases[i].success, HexStringToBytes(cases[i].input, &output)) <<
693 i << ": " << cases[i].input; 693 i << ": " << cases[i].input;
694 for (size_t j = 0; j < cases[i].output_len; ++j) 694 for (size_t j = 0; j < cases[i].output_len; ++j)
695 compare.push_back(static_cast<uint8>(cases[i].output[j])); 695 compare.push_back(static_cast<uint8>(cases[i].output[j]));
696 ASSERT_EQ(output.size(), compare.size()) << i << ": " << cases[i].input; 696 ASSERT_EQ(output.size(), compare.size()) << i << ": " << cases[i].input;
697 EXPECT_TRUE(std::equal(output.begin(), output.end(), compare.begin())) << 697 EXPECT_TRUE(std::equal(output.begin(), output.end(), compare.begin())) <<
698 i << ": " << cases[i].input; 698 i << ": " << cases[i].input;
699 } 699 }
(...skipping 28 matching lines...) Expand all
728 {"123e ", 123.0, false}, 728 {"123e ", 123.0, false},
729 {"123e", 123.0, false}, 729 {"123e", 123.0, false},
730 {" 2.99", 2.99, false}, 730 {" 2.99", 2.99, false},
731 {"1e3.4", 1000.0, false}, 731 {"1e3.4", 1000.0, false},
732 {"nothing", 0.0, false}, 732 {"nothing", 0.0, false},
733 {"-", 0.0, false}, 733 {"-", 0.0, false},
734 {"+", 0.0, false}, 734 {"+", 0.0, false},
735 {"", 0.0, false}, 735 {"", 0.0, false},
736 }; 736 };
737 737
738 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 738 for (size_t i = 0; i < arraysize(cases); ++i) {
739 double output; 739 double output;
740 errno = 1; 740 errno = 1;
741 EXPECT_EQ(cases[i].success, StringToDouble(cases[i].input, &output)); 741 EXPECT_EQ(cases[i].success, StringToDouble(cases[i].input, &output));
742 if (cases[i].success) 742 if (cases[i].success)
743 EXPECT_EQ(1, errno) << i; // confirm that errno is unchanged. 743 EXPECT_EQ(1, errno) << i; // confirm that errno is unchanged.
744 EXPECT_DOUBLE_EQ(cases[i].output, output); 744 EXPECT_DOUBLE_EQ(cases[i].output, output);
745 } 745 }
746 746
747 // One additional test to verify that conversion of numbers in strings with 747 // One additional test to verify that conversion of numbers in strings with
748 // embedded NUL characters. The NUL and extra data after it should be 748 // embedded NUL characters. The NUL and extra data after it should be
(...skipping 12 matching lines...) Expand all
761 } cases[] = { 761 } cases[] = {
762 {0.0, "0"}, 762 {0.0, "0"},
763 {1.25, "1.25"}, 763 {1.25, "1.25"},
764 {1.33518e+012, "1.33518e+12"}, 764 {1.33518e+012, "1.33518e+12"},
765 {1.33489e+012, "1.33489e+12"}, 765 {1.33489e+012, "1.33489e+12"},
766 {1.33505e+012, "1.33505e+12"}, 766 {1.33505e+012, "1.33505e+12"},
767 {1.33545e+009, "1335450000"}, 767 {1.33545e+009, "1335450000"},
768 {1.33503e+009, "1335030000"}, 768 {1.33503e+009, "1335030000"},
769 }; 769 };
770 770
771 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 771 for (size_t i = 0; i < arraysize(cases); ++i) {
772 EXPECT_EQ(cases[i].expected, DoubleToString(cases[i].input)); 772 EXPECT_EQ(cases[i].expected, DoubleToString(cases[i].input));
773 } 773 }
774 774
775 // The following two values were seen in crashes in the wild. 775 // The following two values were seen in crashes in the wild.
776 const char input_bytes[8] = {0, 0, 0, 0, '\xee', '\x6d', '\x73', '\x42'}; 776 const char input_bytes[8] = {0, 0, 0, 0, '\xee', '\x6d', '\x73', '\x42'};
777 double input = 0; 777 double input = 0;
778 memcpy(&input, input_bytes, arraysize(input_bytes)); 778 memcpy(&input, input_bytes, arraysize(input_bytes));
779 EXPECT_EQ("1335179083776", DoubleToString(input)); 779 EXPECT_EQ("1335179083776", DoubleToString(input));
780 const char input_bytes2[8] = 780 const char input_bytes2[8] =
781 {0, 0, 0, '\xa0', '\xda', '\x6c', '\x73', '\x42'}; 781 {0, 0, 0, '\xa0', '\xda', '\x6c', '\x73', '\x42'};
782 input = 0; 782 input = 0;
783 memcpy(&input, input_bytes2, arraysize(input_bytes2)); 783 memcpy(&input, input_bytes2, arraysize(input_bytes2));
784 EXPECT_EQ("1334890332160", DoubleToString(input)); 784 EXPECT_EQ("1334890332160", DoubleToString(input));
785 } 785 }
786 786
787 TEST(StringNumberConversionsTest, HexEncode) { 787 TEST(StringNumberConversionsTest, HexEncode) {
788 std::string hex(HexEncode(NULL, 0)); 788 std::string hex(HexEncode(NULL, 0));
789 EXPECT_EQ(hex.length(), 0U); 789 EXPECT_EQ(hex.length(), 0U);
790 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; 790 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81};
791 hex = HexEncode(bytes, sizeof(bytes)); 791 hex = HexEncode(bytes, sizeof(bytes));
792 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); 792 EXPECT_EQ(hex.compare("01FF02FE038081"), 0);
793 } 793 }
794 794
795 } // namespace base 795 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/field_trial_unittest.cc ('k') | base/strings/string_split_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698