OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_util.h" | 5 #include "base/strings/string_util.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 | 662 |
663 // Verify the lower case as well. | 663 // Verify the lower case as well. |
664 EXPECT_EQ(10, HexDigitToInt('a')); | 664 EXPECT_EQ(10, HexDigitToInt('a')); |
665 EXPECT_EQ(11, HexDigitToInt('b')); | 665 EXPECT_EQ(11, HexDigitToInt('b')); |
666 EXPECT_EQ(12, HexDigitToInt('c')); | 666 EXPECT_EQ(12, HexDigitToInt('c')); |
667 EXPECT_EQ(13, HexDigitToInt('d')); | 667 EXPECT_EQ(13, HexDigitToInt('d')); |
668 EXPECT_EQ(14, HexDigitToInt('e')); | 668 EXPECT_EQ(14, HexDigitToInt('e')); |
669 EXPECT_EQ(15, HexDigitToInt('f')); | 669 EXPECT_EQ(15, HexDigitToInt('f')); |
670 } | 670 } |
671 | 671 |
672 // This checks where we can use the assignment operator for a va_list. We need | |
673 // a way to do this since Visual C doesn't support va_copy, but assignment on | |
674 // va_list is not guaranteed to be a copy. See StringAppendVT which uses this | |
675 // capability. | |
676 static void VariableArgsFunc(const char* format, ...) { | |
677 va_list org; | |
678 va_start(org, format); | |
679 | |
680 va_list dup; | |
681 GG_VA_COPY(dup, org); | |
682 int i1 = va_arg(org, int); | |
683 int j1 = va_arg(org, int); | |
684 char* s1 = va_arg(org, char*); | |
685 double d1 = va_arg(org, double); | |
686 va_end(org); | |
687 | |
688 int i2 = va_arg(dup, int); | |
689 int j2 = va_arg(dup, int); | |
690 char* s2 = va_arg(dup, char*); | |
691 double d2 = va_arg(dup, double); | |
692 | |
693 EXPECT_EQ(i1, i2); | |
694 EXPECT_EQ(j1, j2); | |
695 EXPECT_STREQ(s1, s2); | |
696 EXPECT_EQ(d1, d2); | |
697 | |
698 va_end(dup); | |
699 } | |
700 | |
701 TEST(StringUtilTest, VAList) { | |
702 VariableArgsFunc("%d %d %s %lf", 45, 92, "This is interesting", 9.21); | |
703 } | |
704 | |
705 // Test for Tokenize | 672 // Test for Tokenize |
706 template <typename STR> | 673 template <typename STR> |
707 void TokenizeTest() { | 674 void TokenizeTest() { |
708 std::vector<STR> r; | 675 std::vector<STR> r; |
709 size_t size; | 676 size_t size; |
710 | 677 |
711 size = Tokenize(STR("This is a string"), STR(" "), &r); | 678 size = Tokenize(STR("This is a string"), STR(" "), &r); |
712 EXPECT_EQ(4U, size); | 679 EXPECT_EQ(4U, size); |
713 ASSERT_EQ(4U, r.size()); | 680 ASSERT_EQ(4U, r.size()); |
714 EXPECT_EQ(r[0], STR("This")); | 681 EXPECT_EQ(r[0], STR("This")); |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 const std::string live = kLive; | 1226 const std::string live = kLive; |
1260 std::string dead = live; | 1227 std::string dead = live; |
1261 strncpy(WriteInto(&dead, 5), kDead, 4); | 1228 strncpy(WriteInto(&dead, 5), kDead, 4); |
1262 EXPECT_EQ(kDead, dead); | 1229 EXPECT_EQ(kDead, dead); |
1263 EXPECT_EQ(4u, dead.size()); | 1230 EXPECT_EQ(4u, dead.size()); |
1264 EXPECT_EQ(kLive, live); | 1231 EXPECT_EQ(kLive, live); |
1265 EXPECT_EQ(4u, live.size()); | 1232 EXPECT_EQ(4u, live.size()); |
1266 } | 1233 } |
1267 | 1234 |
1268 } // namespace base | 1235 } // namespace base |
OLD | NEW |