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

Side by Side Diff: core/fxcrt/fx_basic_bstring_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, 7 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
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_string.h" 5 #include "core/fxcrt/include/fx_string.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, ByteStringOperatorSubscript) { 9 TEST(fxcrt, ByteStringOperatorSubscript) {
10 // CFX_ByteString includes the NUL terminator for non-empty strings. 10 // CFX_ByteString includes the NUL terminator for non-empty strings.
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 CFX_ByteString fred("FRED"); 617 CFX_ByteString fred("FRED");
618 CFX_ByteString other_fred = fred; 618 CFX_ByteString other_fred = fred;
619 const FX_CHAR* old_buffer = fred.c_str(); 619 const FX_CHAR* old_buffer = fred.c_str();
620 fred.TrimLeft(); 620 fred.TrimLeft();
621 EXPECT_EQ("FRED", fred); 621 EXPECT_EQ("FRED", fred);
622 EXPECT_EQ("FRED", other_fred); 622 EXPECT_EQ("FRED", other_fred);
623 EXPECT_EQ(old_buffer, fred.c_str()); 623 EXPECT_EQ(old_buffer, fred.c_str());
624 } 624 }
625 } 625 }
626 626
627 TEST(fxcrt, ByteStringReserve) {
628 {
629 CFX_ByteString str;
630 str.Reserve(6);
631 const FX_CHAR* old_buffer = str.c_str();
632 str += "ABCDEF";
633 EXPECT_EQ(old_buffer, str.c_str());
634 str += "Blah Blah Blah Blah Blah Blah";
635 EXPECT_NE(old_buffer, str.c_str());
636 }
637 {
638 CFX_ByteString str("A");
639 str.Reserve(6);
640 const FX_CHAR* old_buffer = str.c_str();
641 str += "BCDEF";
642 EXPECT_EQ(old_buffer, str.c_str());
643 str += "Blah Blah Blah Blah Blah Blah";
644 EXPECT_NE(old_buffer, str.c_str());
645 }
646 }
647
648 TEST(fxcrt, ByteStringGetBuffer) {
649 {
650 CFX_ByteString str;
651 FX_CHAR* buffer = str.GetBuffer(12);
652 strcpy(buffer, "clams");
653 str.ReleaseBuffer();
654 EXPECT_EQ("clams", str);
655 }
656 {
657 CFX_ByteString str("cl");
658 FX_CHAR* buffer = str.GetBuffer(12);
659 strcpy(buffer + 2, "ams");
660 str.ReleaseBuffer();
661 EXPECT_EQ("clams", str);
662 }
663 }
664
665 TEST(fxcrt, ByteStringReleaseBuffer) {
666 {
667 CFX_ByteString str;
668 str.Reserve(12);
669 str += "clams";
670 const FX_CHAR* old_buffer = str.c_str();
671 str.ReleaseBuffer(4);
672 EXPECT_EQ(old_buffer, str.c_str());
673 EXPECT_EQ("clam", str);
674 }
675 {
676 CFX_ByteString str("c");
677 str.Reserve(12);
678 str += "lams";
679 const FX_CHAR* old_buffer = str.c_str();
680 str.ReleaseBuffer(4);
681 EXPECT_EQ(old_buffer, str.c_str());
682 EXPECT_EQ("clam", str);
683 }
684 {
685 CFX_ByteString str;
686 str.Reserve(200);
687 str += "clams";
688 const FX_CHAR* old_buffer = str.c_str();
689 str.ReleaseBuffer(4);
690 EXPECT_NE(old_buffer, str.c_str());
691 EXPECT_EQ("clam", str);
692 }
693 {
694 CFX_ByteString str("c");
695 str.Reserve(200);
696 str += "lams";
697 const FX_CHAR* old_buffer = str.c_str();
698 str.ReleaseBuffer(4);
699 EXPECT_NE(old_buffer, str.c_str());
700 EXPECT_EQ("clam", str);
701 }
702 }
703
627 TEST(fxcrt, ByteStringCNotNull) { 704 TEST(fxcrt, ByteStringCNotNull) {
628 CFX_ByteStringC string3("abc"); 705 CFX_ByteStringC string3("abc");
629 CFX_ByteStringC string6("abcdef"); 706 CFX_ByteStringC string6("abcdef");
630 CFX_ByteStringC alternate_string3("abcdef", 3); 707 CFX_ByteStringC alternate_string3("abcdef", 3);
631 CFX_ByteStringC embedded_nul_string7("abc\0def", 7); 708 CFX_ByteStringC embedded_nul_string7("abc\0def", 7);
632 CFX_ByteStringC illegal_string7("abcdef", 7); 709 CFX_ByteStringC illegal_string7("abcdef", 7);
633 710
634 EXPECT_EQ(3, string3.GetLength()); 711 EXPECT_EQ(3, string3.GetLength());
635 EXPECT_EQ(6, string6.GetLength()); 712 EXPECT_EQ(6, string6.GetLength());
636 EXPECT_EQ(3, alternate_string3.GetLength()); 713 EXPECT_EQ(3, alternate_string3.GetLength());
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 } 1066 }
990 } 1067 }
991 1068
992 TEST(fxcrt, EmptyByteString) { 1069 TEST(fxcrt, EmptyByteString) {
993 CFX_ByteString empty_str; 1070 CFX_ByteString empty_str;
994 EXPECT_TRUE(empty_str.IsEmpty()); 1071 EXPECT_TRUE(empty_str.IsEmpty());
995 EXPECT_EQ(0, empty_str.GetLength()); 1072 EXPECT_EQ(0, empty_str.GetLength());
996 const FX_CHAR* cstr = empty_str.c_str(); 1073 const FX_CHAR* cstr = empty_str.c_str();
997 EXPECT_EQ(0, FXSYS_strlen(cstr)); 1074 EXPECT_EQ(0, FXSYS_strlen(cstr));
998 } 1075 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698