Introduce ScopedFPDFWideString for use in tests.
It is equivalent to std::unique_ptr<FPDF_WCHAR, pdfium::FreeDeleter>.
Use it to shorten the type returned by GetFPDFWideString(). The use of
FPDF_WCHAR also makes the linter complain less about the use of unsigned
short.
Change-Id: Id32c284375151684f8457d84c4faa3fcb514f6ca
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/52871
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index f99e93a..19b22f5 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -53,8 +53,7 @@
EXPECT_FALSE(FPDFAnnot_HasKey(nullptr, "foo"));
static const wchar_t kContents[] = L"Bar";
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
- GetFPDFWideString(kContents);
+ ScopedFPDFWideString text = GetFPDFWideString(kContents);
EXPECT_FALSE(FPDFAnnot_SetStringValue(nullptr, "foo", text.get()));
char buffer[128];
@@ -317,8 +316,7 @@
// Set the content of the annotation.
static const wchar_t kContents[] = L"Hello! This is a customized content.";
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
- GetFPDFWideString(kContents);
+ ScopedFPDFWideString text = GetFPDFWideString(kContents);
ASSERT_TRUE(FPDFAnnot_SetStringValue(
annot.get(), pdfium::annotation::kContents, text.get()));
// Check that the content has been set correctly.
@@ -1017,7 +1015,7 @@
FPDF_PAGEOBJECT text_object =
FPDFPageObj_NewTextObj(document(), "Arial", 12.0f);
EXPECT_TRUE(text_object);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
+ ScopedFPDFWideString text =
GetFPDFWideString(L"I'm a translucent text laying on other text.");
EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
EXPECT_TRUE(FPDFText_SetFillColor(text_object, 0, 0, 255, 150));
@@ -1040,8 +1038,7 @@
EXPECT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object));
// Modify the text in the new annotation.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> new_text =
- GetFPDFWideString(L"New text!");
+ ScopedFPDFWideString new_text = GetFPDFWideString(L"New text!");
EXPECT_TRUE(FPDFText_SetText(text_object, new_text.get()));
EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), text_object));
}
@@ -1107,8 +1104,7 @@
EXPECT_STREQ(L"D:201706071721Z00'00'", BufferToWString(buf).c_str());
// Update the date entry for the annotation.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
- GetFPDFWideString(kNewDate);
+ ScopedFPDFWideString text = GetFPDFWideString(kNewDate);
EXPECT_TRUE(FPDFAnnot_SetStringValue(annot.get(), pdfium::annotation::kM,
text.get()));
}
@@ -1251,8 +1247,7 @@
EXPECT_STREQ("", BufferToString(buf).c_str());
// Check that setting the AP for an invalid appearance mode fails.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> ap_text =
- GetFPDFWideString(L"new test ap");
+ ScopedFPDFWideString ap_text = GetFPDFWideString(L"new test ap");
EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), -1, ap_text.get()));
EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_COUNT,
ap_text.get()));
@@ -1323,8 +1318,7 @@
ASSERT_TRUE(annot);
// Set Down AP. Normal AP is already set.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> ap_text =
- GetFPDFWideString(L"new test ap");
+ ScopedFPDFWideString ap_text = GetFPDFWideString(L"new test ap");
EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
ap_text.get()));
EXPECT_EQ(73970u,
@@ -1359,8 +1353,7 @@
ASSERT_TRUE(annot);
// Set Down AP. Normal AP is already set.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> ap_text =
- GetFPDFWideString(L"new test ap");
+ ScopedFPDFWideString ap_text = GetFPDFWideString(L"new test ap");
EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
ap_text.get()));
EXPECT_EQ(73970u,
@@ -1654,8 +1647,7 @@
buf.size()));
EXPECT_STREQ(L"", BufferToWString(buf).c_str());
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
- GetFPDFWideString(kData);
+ ScopedFPDFWideString text = GetFPDFWideString(kData);
EXPECT_TRUE(FPDFAnnot_SetStringValue(annot.get(), kTestKey, text.get()));
std::fill(buf.begin(), buf.end(), 'x');
@@ -1676,8 +1668,7 @@
buf.data(), buf.size()));
EXPECT_STREQ(L"", BufferToWString(buf).c_str());
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
- GetFPDFWideString(kData);
+ ScopedFPDFWideString text = GetFPDFWideString(kData);
EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER,
text.get()));
diff --git a/fpdfsdk/fpdf_attachment_embeddertest.cpp b/fpdfsdk/fpdf_attachment_embeddertest.cpp
index f2fd769..59508ee 100644
--- a/fpdfsdk/fpdf_attachment_embeddertest.cpp
+++ b/fpdfsdk/fpdf_attachment_embeddertest.cpp
@@ -97,8 +97,7 @@
EXPECT_FALSE(FPDFDoc_AddAttachment(document(), nullptr));
// Add an attachment to the beginning of the embedded file list.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> file_name =
- GetFPDFWideString(L"0.txt");
+ ScopedFPDFWideString file_name = GetFPDFWideString(L"0.txt");
FPDF_ATTACHMENT attachment =
FPDFDoc_AddAttachment(document(), file_name.get());
@@ -160,8 +159,7 @@
EXPECT_EQ(2, FPDFDoc_GetAttachmentCount(document()));
// Add an attachment to the embedded file list.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> file_name =
- GetFPDFWideString(L"5.txt");
+ ScopedFPDFWideString file_name = GetFPDFWideString(L"5.txt");
FPDF_ATTACHMENT attachment =
FPDFDoc_AddAttachment(document(), file_name.get());
constexpr char kContents[] = "Hello World!";
@@ -170,15 +168,13 @@
// Set the date to be an arbitrary value.
constexpr wchar_t kDateW[] = L"D:20170720161527-04'00'";
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> ws_date =
- GetFPDFWideString(kDateW);
+ ScopedFPDFWideString ws_date = GetFPDFWideString(kDateW);
EXPECT_TRUE(
FPDFAttachment_SetStringValue(attachment, kDateKey, ws_date.get()));
// Set the checksum to be an arbitrary value.
constexpr wchar_t kCheckSumW[] = L"<ABCDEF01234567899876543210FEDCBA>";
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> ws_checksum =
- GetFPDFWideString(kCheckSumW);
+ ScopedFPDFWideString ws_checksum = GetFPDFWideString(kCheckSumW);
EXPECT_TRUE(FPDFAttachment_SetStringValue(attachment, kChecksumKey,
ws_checksum.get()));
diff --git a/fpdfsdk/fpdf_doc_embeddertest.cpp b/fpdfsdk/fpdf_doc_embeddertest.cpp
index 13f27d9..a421fd0 100644
--- a/fpdfsdk/fpdf_doc_embeddertest.cpp
+++ b/fpdfsdk/fpdf_doc_embeddertest.cpp
@@ -396,8 +396,7 @@
EXPECT_TRUE(OpenDocument("bookmarks.pdf"));
// Find the first one, based on its known title.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
- GetFPDFWideString(L"A Good Beginning");
+ ScopedFPDFWideString title = GetFPDFWideString(L"A Good Beginning");
FPDF_BOOKMARK child = FPDFBookmark_Find(document(), title.get());
EXPECT_TRUE(child);
@@ -410,8 +409,7 @@
EXPECT_EQ(child, FPDFBookmark_GetFirstChild(document(), nullptr));
// Try to find one using a non-existent title.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> bad_title =
- GetFPDFWideString(L"A BAD Beginning");
+ ScopedFPDFWideString bad_title = GetFPDFWideString(L"A BAD Beginning");
EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), bad_title.get()));
}
@@ -421,8 +419,7 @@
EXPECT_TRUE(OpenDocument("bookmarks_circular.pdf"));
// Try to find a title.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
- GetFPDFWideString(L"anything");
+ ScopedFPDFWideString title = GetFPDFWideString(L"anything");
EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), title.get()));
}
diff --git a/fpdfsdk/fpdf_doc_unittest.cpp b/fpdfsdk/fpdf_doc_unittest.cpp
index feabeb3..aeca3de 100644
--- a/fpdfsdk/fpdf_doc_unittest.cpp
+++ b/fpdfsdk/fpdf_doc_unittest.cpp
@@ -74,8 +74,7 @@
TEST_F(PDFDocTest, FindBookmark) {
{
// No bookmark information.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
- GetFPDFWideString(L"");
+ ScopedFPDFWideString title = GetFPDFWideString(L"");
EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
title = GetFPDFWideString(L"Preface");
@@ -84,8 +83,7 @@
{
// Empty bookmark tree.
m_pRootObj->SetNewFor<CPDF_Dictionary>("Outlines");
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
- GetFPDFWideString(L"");
+ ScopedFPDFWideString title = GetFPDFWideString(L"");
EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
title = GetFPDFWideString(L"Preface");
@@ -118,8 +116,7 @@
bookmarks[0].num);
// Title with no match.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
- GetFPDFWideString(L"Chapter 3");
+ ScopedFPDFWideString title = GetFPDFWideString(L"Chapter 3");
EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
// Title with partial match only.
@@ -163,8 +160,7 @@
bookmarks[0].num);
// Title with no match.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
- GetFPDFWideString(L"Chapter 3");
+ ScopedFPDFWideString title = GetFPDFWideString(L"Chapter 3");
EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
// Title with a match.
@@ -205,8 +201,7 @@
bookmarks[0].num);
// Title with no match.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
- GetFPDFWideString(L"Chapter 8");
+ ScopedFPDFWideString title = GetFPDFWideString(L"Chapter 8");
EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
// Title with a match.
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index 948d356..525e9cc 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -440,8 +440,7 @@
ASSERT_EQ(2, FPDFPage_CountObjects(page));
FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
ASSERT_TRUE(page_object);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text1 =
- GetFPDFWideString(L"Changed for SetText test");
+ ScopedFPDFWideString text1 = GetFPDFWideString(L"Changed for SetText test");
EXPECT_TRUE(FPDFText_SetText(page_object, text1.get()));
// Verify the "Hello, world!" text is gone and "Changed for SetText test" is
@@ -1778,7 +1777,7 @@
FPDF_PAGEOBJECT text_object1 =
FPDFPageObj_NewTextObj(document(), "Arial", 12.0f);
EXPECT_TRUE(text_object1);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text1 =
+ ScopedFPDFWideString text1 =
GetFPDFWideString(L"I'm at the bottom of the page");
EXPECT_TRUE(FPDFText_SetText(text_object1, text1.get()));
FPDFPageObj_Transform(text_object1, 1, 0, 0, 1, 20, 20);
@@ -1803,7 +1802,7 @@
FPDF_PAGEOBJECT text_object2 =
FPDFPageObj_NewTextObj(document(), "TimesNewRomanBold", 15.0f);
EXPECT_TRUE(text_object2);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text2 =
+ ScopedFPDFWideString text2 =
GetFPDFWideString(L"Hi, I'm Bold. Times New Roman Bold.");
EXPECT_TRUE(FPDFText_SetText(text_object2, text2.get()));
FPDFPageObj_Transform(text_object2, 1, 0, 0, 1, 100, 600);
@@ -1828,8 +1827,7 @@
FPDF_PAGEOBJECT text_object3 =
FPDFPageObj_NewTextObj(document(), "Courier-Bold", 20.0f);
EXPECT_TRUE(text_object3);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text3 =
- GetFPDFWideString(L"Can you read me? <:)>");
+ ScopedFPDFWideString text3 = GetFPDFWideString(L"Can you read me? <:)>");
EXPECT_TRUE(FPDFText_SetText(text_object3, text3.get()));
FPDFPageObj_Transform(text_object3, 1, 1.5, 2, 0.5, 200, 200);
FPDFPage_InsertObject(page, text_object3);
@@ -1999,7 +1997,7 @@
FPDF_PAGEOBJECT text_object =
FPDFPageObj_CreateTextObj(document(), font, 12.0f);
EXPECT_TRUE(text_object);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
+ ScopedFPDFWideString text =
GetFPDFWideString(L"I'm at the bottom of the page");
EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 20, 20);
@@ -2156,7 +2154,7 @@
// Add some text to the page
FPDF_PAGEOBJECT text_object =
FPDFPageObj_NewTextObj(document(), "Arial", 12.0f);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
+ ScopedFPDFWideString text =
GetFPDFWideString(L"Something something #text# something");
EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 300, 300);
@@ -2345,7 +2343,7 @@
FPDF_PAGEOBJECT text_object =
FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f);
EXPECT_TRUE(text_object);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
+ ScopedFPDFWideString text =
GetFPDFWideString(L"I am testing my loaded font, WEE.");
EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 400, 400);
@@ -2363,8 +2361,7 @@
// Add some more text, same font
FPDF_PAGEOBJECT text_object2 =
FPDFPageObj_CreateTextObj(document(), font.get(), 15.0f);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text2 =
- GetFPDFWideString(L"Bigger font size");
+ ScopedFPDFWideString text2 = GetFPDFWideString(L"Bigger font size");
EXPECT_TRUE(FPDFText_SetText(text_object2, text2.get()));
FPDFPageObj_Transform(text_object2, 1, 0, 0, 1, 200, 200);
FPDFPage_InsertObject(page, text_object2);
@@ -2427,8 +2424,7 @@
FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f);
ASSERT_TRUE(text_object);
std::wstring wstr = L"ABCDEFGhijklmnop.";
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
- GetFPDFWideString(wstr);
+ ScopedFPDFWideString text = GetFPDFWideString(wstr);
EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 200, 200);
FPDFPage_InsertObject(page, text_object);
@@ -2440,8 +2436,7 @@
std::wstring wstr2 =
L"\u3053\u3093\u306B\u3061\u306f\u4e16\u754C\u3002\u3053\u3053\u306B1"
L"\u756A";
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text2 =
- GetFPDFWideString(wstr2);
+ ScopedFPDFWideString text2 = GetFPDFWideString(wstr2);
EXPECT_TRUE(FPDFText_SetText(text_object2, text2.get()));
FPDFPageObj_Transform(text_object2, 1, 0, 0, 1, 100, 500);
FPDFPage_InsertObject(page, text_object2);
@@ -2606,7 +2601,7 @@
FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f);
EXPECT_TRUE(text_object);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text1 =
+ ScopedFPDFWideString text1 =
GetFPDFWideString(L"I am testing my loaded font, WEE.");
EXPECT_TRUE(FPDFText_SetText(text_object, text1.get()));
FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 400, 400);
diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp
index be3248f..3de1e86 100644
--- a/fpdfsdk/fpdf_formfill_embeddertest.cpp
+++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp
@@ -1377,8 +1377,7 @@
CheckFocusedFieldText(L"");
// Test inserting text into empty text field.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
CheckFocusedFieldText(L"Hello");
@@ -1398,8 +1397,7 @@
CheckFocusedFieldText(L"ABCDEFGH");
// Test inserting text in front of existing text in text field.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
CheckFocusedFieldText(L"HelloABCDEFGH");
@@ -1417,8 +1415,7 @@
ClickOnFormFieldAtPoint(RegularFormAtX(134.0));
// Test inserting text in the middle of existing text in text field.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
CheckFocusedFieldText(L"ABCDHelloEFGH");
@@ -1436,8 +1433,7 @@
ClickOnFormFieldAtPoint(RegularFormAtX(166.0));
// Test inserting text behind existing text in text field.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
CheckFocusedFieldText(L"ABCDEFGHHello");
@@ -1458,8 +1454,7 @@
CheckSelection(L"ABCDEFGHIJKL");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
CheckFocusedFieldText(L"Hello");
@@ -1480,8 +1475,7 @@
CheckSelection(L"ABCDEF");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
CheckFocusedFieldText(L"HelloGHIJKL");
@@ -1502,8 +1496,7 @@
CheckSelection(L"DEFGHI");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of text field to check that insertion worked
@@ -1523,8 +1516,7 @@
CheckSelection(L"GHIJKL");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of text field to check that insertion worked
@@ -1540,8 +1532,7 @@
CheckFocusedFieldText(L"");
// Test inserting text into empty user-editable combobox.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
CheckFocusedFieldText(L"Hello");
@@ -1560,8 +1551,7 @@
ClickOnFormFieldAtPoint(EditableFormBegin());
// Test inserting text in front of existing text in user-editable combobox.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of user-editable combobox text field to check that
@@ -1580,8 +1570,7 @@
// Test inserting text in the middle of existing text in user-editable
// combobox.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of user-editable combobox text field to check that
@@ -1599,8 +1588,7 @@
ClickOnFormFieldAtPoint(EditableFormEnd());
// Test inserting text behind existing text in user-editable combobox.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of user-editable combobox text field to check that
@@ -1620,8 +1608,7 @@
CheckSelection(L"ABCDEFGHIJ");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of user-editable combobox text field to check that
@@ -1641,8 +1628,7 @@
CheckSelection(L"ABCDE");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of user-editable combobox text field to check that
@@ -1662,8 +1648,7 @@
CheckSelection(L"DEFGH");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of user-editable combobox text field to check that
@@ -1683,8 +1668,7 @@
CheckSelection(L"FGHIJ");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of user-editable combobox text field to check that
@@ -1710,8 +1694,7 @@
// Test inserting text into now empty text field so text to be inserted
// exceeds the char limit and is cut off.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hippopotamus");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
CheckFocusedFieldText(L"Hippopotam");
@@ -1736,8 +1719,7 @@
// Test inserting text into now empty text field so text to be inserted
// exceeds the char limit and is cut off.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Zebra");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Zebra");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
CheckFocusedFieldText(L"Zebra");
@@ -1754,8 +1736,7 @@
ClickOnFormFieldAtPoint(CharLimitFormBegin());
// Test inserting text in front of existing text in text field.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hippopotamus");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of text field to check that insertion worked
@@ -1776,8 +1757,7 @@
CheckFocusedFieldText(L"Elephant");
// Test inserting text in the middle of existing text in text field.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hippopotamus");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
CheckFocusedFieldText(L"ElephHiant");
@@ -1796,8 +1776,7 @@
ClickOnFormFieldAtPoint(CharLimitFormAtX(166.0));
// Test inserting text behind existing text in text field.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hippopotamus");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of text field to check that insertion worked
@@ -1817,8 +1796,7 @@
CheckSelection(L"Elephant");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hippopotamus");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of text field to check that insertion worked
@@ -1838,8 +1816,7 @@
CheckSelection(L"Elep");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hippopotamus");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of text field to check that insertion worked
@@ -1859,8 +1836,7 @@
CheckSelection(L"epha");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hippopotamus");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of text field to check that insertion worked
@@ -1880,8 +1856,7 @@
CheckSelection(L"hant");
// Test replacing text selection with text to be inserted.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hippopotamus");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
// Select entire contents of text field to check that insertion worked
@@ -1897,8 +1872,7 @@
CheckFocusedFieldText(L"");
// Test inserting text into empty text field.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
- GetFPDFWideString(L"Hello World");
+ ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello World");
FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
CheckFocusedFieldText(L"Hello World");
diff --git a/fpdfsdk/fpdf_text_embeddertest.cpp b/fpdfsdk/fpdf_text_embeddertest.cpp
index fc9564d..37e8dfa 100644
--- a/fpdfsdk/fpdf_text_embeddertest.cpp
+++ b/fpdfsdk/fpdf_text_embeddertest.cpp
@@ -200,14 +200,10 @@
FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
ASSERT_TRUE(textpage);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> nope =
- GetFPDFWideString(L"nope");
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> world =
- GetFPDFWideString(L"world");
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> world_caps =
- GetFPDFWideString(L"WORLD");
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> world_substr =
- GetFPDFWideString(L"orld");
+ ScopedFPDFWideString nope = GetFPDFWideString(L"nope");
+ ScopedFPDFWideString world = GetFPDFWideString(L"world");
+ ScopedFPDFWideString world_caps = GetFPDFWideString(L"WORLD");
+ ScopedFPDFWideString world_substr = GetFPDFWideString(L"orld");
{
// No occurrences of "nope" in test page.
@@ -320,8 +316,7 @@
FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
ASSERT_TRUE(textpage);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> aaaa =
- GetFPDFWideString(L"aaaa");
+ ScopedFPDFWideString aaaa = GetFPDFWideString(L"aaaa");
{
// Search for "aaaa" yields 2 results in "aaaaaaaaaa".
diff --git a/testing/fx_string_testhelpers.cpp b/testing/fx_string_testhelpers.cpp
index e13bd2d..8087e12 100644
--- a/testing/fx_string_testhelpers.cpp
+++ b/testing/fx_string_testhelpers.cpp
@@ -56,11 +56,9 @@
return platform_string;
}
-std::unique_ptr<unsigned short, pdfium::FreeDeleter> GetFPDFWideString(
- const std::wstring& wstr) {
+ScopedFPDFWideString GetFPDFWideString(const std::wstring& wstr) {
size_t length = sizeof(uint16_t) * (wstr.length() + 1);
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> result(
- static_cast<unsigned short*>(malloc(length)));
+ ScopedFPDFWideString result(static_cast<FPDF_WCHAR*>(malloc(length)));
pdfium::span<uint8_t> result_span(reinterpret_cast<uint8_t*>(result.get()),
length);
size_t i = 0;
diff --git a/testing/fx_string_testhelpers.h b/testing/fx_string_testhelpers.h
index 9f3f759..67ba836 100644
--- a/testing/fx_string_testhelpers.h
+++ b/testing/fx_string_testhelpers.h
@@ -27,9 +27,10 @@
// Deals with differences between UTF16LE and wchar_t.
std::wstring GetPlatformWString(FPDF_WIDESTRING wstr);
+using ScopedFPDFWideString = std::unique_ptr<FPDF_WCHAR, pdfium::FreeDeleter>;
+
// Returns a newly allocated FPDF_WIDESTRING.
// Deals with differences between UTF16LE and wchar_t.
-std::unique_ptr<unsigned short, pdfium::FreeDeleter> GetFPDFWideString(
- const std::wstring& wstr);
+ScopedFPDFWideString GetFPDFWideString(const std::wstring& wstr);
#endif // TESTING_FX_STRING_TESTHELPERS_H_