summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-01-06 10:06:12 -0800
committerTom Sepez <tsepez@chromium.org>2016-01-06 10:06:12 -0800
commitaa326bd6b169dc1b5b9b83048c71799799ab34c6 (patch)
tree5cdae330aa2fb40fecc701655b5c33ce85bf9ed3 /fpdfsdk
parentd368261cc8d604286e29ca6358700e6bb051dcaa (diff)
downloadpdfium-aa326bd6b169dc1b5b9b83048c71799799ab34c6.tar.xz
Return unique_ptrs from test_support functions
R=thestig@chromium.org Review URL: https://codereview.chromium.org/1563513002 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/src/fpdfdoc_embeddertest.cpp14
-rw-r--r--fpdfsdk/src/fpdftext_embeddertest.cpp33
2 files changed, 22 insertions, 25 deletions
diff --git a/fpdfsdk/src/fpdfdoc_embeddertest.cpp b/fpdfsdk/src/fpdfdoc_embeddertest.cpp
index 260f25f309..1c66a15bad 100644
--- a/fpdfsdk/src/fpdfdoc_embeddertest.cpp
+++ b/fpdfsdk/src/fpdfdoc_embeddertest.cpp
@@ -106,8 +106,9 @@ TEST_F(FPDFDocEmbeddertest, FindBookmarks) {
EXPECT_TRUE(OpenDocument("bookmarks.pdf"));
// Find the first one, based on its known title.
- FPDF_WIDESTRING title = GetFPDFWideString(L"A Good Beginning");
- FPDF_BOOKMARK child = FPDFBookmark_Find(document(), title);
+ std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
+ GetFPDFWideString(L"A Good Beginning");
+ FPDF_BOOKMARK child = FPDFBookmark_Find(document(), title.get());
EXPECT_NE(nullptr, child);
// Check that the string matches.
@@ -120,10 +121,7 @@ TEST_F(FPDFDocEmbeddertest, FindBookmarks) {
EXPECT_EQ(child, FPDFBookmark_GetFirstChild(document(), nullptr));
// Try to find one using a non-existent title.
- FPDF_WIDESTRING bad_title = GetFPDFWideString(L"A BAD Beginning");
- EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), bad_title));
-
- // Alas, the typedef includes the "const".
- free(const_cast<unsigned short*>(title));
- free(const_cast<unsigned short*>(bad_title));
+ std::unique_ptr<unsigned short, pdfium::FreeDeleter> bad_title =
+ GetFPDFWideString(L"A BAD Beginning");
+ EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), bad_title.get()));
}
diff --git a/fpdfsdk/src/fpdftext_embeddertest.cpp b/fpdfsdk/src/fpdftext_embeddertest.cpp
index 3772686c88..4653db32ad 100644
--- a/fpdfsdk/src/fpdftext_embeddertest.cpp
+++ b/fpdfsdk/src/fpdftext_embeddertest.cpp
@@ -144,13 +144,17 @@ TEST_F(FPDFTextEmbeddertest, TextSearch) {
FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
EXPECT_NE(nullptr, textpage);
- FPDF_WIDESTRING nope = GetFPDFWideString(L"nope");
- FPDF_WIDESTRING world = GetFPDFWideString(L"world");
- FPDF_WIDESTRING world_caps = GetFPDFWideString(L"WORLD");
- FPDF_WIDESTRING world_substr = GetFPDFWideString(L"orld");
+ 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");
// No occurences of "nope" in test page.
- FPDF_SCHHANDLE search = FPDFText_FindStart(textpage, nope, 0, 0);
+ FPDF_SCHHANDLE search = FPDFText_FindStart(textpage, nope.get(), 0, 0);
EXPECT_NE(nullptr, search);
EXPECT_EQ(0, FPDFText_GetSchResultIndex(search));
EXPECT_EQ(0, FPDFText_GetSchCount(search));
@@ -167,7 +171,7 @@ TEST_F(FPDFTextEmbeddertest, TextSearch) {
FPDFText_FindClose(search);
// Two occurences of "world" in test page.
- search = FPDFText_FindStart(textpage, world, 0, 2);
+ search = FPDFText_FindStart(textpage, world.get(), 0, 2);
EXPECT_NE(nullptr, search);
// Remains not found until advanced.
@@ -201,7 +205,7 @@ TEST_F(FPDFTextEmbeddertest, TextSearch) {
FPDFText_FindClose(search);
// Exact search unaffected by case sensitiity and whole word flags.
- search = FPDFText_FindStart(textpage, world,
+ search = FPDFText_FindStart(textpage, world.get(),
FPDF_MATCHCASE | FPDF_MATCHWHOLEWORD, 0);
EXPECT_NE(nullptr, search);
EXPECT_TRUE(FPDFText_FindNext(search));
@@ -210,7 +214,7 @@ TEST_F(FPDFTextEmbeddertest, TextSearch) {
FPDFText_FindClose(search);
// Default is case-insensitive, so matching agaist caps works.
- search = FPDFText_FindStart(textpage, world_caps, 0, 0);
+ search = FPDFText_FindStart(textpage, world_caps.get(), 0, 0);
EXPECT_NE(nullptr, search);
EXPECT_TRUE(FPDFText_FindNext(search));
EXPECT_EQ(7, FPDFText_GetSchResultIndex(search));
@@ -218,33 +222,28 @@ TEST_F(FPDFTextEmbeddertest, TextSearch) {
FPDFText_FindClose(search);
// But can be made case sensitive, in which case this fails.
- search = FPDFText_FindStart(textpage, world_caps, FPDF_MATCHCASE, 0);
+ search = FPDFText_FindStart(textpage, world_caps.get(), FPDF_MATCHCASE, 0);
EXPECT_FALSE(FPDFText_FindNext(search));
EXPECT_EQ(0, FPDFText_GetSchResultIndex(search));
EXPECT_EQ(0, FPDFText_GetSchCount(search));
FPDFText_FindClose(search);
// Default is match anywhere within word, so matching substirng works.
- search = FPDFText_FindStart(textpage, world_substr, 0, 0);
+ search = FPDFText_FindStart(textpage, world_substr.get(), 0, 0);
EXPECT_TRUE(FPDFText_FindNext(search));
EXPECT_EQ(8, FPDFText_GetSchResultIndex(search));
EXPECT_EQ(4, FPDFText_GetSchCount(search));
FPDFText_FindClose(search);
// But can be made to mach word boundaries, in which case this fails.
- search = FPDFText_FindStart(textpage, world_substr, FPDF_MATCHWHOLEWORD, 0);
+ search =
+ FPDFText_FindStart(textpage, world_substr.get(), FPDF_MATCHWHOLEWORD, 0);
EXPECT_FALSE(FPDFText_FindNext(search));
// TODO(tsepez): investigate strange index/count values in this state.
FPDFText_FindClose(search);
FPDFText_ClosePage(textpage);
UnloadPage(page);
-
- // Alas, the typedef includes the "const".
- free(const_cast<unsigned short*>(nope));
- free(const_cast<unsigned short*>(world));
- free(const_cast<unsigned short*>(world_caps));
- free(const_cast<unsigned short*>(world_substr));
}
// Test that the page has characters despite a bad stream length.