Index: core/fxcrt/fx_basic_bstring_unittest.cpp |
diff --git a/core/fxcrt/fx_basic_bstring_unittest.cpp b/core/fxcrt/fx_basic_bstring_unittest.cpp |
index 73235ddf5f040d0230682b8e39b5a149a05ec8ff..8c72b2a054292257d81691daf8b5ef20bd94c7b3 100644 |
--- a/core/fxcrt/fx_basic_bstring_unittest.cpp |
+++ b/core/fxcrt/fx_basic_bstring_unittest.cpp |
@@ -505,6 +505,37 @@ TEST(fxcrt, ByteStringTrimRight) { |
EXPECT_EQ("", empty); |
} |
+TEST(fxcrt, ByteStringTrimRightCopies) { |
+ { |
+ // With a single reference, no copy takes place. |
+ CFX_ByteString fred(" FRED "); |
+ const FX_CHAR* old_buffer = fred.c_str(); |
+ fred.TrimRight(); |
+ EXPECT_EQ(" FRED", fred); |
+ EXPECT_EQ(old_buffer, fred.c_str()); |
+ } |
+ { |
+ // With multiple references, we must copy. |
+ CFX_ByteString fred(" FRED "); |
+ CFX_ByteString other_fred = fred; |
+ const FX_CHAR* old_buffer = fred.c_str(); |
+ fred.TrimRight(); |
+ EXPECT_EQ(" FRED", fred); |
+ EXPECT_EQ(" FRED ", other_fred); |
+ EXPECT_NE(old_buffer, fred.c_str()); |
+ } |
+ { |
+ // With multiple references, but no modifications, no copy. |
+ CFX_ByteString fred("FRED"); |
+ CFX_ByteString other_fred = fred; |
+ const FX_CHAR* old_buffer = fred.c_str(); |
+ fred.TrimRight(); |
+ EXPECT_EQ("FRED", fred); |
+ EXPECT_EQ("FRED", other_fred); |
+ EXPECT_EQ(old_buffer, fred.c_str()); |
+ } |
+} |
+ |
TEST(fxcrt, ByteStringTrimLeft) { |
CFX_ByteString fred(" FRED "); |
fred.TrimLeft(); |
@@ -533,6 +564,37 @@ TEST(fxcrt, ByteStringTrimLeft) { |
EXPECT_EQ("", empty); |
} |
+TEST(fxcrt, ByteStringTrimLeftCopies) { |
+ { |
+ // With a single reference, no copy takes place. |
+ CFX_ByteString fred(" FRED "); |
+ const FX_CHAR* old_buffer = fred.c_str(); |
+ fred.TrimLeft(); |
+ EXPECT_EQ("FRED ", fred); |
+ EXPECT_EQ(old_buffer, fred.c_str()); |
+ } |
+ { |
+ // With multiple references, we must copy. |
+ CFX_ByteString fred(" FRED "); |
+ CFX_ByteString other_fred = fred; |
+ const FX_CHAR* old_buffer = fred.c_str(); |
+ fred.TrimLeft(); |
+ EXPECT_EQ("FRED ", fred); |
+ EXPECT_EQ(" FRED ", other_fred); |
+ EXPECT_NE(old_buffer, fred.c_str()); |
+ } |
+ { |
+ // With multiple references, but no modifications, no copy. |
+ CFX_ByteString fred("FRED"); |
+ CFX_ByteString other_fred = fred; |
+ const FX_CHAR* old_buffer = fred.c_str(); |
+ fred.TrimLeft(); |
+ EXPECT_EQ("FRED", fred); |
+ EXPECT_EQ("FRED", other_fred); |
+ EXPECT_EQ(old_buffer, fred.c_str()); |
+ } |
+} |
+ |
TEST(fxcrt, ByteStringCNotNull) { |
CFX_ByteStringC string3("abc"); |
CFX_ByteStringC string6("abcdef"); |