summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_basic_wstring_unittest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/fx_basic_wstring_unittest.cpp')
-rw-r--r--core/fxcrt/fx_basic_wstring_unittest.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/core/fxcrt/fx_basic_wstring_unittest.cpp b/core/fxcrt/fx_basic_wstring_unittest.cpp
index cfc190f72a..bc38141a95 100644
--- a/core/fxcrt/fx_basic_wstring_unittest.cpp
+++ b/core/fxcrt/fx_basic_wstring_unittest.cpp
@@ -472,6 +472,37 @@ TEST(fxcrt, WideStringTrimRight) {
EXPECT_EQ(L"", empty);
}
+TEST(fxcrt, WideStringTrimRightCopies) {
+ {
+ // With a single reference, no copy takes place.
+ CFX_WideString fred(L" FRED ");
+ const FX_WCHAR* old_buffer = fred.c_str();
+ fred.TrimRight();
+ EXPECT_EQ(L" FRED", fred);
+ EXPECT_EQ(old_buffer, fred.c_str());
+ }
+ {
+ // With multiple references, we must copy.
+ CFX_WideString fred(L" FRED ");
+ CFX_WideString other_fred = fred;
+ const FX_WCHAR* old_buffer = fred.c_str();
+ fred.TrimRight();
+ EXPECT_EQ(L" FRED", fred);
+ EXPECT_EQ(L" FRED ", other_fred);
+ EXPECT_NE(old_buffer, fred.c_str());
+ }
+ {
+ // With multiple references, but no modifications, no copy.
+ CFX_WideString fred(L"FRED");
+ CFX_WideString other_fred = fred;
+ const FX_WCHAR* old_buffer = fred.c_str();
+ fred.TrimRight();
+ EXPECT_EQ(L"FRED", fred);
+ EXPECT_EQ(L"FRED", other_fred);
+ EXPECT_EQ(old_buffer, fred.c_str());
+ }
+}
+
TEST(fxcrt, WideStringTrimLeft) {
CFX_WideString fred(L" FRED ");
fred.TrimLeft();
@@ -500,6 +531,37 @@ TEST(fxcrt, WideStringTrimLeft) {
EXPECT_EQ(L"", empty);
}
+TEST(fxcrt, WideStringTrimLeftCopies) {
+ {
+ // With a single reference, no copy takes place.
+ CFX_WideString fred(L" FRED ");
+ const FX_WCHAR* old_buffer = fred.c_str();
+ fred.TrimLeft();
+ EXPECT_EQ(L"FRED ", fred);
+ EXPECT_EQ(old_buffer, fred.c_str());
+ }
+ {
+ // With multiple references, we must copy.
+ CFX_WideString fred(L" FRED ");
+ CFX_WideString other_fred = fred;
+ const FX_WCHAR* old_buffer = fred.c_str();
+ fred.TrimLeft();
+ EXPECT_EQ(L"FRED ", fred);
+ EXPECT_EQ(L" FRED ", other_fred);
+ EXPECT_NE(old_buffer, fred.c_str());
+ }
+ {
+ // With multiple references, but no modifications, no copy.
+ CFX_WideString fred(L"FRED");
+ CFX_WideString other_fred = fred;
+ const FX_WCHAR* old_buffer = fred.c_str();
+ fred.TrimLeft();
+ EXPECT_EQ(L"FRED", fred);
+ EXPECT_EQ(L"FRED", other_fred);
+ EXPECT_EQ(old_buffer, fred.c_str());
+ }
+}
+
TEST(fxcrt, WideStringUTF16LE_Encode) {
struct UTF16LEEncodeCase {
CFX_WideString ws;