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

Unified 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: Remove stray TrimLeft() 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fxcrt/fx_basic_wstring.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 708556af1d1299ead0ed251984a98070f3a4d26d..02281afd368931293b7d9ac82a1a275d77f49d01 100644
--- a/core/fxcrt/fx_basic_wstring_unittest.cpp
+++ b/core/fxcrt/fx_basic_wstring_unittest.cpp
@@ -591,6 +591,83 @@ TEST(fxcrt, WideStringTrimLeftCopies) {
}
}
+TEST(fxcrt, WideStringReserve) {
+ {
+ CFX_WideString str;
+ str.Reserve(6);
+ const FX_WCHAR* old_buffer = str.c_str();
+ str += L"ABCDEF";
+ EXPECT_EQ(old_buffer, str.c_str());
+ str += L"Blah Blah Blah Blah Blah Blah";
+ EXPECT_NE(old_buffer, str.c_str());
+ }
+ {
+ CFX_WideString str(L"A");
+ str.Reserve(6);
+ const FX_WCHAR* old_buffer = str.c_str();
+ str += L"BCDEF";
+ EXPECT_EQ(old_buffer, str.c_str());
+ str += L"Blah Blah Blah Blah Blah Blah";
+ EXPECT_NE(old_buffer, str.c_str());
+ }
+}
+
+TEST(fxcrt, WideStringGetBuffer) {
+ {
+ CFX_WideString str;
+ FX_WCHAR* buffer = str.GetBuffer(12);
+ wcscpy(buffer, L"clams");
+ str.ReleaseBuffer();
+ EXPECT_EQ(L"clams", str);
+ }
+ {
+ CFX_WideString str(L"cl");
+ FX_WCHAR* buffer = str.GetBuffer(12);
+ wcscpy(buffer + 2, L"ams");
+ str.ReleaseBuffer();
+ EXPECT_EQ(L"clams", str);
+ }
+}
+
+TEST(fxcrt, WideStringReleaseBuffer) {
+ {
+ CFX_WideString str;
+ str.Reserve(12);
+ str += L"clams";
+ const FX_WCHAR* old_buffer = str.c_str();
+ str.ReleaseBuffer(4);
+ EXPECT_EQ(old_buffer, str.c_str());
+ EXPECT_EQ(L"clam", str);
+ }
+ {
+ CFX_WideString str(L"c");
+ str.Reserve(12);
+ str += L"lams";
+ const FX_WCHAR* old_buffer = str.c_str();
+ str.ReleaseBuffer(4);
+ EXPECT_EQ(old_buffer, str.c_str());
+ EXPECT_EQ(L"clam", str);
+ }
+ {
+ CFX_WideString str;
+ str.Reserve(200);
+ str += L"clams";
+ const FX_WCHAR* old_buffer = str.c_str();
+ str.ReleaseBuffer(4);
+ EXPECT_NE(old_buffer, str.c_str());
+ EXPECT_EQ(L"clam", str);
+ }
+ {
+ CFX_WideString str(L"c");
+ str.Reserve(200);
+ str += L"lams";
+ const FX_WCHAR* old_buffer = str.c_str();
+ str.ReleaseBuffer(4);
+ EXPECT_NE(old_buffer, str.c_str());
+ EXPECT_EQ(L"clam", str);
+ }
+}
+
TEST(fxcrt, WideStringUTF16LE_Encode) {
struct UTF16LEEncodeCase {
CFX_WideString ws;
« 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