| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium 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 "core/fxcrt/include/fx_basic.h" | 5 #include "core/fxcrt/include/fx_basic.h" |
| 6 #include "testing/fx_string_testhelpers.h" | 6 #include "testing/fx_string_testhelpers.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 TEST(fxcrt, WideStringOperatorSubscript) { | 9 TEST(fxcrt, WideStringOperatorSubscript) { |
| 10 // CFX_WideString includes the NUL terminator for non-empty strings. | 10 // CFX_WideString includes the NUL terminator for non-empty strings. |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 CFX_WideString fred(L"FRED"); | 584 CFX_WideString fred(L"FRED"); |
| 585 CFX_WideString other_fred = fred; | 585 CFX_WideString other_fred = fred; |
| 586 const FX_WCHAR* old_buffer = fred.c_str(); | 586 const FX_WCHAR* old_buffer = fred.c_str(); |
| 587 fred.TrimLeft(); | 587 fred.TrimLeft(); |
| 588 EXPECT_EQ(L"FRED", fred); | 588 EXPECT_EQ(L"FRED", fred); |
| 589 EXPECT_EQ(L"FRED", other_fred); | 589 EXPECT_EQ(L"FRED", other_fred); |
| 590 EXPECT_EQ(old_buffer, fred.c_str()); | 590 EXPECT_EQ(old_buffer, fred.c_str()); |
| 591 } | 591 } |
| 592 } | 592 } |
| 593 | 593 |
| 594 TEST(fxcrt, WideStringReserve) { |
| 595 { |
| 596 CFX_WideString str; |
| 597 str.Reserve(6); |
| 598 const FX_WCHAR* old_buffer = str.c_str(); |
| 599 str += L"ABCDEF"; |
| 600 EXPECT_EQ(old_buffer, str.c_str()); |
| 601 str += L"Blah Blah Blah Blah Blah Blah"; |
| 602 EXPECT_NE(old_buffer, str.c_str()); |
| 603 } |
| 604 { |
| 605 CFX_WideString str(L"A"); |
| 606 str.Reserve(6); |
| 607 const FX_WCHAR* old_buffer = str.c_str(); |
| 608 str += L"BCDEF"; |
| 609 EXPECT_EQ(old_buffer, str.c_str()); |
| 610 str += L"Blah Blah Blah Blah Blah Blah"; |
| 611 EXPECT_NE(old_buffer, str.c_str()); |
| 612 } |
| 613 } |
| 614 |
| 615 TEST(fxcrt, WideStringGetBuffer) { |
| 616 { |
| 617 CFX_WideString str; |
| 618 FX_WCHAR* buffer = str.GetBuffer(12); |
| 619 wcscpy(buffer, L"clams"); |
| 620 str.ReleaseBuffer(); |
| 621 EXPECT_EQ(L"clams", str); |
| 622 } |
| 623 { |
| 624 CFX_WideString str(L"cl"); |
| 625 FX_WCHAR* buffer = str.GetBuffer(12); |
| 626 wcscpy(buffer + 2, L"ams"); |
| 627 str.ReleaseBuffer(); |
| 628 EXPECT_EQ(L"clams", str); |
| 629 } |
| 630 } |
| 631 |
| 632 TEST(fxcrt, WideStringReleaseBuffer) { |
| 633 { |
| 634 CFX_WideString str; |
| 635 str.Reserve(12); |
| 636 str += L"clams"; |
| 637 const FX_WCHAR* old_buffer = str.c_str(); |
| 638 str.ReleaseBuffer(4); |
| 639 EXPECT_EQ(old_buffer, str.c_str()); |
| 640 EXPECT_EQ(L"clam", str); |
| 641 } |
| 642 { |
| 643 CFX_WideString str(L"c"); |
| 644 str.Reserve(12); |
| 645 str += L"lams"; |
| 646 const FX_WCHAR* old_buffer = str.c_str(); |
| 647 str.ReleaseBuffer(4); |
| 648 EXPECT_EQ(old_buffer, str.c_str()); |
| 649 EXPECT_EQ(L"clam", str); |
| 650 } |
| 651 { |
| 652 CFX_WideString str; |
| 653 str.Reserve(200); |
| 654 str += L"clams"; |
| 655 const FX_WCHAR* old_buffer = str.c_str(); |
| 656 str.ReleaseBuffer(4); |
| 657 EXPECT_NE(old_buffer, str.c_str()); |
| 658 EXPECT_EQ(L"clam", str); |
| 659 } |
| 660 { |
| 661 CFX_WideString str(L"c"); |
| 662 str.Reserve(200); |
| 663 str += L"lams"; |
| 664 const FX_WCHAR* old_buffer = str.c_str(); |
| 665 str.ReleaseBuffer(4); |
| 666 EXPECT_NE(old_buffer, str.c_str()); |
| 667 EXPECT_EQ(L"clam", str); |
| 668 } |
| 669 } |
| 670 |
| 594 TEST(fxcrt, WideStringUTF16LE_Encode) { | 671 TEST(fxcrt, WideStringUTF16LE_Encode) { |
| 595 struct UTF16LEEncodeCase { | 672 struct UTF16LEEncodeCase { |
| 596 CFX_WideString ws; | 673 CFX_WideString ws; |
| 597 CFX_ByteString bs; | 674 CFX_ByteString bs; |
| 598 } utf16le_encode_cases[] = { | 675 } utf16le_encode_cases[] = { |
| 599 {L"", CFX_ByteString("\0\0", 2)}, | 676 {L"", CFX_ByteString("\0\0", 2)}, |
| 600 {L"abc", CFX_ByteString("a\0b\0c\0\0\0", 8)}, | 677 {L"abc", CFX_ByteString("a\0b\0c\0\0\0", 8)}, |
| 601 {L"abcdef", CFX_ByteString("a\0b\0c\0d\0e\0f\0\0\0", 14)}, | 678 {L"abcdef", CFX_ByteString("a\0b\0c\0d\0e\0f\0\0\0", 14)}, |
| 602 {L"abc\0def", CFX_ByteString("a\0b\0c\0\0\0", 8)}, | 679 {L"abc\0def", CFX_ByteString("a\0b\0c\0\0\0", 8)}, |
| 603 {L"\xaabb\xccdd", CFX_ByteString("\xbb\xaa\xdd\xcc\0\0", 6)}, | 680 {L"\xaabb\xccdd", CFX_ByteString("\xbb\xaa\xdd\xcc\0\0", 6)}, |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 } | 907 } |
| 831 } | 908 } |
| 832 | 909 |
| 833 TEST(fxcrt, EmptyWideString) { | 910 TEST(fxcrt, EmptyWideString) { |
| 834 CFX_WideString empty_str; | 911 CFX_WideString empty_str; |
| 835 EXPECT_TRUE(empty_str.IsEmpty()); | 912 EXPECT_TRUE(empty_str.IsEmpty()); |
| 836 EXPECT_EQ(0, empty_str.GetLength()); | 913 EXPECT_EQ(0, empty_str.GetLength()); |
| 837 const FX_WCHAR* cstr = empty_str.c_str(); | 914 const FX_WCHAR* cstr = empty_str.c_str(); |
| 838 EXPECT_EQ(0, FXSYS_wcslen(cstr)); | 915 EXPECT_EQ(0, FXSYS_wcslen(cstr)); |
| 839 } | 916 } |
| OLD | NEW |