| Index: core/fxcrt/fx_basic_wstring_unittest.cpp
|
| diff --git a/core/fxcrt/fx_basic_wstring_unittest.cpp b/core/fxcrt/fx_basic_wstring_unittest.cpp
|
| index cfc190f72ae75384f98d5dc0f43b8af8c3657622..bc38141a95ca9f317d07b4850e28a8877f0c3360 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;
|
|
|