| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 ASSERT_EQ(a.rfind(b), 0U); | 288 ASSERT_EQ(a.rfind(b), 0U); |
| 289 ASSERT_EQ(a.rfind(b, 1), 0U); | 289 ASSERT_EQ(a.rfind(b, 1), 0U); |
| 290 ASSERT_EQ(a.rfind(c), 23U); | 290 ASSERT_EQ(a.rfind(c), 23U); |
| 291 ASSERT_EQ(a.rfind(c, 22U), Piece::npos); | 291 ASSERT_EQ(a.rfind(c, 22U), Piece::npos); |
| 292 ASSERT_EQ(a.rfind(c, 1U), Piece::npos); | 292 ASSERT_EQ(a.rfind(c, 1U), Piece::npos); |
| 293 ASSERT_EQ(a.rfind(c, 0U), Piece::npos); | 293 ASSERT_EQ(a.rfind(c, 0U), Piece::npos); |
| 294 ASSERT_EQ(b.rfind(c), Piece::npos); | 294 ASSERT_EQ(b.rfind(c), Piece::npos); |
| 295 ASSERT_EQ(b.rfind(c, 0U), Piece::npos); | 295 ASSERT_EQ(b.rfind(c, 0U), Piece::npos); |
| 296 ASSERT_EQ(a.rfind(d), static_cast<size_t>(a.as_string().rfind(TypeParam()))); | 296 ASSERT_EQ(a.rfind(d), static_cast<size_t>(a.as_string().rfind(TypeParam()))); |
| 297 ASSERT_EQ(a.rfind(e), a.as_string().rfind(TypeParam())); | 297 ASSERT_EQ(a.rfind(e), a.as_string().rfind(TypeParam())); |
| 298 ASSERT_EQ(a.rfind(d), static_cast<size_t>(TypeParam(a).rfind(TypeParam()))); |
| 299 ASSERT_EQ(a.rfind(e), TypeParam(a).rfind(TypeParam())); |
| 298 ASSERT_EQ(a.rfind(d, 12), 12U); | 300 ASSERT_EQ(a.rfind(d, 12), 12U); |
| 299 ASSERT_EQ(a.rfind(e, 17), 17U); | 301 ASSERT_EQ(a.rfind(e, 17), 17U); |
| 300 ASSERT_EQ(a.rfind(g), Piece::npos); | 302 ASSERT_EQ(a.rfind(g), Piece::npos); |
| 301 ASSERT_EQ(d.rfind(b), Piece::npos); | 303 ASSERT_EQ(d.rfind(b), Piece::npos); |
| 302 ASSERT_EQ(e.rfind(b), Piece::npos); | 304 ASSERT_EQ(e.rfind(b), Piece::npos); |
| 303 ASSERT_EQ(d.rfind(b, 4), Piece::npos); | 305 ASSERT_EQ(d.rfind(b, 4), Piece::npos); |
| 304 ASSERT_EQ(e.rfind(b, 7), Piece::npos); | 306 ASSERT_EQ(e.rfind(b, 7), Piece::npos); |
| 305 // empty string nonsense | 307 // empty string nonsense |
| 306 ASSERT_EQ(d.rfind(d, 4), std::string().rfind(std::string())); | 308 ASSERT_EQ(d.rfind(d, 4), std::string().rfind(std::string())); |
| 307 ASSERT_EQ(e.rfind(d, 7), std::string().rfind(std::string())); | 309 ASSERT_EQ(e.rfind(d, 7), std::string().rfind(std::string())); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 c.set(foobar.c_str(), 0); | 513 c.set(foobar.c_str(), 0); |
| 512 ASSERT_EQ(c, e); | 514 ASSERT_EQ(c, e); |
| 513 c.set(foobar.c_str(), 7); // Note, has an embedded NULL | 515 c.set(foobar.c_str(), 7); // Note, has an embedded NULL |
| 514 ASSERT_NE(c, a); | 516 ASSERT_NE(c, a); |
| 515 | 517 |
| 516 // as_string | 518 // as_string |
| 517 TypeParam s3(a.as_string().c_str(), 7); // Note, has an embedded NULL | 519 TypeParam s3(a.as_string().c_str(), 7); // Note, has an embedded NULL |
| 518 ASSERT_TRUE(c == s3); | 520 ASSERT_TRUE(c == s3); |
| 519 TypeParam s4(e.as_string()); | 521 TypeParam s4(e.as_string()); |
| 520 ASSERT_TRUE(s4.empty()); | 522 ASSERT_TRUE(s4.empty()); |
| 523 |
| 524 // operator STRING_TYPE() |
| 525 TypeParam s5(TypeParam(a).c_str(), 7); // Note, has an embedded NULL |
| 526 ASSERT_TRUE(c == s5); |
| 527 TypeParam s6(e); |
| 528 ASSERT_TRUE(s6.empty()); |
| 521 } | 529 } |
| 522 | 530 |
| 523 TEST(StringPieceTest, CheckCustom) { | 531 TEST(StringPieceTest, CheckCustom) { |
| 524 StringPiece a("foobar"); | 532 StringPiece a("foobar"); |
| 525 std::string s1("123"); | 533 std::string s1("123"); |
| 526 s1 += '\0'; | 534 s1 += '\0'; |
| 527 s1 += "456"; | 535 s1 += "456"; |
| 528 StringPiece b(s1); | 536 StringPiece b(s1); |
| 529 StringPiece e; | 537 StringPiece e; |
| 530 std::string s2; | 538 std::string s2; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 TYPED_TEST(CommonStringPieceTest, CheckNULL) { | 592 TYPED_TEST(CommonStringPieceTest, CheckNULL) { |
| 585 // we used to crash here, but now we don't. | 593 // we used to crash here, but now we don't. |
| 586 BasicStringPiece<TypeParam> s(NULL); | 594 BasicStringPiece<TypeParam> s(NULL); |
| 587 ASSERT_EQ(s.data(), (const typename TypeParam::value_type*)NULL); | 595 ASSERT_EQ(s.data(), (const typename TypeParam::value_type*)NULL); |
| 588 ASSERT_EQ(s.size(), 0U); | 596 ASSERT_EQ(s.size(), 0U); |
| 589 | 597 |
| 590 s.set(NULL); | 598 s.set(NULL); |
| 591 ASSERT_EQ(s.data(), (const typename TypeParam::value_type*)NULL); | 599 ASSERT_EQ(s.data(), (const typename TypeParam::value_type*)NULL); |
| 592 ASSERT_EQ(s.size(), 0U); | 600 ASSERT_EQ(s.size(), 0U); |
| 593 | 601 |
| 594 TypeParam str = s.as_string(); | 602 TypeParam str(s); |
| 603 ASSERT_EQ(str.length(), 0U); |
| 604 ASSERT_EQ(str, TypeParam()); |
| 605 |
| 606 str = s.as_string(); |
| 595 ASSERT_EQ(str.length(), 0U); | 607 ASSERT_EQ(str.length(), 0U); |
| 596 ASSERT_EQ(str, TypeParam()); | 608 ASSERT_EQ(str, TypeParam()); |
| 597 } | 609 } |
| 598 | 610 |
| 599 TYPED_TEST(CommonStringPieceTest, CheckComparisons2) { | 611 TYPED_TEST(CommonStringPieceTest, CheckComparisons2) { |
| 600 TypeParam alphabet(TestFixture::as_string("abcdefghijklmnopqrstuvwxyz")); | 612 TypeParam alphabet(TestFixture::as_string("abcdefghijklmnopqrstuvwxyz")); |
| 601 TypeParam alphabet_z(TestFixture::as_string("abcdefghijklmnopqrstuvwxyzz")); | 613 TypeParam alphabet_z(TestFixture::as_string("abcdefghijklmnopqrstuvwxyzz")); |
| 602 TypeParam alphabet_y(TestFixture::as_string("abcdefghijklmnopqrstuvwxyy")); | 614 TypeParam alphabet_y(TestFixture::as_string("abcdefghijklmnopqrstuvwxyy")); |
| 603 BasicStringPiece<TypeParam> abc(alphabet); | 615 BasicStringPiece<TypeParam> abc(alphabet); |
| 604 | 616 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 ASSERT_TRUE(empty == BasicStringPiece<TypeParam>(NULL, | 694 ASSERT_TRUE(empty == BasicStringPiece<TypeParam>(NULL, |
| 683 static_cast<typename BasicStringPiece<TypeParam>::size_type>(0))); | 695 static_cast<typename BasicStringPiece<TypeParam>::size_type>(0))); |
| 684 ASSERT_TRUE(empty == BasicStringPiece<TypeParam>()); | 696 ASSERT_TRUE(empty == BasicStringPiece<TypeParam>()); |
| 685 ASSERT_TRUE(str == BasicStringPiece<TypeParam>(str.begin(), str.end())); | 697 ASSERT_TRUE(str == BasicStringPiece<TypeParam>(str.begin(), str.end())); |
| 686 ASSERT_TRUE(empty == BasicStringPiece<TypeParam>(str.begin(), str.begin())); | 698 ASSERT_TRUE(empty == BasicStringPiece<TypeParam>(str.begin(), str.begin())); |
| 687 ASSERT_TRUE(empty == BasicStringPiece<TypeParam>(empty)); | 699 ASSERT_TRUE(empty == BasicStringPiece<TypeParam>(empty)); |
| 688 ASSERT_TRUE(empty == BasicStringPiece<TypeParam>(empty.begin(), empty.end())); | 700 ASSERT_TRUE(empty == BasicStringPiece<TypeParam>(empty.begin(), empty.end())); |
| 689 } | 701 } |
| 690 | 702 |
| 691 } // namespace base | 703 } // namespace base |
| OLD | NEW |