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

Side by Side Diff: core/fxcrt/fx_basic_wstring_unittest.cpp

Issue 1916303004: CFX_ByteString::Reserve(), ReleaseBuffer() fixes. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Assert private copy, saner behaviour with out-of-bounds args. Created 4 years, 8 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 | « core/fxcrt/fx_basic_wstring.cpp ('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 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
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.TrimLeft();
Lei Zhang 2016/04/26 18:51:12 The bytestring version doesn't have this. Intentio
Tom Sepez 2016/04/26 18:57:11 Argh, cut n paste fail.
609 str += L"BCDEF";
610 EXPECT_EQ(old_buffer, str.c_str());
611 str += L"Blah Blah Blah Blah Blah Blah";
612 EXPECT_NE(old_buffer, str.c_str());
613 }
614 }
615
616 TEST(fxcrt, WideStringGetBuffer) {
617 {
618 CFX_WideString str;
619 FX_WCHAR* buffer = str.GetBuffer(12);
620 wcscpy(buffer, L"clams");
621 str.ReleaseBuffer();
622 EXPECT_EQ(L"clams", str);
623 }
624 {
625 CFX_WideString str(L"cl");
626 FX_WCHAR* buffer = str.GetBuffer(12);
627 wcscpy(buffer + 2, L"ams");
628 str.ReleaseBuffer();
629 EXPECT_EQ(L"clams", str);
630 }
631 }
632
633 TEST(fxcrt, WideStringReleaseBuffer) {
634 {
635 CFX_WideString str;
636 str.Reserve(12);
637 str += L"clams";
638 const FX_WCHAR* old_buffer = str.c_str();
639 str.ReleaseBuffer(4);
640 EXPECT_EQ(old_buffer, str.c_str());
641 EXPECT_EQ(L"clam", str);
642 }
643 {
644 CFX_WideString str(L"c");
645 str.Reserve(12);
646 str += L"lams";
647 const FX_WCHAR* old_buffer = str.c_str();
648 str.ReleaseBuffer(4);
649 EXPECT_EQ(old_buffer, str.c_str());
650 EXPECT_EQ(L"clam", str);
651 }
652 {
653 CFX_WideString str;
654 str.Reserve(200);
655 str += L"clams";
656 const FX_WCHAR* old_buffer = str.c_str();
657 str.ReleaseBuffer(4);
658 EXPECT_NE(old_buffer, str.c_str());
659 EXPECT_EQ(L"clam", str);
660 }
661 {
662 CFX_WideString str(L"c");
663 str.Reserve(200);
664 str += L"lams";
665 const FX_WCHAR* old_buffer = str.c_str();
666 str.ReleaseBuffer(4);
667 EXPECT_NE(old_buffer, str.c_str());
668 EXPECT_EQ(L"clam", str);
669 }
670 }
671
594 TEST(fxcrt, WideStringUTF16LE_Encode) { 672 TEST(fxcrt, WideStringUTF16LE_Encode) {
595 struct UTF16LEEncodeCase { 673 struct UTF16LEEncodeCase {
596 CFX_WideString ws; 674 CFX_WideString ws;
597 CFX_ByteString bs; 675 CFX_ByteString bs;
598 } utf16le_encode_cases[] = { 676 } utf16le_encode_cases[] = {
599 {L"", CFX_ByteString("\0\0", 2)}, 677 {L"", CFX_ByteString("\0\0", 2)},
600 {L"abc", CFX_ByteString("a\0b\0c\0\0\0", 8)}, 678 {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)}, 679 {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)}, 680 {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)}, 681 {L"\xaabb\xccdd", CFX_ByteString("\xbb\xaa\xdd\xcc\0\0", 6)},
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 } 908 }
831 } 909 }
832 910
833 TEST(fxcrt, EmptyWideString) { 911 TEST(fxcrt, EmptyWideString) {
834 CFX_WideString empty_str; 912 CFX_WideString empty_str;
835 EXPECT_TRUE(empty_str.IsEmpty()); 913 EXPECT_TRUE(empty_str.IsEmpty());
836 EXPECT_EQ(0, empty_str.GetLength()); 914 EXPECT_EQ(0, empty_str.GetLength());
837 const FX_WCHAR* cstr = empty_str.c_str(); 915 const FX_WCHAR* cstr = empty_str.c_str();
838 EXPECT_EQ(0, FXSYS_wcslen(cstr)); 916 EXPECT_EQ(0, FXSYS_wcslen(cstr));
839 } 917 }
OLDNEW
« no previous file with comments | « core/fxcrt/fx_basic_wstring.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698