Switch to LoadScopedPage()
Bug: 354025368
Change-Id: Ie6bbf7d2df60bc942566650dcfafd2fb38532d4b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/124010
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@google.com>
diff --git a/AUTHORS b/AUTHORS
index abd91f7..74d839a 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -22,6 +22,7 @@
Dorian Rudolph <dorianrudo97@gmail.com>
Felix Kauselmann <licorn@gmail.com>
GiWan Go <gogil@stealien.com>
+Helmut Januschka <helmut@januschka.com>
Huy Ngo <huyna89@gmail.com>
Ivan Odulo <ivanodulo@gmail.com>
Jiang Jiang <jiangj@opera.com>
diff --git a/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp b/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp
index 741401c..41b5959 100644
--- a/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp
+++ b/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp
@@ -28,12 +28,11 @@
{
// Do some read only operations.
ASSERT_GE(1, FPDF_GetPageCount(document()));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
EXPECT_EQ(595, FPDFBitmap_GetWidth(bitmap.get()));
EXPECT_EQ(842, FPDFBitmap_GetHeight(bitmap.get()));
- UnloadPage(page);
}
// Save when we have additional loaded data.
diff --git a/core/fpdfapi/parser/cpdf_parser_embeddertest.cpp b/core/fpdfapi/parser/cpdf_parser_embeddertest.cpp
index 17ac00f..cb75956 100644
--- a/core/fpdfapi/parser/cpdf_parser_embeddertest.cpp
+++ b/core/fpdfapi/parser/cpdf_parser_embeddertest.cpp
@@ -17,9 +17,7 @@
TEST_F(CPDFParserEmbedderTest, Bug481363) {
// Test colorspace object with malformed dictionary.
ASSERT_TRUE(OpenDocument("bug_481363.pdf"));
- FPDF_PAGE page = LoadPage(0);
- EXPECT_TRUE(page);
- UnloadPage(page);
+ EXPECT_TRUE(LoadScopedPage(0));
}
TEST_F(CPDFParserEmbedderTest, Bug544880) {
@@ -43,15 +41,14 @@
// Test the case that cross reference entries, which are well formed,
// but do not match with the objects.
ASSERT_TRUE(OpenDocument("bug_602650.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page.get());
EXPECT_TRUE(text_page);
// The page should not be blank.
EXPECT_LT(0, FPDFText_CountChars(text_page));
FPDFText_ClosePage(text_page);
- UnloadPage(page);
}
TEST_F(CPDFParserEmbedderTest, Bug757705) {
@@ -64,21 +61,19 @@
// check that the second page was correctly loaded. Because it is contains
// crossrefs for second page.
EXPECT_EQ(2, GetPageCount());
- FPDF_PAGE page = LoadPage(1);
+ ScopedEmbedderTestPage page = LoadScopedPage(1);
EXPECT_TRUE(page);
- FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page.get());
EXPECT_TRUE(text_page);
// The page should not be blank.
EXPECT_LT(0, FPDFText_CountChars(text_page));
FPDFText_ClosePage(text_page);
- UnloadPage(page);
}
TEST_F(CPDFParserEmbedderTest, Bug828049) {
ASSERT_TRUE(OpenDocument("bug_828049.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- UnloadPage(page);
}
// crbug.com/1191313
diff --git a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp
index 0bef0f8..8b0617d 100644
--- a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp
@@ -44,9 +44,8 @@
void OpenAndVerifyHelloWorldDocumentWithPassword(const char* filename,
const char* password) {
ASSERT_TRUE(OpenDocumentWithPassword(filename, password));
- FPDF_PAGE page = LoadPage(0);
- VerifyHelloWorldPage(page);
- UnloadPage(page);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
+ VerifyHelloWorldPage(page.get());
}
void VerifySavedHelloWorldDocumentWithPassword(const char* password) {
@@ -79,15 +78,14 @@
}
void RemoveGoodbyeObject() {
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
{
- ScopedFPDFPageObject goodbye_object(FPDFPage_GetObject(page, 1));
+ ScopedFPDFPageObject goodbye_object(FPDFPage_GetObject(page.get(), 1));
ASSERT_TRUE(goodbye_object);
- ASSERT_TRUE(FPDFPage_RemoveObject(page, goodbye_object.get()));
+ ASSERT_TRUE(FPDFPage_RemoveObject(page.get(), goodbye_object.get()));
}
- ASSERT_TRUE(FPDFPage_GenerateContent(page));
- VerifyModifiedHelloWorldPage(page);
- UnloadPage(page);
+ ASSERT_TRUE(FPDFPage_GenerateContent(page.get()));
+ VerifyModifiedHelloWorldPage(page.get());
}
private:
@@ -162,19 +160,18 @@
ASSERT_TRUE(OpenDocumentWithOptions("encrypted.pdf", "5678",
LinearizeOption::kMustLinearize,
JavaScriptOption::kEnableJavaScript));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(10, 10, 20, 20);
ASSERT_TRUE(red_rect);
EXPECT_TRUE(FPDFPageObj_SetFillColor(red_rect, 255, 0, 0, 255));
EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0));
- FPDFPage_InsertObject(page, red_rect);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ FPDFPage_InsertObject(page.get(), red_rect);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 612, 792, checksum);
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
SetWholeFileAvailable();
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
}
std::string new_file = GetString();
FPDF_FILEACCESS file_access = {}; // Aggregate initialization.
diff --git a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
index e5b8b05..4be2012 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
@@ -17,32 +17,29 @@
// Tests specifying multiple image filters for a stream. Should not cause a
// crash when rendered.
ASSERT_TRUE(OpenDocument("bug_552046.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 612, 792, kBlankPage612By792Checksum);
- UnloadPage(page);
}
TEST_F(FPDFParserDecodeEmbedderTest, Bug555784) {
// Tests bad input to the run length decoder that caused a heap overflow.
// Should not cause a crash when rendered.
ASSERT_TRUE(OpenDocument("bug_555784.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 612, 792, kBlankPage612By792Checksum);
- UnloadPage(page);
}
TEST_F(FPDFParserDecodeEmbedderTest, Bug455199) {
// Tests object numbers with a value > 01000000.
// Should open successfully.
ASSERT_TRUE(OpenDocument("bug_455199.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 200, 200, pdfium::HelloWorldChecksum());
- UnloadPage(page);
}
diff --git a/core/fpdfapi/render/fpdf_progressive_render_embeddertest.cpp b/core/fpdfapi/render/fpdf_progressive_render_embeddertest.cpp
index 702c1cd..b6c40c7 100644
--- a/core/fpdfapi/render/fpdf_progressive_render_embeddertest.cpp
+++ b/core/fpdfapi/render/fpdf_progressive_render_embeddertest.cpp
@@ -236,70 +236,67 @@
// Test rendering of page content using progressive render APIs
// without pausing the rendering.
ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
FakePause pause(false);
- EXPECT_TRUE(StartRenderPage(page, &pause));
- ScopedFPDFBitmap bitmap = FinishRenderPage(page);
+ EXPECT_TRUE(StartRenderPage(page.get(), &pause));
+ ScopedFPDFBitmap bitmap = FinishRenderPage(page.get());
CompareBitmap(bitmap.get(), 595, 842,
AnnotationStampWithApBaseContentChecksum());
- UnloadPage(page);
}
TEST_F(FPDFProgressiveRenderEmbedderTest, RenderWithPause) {
// Test rendering of page content using progressive render APIs
// with pause in rendering.
ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
FakePause pause(true);
- bool render_done = StartRenderPage(page, &pause);
+ bool render_done = StartRenderPage(page.get(), &pause);
EXPECT_FALSE(render_done);
while (!render_done) {
- render_done = ContinueRenderPage(page, &pause);
+ render_done = ContinueRenderPage(page.get(), &pause);
}
- ScopedFPDFBitmap bitmap = FinishRenderPage(page);
+ ScopedFPDFBitmap bitmap = FinishRenderPage(page.get());
CompareBitmap(bitmap.get(), 595, 842,
AnnotationStampWithApBaseContentChecksum());
- UnloadPage(page);
}
TEST_F(FPDFProgressiveRenderEmbedderTest, RenderAnnotWithPause) {
// Test rendering of the page with annotations using progressive render APIs
// with pause in rendering.
ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
FakePause pause(true);
- bool render_done = StartRenderPageWithFlags(page, &pause, FPDF_ANNOT);
+ bool render_done = StartRenderPageWithFlags(page.get(), &pause, FPDF_ANNOT);
EXPECT_FALSE(render_done);
while (!render_done) {
- render_done = ContinueRenderPage(page, &pause);
+ render_done = ContinueRenderPage(page.get(), &pause);
}
- ScopedFPDFBitmap bitmap = FinishRenderPage(page);
+ ScopedFPDFBitmap bitmap = FinishRenderPage(page.get());
CompareBitmap(bitmap.get(), 595, 842,
pdfium::AnnotationStampWithApChecksum());
- UnloadPage(page);
}
TEST_F(FPDFProgressiveRenderEmbedderTest, RenderFormsWithPause) {
// Test rendering of the page with forms using progressive render APIs
// with pause in rendering.
ASSERT_TRUE(OpenDocument("text_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
FakePause pause(true);
- bool render_done = StartRenderPage(page, &pause);
+ bool render_done = StartRenderPage(page.get(), &pause);
EXPECT_FALSE(render_done);
while (!render_done) {
- render_done = ContinueRenderPage(page, &pause);
+ render_done = ContinueRenderPage(page.get(), &pause);
}
- ScopedFPDFBitmap bitmap = FinishRenderPageWithForms(page, form_handle());
+ ScopedFPDFBitmap bitmap =
+ FinishRenderPageWithForms(page.get(), form_handle());
CompareBitmap(bitmap.get(), 300, 300, pdfium::TextFormChecksum());
- UnloadPage(page);
}
void FPDFProgressiveRenderEmbedderTest::VerifyRenderingWithColorScheme(
@@ -312,14 +309,13 @@
const char* md5) {
ASSERT_TRUE(document());
- FPDF_PAGE page = LoadPage(page_num);
+ ScopedEmbedderTestPage page = LoadScopedPage(page_num);
ASSERT_TRUE(page);
ScopedFPDFBitmap bitmap = RenderPageWithForcedColorScheme(
- page, form_handle(), flags, color_scheme, background_color);
+ page.get(), form_handle(), flags, color_scheme, background_color);
ASSERT_TRUE(bitmap);
CompareBitmap(bitmap.get(), bitmap_width, bitmap_height, md5);
- UnloadPage(page);
}
TEST_F(FPDFProgressiveRenderEmbedderTest, RenderTextWithColorScheme) {
diff --git a/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp b/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp
index f3b6cae..68505e5 100644
--- a/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp
+++ b/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp
@@ -12,9 +12,8 @@
TEST_F(FPDFRenderPatternEmbedderTest, LoadError_547706) {
// Test shading where object is a dictionary instead of a stream.
ASSERT_TRUE(OpenDocument("bug_547706.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 612, 792, pdfium::kBlankPage612By792Checksum);
- UnloadPage(page);
}
diff --git a/core/fxcodec/jbig2/jbig2_embeddertest.cpp b/core/fxcodec/jbig2/jbig2_embeddertest.cpp
index c017e48..80cbd6d 100644
--- a/core/fxcodec/jbig2/jbig2_embeddertest.cpp
+++ b/core/fxcodec/jbig2/jbig2_embeddertest.cpp
@@ -18,9 +18,8 @@
// Test jbig2 image in PDF file can be loaded successfully.
// Should not crash.
ASSERT_TRUE(OpenDocument("bug_631912.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 691, 432, "726c2b8c89df0ab40627322d1dddd521");
- UnloadPage(page);
}
diff --git a/core/fxge/fx_ge_text_embeddertest.cpp b/core/fxge/fx_ge_text_embeddertest.cpp
index 9a79620..5276f98 100644
--- a/core/fxge/fx_ge_text_embeddertest.cpp
+++ b/core/fxge/fx_ge_text_embeddertest.cpp
@@ -23,10 +23,9 @@
TEST_F(FXGETextEmbedderTest, BadItalic) {
// Shouldn't crash.
ASSERT_TRUE(OpenDocument("bug_601362.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
EXPECT_EQ(612, FPDFBitmap_GetWidth(bitmap.get()));
EXPECT_EQ(792, FPDFBitmap_GetHeight(bitmap.get()));
- UnloadPage(page);
}
diff --git a/core/fxge/skia/fx_skia_device_embeddertest.cpp b/core/fxge/skia/fx_skia_device_embeddertest.cpp
index 6e54863..5440435 100644
--- a/core/fxge/skia/fx_skia_device_embeddertest.cpp
+++ b/core/fxge/skia/fx_skia_device_embeddertest.cpp
@@ -263,7 +263,7 @@
}
ASSERT_TRUE(OpenDocument("bug_2034.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
std::set<int> image_ids;
@@ -281,14 +281,12 @@
}));
// Render top half.
- RenderPageToSkCanvas(page, /*start_x=*/0, /*start_y=*/0,
+ RenderPageToSkCanvas(page.get(), /*start_x=*/0, /*start_y=*/0,
/*size_x=*/kPageWidth, /*size_y=*/kPageHeight, canvas);
// Render bottom half.
- RenderPageToSkCanvas(page, /*start_x=*/0, /*start_y=*/-kPageHeight / 2,
+ RenderPageToSkCanvas(page.get(), /*start_x=*/0, /*start_y=*/-kPageHeight / 2,
/*size_x=*/kPageWidth, /*size_y=*/kPageHeight, canvas);
EXPECT_THAT(image_ids, SizeIs(1));
-
- UnloadPage(page);
}
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index 21fd3c7..ead0815 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -346,7 +346,7 @@
TEST_F(FPDFAnnotEmbedderTest, BadParams) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
EXPECT_EQ(0, FPDFPage_GetAnnotCount(nullptr));
@@ -354,8 +354,8 @@
EXPECT_FALSE(FPDFPage_GetAnnot(nullptr, 0));
EXPECT_FALSE(FPDFPage_GetAnnot(nullptr, -1));
EXPECT_FALSE(FPDFPage_GetAnnot(nullptr, 1));
- EXPECT_FALSE(FPDFPage_GetAnnot(page, -1));
- EXPECT_FALSE(FPDFPage_GetAnnot(page, 1));
+ EXPECT_FALSE(FPDFPage_GetAnnot(page.get(), -1));
+ EXPECT_FALSE(FPDFPage_GetAnnot(page.get(), 1));
EXPECT_EQ(FPDF_ANNOT_UNKNOWN, FPDFAnnot_GetSubtype(nullptr));
@@ -376,35 +376,29 @@
EXPECT_EQ(0u, FPDFAnnot_GetStringValue(nullptr, "foo", buffer, 0));
EXPECT_EQ(0u,
FPDFAnnot_GetStringValue(nullptr, "foo", buffer, sizeof(buffer)));
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, BadAnnotsEntry) {
ASSERT_TRUE(OpenDocument("bad_annots_entry.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
- EXPECT_FALSE(FPDFPage_GetAnnot(page, 0));
-
- UnloadPage(page);
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(page.get()));
+ EXPECT_FALSE(FPDFPage_GetAnnot(page.get(), 0));
}
TEST_F(FPDFAnnotEmbedderTest, RenderAnnotWithOnlyRolloverAP) {
// Open a file with one annotation and load its first page.
ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// This annotation has a malformed appearance stream, which does not have its
// normal appearance defined, only its rollover appearance. In this case, its
// normal appearance should be generated, allowing the highlight annotation to
// still display.
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, RenderMultilineMarkupAnnotWithoutAP) {
@@ -417,13 +411,11 @@
// Open a file with multiline markup annotations.
ASSERT_TRUE(OpenDocument("annotation_markup_multiline_no_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 595, 842, checksum);
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, ExtractHighlightLongContent) {
@@ -572,36 +564,35 @@
TEST_F(FPDFAnnotEmbedderTest, AddIllegalSubtypeAnnotation) {
// Open a file with one annotation and load its first page.
ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Add an annotation with an illegal subtype.
- ASSERT_FALSE(FPDFPage_CreateAnnot(page, -1));
-
- UnloadPage(page);
+ ASSERT_FALSE(FPDFPage_CreateAnnot(page.get(), -1));
}
TEST_F(FPDFAnnotEmbedderTest, AddFirstTextAnnotation) {
// Open a file with no annotation and load its first page.
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(0, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(0, FPDFPage_GetAnnotCount(page.get()));
{
// Add a text annotation to the page.
- ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT));
+ ScopedFPDFAnnotation annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_TEXT));
ASSERT_TRUE(annot);
// Check that there is now 1 annotations on this page.
- EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(page.get()));
// Check that the subtype of the annotation is correct.
EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get()));
}
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get()));
@@ -663,26 +654,26 @@
buf.data(), length_bytes));
EXPECT_EQ(kContents, GetPlatformWString(buf.data()));
}
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, AddAndSaveLinkAnnotation) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 200, 200, pdfium::HelloWorldChecksum());
}
- EXPECT_EQ(0, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(0, FPDFPage_GetAnnotCount(page.get()));
constexpr char kUri[] = "https://pdfium.org/";
{
// Add a link annotation to the page and set its URI.
- ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_LINK));
+ ScopedFPDFAnnotation annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_LINK));
ASSERT_TRUE(annot);
- EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(page.get()));
EXPECT_EQ(FPDF_ANNOT_LINK, FPDFAnnot_GetSubtype(annot.get()));
EXPECT_TRUE(FPDFAnnot_SetURI(annot.get(), kUri));
VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
@@ -702,60 +693,59 @@
/*vertical_radius=*/0.0f,
/*border_width=*/0.0f));
- VerifyUriActionInLink(document(), FPDFLink_GetLinkAtPoint(page, 40.0, 50.0),
- kUri);
+ VerifyUriActionInLink(
+ document(), FPDFLink_GetLinkAtPoint(page.get(), 40.0, 50.0), kUri);
}
{
// Add an ink annotation to the page. Trying to add a link to it fails.
- ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_INK));
+ ScopedFPDFAnnotation annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK));
ASSERT_TRUE(annot);
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(page.get()));
EXPECT_EQ(FPDF_ANNOT_INK, FPDFAnnot_GetSubtype(annot.get()));
EXPECT_FALSE(FPDFAnnot_SetURI(annot.get(), kUri));
}
// Remove the ink annotation added above for negative testing.
- EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 1));
- EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+ EXPECT_TRUE(FPDFPage_RemoveAnnot(page.get(), 1));
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(page.get()));
- // Save the document, closing the page.
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Reopen the document and make sure it still renders the same. Since the link
// does not have a border, it does not affect the rendering.
ASSERT_TRUE(OpenSavedDocument());
- page = LoadSavedPage(0);
- ASSERT_TRUE(page);
- VerifySavedRendering(page, 200, 200, pdfium::HelloWorldChecksum());
- EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+ FPDF_PAGE saved_page = LoadSavedPage(0);
+ ASSERT_TRUE(saved_page);
+ VerifySavedRendering(saved_page, 200, 200, pdfium::HelloWorldChecksum());
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(saved_page));
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(saved_page, 0));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_LINK, FPDFAnnot_GetSubtype(annot.get()));
VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
- VerifyUriActionInLink(document(), FPDFLink_GetLinkAtPoint(page, 40.0, 50.0),
- kUri);
+ VerifyUriActionInLink(
+ document(), FPDFLink_GetLinkAtPoint(saved_page, 40.0, 50.0), kUri);
}
- CloseSavedPage(page);
+ CloseSavedPage(saved_page);
CloseSavedDocument();
}
TEST_F(FPDFAnnotEmbedderTest, AddAndSaveUnderlineAnnotation) {
// Open a file with one annotation and load its first page.
ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Check that there is a total of one annotation on its first page, and verify
// its quadpoints.
- EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(page.get()));
FS_QUADPOINTSF quadpoints;
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints));
EXPECT_EQ(115.802643f, quadpoints.x1);
@@ -767,16 +757,14 @@
// Add an underline annotation to the page and set its quadpoints.
{
ScopedFPDFAnnotation annot(
- FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE));
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_UNDERLINE));
ASSERT_TRUE(annot);
quadpoints.x1 = 140.802643f;
quadpoints.x3 = 140.802643f;
ASSERT_TRUE(FPDFAnnot_AppendAttachmentPoints(annot.get(), &quadpoints));
}
- // Save the document and close the page.
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Open the saved document.
const char* checksum = []() {
@@ -793,17 +781,17 @@
}();
ASSERT_TRUE(OpenSavedDocument());
- page = LoadSavedPage(0);
- ASSERT_TRUE(page);
- VerifySavedRendering(page, 612, 792, checksum);
+ FPDF_PAGE saved_page = LoadSavedPage(0);
+ ASSERT_TRUE(saved_page);
+ VerifySavedRendering(saved_page, 612, 792, checksum);
// Check that the saved document has 2 annotations on the first page
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(saved_page));
{
// Check that the second annotation is an underline annotation and verify
// its quadpoints.
- ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(saved_page, 1));
ASSERT_TRUE(new_annot);
EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot.get()));
FS_QUADPOINTSF new_quadpoints;
@@ -815,19 +803,19 @@
EXPECT_NEAR(quadpoints.y4, new_quadpoints.y4, 0.001f);
}
- CloseSavedPage(page);
+ CloseSavedPage(saved_page);
CloseSavedDocument();
}
TEST_F(FPDFAnnotEmbedderTest, GetAndSetQuadPoints) {
// Open a file with four annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(4, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(4, FPDFPage_GetAnnotCount(page.get()));
// Retrieve the highlight annotation.
- FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
+ FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page.get(), 0);
ASSERT_TRUE(annot);
ASSERT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot));
@@ -889,7 +877,7 @@
FPDFPage_CloseAnnot(annot);
// Retrieve the square annotation
- FPDF_ANNOTATION squareAnnot = FPDFPage_GetAnnot(page, 2);
+ FPDF_ANNOTATION squareAnnot = FPDFPage_GetAnnot(page.get(), 2);
{
// Check that attempting to set its quadpoints would fail
@@ -900,7 +888,6 @@
}
FPDFPage_CloseAnnot(squareAnnot);
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, ModifyRectQuadpointsWithAP) {
@@ -955,13 +942,13 @@
// Open a file with four annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(4, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(4, FPDFPage_GetAnnotCount(page.get()));
// Check that the original file renders correctly.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, md5_original);
}
@@ -970,7 +957,7 @@
// Retrieve the highlight annotation which has its AP stream already defined.
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get()));
@@ -1001,7 +988,8 @@
// Check that updating quadpoints does not change the annotation's position.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap =
+ RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, md5_original);
}
@@ -1022,13 +1010,13 @@
// Check that updating the rectangle changes the annotation's position.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, md5_modified_highlight);
}
{
// Retrieve the square annotation which has its AP stream already defined.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 2));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(annot.get()));
@@ -1042,26 +1030,23 @@
// Check that updating the rectangle changes the square annotation's
// position.
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, md5_modified_square);
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, CountAttachmentPoints) {
// Open a file with multiline markup annotations.
ASSERT_TRUE(OpenDocument("annotation_markup_multiline_no_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// This is a three line annotation.
EXPECT_EQ(3u, FPDFAnnot_CountAttachmentPoints(annot.get()));
}
- UnloadPage(page);
// null annotation should return 0
EXPECT_EQ(0u, FPDFAnnot_CountAttachmentPoints(nullptr));
@@ -1193,24 +1178,24 @@
// Open a file with two annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(page.get()));
// Check that the page renders correctly.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 595, 842, AnnotationStampWithApChecksum());
}
{
// Retrieve the stamp annotation which has its AP stream already defined.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Check that this annotation has one path object and retrieve it.
EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
- ASSERT_EQ(32, FPDFPage_CountObjects(page));
+ ASSERT_EQ(32, FPDFPage_CountObjects(page.get()));
FPDF_PAGEOBJECT path = FPDFAnnot_GetObject(annot.get(), 1);
EXPECT_FALSE(path);
path = FPDFAnnot_GetObject(annot.get(), 0);
@@ -1223,7 +1208,8 @@
// Check that the page with the modified annotation renders correctly.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap =
+ RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 595, 842, md5_modified_path);
}
@@ -1238,23 +1224,24 @@
// The object is in the annontation, not in the page, so the page object
// array should not change.
- ASSERT_EQ(32, FPDFPage_CountObjects(page));
+ ASSERT_EQ(32, FPDFPage_CountObjects(page.get()));
// Check that the page with an annotation with two paths renders correctly.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap =
+ RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 595, 842, md5_two_paths);
}
// Delete the newly added path object.
EXPECT_TRUE(FPDFAnnot_RemoveObject(annot.get(), 1));
EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
- ASSERT_EQ(32, FPDFPage_CountObjects(page));
+ ASSERT_EQ(32, FPDFPage_CountObjects(page.get()));
}
// Check that the page renders the same as before.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 595, 842, md5_modified_path);
}
@@ -1262,7 +1249,8 @@
{
// Create another stamp annotation and set its annotation rectangle.
- ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP));
+ ScopedFPDFAnnotation annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_STAMP));
ASSERT_TRUE(annot);
rect.left = 200.f;
rect.bottom = 400.f;
@@ -1291,21 +1279,19 @@
EXPECT_EQ(rect.top, new_rect.top);
}
- // Save the document and close the page.
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Open the saved document.
ASSERT_TRUE(OpenSavedDocument());
- page = LoadSavedPage(0);
- ASSERT_TRUE(page);
- VerifySavedRendering(page, 595, 842, md5_new_annot);
+ FPDF_PAGE saved_page = LoadSavedPage(0);
+ ASSERT_TRUE(saved_page);
+ VerifySavedRendering(saved_page, 595, 842, md5_new_annot);
// Check that the document has a correct count of annotations and objects.
- EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(3, FPDFPage_GetAnnotCount(saved_page));
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(saved_page, 2));
ASSERT_TRUE(annot);
EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
@@ -1318,25 +1304,25 @@
EXPECT_EQ(rect.top, new_rect.top);
}
- CloseSavedPage(page);
+ CloseSavedPage(saved_page);
CloseSavedDocument();
}
TEST_F(FPDFAnnotEmbedderTest, ModifyAnnotationFlags) {
// Open a file with an annotation and load its first page.
ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Check that the page renders correctly.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
}
{
// Retrieve the annotation.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Check that the original flag values are as expected.
@@ -1360,7 +1346,8 @@
// Check that the page renders correctly without rendering the annotation.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap =
+ RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, pdfium::kBlankPage612By792Checksum);
}
@@ -1375,12 +1362,11 @@
// Check that the page renders correctly as before.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap =
+ RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
}
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, AddAndModifyImage) {
@@ -1419,13 +1405,13 @@
// Open a file with two annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(page.get()));
// Check that the page renders correctly.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 595, 842, AnnotationStampWithApChecksum());
}
@@ -1434,7 +1420,9 @@
{
// Create a stamp annotation and set its annotation rectangle.
- ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP));
+ ScopedFPDFAnnotation annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_STAMP));
+ FPDF_PAGE page0 = page.get();
ASSERT_TRUE(annot);
FS_RECTF rect;
rect.left = 200.f;
@@ -1450,7 +1438,7 @@
EXPECT_EQ(kBitmapSize, FPDFBitmap_GetWidth(image_bitmap));
EXPECT_EQ(kBitmapSize, FPDFBitmap_GetHeight(image_bitmap));
FPDF_PAGEOBJECT image_object = FPDFPageObj_NewImageObj(document());
- ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
+ ASSERT_TRUE(FPDFImageObj_SetBitmap(&page0, 0, image_object, image_bitmap));
static constexpr FS_MATRIX kBitmapScaleMatrix{kBitmapSize, 0, 0,
kBitmapSize, 0, 0};
ASSERT_TRUE(FPDFPageObj_SetMatrix(image_object, &kBitmapScaleMatrix));
@@ -1460,13 +1448,13 @@
// Check that the page renders correctly with the new image object.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 595, 842, md5_new_image);
}
{
// Retrieve the newly added stamp annotation and its image object.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 2));
ASSERT_TRUE(annot);
EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
FPDF_PAGEOBJECT image_object = FPDFAnnot_GetObject(annot.get(), 0);
@@ -1475,13 +1463,14 @@
// Modify the image in the new annotation.
ASSERT_TRUE(FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize,
kBitmapSize, 0xff000000));
- ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
+ FPDF_PAGE page_ptr = page.get();
+ ASSERT_TRUE(
+ FPDFImageObj_SetBitmap(&page_ptr, 0, image_object, image_bitmap));
EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), image_object));
}
// Save the document and close the page.
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
FPDFBitmap_Destroy(image_bitmap);
// Test that the saved document renders the modified image object correctly.
@@ -1528,19 +1517,20 @@
// Open a file with two annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(page.get()));
// Check that the page renders correctly.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 595, 842, AnnotationStampWithApChecksum());
}
{
// Create a stamp annotation and set its annotation rectangle.
- ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP));
+ ScopedFPDFAnnotation annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_STAMP));
ASSERT_TRUE(annot);
FS_RECTF rect;
rect.left = 200.f;
@@ -1563,13 +1553,13 @@
// Check that the page renders correctly with the new text object.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 595, 842, md5_new_text);
}
{
// Retrieve the newly added stamp annotation and its text object.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 2));
ASSERT_TRUE(annot);
EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
FPDF_PAGEOBJECT text_object = FPDFAnnot_GetObject(annot.get(), 0);
@@ -1583,31 +1573,29 @@
// Check that the page renders correctly with the modified text object.
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 595, 842, md5_modified_text);
}
// Remove the new annotation, and check that the page renders as before.
- EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 2));
+ EXPECT_TRUE(FPDFPage_RemoveAnnot(page.get(), 2));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 595, 842, AnnotationStampWithApChecksum());
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetSetStringValue) {
// Open a file with four annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
static const wchar_t kNewDate[] = L"D:201706282359Z00'00'";
{
// Retrieve the first annotation.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Check that a non-existent key does not exist.
@@ -1650,7 +1638,6 @@
// Save the document and close the page.
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
const char* md5 = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -1671,11 +1658,11 @@
// Open the saved annotation.
ASSERT_TRUE(OpenSavedDocument());
- page = LoadSavedPage(0);
- ASSERT_TRUE(page);
- VerifySavedRendering(page, 595, 842, md5);
+ FPDF_PAGE saved_page = LoadSavedPage(0);
+ ASSERT_TRUE(saved_page);
+ VerifySavedRendering(saved_page, 595, 842, md5);
{
- ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(saved_page, 0));
// Check that the string value of the modified date is the newly-set
// value.
@@ -1691,19 +1678,19 @@
EXPECT_EQ(kNewDate, GetPlatformWString(buf.data()));
}
- CloseSavedPage(page);
+ CloseSavedPage(saved_page);
CloseSavedDocument();
}
TEST_F(FPDFAnnotEmbedderTest, GetNumberValue) {
// Open a file with four text annotations and load its first page.
ASSERT_TRUE(OpenDocument("text_form_multiple.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// First two annotations do not have "MaxLen" attribute.
for (int i = 0; i < 2; i++) {
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), i));
ASSERT_TRUE(annot);
// Verify that no "MaxLen" key present.
@@ -1714,7 +1701,7 @@
}
// Annotation in index 2 has "MaxLen" of 10.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 2));
ASSERT_TRUE(annot);
// Verify that "MaxLen" key present.
@@ -1731,14 +1718,12 @@
// Ask for key that exists but is not a number.
EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(), "V", &value));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetSetAP) {
// Open a file with four annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
@@ -1746,7 +1731,7 @@
static constexpr size_t kExpectNormalAPLength = 73970;
// Retrieve the first annotation.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Check that the string value of an AP returns the expected length.
@@ -1826,13 +1811,12 @@
// Save the modified document, then reopen it.
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
ASSERT_TRUE(OpenSavedDocument());
- page = LoadSavedPage(0);
+ FPDF_PAGE saved_page = LoadSavedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(saved_page, 0));
// Check that the new annotation value is equal to the value we set before
// saving.
@@ -1848,19 +1832,19 @@
}
// Close saved document.
- CloseSavedPage(page);
+ CloseSavedPage(saved_page);
CloseSavedDocument();
}
TEST_F(FPDFAnnotEmbedderTest, RemoveOptionalAP) {
// Open a file with four annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Retrieve the first annotation.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Set Down AP. Normal AP is already set.
@@ -1883,19 +1867,17 @@
EXPECT_EQ(2u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
nullptr, 0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, RemoveRequiredAP) {
// Open a file with four annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Retrieve the first annotation.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Set Down AP. Normal AP is already set.
@@ -1916,23 +1898,21 @@
EXPECT_EQ(2u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
nullptr, 0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, ExtractLinkedAnnotations) {
// Open a file with annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(-1, FPDFPage_GetAnnotIndex(page, nullptr));
+ EXPECT_EQ(-1, FPDFPage_GetAnnotIndex(page.get(), nullptr));
{
// Retrieve the highlight annotation which has its popup defined.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get()));
- EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot.get()));
+ EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page.get(), annot.get()));
static const char kPopupKey[] = "Popup";
ASSERT_TRUE(FPDFAnnot_HasKey(annot.get(), kPopupKey));
ASSERT_EQ(FPDF_OBJECT_REFERENCE,
@@ -1943,7 +1923,7 @@
FPDFAnnot_GetLinkedAnnot(annot.get(), kPopupKey));
ASSERT_TRUE(popup);
EXPECT_EQ(FPDF_ANNOT_POPUP, FPDFAnnot_GetSubtype(popup.get()));
- EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, popup.get()));
+ EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page.get(), popup.get()));
FS_RECTF rect;
ASSERT_TRUE(FPDFAnnot_GetRect(popup.get(), &rect));
EXPECT_NEAR(612.0f, rect.left, 0.001f);
@@ -1962,19 +1942,17 @@
FPDFAnnot_GetValueType(annot.get(), pdfium::annotation::kP));
EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot.get(), pdfium::annotation::kP));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormFieldFlagsTextField) {
// Open file with form text fields.
ASSERT_TRUE(OpenDocument("text_form_multiple.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Retrieve the first annotation: user-editable text field.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Check that the flag values are as expected.
@@ -1988,7 +1966,7 @@
{
// Retrieve the second annotation: read-only text field.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
// Check that the flag values are as expected.
@@ -2002,7 +1980,7 @@
{
// Retrieve the fourth annotation: user-editable password text field.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 3));
ASSERT_TRUE(annot);
// Check that the flag values are as expected.
@@ -2013,19 +1991,17 @@
EXPECT_FALSE(flags & FPDF_FORMFLAG_TEXT_MULTILINE);
EXPECT_TRUE(flags & FPDF_FORMFLAG_TEXT_PASSWORD);
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormFieldFlagsComboBox) {
// Open file with form text fields.
ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Retrieve the first annotation: user-editable combobox.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Check that the flag values are as expected.
@@ -2040,7 +2016,7 @@
{
// Retrieve the second annotation: regular combobox.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
// Check that the flag values are as expected.
@@ -2055,7 +2031,7 @@
{
// Retrieve the third annotation: read-only combobox.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 2));
ASSERT_TRUE(annot);
// Check that the flag values are as expected.
@@ -2067,49 +2043,46 @@
EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_MULTI_SELECT);
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormAnnotNull) {
// Open file with form text fields.
ASSERT_TRUE(OpenDocument("text_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Attempt to get an annotation where no annotation exists on page.
static const FS_POINTF kOriginPoint = {0.0f, 0.0f};
EXPECT_FALSE(
- FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kOriginPoint));
+ FPDFAnnot_GetFormFieldAtPoint(form_handle(), page.get(), &kOriginPoint));
static const FS_POINTF kValidPoint = {120.0f, 120.0f};
{
// Verify there is an annotation.
ScopedFPDFAnnotation annot(
- FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kValidPoint));
+ FPDFAnnot_GetFormFieldAtPoint(form_handle(), page.get(), &kValidPoint));
EXPECT_TRUE(annot);
}
// Try other bad inputs at a valid location.
EXPECT_FALSE(FPDFAnnot_GetFormFieldAtPoint(nullptr, nullptr, &kValidPoint));
- EXPECT_FALSE(FPDFAnnot_GetFormFieldAtPoint(nullptr, page, &kValidPoint));
+ EXPECT_FALSE(
+ FPDFAnnot_GetFormFieldAtPoint(nullptr, page.get(), &kValidPoint));
EXPECT_FALSE(
FPDFAnnot_GetFormFieldAtPoint(form_handle(), nullptr, &kValidPoint));
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormAnnotAndCheckFlagsTextField) {
// Open file with form text fields.
ASSERT_TRUE(OpenDocument("text_form_multiple.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Retrieve user-editable text field annotation.
static const FS_POINTF kPoint = {105.0f, 118.0f};
ScopedFPDFAnnotation annot(
- FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
+ FPDFAnnot_GetFormFieldAtPoint(form_handle(), page.get(), &kPoint));
ASSERT_TRUE(annot);
// Check that interactive form annotation flag values are as expected.
@@ -2123,7 +2096,7 @@
// Retrieve read-only text field annotation.
static const FS_POINTF kPoint = {105.0f, 202.0f};
ScopedFPDFAnnotation annot(
- FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
+ FPDFAnnot_GetFormFieldAtPoint(form_handle(), page.get(), &kPoint));
ASSERT_TRUE(annot);
// Check that interactive form annotation flag values are as expected.
@@ -2132,21 +2105,19 @@
EXPECT_FALSE(flags & FPDF_FORMFLAG_REQUIRED);
EXPECT_FALSE(flags & FPDF_FORMFLAG_NOEXPORT);
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormAnnotAndCheckFlagsComboBox) {
// Open file with form comboboxes.
ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Retrieve user-editable combobox annotation.
static const FS_POINTF kPoint = {102.0f, 363.0f};
ScopedFPDFAnnotation annot(
- FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
+ FPDFAnnot_GetFormFieldAtPoint(form_handle(), page.get(), &kPoint));
ASSERT_TRUE(annot);
// Check that interactive form annotation flag values are as expected.
@@ -2163,7 +2134,7 @@
// Retrieve regular combobox annotation.
static const FS_POINTF kPoint = {102.0f, 413.0f};
ScopedFPDFAnnotation annot(
- FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
+ FPDFAnnot_GetFormFieldAtPoint(form_handle(), page.get(), &kPoint));
ASSERT_TRUE(annot);
// Check that interactive form annotation flag values are as expected.
@@ -2180,7 +2151,7 @@
// Retrieve read-only combobox annotation.
static const FS_POINTF kPoint = {102.0f, 513.0f};
ScopedFPDFAnnotation annot(
- FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
+ FPDFAnnot_GetFormFieldAtPoint(form_handle(), page.get(), &kPoint));
ASSERT_TRUE(annot);
// Check that interactive form annotation flag values are as expected.
@@ -2192,8 +2163,6 @@
EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_MULTI_SELECT);
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, Bug1206) {
@@ -2207,7 +2176,7 @@
ASSERT_TRUE(OpenDocument("bug_1206.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
@@ -2216,7 +2185,7 @@
ClearString();
for (size_t i = 0; i < 10; ++i) {
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, expected_bitmap);
ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
@@ -2225,15 +2194,13 @@
EXPECT_GT(GetString().size(), original_size);
ClearString();
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, Bug1212) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(0, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(0, FPDFPage_GetAnnotCount(page.get()));
static const char kTestKey[] = "test";
static const wchar_t kData[] = L"\xf6\xe4";
@@ -2242,9 +2209,10 @@
{
// Add a text annotation to the page.
- ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT));
+ ScopedFPDFAnnotation annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_TEXT));
ASSERT_TRUE(annot);
- EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(page.get()));
EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get()));
// Make sure there is no test key, add set a value there, and read it back.
@@ -2263,11 +2231,12 @@
}
{
- ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP));
+ ScopedFPDFAnnotation annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_STAMP));
ASSERT_TRUE(annot);
const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f};
EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect));
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(page.get()));
EXPECT_EQ(FPDF_ANNOT_STAMP, FPDFAnnot_GetSubtype(annot.get()));
// Also do the same test for its appearance string.
std::fill(buf.begin(), buf.end(), 'x');
@@ -2287,7 +2256,6 @@
EXPECT_EQ(kData, GetPlatformWString(buf.data()));
}
- UnloadPage(page);
{
// Save a copy, open the copy, and check the annotation again.
@@ -2329,16 +2297,16 @@
TEST_F(FPDFAnnotEmbedderTest, GetOptionCountCombobox) {
// Open a file with combobox widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(3, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
- annot.reset(FPDFPage_GetAnnot(page, 1));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
EXPECT_EQ(26, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
@@ -2348,61 +2316,55 @@
EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(), nullptr));
EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(nullptr, annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetOptionCountListbox) {
// Open a file with listbox widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("listbox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(3, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
- annot.reset(FPDFPage_GetAnnot(page, 1));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
EXPECT_EQ(26, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetOptionCountInvalidAnnotations) {
// Open a file with ink annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// annotations do not have "Opt" array and will return -1
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
- annot.reset(FPDFPage_GetAnnot(page, 1));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetOptionLabelCombobox) {
// Open a file with combobox widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
int index = 0;
@@ -2414,7 +2376,7 @@
buf.data(), length_bytes));
EXPECT_EQ(L"Foo", GetPlatformWString(buf.data()));
- annot.reset(FPDFPage_GetAnnot(page, 1));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
index = 0;
@@ -2447,18 +2409,16 @@
EXPECT_EQ(0u,
FPDFAnnot_GetOptionLabel(form_handle(), nullptr, 0, nullptr, 0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetOptionLabelListbox) {
// Open a file with listbox widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("listbox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
int index = 0;
@@ -2470,7 +2430,7 @@
buf.data(), length_bytes));
EXPECT_EQ(L"Foo", GetPlatformWString(buf.data()));
- annot.reset(FPDFPage_GetAnnot(page, 1));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
index = 0;
@@ -2497,42 +2457,38 @@
EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 26,
nullptr, 0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetOptionLabelInvalidAnnotations) {
// Open a file with ink annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// annotations do not have "Opt" array and will return 0
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 0,
nullptr, 0));
- annot.reset(FPDFPage_GetAnnot(page, 1));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 0,
nullptr, 0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, IsOptionSelectedCombobox) {
// Open a file with combobox widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Checks for Combobox with no Values (/V) or Selected Indices (/I) objects.
@@ -2542,7 +2498,7 @@
EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
}
- annot.reset(FPDFPage_GetAnnot(page, 1));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
// Checks for Combobox with Values (/V) object which is just a string.
@@ -2566,18 +2522,16 @@
FPDFAnnot_IsOptionSelected(form_handle(), nullptr, /*index=*/0));
EXPECT_FALSE(FPDFAnnot_IsOptionSelected(nullptr, annot.get(), /*index=*/0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, IsOptionSelectedListbox) {
// Open a file with listbox widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("listbox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Checks for Listbox with no Values (/V) or Selected Indices (/I) objects.
@@ -2587,7 +2541,7 @@
EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
}
- annot.reset(FPDFPage_GetAnnot(page, 1));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
// Checks for Listbox with Values (/V) object which is just a string.
@@ -2598,7 +2552,7 @@
FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
}
- annot.reset(FPDFPage_GetAnnot(page, 3));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 3));
ASSERT_TRUE(annot);
// Checks for Listbox with only Selected indices (/I) object which is an
@@ -2611,7 +2565,7 @@
FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
}
- annot.reset(FPDFPage_GetAnnot(page, 4));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 4));
ASSERT_TRUE(annot);
// Checks for Listbox with Values (/V) object which is an array with
@@ -2624,7 +2578,7 @@
FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
}
- annot.reset(FPDFPage_GetAnnot(page, 5));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 5));
ASSERT_TRUE(annot);
// Checks for Listbox with both Values (/V) and Selected Indices (/I)
@@ -2637,58 +2591,54 @@
FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
}
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, IsOptionSelectedInvalidAnnotations) {
// Open a file with multiple form field annotations and load its first page.
ASSERT_TRUE(OpenDocument("multiple_form_types.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Checks for link annotation.
EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(),
/*index=*/0));
- annot.reset(FPDFPage_GetAnnot(page, 3));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 3));
ASSERT_TRUE(annot);
// Checks for text field annotation.
EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(),
/*index=*/0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFontSizeCombobox) {
// Open a file with combobox annotations and load its first page.
ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// All 3 widgets have Tf font size 12.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
float value;
ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
EXPECT_EQ(12.0, value);
- annot.reset(FPDFPage_GetAnnot(page, 1));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
float value_two;
ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_two));
EXPECT_EQ(12.0, value_two);
- annot.reset(FPDFPage_GetAnnot(page, 2));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 2));
ASSERT_TRUE(annot);
float value_three;
@@ -2696,33 +2646,31 @@
FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_three));
EXPECT_EQ(12.0, value_three);
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFontSizeTextField) {
// Open a file with textfield annotations and load its first page.
ASSERT_TRUE(OpenDocument("text_form_multiple.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// All 4 widgets have Tf font size 12.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
float value;
ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
EXPECT_EQ(12.0, value);
- annot.reset(FPDFPage_GetAnnot(page, 1));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
float value_two;
ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_two));
EXPECT_EQ(12.0, value_two);
- annot.reset(FPDFPage_GetAnnot(page, 2));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 2));
ASSERT_TRUE(annot);
float value_three;
@@ -2734,41 +2682,37 @@
ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_four));
EXPECT_EQ(12.0, value_four);
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFontSizeInvalidAnnotationTypes) {
// Open a file with ink annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Annotations that do not have variable text and will return -1.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
float value;
ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
- annot.reset(FPDFPage_GetAnnot(page, 1));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFontSizeInvalidArguments) {
// Open a file with combobox annotations and load its first page.
ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Check bad form handle / annot.
@@ -2777,38 +2721,34 @@
ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(), nullptr, &value));
ASSERT_FALSE(FPDFAnnot_GetFontSize(nullptr, nullptr, &value));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFontSizeNegative) {
// Open a file with textfield annotations and load its first page.
ASSERT_TRUE(OpenDocument("text_form_negative_fontsize.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Obtain the first annotation, a text field with negative font size, -12.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
float value;
ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
EXPECT_EQ(-12.0, value);
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFontColor) {
// Open a file with textfield annotations and load its first page.
ASSERT_TRUE(OpenDocument("text_form_color.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Obtain the first annotation, a text field with orange color.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// Negative testing.
@@ -2833,128 +2773,114 @@
EXPECT_EQ(0x80U, G);
EXPECT_EQ(0x00U, B);
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, IsCheckedCheckbox) {
// Open a file with checkbox and radiobuttons widget annotations and load its
// first page.
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, IsCheckedCheckboxReadOnly) {
// Open a file with checkbox and radiobutton widget annotations and load its
// first page.
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, IsCheckedRadioButton) {
// Open a file with checkbox and radiobutton widget annotations and load its
// first page.
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 5));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 5));
ASSERT_TRUE(annot);
ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
- annot.reset(FPDFPage_GetAnnot(page, 6));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 6));
ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
- annot.reset(FPDFPage_GetAnnot(page, 7));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 7));
ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, IsCheckedRadioButtonReadOnly) {
// Open a file with checkbox and radiobutton widget annotations and load its
// first page.
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 2));
ASSERT_TRUE(annot);
ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
- annot.reset(FPDFPage_GetAnnot(page, 3));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 3));
ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
- annot.reset(FPDFPage_GetAnnot(page, 4));
+ annot.reset(FPDFPage_GetAnnot(page.get(), 4));
ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, IsCheckedInvalidArguments) {
// Open a file with checkbox and radiobuttons widget annotations and load its
// first page.
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
ASSERT_FALSE(FPDFAnnot_IsChecked(nullptr, annot.get()));
ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), nullptr));
ASSERT_FALSE(FPDFAnnot_IsChecked(nullptr, nullptr));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, IsCheckedInvalidWidgetType) {
// Open a file with text widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("text_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormFieldType) {
ASSERT_TRUE(OpenDocument("multiple_form_types.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
EXPECT_EQ(-1, FPDFAnnot_GetFormFieldType(form_handle(), nullptr));
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
EXPECT_EQ(-1, FPDFAnnot_GetFormFieldType(nullptr, annot.get()));
}
@@ -2969,24 +2895,23 @@
{4, FPDF_FORMFIELD_CHECKBOX},
{5, FPDF_FORMFIELD_RADIOBUTTON}};
for (const auto& test : kTests) {
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, test.input));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), test.input));
ASSERT_TRUE(annot);
EXPECT_EQ(test.output,
FPDFAnnot_GetFormFieldType(form_handle(), annot.get()));
}
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormFieldValueTextField) {
ASSERT_TRUE(OpenDocument("text_form_multiple.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
EXPECT_EQ(0u,
FPDFAnnot_GetFormFieldValue(form_handle(), nullptr, nullptr, 0));
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(0u,
@@ -3001,7 +2926,7 @@
EXPECT_EQ(L"", GetPlatformWString(buf.data()));
}
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 2));
ASSERT_TRUE(annot);
unsigned long length_bytes =
@@ -3012,16 +2937,15 @@
buf.data(), length_bytes));
EXPECT_EQ(L"Elephant", GetPlatformWString(buf.data()));
}
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormFieldValueComboBox) {
ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
unsigned long length_bytes =
@@ -3033,7 +2957,7 @@
EXPECT_EQ(L"", GetPlatformWString(buf.data()));
}
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
unsigned long length_bytes =
@@ -3044,19 +2968,18 @@
buf.data(), length_bytes));
EXPECT_EQ(L"Banana", GetPlatformWString(buf.data()));
}
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormFieldNameTextField) {
ASSERT_TRUE(OpenDocument("text_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
EXPECT_EQ(0u,
FPDFAnnot_GetFormFieldName(form_handle(), nullptr, nullptr, 0));
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(0u, FPDFAnnot_GetFormFieldName(nullptr, annot.get(), nullptr, 0));
@@ -3069,16 +2992,15 @@
buf.data(), length_bytes));
EXPECT_EQ(L"Text Box", GetPlatformWString(buf.data()));
}
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormFieldNameComboBox) {
ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
unsigned long length_bytes =
@@ -3089,12 +3011,11 @@
buf.data(), length_bytes));
EXPECT_EQ(L"Combo_Editable", GetPlatformWString(buf.data()));
}
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, FocusableAnnotSubtypes) {
ASSERT_TRUE(OpenDocument("annots.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Verify widgets are by default focusable.
@@ -3110,7 +3031,7 @@
const FPDF_ANNOTATION_SUBTYPE kExpectedDefaultFocusableSubtypes[] = {
FPDF_ANNOT_WIDGET};
- VerifyAnnotationSubtypesAndFocusability(form_handle(), page,
+ VerifyAnnotationSubtypesAndFocusability(form_handle(), page.get(),
kExpectedAnnotSubtypes,
kExpectedDefaultFocusableSubtypes);
@@ -3125,7 +3046,7 @@
FPDFAnnot_SetFocusableSubtypes(form_handle(), kDefaultSubtypes, 0));
ASSERT_EQ(0, FPDFAnnot_GetFocusableSubtypesCount(form_handle()));
- VerifyAnnotationSubtypesAndFocusability(form_handle(), page,
+ VerifyAnnotationSubtypesAndFocusability(form_handle(), page.get(),
kExpectedAnnotSubtypes, {});
// Now make links focusable.
@@ -3134,7 +3055,7 @@
const FPDF_ANNOTATION_SUBTYPE kExpectedLinkocusableSubtypes[] = {
FPDF_ANNOT_LINK};
- VerifyAnnotationSubtypesAndFocusability(form_handle(), page,
+ VerifyAnnotationSubtypesAndFocusability(form_handle(), page.get(),
kExpectedAnnotSubtypes,
kExpectedLinkocusableSubtypes);
@@ -3152,13 +3073,11 @@
FPDFAnnot_GetFocusableSubtypes(form_handle(), nullptr, subtypes.size()));
EXPECT_FALSE(
FPDFAnnot_GetFocusableSubtypes(form_handle(), subtypes.data(), 0));
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, FocusableAnnotRendering) {
ASSERT_TRUE(OpenDocument("annots.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
@@ -3179,7 +3098,7 @@
#endif
}();
// Check the initial rendering.
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, md5_sum);
}
@@ -3214,11 +3133,11 @@
#endif
}();
// Focus the first link and check the rendering.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_LINK, FPDFAnnot_GetSubtype(annot.get()));
EXPECT_TRUE(FORM_SetFocusedAnnot(form_handle(), annot.get()));
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, md5_sum);
}
@@ -3240,27 +3159,25 @@
#endif
}();
// Focus the first highlight and check the rendering.
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 4));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 4));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get()));
EXPECT_TRUE(FORM_SetFocusedAnnot(form_handle(), annot.get()));
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, md5_sum);
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetLinkFromAnnotation) {
ASSERT_TRUE(OpenDocument("annots.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
constexpr char kExpectedResult[] =
"https://cs.chromium.org/chromium/src/third_party/pdfium/public/"
"fpdf_text.h";
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 3));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_LINK, FPDFAnnot_GetSubtype(annot.get()));
VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()),
@@ -3268,21 +3185,19 @@
}
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 4));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 4));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get()));
EXPECT_FALSE(FPDFAnnot_GetLink(annot.get()));
}
EXPECT_FALSE(FPDFAnnot_GetLink(nullptr));
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormControlCountRadioButton) {
// Open a file with radio button widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
@@ -3290,7 +3205,7 @@
EXPECT_EQ(-1,
FPDFAnnot_GetFormControlCount(form_handle(), /*annot=*/nullptr));
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 3));
ASSERT_TRUE(annot);
// Checks for bad form handle.
@@ -3299,44 +3214,38 @@
EXPECT_EQ(3, FPDFAnnot_GetFormControlCount(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormControlCountCheckBox) {
// Open a file with checkbox widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(1, FPDFAnnot_GetFormControlCount(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormControlCountInvalidAnnotation) {
// Open a file with ink annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(-1, FPDFAnnot_GetFormControlCount(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormControlIndexRadioButton) {
// Open a file with radio button widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
@@ -3344,7 +3253,7 @@
EXPECT_EQ(-1,
FPDFAnnot_GetFormControlIndex(form_handle(), /*annot=*/nullptr));
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 3));
ASSERT_TRUE(annot);
// Checks for bad form handle.
@@ -3353,44 +3262,38 @@
EXPECT_EQ(1, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormControlIndexCheckBox) {
// Open a file with checkbox widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(0, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormControlIndexInvalidAnnotation) {
// Open a file with ink annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(-1, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormFieldExportValueRadioButton) {
// Open a file with radio button widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
@@ -3399,7 +3302,7 @@
form_handle(), /*annot=*/nullptr,
/*buffer=*/nullptr, /*buflen=*/0));
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 6));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 6));
ASSERT_TRUE(annot);
// Checks for bad form handle.
@@ -3416,18 +3319,16 @@
buf.data(), length_bytes));
EXPECT_EQ(L"value2", GetPlatformWString(buf.data()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormFieldExportValueCheckBox) {
// Open a file with checkbox widget annotations and load its first page.
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
unsigned long length_bytes =
@@ -3439,50 +3340,44 @@
buf.data(), length_bytes));
EXPECT_EQ(L"Yes", GetPlatformWString(buf.data()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, GetFormFieldExportValueInvalidAnnotation) {
// Open a file with ink annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(0u, FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(),
/*buffer=*/nullptr,
/*buflen=*/0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, Redactannotation) {
ASSERT_TRUE(OpenDocument("redact_annot.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(page.get()));
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_REDACT, FPDFAnnot_GetSubtype(annot.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, PolygonAnnotation) {
ASSERT_TRUE(OpenDocument("polygon_annot.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(page.get()));
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// FPDFAnnot_GetVertices() positive testing.
@@ -3514,7 +3409,7 @@
}
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
// This has an odd number of elements in the vertices array, ignore the last
@@ -3535,21 +3430,20 @@
{
// Wrong annotation type.
- ScopedFPDFAnnotation ink_annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_INK));
+ ScopedFPDFAnnotation ink_annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK));
EXPECT_EQ(0U, FPDFAnnot_GetVertices(ink_annot.get(), nullptr, 0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, InkAnnotation) {
ASSERT_TRUE(OpenDocument("ink_annot.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(page.get()));
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// FPDFAnnot_GetInkListCount() and FPDFAnnot_GetInkListPath() positive
@@ -3593,7 +3487,7 @@
}
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
// This has an odd number of elements in the path array, ignore the last
@@ -3621,24 +3515,22 @@
{
// Wrong annotation type.
ScopedFPDFAnnotation polygon_annot(
- FPDFPage_CreateAnnot(page, FPDF_ANNOT_POLYGON));
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_POLYGON));
EXPECT_EQ(0U, FPDFAnnot_GetInkListCount(polygon_annot.get()));
const unsigned long kPathIndex = 0;
EXPECT_EQ(0U, FPDFAnnot_GetInkListPath(polygon_annot.get(), kPathIndex,
nullptr, 0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, LineAnnotation) {
ASSERT_TRUE(OpenDocument("line_annot.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(page.get()));
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// FPDFAnnot_GetVertices() positive testing.
@@ -3656,7 +3548,7 @@
}
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
// Too few elements in the line array.
@@ -3667,23 +3559,22 @@
{
// Wrong annotation type.
- ScopedFPDFAnnotation ink_annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_INK));
+ ScopedFPDFAnnotation ink_annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK));
FS_POINTF start;
FS_POINTF end;
EXPECT_FALSE(FPDFAnnot_GetLine(ink_annot.get(), &start, &end));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, AnnotationBorder) {
ASSERT_TRUE(OpenDocument("line_annot.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(page.get()));
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// FPDFAnnot_GetBorder() positive testing.
@@ -3702,7 +3593,7 @@
}
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
// Too few elements in the border array.
@@ -3728,18 +3619,16 @@
/*vertical_radius=*/2.5f,
/*border_width=*/3.0f));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, AnnotationJavaScript) {
ASSERT_TRUE(OpenDocument("annot_javascript.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(page.get()));
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// FPDFAnnot_GetFormAdditionalActionJavaScript() positive testing.
@@ -3764,18 +3653,16 @@
form_handle(), annot.get(), FPDF_ANNOT_AACTION_KEY_STROKE,
nullptr, 0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, FormFieldAlternateName) {
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(8, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(8, FPDFPage_GetAnnotCount(page.get()));
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
// FPDFAnnot_GetFormFieldAlternateName() positive testing.
@@ -3793,8 +3680,6 @@
EXPECT_EQ(0u, FPDFAnnot_GetFormFieldAlternateName(nullptr, annot.get(),
nullptr, 0));
}
-
- UnloadPage(page);
}
// Due to https://crbug.com/pdfium/570, the AnnotationBorder test above cannot
@@ -3802,9 +3687,9 @@
// square annotation in annots.pdf for testing.
TEST_F(FPDFAnnotEmbedderTest, AnnotationBorderRendering) {
ASSERT_TRUE(OpenDocument("annots.pdf"));
- FPDF_PAGE page = LoadPage(1);
+ ScopedEmbedderTestPage page = LoadScopedPage(1);
ASSERT_TRUE(page);
- EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(3, FPDFPage_GetAnnotCount(page.get()));
const char* original_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -3840,12 +3725,13 @@
}();
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 2));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(annot.get()));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap =
+ RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, original_checksum);
}
@@ -3854,32 +3740,32 @@
/*border_width=*/4.0f));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap =
+ RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, modified_checksum);
}
}
// Save the document and close the page.
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
ASSERT_TRUE(OpenSavedDocument());
- page = LoadSavedPage(1);
- ASSERT_TRUE(page);
- VerifySavedRendering(page, 612, 792, modified_checksum);
+ FPDF_PAGE saved_page = LoadSavedPage(1);
+ ASSERT_TRUE(saved_page);
+ VerifySavedRendering(saved_page, 612, 792, modified_checksum);
- CloseSavedPage(page);
+ CloseSavedPage(saved_page);
CloseSavedDocument();
}
TEST_F(FPDFAnnotEmbedderTest, GetAndAddFileAttachmentAnnotation) {
ASSERT_TRUE(OpenDocument("annotation_fileattachment.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(page.get()));
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_FILEATTACHMENT, FPDFAnnot_GetSubtype(annot.get()));
@@ -3907,11 +3793,11 @@
{
// Add a file attachment annotation to the page.
ScopedFPDFAnnotation annot(
- FPDFPage_CreateAnnot(page, FPDF_ANNOT_FILEATTACHMENT));
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_FILEATTACHMENT));
ASSERT_TRUE(annot);
// Check that there is now 2 annotations on this page.
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(page.get()));
ScopedFPDFWideString file_name = GetFPDFWideString(L"0.txt");
FPDF_ATTACHMENT attachment =
@@ -3923,7 +3809,7 @@
}
{
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(annot);
EXPECT_EQ(FPDF_ANNOT_FILEATTACHMENT, FPDFAnnot_GetSubtype(annot.get()));
@@ -3939,26 +3825,24 @@
FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
EXPECT_EQ(L"0.txt", GetPlatformWString(buf.data()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFAnnotEmbedderTest, BadCasesFileAttachmentAnnotation) {
ASSERT_TRUE(OpenDocument("annotation_fileattachment.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(page.get()));
{
ASSERT_FALSE(FPDFAnnot_GetFileAttachment(nullptr));
ScopedFPDFAnnotation text_annot(
- FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT));
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_TEXT));
ASSERT_TRUE(text_annot);
ASSERT_FALSE(FPDFAnnot_GetFileAttachment(text_annot.get()));
ScopedFPDFAnnotation newly_file_annot(
- FPDFPage_CreateAnnot(page, FPDF_ANNOT_FILEATTACHMENT));
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_FILEATTACHMENT));
ASSERT_TRUE(newly_file_annot);
ASSERT_FALSE(FPDFAnnot_GetFileAttachment(newly_file_annot.get()));
}
@@ -3971,7 +3855,7 @@
ASSERT_FALSE(FPDFAnnot_AddFileAttachment(nullptr, empty_name.get()));
ASSERT_FALSE(FPDFAnnot_AddFileAttachment(nullptr, not_empty_name.get()));
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_TRUE(annot);
ASSERT_FALSE(FPDFAnnot_AddFileAttachment(annot.get(), nullptr));
@@ -3981,6 +3865,4 @@
EXPECT_NE(old_attachment,
FPDFAnnot_AddFileAttachment(annot.get(), not_empty_name.get()));
}
-
- UnloadPage(page);
}
diff --git a/fpdfsdk/fpdf_doc_embeddertest.cpp b/fpdfsdk/fpdf_doc_embeddertest.cpp
index 28e8584..49c8cd8 100644
--- a/fpdfsdk/fpdf_doc_embeddertest.cpp
+++ b/fpdfsdk/fpdf_doc_embeddertest.cpp
@@ -220,31 +220,27 @@
TEST_F(FPDFDocEmbedderTest, Bug1506Second) {
ASSERT_TRUE(OpenDocument("bug_1506.pdf"));
- std::vector<FPDF_PAGE> pages;
- for (int i : {0, 2})
- pages.push_back(LoadPage(i));
+ std::vector<ScopedEmbedderTestPage> pages;
+ for (int i : {0, 2}) {
+ pages.push_back(LoadScopedPage(i));
+ }
FPDF_DEST dest = FPDF_GetNamedDestByName(document(), "First");
ASSERT_TRUE(dest);
EXPECT_EQ(3, FPDFDest_GetDestPageIndex(document(), dest));
-
- for (FPDF_PAGE page : pages)
- UnloadPage(page);
}
TEST_F(FPDFDocEmbedderTest, Bug1506Third) {
ASSERT_TRUE(OpenDocument("bug_1506.pdf"));
- std::vector<FPDF_PAGE> pages;
- for (int i : {0, 1, 3})
- pages.push_back(LoadPage(i));
+ std::vector<ScopedEmbedderTestPage> pages;
+ for (int i : {0, 1, 3}) {
+ pages.push_back(LoadScopedPage(i));
+ }
FPDF_DEST dest = FPDF_GetNamedDestByName(document(), "First");
ASSERT_TRUE(dest);
EXPECT_EQ(3, FPDFDest_GetDestPageIndex(document(), dest));
-
- for (FPDF_PAGE page : pages)
- UnloadPage(page);
}
TEST_F(FPDFDocEmbedderTest, Bug680376) {
@@ -259,20 +255,20 @@
TEST_F(FPDFDocEmbedderTest, Bug821454) {
ASSERT_TRUE(OpenDocument("bug_821454.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Cover some invalid argument cases while we're at it.
EXPECT_FALSE(FPDFLink_GetLinkAtPoint(nullptr, 150, 360));
EXPECT_EQ(-1, FPDFLink_GetLinkZOrderAtPoint(nullptr, 150, 360));
- FPDF_LINK link1 = FPDFLink_GetLinkAtPoint(page, 150, 360);
+ FPDF_LINK link1 = FPDFLink_GetLinkAtPoint(page.get(), 150, 360);
ASSERT_TRUE(link1);
- FPDF_LINK link2 = FPDFLink_GetLinkAtPoint(page, 150, 420);
+ FPDF_LINK link2 = FPDFLink_GetLinkAtPoint(page.get(), 150, 420);
ASSERT_TRUE(link2);
- EXPECT_EQ(0, FPDFLink_GetLinkZOrderAtPoint(page, 150, 360));
- EXPECT_EQ(1, FPDFLink_GetLinkZOrderAtPoint(page, 150, 420));
+ EXPECT_EQ(0, FPDFLink_GetLinkZOrderAtPoint(page.get(), 150, 360));
+ EXPECT_EQ(1, FPDFLink_GetLinkZOrderAtPoint(page.get(), 150, 420));
FPDF_DEST dest1 = FPDFLink_GetDest(document(), link1);
ASSERT_TRUE(dest1);
@@ -319,8 +315,6 @@
EXPECT_FLOAT_EQ(150.0f, x);
EXPECT_FLOAT_EQ(250.0f, y);
}
-
- UnloadPage(page);
}
TEST_F(FPDFDocEmbedderTest, ActionBadArguments) {
@@ -338,11 +332,11 @@
TEST_F(FPDFDocEmbedderTest, ActionLaunch) {
ASSERT_TRUE(OpenDocument("launch_action.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// The target action is nearly the size of the whole page.
- FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100);
+ FPDF_LINK link = FPDFLink_GetLinkAtPoint(page.get(), 100, 100);
ASSERT_TRUE(link);
FPDF_ACTION action = FPDFLink_GetAction(link);
@@ -362,18 +356,16 @@
// Other public methods are not appropriate for launch actions.
EXPECT_FALSE(FPDFAction_GetDest(document(), action));
EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, sizeof(buf)));
-
- UnloadPage(page);
}
TEST_F(FPDFDocEmbedderTest, ActionUri) {
ASSERT_TRUE(OpenDocument("uri_action.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// The target action is nearly the size of the whole page.
- FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100);
+ FPDF_LINK link = FPDFLink_GetLinkAtPoint(page.get(), 100, 100);
ASSERT_TRUE(link);
FPDF_ACTION action = FPDFLink_GetAction(link);
@@ -393,18 +385,16 @@
// Other public methods are not appropriate for URI actions
EXPECT_FALSE(FPDFAction_GetDest(document(), action));
EXPECT_EQ(0u, FPDFAction_GetFilePath(action, buf, sizeof(buf)));
-
- UnloadPage(page);
}
TEST_F(FPDFDocEmbedderTest, ActionUriNonAscii) {
ASSERT_TRUE(OpenDocument("uri_action_nonascii.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// The target action is nearly the size of the whole page.
- FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100);
+ FPDF_LINK link = FPDFLink_GetLinkAtPoint(page.get(), 100, 100);
ASSERT_TRUE(link);
FPDF_ACTION action = FPDFLink_GetAction(link);
@@ -424,40 +414,37 @@
char buf[1024];
EXPECT_EQ(bufsize, FPDFAction_GetURIPath(document(), action, buf, bufsize));
EXPECT_STREQ(kExpectedResult, buf);
-
- UnloadPage(page);
}
TEST_F(FPDFDocEmbedderTest, LinkToAnnotConversion) {
ASSERT_TRUE(OpenDocument("annots.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- FPDF_LINK first_link = FPDFLink_GetLinkAtPoint(page, 69.00, 653.00);
- ScopedFPDFAnnotation first_annot(FPDFLink_GetAnnot(page, first_link));
- EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, first_annot.get()));
+ FPDF_LINK first_link = FPDFLink_GetLinkAtPoint(page.get(), 69.00, 653.00);
+ ScopedFPDFAnnotation first_annot(FPDFLink_GetAnnot(page.get(), first_link));
+ EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page.get(), first_annot.get()));
- FPDF_LINK second_link = FPDFLink_GetLinkAtPoint(page, 80.00, 633.00);
- ScopedFPDFAnnotation second_annot(FPDFLink_GetAnnot(page, second_link));
- EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, second_annot.get()));
+ FPDF_LINK second_link = FPDFLink_GetLinkAtPoint(page.get(), 80.00, 633.00);
+ ScopedFPDFAnnotation second_annot(
+ FPDFLink_GetAnnot(page.get(), second_link));
+ EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page.get(), second_annot.get()));
// Also test invalid arguments.
EXPECT_FALSE(FPDFLink_GetAnnot(nullptr, nullptr));
- EXPECT_FALSE(FPDFLink_GetAnnot(page, nullptr));
+ EXPECT_FALSE(FPDFLink_GetAnnot(page.get(), nullptr));
EXPECT_FALSE(FPDFLink_GetAnnot(nullptr, second_link));
}
-
- UnloadPage(page);
}
TEST_F(FPDFDocEmbedderTest, ActionGoto) {
ASSERT_TRUE(OpenDocument("goto_action.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// The target action is nearly the size of the whole page.
- FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100);
+ FPDF_LINK link = FPDFLink_GetLinkAtPoint(page.get(), 100, 100);
ASSERT_TRUE(link);
FPDF_ACTION action = FPDFLink_GetAction(link);
@@ -471,18 +458,16 @@
char buf[1024];
EXPECT_EQ(0u, FPDFAction_GetFilePath(action, buf, sizeof(buf)));
EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, sizeof(buf)));
-
- UnloadPage(page);
}
TEST_F(FPDFDocEmbedderTest, ActionEmbeddedGoto) {
ASSERT_TRUE(OpenDocument("gotoe_action.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// The target action is nearly the size of the whole page.
- FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100);
+ FPDF_LINK link = FPDFLink_GetLinkAtPoint(page.get(), 100, 100);
ASSERT_TRUE(link);
FPDF_ACTION action = FPDFLink_GetAction(link);
@@ -508,18 +493,16 @@
EXPECT_EQ(kExpectedLength, bufsize);
EXPECT_EQ(kExpectedLength, FPDFAction_GetFilePath(action, buf, bufsize));
EXPECT_STREQ(kExpectedResult, buf);
-
- UnloadPage(page);
}
TEST_F(FPDFDocEmbedderTest, ActionNonesuch) {
ASSERT_TRUE(OpenDocument("nonesuch_action.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// The target action is nearly the size of the whole page.
- FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100);
+ FPDF_LINK link = FPDFLink_GetLinkAtPoint(page.get(), 100, 100);
ASSERT_TRUE(link);
FPDF_ACTION action = FPDFLink_GetAction(link);
@@ -532,8 +515,6 @@
EXPECT_FALSE(FPDFAction_GetDest(document(), action));
EXPECT_EQ(0u, FPDFAction_GetFilePath(action, buf, sizeof(buf)));
EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, sizeof(buf)));
-
- UnloadPage(page);
}
TEST_F(FPDFDocEmbedderTest, NoBookmarks) {
@@ -691,53 +672,49 @@
ASSERT_TRUE(OpenDocument("rectangles_multi_pages.pdf"));
EXPECT_EQ(5, FPDF_GetPageCount(document()));
for (int i = 0; i < 5; ++i) {
- FPDF_PAGE page = LoadPage(i);
+ ScopedEmbedderTestPage page = LoadScopedPage(i);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
const PageData& expected = expected_page_data[i];
CompareBitmap(bitmap.get(), expected.width, expected.height,
expected.checksum);
- UnloadPage(page);
}
// Delete the first page and render again. (original page indices 1-4)
FPDFPage_Delete(document(), 0);
EXPECT_EQ(4, FPDF_GetPageCount(document()));
for (int i = 0; i < 4; ++i) {
- FPDF_PAGE page = LoadPage(i);
+ ScopedEmbedderTestPage page = LoadScopedPage(i);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
const PageData& expected = expected_page_data[i + 1];
CompareBitmap(bitmap.get(), expected.width, expected.height,
expected.checksum);
- UnloadPage(page);
}
// Delete the last page and render again. (original page indices 1-3)
FPDFPage_Delete(document(), 3);
EXPECT_EQ(3, FPDF_GetPageCount(document()));
for (int i = 0; i < 3; ++i) {
- FPDF_PAGE page = LoadPage(i);
+ ScopedEmbedderTestPage page = LoadScopedPage(i);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
const PageData& expected = expected_page_data[i + 1];
CompareBitmap(bitmap.get(), expected.width, expected.height,
expected.checksum);
- UnloadPage(page);
}
// Delete the middle page and render again. (original page indices 1, 3)
FPDFPage_Delete(document(), 1);
EXPECT_EQ(2, FPDF_GetPageCount(document()));
for (int i = 0; i < 2; ++i) {
- FPDF_PAGE page = LoadPage(i);
+ ScopedEmbedderTestPage page = LoadScopedPage(i);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
int adjusted_index = i == 0 ? 1 : 3;
const PageData& expected = expected_page_data[adjusted_index];
CompareBitmap(bitmap.get(), expected.width, expected.height,
expected.checksum);
- UnloadPage(page);
}
}
@@ -949,15 +926,15 @@
TEST_F(FPDFDocEmbedderTest, GetPageAAction) {
ASSERT_TRUE(OpenDocument("get_page_aaction.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
EXPECT_FALSE(FPDF_GetPageAAction(nullptr, FPDFPAGE_AACTION_OPEN));
- EXPECT_FALSE(FPDF_GetPageAAction(page, FPDFPAGE_AACTION_CLOSE));
- EXPECT_FALSE(FPDF_GetPageAAction(page, -1));
- EXPECT_FALSE(FPDF_GetPageAAction(page, 999));
+ EXPECT_FALSE(FPDF_GetPageAAction(page.get(), FPDFPAGE_AACTION_CLOSE));
+ EXPECT_FALSE(FPDF_GetPageAAction(page.get(), -1));
+ EXPECT_FALSE(FPDF_GetPageAAction(page.get(), 999));
- FPDF_ACTION action = FPDF_GetPageAAction(page, FPDFPAGE_AACTION_OPEN);
+ FPDF_ACTION action = FPDF_GetPageAAction(page.get(), FPDFPAGE_AACTION_OPEN);
EXPECT_EQ(static_cast<unsigned long>(PDFACTION_EMBEDDEDGOTO),
FPDFAction_GetType(action));
@@ -970,13 +947,10 @@
EXPECT_EQ(kExpectedLength, FPDFAction_GetFilePath(action, buf, bufsize));
EXPECT_STREQ(kExpectedResult, buf);
- UnloadPage(page);
+ ScopedEmbedderTestPage page1 = LoadScopedPage(1);
- page = LoadPage(1);
- EXPECT_TRUE(page);
- EXPECT_FALSE(FPDF_GetPageAAction(page, -1));
-
- UnloadPage(page);
+ EXPECT_TRUE(page1.get());
+ EXPECT_FALSE(FPDF_GetPageAAction(page1.get(), -1));
}
TEST_F(FPDFDocEmbedderTest, NoPageLabels) {
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index 9025e6b..8cae5c3 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -405,11 +405,10 @@
ScopedFPDFBitmap orig_bitmap;
{
ASSERT_TRUE(OpenDocument("black.pdf"));
- FPDF_PAGE orig_page = LoadPage(0);
+ ScopedEmbedderTestPage orig_page = LoadScopedPage(0);
ASSERT_TRUE(orig_page);
- orig_bitmap = RenderLoadedPage(orig_page);
+ orig_bitmap = RenderLoadedPage(orig_page.get());
CompareBitmap(orig_bitmap.get(), 612, 792, kAllBlackChecksum);
- UnloadPage(orig_page);
}
// Create a new document from |orig_bitmap| and save it.
@@ -626,12 +625,12 @@
TEST_F(FPDFEditEmbedderTest, ClipPath) {
// Load document with a clipped rectangle.
ASSERT_TRUE(OpenDocument("clip_path.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
- FPDF_PAGEOBJECT triangle = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT triangle = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(triangle);
// Test that we got the expected triangle.
@@ -715,19 +714,17 @@
EXPECT_EQ(35, y);
EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment));
EXPECT_FALSE(FPDFPathSegment_GetClose(segment));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, Bug1399) {
// Load document with a clipped rectangle.
ASSERT_TRUE(OpenDocument("bug_1399.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(7, FPDFPage_CountObjects(page));
+ ASSERT_EQ(7, FPDFPage_CountObjects(page.get()));
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(obj);
ASSERT_EQ(2, FPDFPath_CountSegments(obj));
@@ -754,8 +751,6 @@
EXPECT_EQ(-1, FPDFClipPath_CountPaths(clip_path));
EXPECT_EQ(-1, FPDFClipPath_CountPathSegments(clip_path, 0));
EXPECT_FALSE(FPDFClipPath_GetPathSegment(clip_path, 0, 0));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, Bug1549) {
@@ -763,26 +758,25 @@
static const char kRemovedChecksum[] = "6ec2f27531927882624b37bc7d8e12f4";
ASSERT_TRUE(OpenDocument("bug_1549.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 100, 150, kOriginalChecksum);
- ScopedFPDFPageObject obj(FPDFPage_GetObject(page, 0));
+ ScopedFPDFPageObject obj(FPDFPage_GetObject(page.get(), 0));
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj.get()));
- ASSERT_TRUE(FPDFPage_RemoveObject(page, obj.get()));
+ ASSERT_TRUE(FPDFPage_RemoveObject(page.get(), obj.get()));
}
- ASSERT_TRUE(FPDFPage_GenerateContent(page));
+ ASSERT_TRUE(FPDFPage_GenerateContent(page.get()));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 100, 150, kRemovedChecksum);
}
ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// TODO(crbug.com/pdfium/1549): Should be `kRemovedChecksum`.
VerifySavedDocument(100, 150, "4f9889cd5993db20f1ab37d677ac8d26");
@@ -791,19 +785,19 @@
TEST_F(FPDFEditEmbedderTest, SetText) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Get the "Hello, world!" text object and change it.
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(page_object);
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
// now displayed.
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
const char* changed_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -822,15 +816,14 @@
#endif
}();
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, changed_checksum);
}
// Now save the result.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the changes were kept in the saved .pdf.
ASSERT_TRUE(OpenSavedDocument());
@@ -848,11 +841,11 @@
TEST_F(FPDFEditEmbedderTest, SetCharcodesBadParams) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(page_object);
const uint32_t kDummyValue = 42;
@@ -861,14 +854,12 @@
EXPECT_FALSE(FPDFText_SetCharcodes(nullptr, &kDummyValue, 0));
EXPECT_FALSE(FPDFText_SetCharcodes(nullptr, &kDummyValue, 1));
EXPECT_FALSE(FPDFText_SetCharcodes(page_object, nullptr, 1));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, SetTextKeepClippingPath) {
// Load document with some text, with parts clipped.
ASSERT_TRUE(OpenDocument("bug_1558.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
const char* original_checksum = []() {
@@ -889,19 +880,19 @@
}();
{
// When opened before any editing and saving, the clipping path is rendered.
- ScopedFPDFBitmap original_bitmap = RenderPage(page);
+ ScopedFPDFBitmap original_bitmap = RenderPage(page.get());
CompareBitmap(original_bitmap.get(), 200, 200, original_checksum);
}
// "Change" the text in the objects to their current values to force them to
// regenerate when saving.
{
- ScopedFPDFTextPage text_page(FPDFText_LoadPage(page));
+ ScopedFPDFTextPage text_page(FPDFText_LoadPage(page.get()));
ASSERT_TRUE(text_page);
- const int obj_count = FPDFPage_CountObjects(page);
+ const int obj_count = FPDFPage_CountObjects(page.get());
ASSERT_EQ(2, obj_count);
for (int i = 0; i < obj_count; ++i) {
- FPDF_PAGEOBJECT text_obj = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT text_obj = FPDFPage_GetObject(page.get(), i);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_obj));
unsigned long size =
FPDFTextObj_GetText(text_obj, text_page.get(),
@@ -916,14 +907,13 @@
{
// After editing but before saving, the clipping path is retained.
- ScopedFPDFBitmap edited_bitmap = RenderPage(page);
+ ScopedFPDFBitmap edited_bitmap = RenderPage(page.get());
CompareBitmap(edited_bitmap.get(), 200, 200, original_checksum);
}
// Save the file.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Open the saved copy and render it.
ASSERT_TRUE(OpenSavedDocument());
@@ -942,7 +932,7 @@
TEST_F(FPDFEditEmbedderTest, Bug1574) {
// Load document with some text within a clipping path.
ASSERT_TRUE(OpenDocument("bug_1574.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
const char* original_checksum = []() {
@@ -963,18 +953,18 @@
}();
{
// When opened before any editing and saving, the text object is rendered.
- ScopedFPDFBitmap original_bitmap = RenderPage(page);
+ ScopedFPDFBitmap original_bitmap = RenderPage(page.get());
CompareBitmap(original_bitmap.get(), 200, 300, original_checksum);
}
// "Change" the text in the objects to their current values to force them to
// regenerate when saving.
{
- ScopedFPDFTextPage text_page(FPDFText_LoadPage(page));
+ ScopedFPDFTextPage text_page(FPDFText_LoadPage(page.get()));
ASSERT_TRUE(text_page);
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
- FPDF_PAGEOBJECT text_obj = FPDFPage_GetObject(page, 1);
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
+ FPDF_PAGEOBJECT text_obj = FPDFPage_GetObject(page.get(), 1);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_obj));
unsigned long size = FPDFTextObj_GetText(text_obj, text_page.get(),
@@ -987,9 +977,8 @@
}
// Save the file.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Open the saved copy and render it.
ASSERT_TRUE(OpenSavedDocument());
@@ -1007,7 +996,7 @@
TEST_F(FPDFEditEmbedderTest, Bug1893) {
ASSERT_TRUE(OpenDocument("bug_1893.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
{
const char* original_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -1026,11 +1015,11 @@
#endif
}();
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 200, 300, original_checksum);
}
- EXPECT_EQ(3, FPDFPage_CountObjects(page));
+ EXPECT_EQ(3, FPDFPage_CountObjects(page.get()));
const char* removed_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -1051,16 +1040,15 @@
// Remove the underline and regenerate the page content.
{
- ScopedFPDFPageObject object(FPDFPage_GetObject(page, 0));
- ASSERT_TRUE(FPDFPage_RemoveObject(page, object.get()));
- ASSERT_TRUE(FPDFPage_GenerateContent(page));
+ ScopedFPDFPageObject object(FPDFPage_GetObject(page.get(), 0));
+ ASSERT_TRUE(FPDFPage_RemoveObject(page.get(), object.get()));
+ ASSERT_TRUE(FPDFPage_GenerateContent(page.get()));
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 200, 300, removed_checksum);
}
ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
{
ASSERT_TRUE(OpenSavedDocument());
@@ -1075,12 +1063,12 @@
TEST_F(FPDFEditEmbedderTest, RemoveTextObject) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Show what the original file looks like.
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, HelloWorldChecksum());
}
@@ -1088,40 +1076,40 @@
// before calling FPDFPage_RemoveObject() below, so ASAN does not report
// dangling pointers.
{
- ScopedFPDFTextPage text_page(FPDFText_LoadPage(page));
+ ScopedFPDFTextPage text_page(FPDFText_LoadPage(page.get()));
ASSERT_TRUE(text_page);
EXPECT_EQ(30, FPDFText_CountChars(text_page.get()));
EXPECT_EQ(0, FPDFText_GetFontWeight(text_page.get(), 0));
}
// Get the "Hello, world!" text object and remove it.
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
{
- ScopedFPDFPageObject page_object(FPDFPage_GetObject(page, 0));
+ ScopedFPDFPageObject page_object(FPDFPage_GetObject(page.get(), 0));
ASSERT_TRUE(page_object);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(page_object.get()));
- EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object.get()));
+ EXPECT_TRUE(FPDFPage_RemoveObject(page.get(), page_object.get()));
}
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
// Verify the "Hello, world!" text is gone.
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, FirstRemovedChecksum());
}
// Create a new text page, which has updated results.
{
- ScopedFPDFTextPage text_page(FPDFText_LoadPage(page));
+ ScopedFPDFTextPage text_page(FPDFText_LoadPage(page.get()));
ASSERT_TRUE(text_page);
EXPECT_EQ(15, FPDFText_CountChars(text_page.get()));
EXPECT_EQ(0, FPDFText_GetFontWeight(text_page.get(), 0));
}
// Verify the rendering again after calling FPDFPage_GenerateContent().
- ASSERT_TRUE(FPDFPage_GenerateContent(page));
+ ASSERT_TRUE(FPDFPage_GenerateContent(page.get()));
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, FirstRemovedChecksum());
}
@@ -1133,51 +1121,49 @@
EXPECT_THAT(GetString(), Not(HasSubstr("/F1")));
EXPECT_THAT(GetString(), Not(HasSubstr("/F2")));
EXPECT_THAT(GetString(), Not(HasSubstr("/Times-Roman")));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest,
RemoveTextObjectWithTwoPagesSharingContentStreamAndResources) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world_2_pages.pdf"));
- FPDF_PAGE page1 = LoadPage(0);
+ ScopedEmbedderTestPage page1 = LoadScopedPage(0);
ASSERT_TRUE(page1);
- FPDF_PAGE page2 = LoadPage(1);
+ ScopedEmbedderTestPage page2 = LoadScopedPage(1);
ASSERT_TRUE(page2);
// Show what the original file looks like.
{
- ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
+ ScopedFPDFBitmap page1_bitmap = RenderPage(page1.get());
CompareBitmap(page1_bitmap.get(), 200, 200, HelloWorldChecksum());
- ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
+ ScopedFPDFBitmap page2_bitmap = RenderPage(page2.get());
CompareBitmap(page2_bitmap.get(), 200, 200, HelloWorldChecksum());
}
// Get the "Hello, world!" text object from page 1 and remove it.
- ASSERT_EQ(2, FPDFPage_CountObjects(page1));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page1.get()));
{
- ScopedFPDFPageObject page_object(FPDFPage_GetObject(page1, 0));
+ ScopedFPDFPageObject page_object(FPDFPage_GetObject(page1.get(), 0));
ASSERT_TRUE(page_object);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(page_object.get()));
- EXPECT_TRUE(FPDFPage_RemoveObject(page1, page_object.get()));
+ EXPECT_TRUE(FPDFPage_RemoveObject(page1.get(), page_object.get()));
}
- ASSERT_EQ(1, FPDFPage_CountObjects(page1));
+ ASSERT_EQ(1, FPDFPage_CountObjects(page1.get()));
// Verify the "Hello, world!" text is gone from page 1.
{
- ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
+ ScopedFPDFBitmap page1_bitmap = RenderPage(page1.get());
CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
- ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
+ ScopedFPDFBitmap page2_bitmap = RenderPage(page2.get());
CompareBitmap(page2_bitmap.get(), 200, 200, HelloWorldChecksum());
}
// Verify the rendering again after calling FPDFPage_GenerateContent().
- ASSERT_TRUE(FPDFPage_GenerateContent(page1));
+ ASSERT_TRUE(FPDFPage_GenerateContent(page1.get()));
{
- ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
+ ScopedFPDFBitmap page1_bitmap = RenderPage(page1.get());
CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
- ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
+ ScopedFPDFBitmap page2_bitmap = RenderPage(page2.get());
CompareBitmap(page2_bitmap.get(), 200, 200, HelloWorldChecksum());
}
@@ -1198,52 +1184,49 @@
EXPECT_THAT(split_saved_data, Contains(HasSubstr("/F1")).Times(1));
EXPECT_THAT(split_saved_data, Contains(HasSubstr("/F2")).Times(1));
EXPECT_THAT(split_saved_data, Contains(HasSubstr("/Times-Roman")).Times(1));
-
- UnloadPage(page1);
- UnloadPage(page2);
}
TEST_F(FPDFEditEmbedderTest,
RemoveTextObjectWithTwoPagesSharingContentArrayAndResources) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world_2_pages_split_streams.pdf"));
- FPDF_PAGE page1 = LoadPage(0);
+ ScopedEmbedderTestPage page1 = LoadScopedPage(0);
ASSERT_TRUE(page1);
- FPDF_PAGE page2 = LoadPage(1);
+ ScopedEmbedderTestPage page2 = LoadScopedPage(1);
ASSERT_TRUE(page2);
// Show what the original file looks like.
{
- ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
+ ScopedFPDFBitmap page1_bitmap = RenderPage(page1.get());
CompareBitmap(page1_bitmap.get(), 200, 200, HelloWorldChecksum());
- ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
+ ScopedFPDFBitmap page2_bitmap = RenderPage(page2.get());
CompareBitmap(page2_bitmap.get(), 200, 200, HelloWorldChecksum());
}
// Get the "Hello, world!" text object from page 1 and remove it.
- ASSERT_EQ(2, FPDFPage_CountObjects(page1));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page1.get()));
{
- ScopedFPDFPageObject page_object(FPDFPage_GetObject(page1, 0));
+ ScopedFPDFPageObject page_object(FPDFPage_GetObject(page1.get(), 0));
ASSERT_TRUE(page_object);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(page_object.get()));
- EXPECT_TRUE(FPDFPage_RemoveObject(page1, page_object.get()));
+ EXPECT_TRUE(FPDFPage_RemoveObject(page1.get(), page_object.get()));
}
- ASSERT_EQ(1, FPDFPage_CountObjects(page1));
+ ASSERT_EQ(1, FPDFPage_CountObjects(page1.get()));
// Verify the "Hello, world!" text is gone from page 1.
{
- ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
+ ScopedFPDFBitmap page1_bitmap = RenderPage(page1.get());
CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
- ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
+ ScopedFPDFBitmap page2_bitmap = RenderPage(page2.get());
CompareBitmap(page2_bitmap.get(), 200, 200, HelloWorldChecksum());
}
// Verify the rendering again after calling FPDFPage_GenerateContent().
- ASSERT_TRUE(FPDFPage_GenerateContent(page1));
+ ASSERT_TRUE(FPDFPage_GenerateContent(page1.get()));
{
- ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
+ ScopedFPDFBitmap page1_bitmap = RenderPage(page1.get());
CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
- ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
+ ScopedFPDFBitmap page2_bitmap = RenderPage(page2.get());
CompareBitmap(page2_bitmap.get(), 200, 200, HelloWorldChecksum());
}
@@ -1257,51 +1240,48 @@
VerifySavedRendering(saved_page2, 200, 200, HelloWorldChecksum());
CloseSavedPage(saved_page2);
CloseSavedDocument();
-
- UnloadPage(page1);
- UnloadPage(page2);
}
TEST_F(FPDFEditEmbedderTest, RemoveTextObjectWithTwoPagesSharingResourcesDict) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world_2_pages_shared_resources_dict.pdf"));
- FPDF_PAGE page1 = LoadPage(0);
+ ScopedEmbedderTestPage page1 = LoadScopedPage(0);
ASSERT_TRUE(page1);
- FPDF_PAGE page2 = LoadPage(1);
+ ScopedEmbedderTestPage page2 = LoadScopedPage(1);
ASSERT_TRUE(page2);
// Show what the original file looks like.
{
- ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
+ ScopedFPDFBitmap page1_bitmap = RenderPage(page1.get());
CompareBitmap(page1_bitmap.get(), 200, 200, HelloWorldChecksum());
- ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
+ ScopedFPDFBitmap page2_bitmap = RenderPage(page2.get());
CompareBitmap(page2_bitmap.get(), 200, 200, HelloWorldChecksum());
}
// Get the "Hello, world!" text object from page 1 and remove it.
- ASSERT_EQ(2, FPDFPage_CountObjects(page1));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page1.get()));
{
- ScopedFPDFPageObject page_object(FPDFPage_GetObject(page1, 0));
+ ScopedFPDFPageObject page_object(FPDFPage_GetObject(page1.get(), 0));
ASSERT_TRUE(page_object);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(page_object.get()));
- EXPECT_TRUE(FPDFPage_RemoveObject(page1, page_object.get()));
+ EXPECT_TRUE(FPDFPage_RemoveObject(page1.get(), page_object.get()));
}
- ASSERT_EQ(1, FPDFPage_CountObjects(page1));
+ ASSERT_EQ(1, FPDFPage_CountObjects(page1.get()));
// Verify the "Hello, world!" text is gone from page 1
{
- ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
+ ScopedFPDFBitmap page1_bitmap = RenderPage(page1.get());
CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
- ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
+ ScopedFPDFBitmap page2_bitmap = RenderPage(page2.get());
CompareBitmap(page2_bitmap.get(), 200, 200, HelloWorldChecksum());
}
// Verify the rendering again after calling FPDFPage_GenerateContent().
- ASSERT_TRUE(FPDFPage_GenerateContent(page1));
+ ASSERT_TRUE(FPDFPage_GenerateContent(page1.get()));
{
- ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
+ ScopedFPDFBitmap page1_bitmap = RenderPage(page1.get());
CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
- ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
+ ScopedFPDFBitmap page2_bitmap = RenderPage(page2.get());
CompareBitmap(page2_bitmap.get(), 200, 200, HelloWorldChecksum());
}
@@ -1315,9 +1295,6 @@
VerifySavedRendering(saved_page2, 200, 200, HelloWorldChecksum());
CloseSavedPage(saved_page2);
CloseSavedDocument();
-
- UnloadPage(page1);
- UnloadPage(page2);
}
void CheckMarkCounts(FPDF_PAGE page,
@@ -1443,18 +1420,16 @@
TEST_F(FPDFEditEmbedderTest, ReadMarkedObjectsIndirectDict) {
// Load document with some text marked with an indirect property.
ASSERT_TRUE(OpenDocument("text_in_page_marked_indirect.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- CheckMarkCounts(page, 1, 19, 8, 4, 9, 1);
-
- UnloadPage(page);
+ CheckMarkCounts(page.get(), 1, 19, 8, 4, 9, 1);
}
TEST_F(FPDFEditEmbedderTest, RemoveMarkedObjectsPrime) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("text_in_page_marked.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Show what the original file looks like.
@@ -1479,17 +1454,17 @@
return "3d5a3de53d5866044c2b6bf339742c97";
#endif // BUILDFLAG(IS_APPLE)
}();
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, original_checksum);
}
constexpr int expected_object_count = 19;
- CheckMarkCounts(page, 1, expected_object_count, 8, 4, 9, 1);
+ CheckMarkCounts(page.get(), 1, expected_object_count, 8, 4, 9, 1);
// Get all objects marked with "Prime"
std::vector<FPDF_PAGEOBJECT> primes;
for (int i = 0; i < expected_object_count; ++i) {
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), i);
int mark_count = FPDFPageObj_CountMarks(page_object);
for (int j = 0; j < mark_count; ++j) {
@@ -1511,11 +1486,11 @@
// Remove all objects marked with "Prime".
for (FPDF_PAGEOBJECT page_object : primes) {
- EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ EXPECT_TRUE(FPDFPage_RemoveObject(page.get(), page_object));
FPDFPageObj_Destroy(page_object);
}
- EXPECT_EQ(11, FPDFPage_CountObjects(page));
+ EXPECT_EQ(11, FPDFPage_CountObjects(page.get()));
const char* non_primes_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
#if BUILDFLAG(IS_WIN)
@@ -1557,14 +1532,13 @@
#endif // BUILDFLAG(IS_APPLE)
}();
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, non_primes_checksum);
}
// Save the file.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the prime marks are not there anymore.
ASSERT_TRUE(OpenSavedDocument());
@@ -1584,15 +1558,15 @@
TEST_F(FPDFEditEmbedderTest, RemoveMarks) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("text_in_page_marked.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
constexpr int kExpectedObjectCount = 19;
- CheckMarkCounts(page, 1, kExpectedObjectCount, 8, 4, 9, 1);
+ CheckMarkCounts(page.get(), 1, kExpectedObjectCount, 8, 4, 9, 1);
// Remove all "Prime" content marks.
for (int i = 0; i < kExpectedObjectCount; ++i) {
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), i);
int mark_count = FPDFPageObj_CountMarks(page_object);
for (int j = mark_count - 1; j >= 0; --j) {
@@ -1617,12 +1591,11 @@
}
// Verify there are 0 "Prime" content marks now.
- CheckMarkCounts(page, 1, kExpectedObjectCount, 0, 4, 9, 1);
+ CheckMarkCounts(page.get(), 1, kExpectedObjectCount, 0, 4, 9, 1);
// Save the file.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the prime marks are not there anymore.
ASSERT_TRUE(OpenSavedDocument());
@@ -1638,15 +1611,15 @@
TEST_F(FPDFEditEmbedderTest, RemoveMarkParam) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("text_in_page_marked.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
constexpr int kExpectedObjectCount = 19;
- CheckMarkCounts(page, 1, kExpectedObjectCount, 8, 4, 9, 1);
+ CheckMarkCounts(page.get(), 1, kExpectedObjectCount, 8, 4, 9, 1);
// Remove all "Square" content marks parameters.
for (int i = 0; i < kExpectedObjectCount; ++i) {
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), i);
int mark_count = FPDFPageObj_CountMarks(page_object);
for (int j = 0; j < mark_count; ++j) {
@@ -1677,9 +1650,8 @@
}
// Save the file.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the "Factor" parameters are still gone.
ASSERT_TRUE(OpenSavedDocument());
@@ -1723,24 +1695,23 @@
TEST_F(FPDFEditEmbedderTest, MaintainMarkedObjects) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("text_in_page_marked.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Iterate over all objects, counting the number of times each content mark
// name appears.
- CheckMarkCounts(page, 1, 19, 8, 4, 9, 1);
+ CheckMarkCounts(page.get(), 1, 19, 8, 4, 9, 1);
// Remove first page object.
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
- EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 0);
+ EXPECT_TRUE(FPDFPage_RemoveObject(page.get(), page_object));
FPDFPageObj_Destroy(page_object);
- CheckMarkCounts(page, 2, 18, 8, 3, 9, 1);
+ CheckMarkCounts(page.get(), 2, 18, 8, 3, 9, 1);
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
ASSERT_TRUE(OpenSavedDocument());
FPDF_PAGE saved_page = LoadSavedPage(0);
@@ -1755,24 +1726,23 @@
TEST_F(FPDFEditEmbedderTest, MaintainIndirectMarkedObjects) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("text_in_page_marked_indirect.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Iterate over all objects, counting the number of times each content mark
// name appears.
- CheckMarkCounts(page, 1, 19, 8, 4, 9, 1);
+ CheckMarkCounts(page.get(), 1, 19, 8, 4, 9, 1);
// Remove first page object.
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
- EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 0);
+ EXPECT_TRUE(FPDFPage_RemoveObject(page.get(), page_object));
FPDFPageObj_Destroy(page_object);
- CheckMarkCounts(page, 2, 18, 8, 3, 9, 1);
+ CheckMarkCounts(page.get(), 2, 18, 8, 3, 9, 1);
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
ASSERT_TRUE(OpenSavedDocument());
FPDF_PAGE saved_page = LoadSavedPage(0);
@@ -1787,22 +1757,21 @@
TEST_F(FPDFEditEmbedderTest, RemoveExistingPageObject) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Get the "Hello, world!" text object and remove it.
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(page_object);
- EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ EXPECT_TRUE(FPDFPage_RemoveObject(page.get(), page_object));
// Verify the "Hello, world!" text is gone.
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
// Save the file
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
FPDFPageObj_Destroy(page_object);
// Re-open the file and check the page object count is still 1.
@@ -1817,18 +1786,18 @@
TEST_F(FPDFEditEmbedderTest, RemoveExistingPageObjectSplitStreamsNotLonely) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world_split_streams.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Get the "Hello, world!" text object and remove it. There is another object
// in the same stream that says "Goodbye, world!"
- ASSERT_EQ(3, FPDFPage_CountObjects(page));
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(3, FPDFPage_CountObjects(page.get()));
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(page_object);
- EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ EXPECT_TRUE(FPDFPage_RemoveObject(page.get(), page_object));
// Verify the "Hello, world!" text is gone.
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
const char* hello_removed_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
#if BUILDFLAG(IS_WIN)
@@ -1846,14 +1815,13 @@
#endif
}();
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, hello_removed_checksum);
}
// Save the file
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
FPDFPageObj_Destroy(page_object);
// Re-open the file and check the page object count is still 2.
@@ -1874,27 +1842,26 @@
TEST_F(FPDFEditEmbedderTest, RemoveExistingPageObjectSplitStreamsLonely) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world_split_streams.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Get the "Greetings, world!" text object and remove it. This is the only
// object in the stream.
- ASSERT_EQ(3, FPDFPage_CountObjects(page));
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 2);
+ ASSERT_EQ(3, FPDFPage_CountObjects(page.get()));
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 2);
ASSERT_TRUE(page_object);
- EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ EXPECT_TRUE(FPDFPage_RemoveObject(page.get(), page_object));
// Verify the "Greetings, world!" text is gone.
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, HelloWorldChecksum());
}
// Save the file
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
FPDFPageObj_Destroy(page_object);
// Re-open the file and check the page object count is still 2.
@@ -1915,15 +1882,15 @@
TEST_F(FPDFEditEmbedderTest, GetContentStream) {
// Load document with some text split across streams.
ASSERT_TRUE(OpenDocument("split_streams.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Content stream 0: page objects 0-14.
// Content stream 1: page objects 15-17.
// Content stream 2: page object 18.
- ASSERT_EQ(19, FPDFPage_CountObjects(page));
+ ASSERT_EQ(19, FPDFPage_CountObjects(page.get()));
for (int i = 0; i < 19; i++) {
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), i);
ASSERT_TRUE(page_object);
CPDF_PageObject* cpdf_page_object =
CPDFPageObjectFromFPDFPageObject(page_object);
@@ -1934,41 +1901,39 @@
else
EXPECT_EQ(2, cpdf_page_object->GetContentStream()) << i;
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, RemoveAllFromStream) {
// Load document with some text split across streams.
ASSERT_TRUE(OpenDocument("split_streams.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Content stream 0: page objects 0-14.
// Content stream 1: page objects 15-17.
// Content stream 2: page object 18.
- ASSERT_EQ(19, FPDFPage_CountObjects(page));
+ ASSERT_EQ(19, FPDFPage_CountObjects(page.get()));
// Loop backwards because objects will being removed, which shifts the indexes
// after the removed position.
for (int i = 18; i >= 0; i--) {
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), i);
ASSERT_TRUE(page_object);
CPDF_PageObject* cpdf_page_object =
CPDFPageObjectFromFPDFPageObject(page_object);
// Empty content stream 1.
if (cpdf_page_object->GetContentStream() == 1) {
- EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ EXPECT_TRUE(FPDFPage_RemoveObject(page.get(), page_object));
FPDFPageObj_Destroy(page_object);
}
}
// Content stream 0: page objects 0-14.
// Content stream 2: page object 15.
- ASSERT_EQ(16, FPDFPage_CountObjects(page));
+ ASSERT_EQ(16, FPDFPage_CountObjects(page.get()));
for (int i = 0; i < 16; i++) {
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), i);
ASSERT_TRUE(page_object);
CPDF_PageObject* cpdf_page_object =
CPDFPageObjectFromFPDFPageObject(page_object);
@@ -1980,13 +1945,13 @@
// Generate contents should remove the empty stream and update the page
// objects' contents stream indexes.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
// Content stream 0: page objects 0-14.
// Content stream 1: page object 15.
- ASSERT_EQ(16, FPDFPage_CountObjects(page));
+ ASSERT_EQ(16, FPDFPage_CountObjects(page.get()));
for (int i = 0; i < 16; i++) {
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), i);
ASSERT_TRUE(page_object);
CPDF_PageObject* cpdf_page_object =
CPDFPageObjectFromFPDFPageObject(page_object);
@@ -2017,13 +1982,12 @@
#endif // BUILDFLAG(IS_APPLE)
}();
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, stream1_removed_checksum);
}
// Save the file
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the page object count is still 16, and that
// content stream 1 was removed.
@@ -2057,41 +2021,40 @@
TEST_F(FPDFEditEmbedderTest, RemoveAllFromSingleStream) {
// Load document with a single stream.
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Content stream 0: page objects 0-1.
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
// Loop backwards because objects will being removed, which shifts the indexes
// after the removed position.
for (int i = 1; i >= 0; i--) {
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), i);
ASSERT_TRUE(page_object);
CPDF_PageObject* cpdf_page_object =
CPDFPageObjectFromFPDFPageObject(page_object);
ASSERT_EQ(0, cpdf_page_object->GetContentStream());
- ASSERT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ ASSERT_TRUE(FPDFPage_RemoveObject(page.get(), page_object));
FPDFPageObj_Destroy(page_object);
}
// No more objects in the stream
- ASSERT_EQ(0, FPDFPage_CountObjects(page));
+ ASSERT_EQ(0, FPDFPage_CountObjects(page.get()));
// Generate contents should remove the empty stream and update the page
// objects' contents stream indexes.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
- ASSERT_EQ(0, FPDFPage_CountObjects(page));
+ ASSERT_EQ(0, FPDFPage_CountObjects(page.get()));
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedChecksum);
}
// Save the file
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the page object count is still 0.
ASSERT_TRUE(OpenSavedDocument());
@@ -2111,45 +2074,44 @@
TEST_F(FPDFEditEmbedderTest, RemoveFirstFromSingleStream) {
// Load document with a single stream.
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Content stream 0: page objects 0-1.
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
// Remove first object.
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(page_object);
CPDF_PageObject* cpdf_page_object =
CPDFPageObjectFromFPDFPageObject(page_object);
ASSERT_EQ(0, cpdf_page_object->GetContentStream());
- ASSERT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ ASSERT_TRUE(FPDFPage_RemoveObject(page.get(), page_object));
FPDFPageObj_Destroy(page_object);
// One object left in the stream.
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
- page_object = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
+ page_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(page_object);
cpdf_page_object = CPDFPageObjectFromFPDFPageObject(page_object);
ASSERT_EQ(0, cpdf_page_object->GetContentStream());
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
// Still one object left in the stream.
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
- page_object = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
+ page_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(page_object);
cpdf_page_object = CPDFPageObjectFromFPDFPageObject(page_object);
ASSERT_EQ(0, cpdf_page_object->GetContentStream());
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, FirstRemovedChecksum());
}
// Save the file
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the page object count is still 0.
ASSERT_TRUE(OpenSavedDocument());
@@ -2173,46 +2135,45 @@
TEST_F(FPDFEditEmbedderTest, RemoveLastFromSingleStream) {
// Load document with a single stream.
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Content stream 0: page objects 0-1.
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
// Remove last object
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 1);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 1);
ASSERT_TRUE(page_object);
CPDF_PageObject* cpdf_page_object =
CPDFPageObjectFromFPDFPageObject(page_object);
ASSERT_EQ(0, cpdf_page_object->GetContentStream());
- ASSERT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ ASSERT_TRUE(FPDFPage_RemoveObject(page.get(), page_object));
FPDFPageObj_Destroy(page_object);
// One object left in the stream.
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
- page_object = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
+ page_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(page_object);
cpdf_page_object = CPDFPageObjectFromFPDFPageObject(page_object);
ASSERT_EQ(0, cpdf_page_object->GetContentStream());
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
// Still one object left in the stream.
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
- page_object = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
+ page_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(page_object);
cpdf_page_object = CPDFPageObjectFromFPDFPageObject(page_object);
ASSERT_EQ(0, cpdf_page_object->GetContentStream());
using pdfium::HelloWorldRemovedChecksum;
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, HelloWorldRemovedChecksum());
}
// Save the file
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the page object count is still 0.
ASSERT_TRUE(OpenSavedDocument());
@@ -2236,39 +2197,38 @@
TEST_F(FPDFEditEmbedderTest, RemoveAllFromMultipleStreams) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world_split_streams.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Content stream 0: page objects 0-1.
// Content stream 1: page object 2.
- ASSERT_EQ(3, FPDFPage_CountObjects(page));
+ ASSERT_EQ(3, FPDFPage_CountObjects(page.get()));
// Loop backwards because objects will being removed, which shifts the indexes
// after the removed position.
for (int i = 2; i >= 0; i--) {
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), i);
ASSERT_TRUE(page_object);
- ASSERT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ ASSERT_TRUE(FPDFPage_RemoveObject(page.get(), page_object));
FPDFPageObj_Destroy(page_object);
}
// No more objects in the page.
- ASSERT_EQ(0, FPDFPage_CountObjects(page));
+ ASSERT_EQ(0, FPDFPage_CountObjects(page.get()));
// Generate contents should remove the empty streams and update the page
// objects' contents stream indexes.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
- ASSERT_EQ(0, FPDFPage_CountObjects(page));
+ ASSERT_EQ(0, FPDFPage_CountObjects(page.get()));
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedChecksum);
}
// Save the file
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the page object count is still 0.
ASSERT_TRUE(OpenSavedDocument());
@@ -2288,23 +2248,22 @@
TEST_F(FPDFEditEmbedderTest, InsertPageObjectAndSave) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Add a red rectangle.
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(20, 100, 50, 50);
EXPECT_TRUE(FPDFPageObj_SetFillColor(red_rect, 255, 0, 0, 255));
EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0));
- FPDFPage_InsertObject(page, red_rect);
+ FPDFPage_InsertObject(page.get(), red_rect);
// Verify the red rectangle was added.
- ASSERT_EQ(3, FPDFPage_CountObjects(page));
+ ASSERT_EQ(3, FPDFPage_CountObjects(page.get()));
// Save the file
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the page object count is still 3.
ASSERT_TRUE(OpenSavedDocument());
@@ -2318,27 +2277,26 @@
TEST_F(FPDFEditEmbedderTest, InsertPageObjectEditAndSave) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Add a red rectangle.
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(20, 100, 50, 50);
EXPECT_TRUE(FPDFPageObj_SetFillColor(red_rect, 255, 100, 100, 255));
EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0));
- FPDFPage_InsertObject(page, red_rect);
+ FPDFPage_InsertObject(page.get(), red_rect);
// Verify the red rectangle was added.
- ASSERT_EQ(3, FPDFPage_CountObjects(page));
+ ASSERT_EQ(3, FPDFPage_CountObjects(page.get()));
// Generate content but change it again
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDFPageObj_SetFillColor(red_rect, 255, 0, 0, 255));
// Save the file
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the page object count is still 3.
ASSERT_TRUE(OpenSavedDocument());
@@ -2354,24 +2312,24 @@
// Load document with many objects.
ASSERT_TRUE(OpenDocument("many_rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
using pdfium::ManyRectanglesChecksum;
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 300, ManyRectanglesChecksum());
}
// Add a black rectangle.
- ASSERT_EQ(kOriginalObjectCount, FPDFPage_CountObjects(page));
+ ASSERT_EQ(kOriginalObjectCount, FPDFPage_CountObjects(page.get()));
FPDF_PAGEOBJECT black_rect = FPDFPageObj_CreateNewRect(20, 100, 50, 50);
EXPECT_TRUE(FPDFPageObj_SetFillColor(black_rect, 0, 0, 0, 255));
EXPECT_TRUE(FPDFPath_SetDrawMode(black_rect, FPDF_FILLMODE_ALTERNATE, 0));
- FPDFPage_InsertObject(page, black_rect);
+ FPDFPage_InsertObject(page.get(), black_rect);
// Verify the black rectangle was added.
- ASSERT_EQ(kOriginalObjectCount + 1, FPDFPage_CountObjects(page));
+ ASSERT_EQ(kOriginalObjectCount + 1, FPDFPage_CountObjects(page.get()));
const char* plus_rectangle_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
return "0d3715fcfb9bd0dd25dcce60800bff47";
@@ -2379,14 +2337,13 @@
return "6b9396ab570754b32b04ca629e902f77";
}();
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 300, plus_rectangle_checksum);
}
// Save the file.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the rectangle added is still there.
ASSERT_TRUE(OpenSavedDocument());
@@ -2502,14 +2459,14 @@
TEST_F(FPDFEditEmbedderTest, PathOnTopOfText) {
// Load document with some text
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Add an opaque rectangle on top of some of the text.
FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(20, 100, 50, 50);
EXPECT_TRUE(FPDFPageObj_SetFillColor(red_rect, 255, 0, 0, 255));
EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0));
- FPDFPage_InsertObject(page, red_rect);
+ FPDFPage_InsertObject(page.get(), red_rect);
// Add a transparent triangle on top of other part of the text.
FPDF_PAGEOBJECT black_path = FPDFPageObj_CreateNewPath(20, 50);
@@ -2518,10 +2475,10 @@
EXPECT_TRUE(FPDFPath_LineTo(black_path, 30, 80));
EXPECT_TRUE(FPDFPath_LineTo(black_path, 40, 10));
EXPECT_TRUE(FPDFPath_Close(black_path));
- FPDFPage_InsertObject(page, black_path);
+ FPDFPage_InsertObject(page.get(), black_path);
// Render and check the result.
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
const char* checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
#if BUILDFLAG(IS_WIN)
@@ -2539,26 +2496,25 @@
#endif
}();
CompareBitmap(bitmap.get(), 200, 200, checksum);
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, EditOverExistingContent) {
// Load document with existing content
ASSERT_TRUE(OpenDocument("bug_717.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Add a transparent rectangle on top of the existing content
FPDF_PAGEOBJECT red_rect2 = FPDFPageObj_CreateNewRect(90, 700, 25, 50);
EXPECT_TRUE(FPDFPageObj_SetFillColor(red_rect2, 255, 0, 0, 100));
EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect2, FPDF_FILLMODE_ALTERNATE, 0));
- FPDFPage_InsertObject(page, red_rect2);
+ FPDFPage_InsertObject(page.get(), red_rect2);
// Add an opaque rectangle on top of the existing content
FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(115, 700, 25, 50);
EXPECT_TRUE(FPDFPageObj_SetFillColor(red_rect, 255, 0, 0, 255));
EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0));
- FPDFPage_InsertObject(page, red_rect);
+ FPDFPage_InsertObject(page.get(), red_rect);
const char* original_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -2566,13 +2522,12 @@
}
return "ad04e5bd0f471a9a564fb034bd0fb073";
}();
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 612, 792, original_checksum);
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
// Now save the result, closing the page and document
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
ASSERT_TRUE(OpenSavedDocument());
FPDF_PAGE saved_page = LoadSavedPage(0);
@@ -2825,20 +2780,18 @@
TEST_F(FPDFEditEmbedderTest, GetTextRenderMode) {
ASSERT_TRUE(OpenDocument("text_render_mode.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
EXPECT_EQ(FPDF_TEXTRENDERMODE_UNKNOWN,
FPDFTextObj_GetTextRenderMode(nullptr));
- FPDF_PAGEOBJECT fill = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT fill = FPDFPage_GetObject(page.get(), 0);
EXPECT_EQ(FPDF_TEXTRENDERMODE_FILL, FPDFTextObj_GetTextRenderMode(fill));
- FPDF_PAGEOBJECT stroke = FPDFPage_GetObject(page, 1);
+ FPDF_PAGEOBJECT stroke = FPDFPage_GetObject(page.get(), 1);
EXPECT_EQ(FPDF_TEXTRENDERMODE_STROKE, FPDFTextObj_GetTextRenderMode(stroke));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, SetTextRenderMode) {
@@ -2867,13 +2820,13 @@
{
ASSERT_TRUE(OpenDocument("text_render_mode.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
// Check the bitmap
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 612, 446, original_checksum);
}
@@ -2883,7 +2836,7 @@
EXPECT_FALSE(
FPDFTextObj_SetTextRenderMode(nullptr, FPDF_TEXTRENDERMODE_INVISIBLE));
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(page_object);
EXPECT_EQ(FPDF_TEXTRENDERMODE_FILL,
FPDFTextObj_GetTextRenderMode(page_object));
@@ -2899,15 +2852,14 @@
// Check that bitmap displays changed content
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 612, 446, stroke_checksum);
}
// Save a copy.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
}
{
@@ -2945,10 +2897,10 @@
// good object tests
ASSERT_TRUE(OpenDocument("text_font.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
- FPDF_PAGEOBJECT text = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
+ FPDF_PAGEOBJECT text = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(text);
float font_size;
ASSERT_TRUE(FPDFTextObj_GetFontSize(text, &font_size));
@@ -3072,21 +3024,19 @@
ASSERT_EQ(1, FPDFFont_GetIsEmbedded(font));
ASSERT_EQ(-1, FPDFFont_GetIsEmbedded(nullptr));
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, NoEmbeddedFontData) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
// Since hello_world.pdf does not embed any font data, FPDFFont_GetFontData()
// will return the substitution font data. Since pdfium_embeddertest is
// hermetic, this first object consistently maps to Tinos-Regular.ttf.
constexpr size_t kTinosRegularSize = 469968;
- FPDF_PAGEOBJECT text = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT text = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(text);
FPDF_FONT font = FPDFTextObj_GetFont(text);
ASSERT_TRUE(font);
@@ -3101,7 +3051,7 @@
// Similarly, the second object consistently maps to Arimo-Regular.ttf.
constexpr size_t kArimoRegularSize = 436180;
- text = FPDFPage_GetObject(page, 1);
+ text = FPDFPage_GetObject(page.get(), 1);
ASSERT_TRUE(text);
font = FPDFTextObj_GetFont(text);
ASSERT_TRUE(font);
@@ -3111,8 +3061,6 @@
EXPECT_EQ(kArimoRegularSize, buf_bytes_required);
EXPECT_EQ("7ac02a544211773d9636e056e9da6c35", GenerateMD5Base16(buf));
EXPECT_EQ(0, FPDFFont_GetIsEmbedded(font));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, Type1BaseFontName) {
@@ -3153,10 +3101,10 @@
EXPECT_FALSE(FPDFGlyphPath_GetGlyphPathSegment(nullptr, 1));
ASSERT_TRUE(OpenDocument("text_font.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
- FPDF_PAGEOBJECT text = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
+ FPDF_PAGEOBJECT text = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(text);
FPDF_FONT font = FPDFTextObj_GetFont(text);
ASSERT_TRUE(font);
@@ -3176,17 +3124,15 @@
FPDF_PATHSEGMENT segment = FPDFGlyphPath_GetGlyphPathSegment(gpath, 1);
ASSERT_TRUE(segment);
EXPECT_EQ(FPDF_SEGMENT_BEZIERTO, FPDFPathSegment_GetType(segment));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, FormGetObjects) {
ASSERT_TRUE(OpenDocument("form_object.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
- FPDF_PAGEOBJECT form = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT form = FPDFPage_GetObject(page.get(), 0);
ASSERT_EQ(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(form));
ASSERT_EQ(-1, FPDFFormObj_CountObjects(nullptr));
ASSERT_EQ(2, FPDFFormObj_CountObjects(form));
@@ -3230,10 +3176,8 @@
// Show that FPDFPage_RemoveObject() cannot remove page objects from within
// `form`. This is working as intended, as FPDFPage_RemoveObject() only works
// for page object within `page`.
- EXPECT_FALSE(FPDFPage_RemoveObject(page, text1));
- EXPECT_FALSE(FPDFPage_RemoveObject(page, text2));
-
- UnloadPage(page);
+ EXPECT_FALSE(FPDFPage_RemoveObject(page.get(), text1));
+ EXPECT_FALSE(FPDFPage_RemoveObject(page.get(), text2));
}
TEST_F(FPDFEditEmbedderTest, ModifyFormObject) {
@@ -3271,30 +3215,28 @@
}();
ASSERT_TRUE(OpenDocument("form_object.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 62, 69, orig_checksum);
}
- FPDF_PAGEOBJECT form = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT form = FPDFPage_GetObject(page.get(), 0);
ASSERT_EQ(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(form));
FPDFPageObj_Transform(form, 0.5, 0, 0, 0.5, 0, 0);
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 62, 69, new_checksum);
}
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
VerifySavedDocument(62, 69, new_checksum);
-
- UnloadPage(page);
}
// Tests adding text from standard font using FPDFText_LoadStandardFont.
@@ -3651,11 +3593,10 @@
TEST_F(FPDFEditEmbedderTest, NormalizeNegativeRotation) {
// Load document with a -90 degree rotation
ASSERT_TRUE(OpenDocument("bug_713197.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- EXPECT_EQ(3, FPDFPage_GetRotation(page));
- UnloadPage(page);
+ EXPECT_EQ(3, FPDFPage_GetRotation(page.get()));
}
TEST_F(FPDFEditEmbedderTest, AddTrueTypeFontText) {
@@ -3717,20 +3658,19 @@
TEST_F(FPDFEditEmbedderTest, TransformAnnot) {
// Open a file with one annotation and load its first page.
ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Add an underline annotation to the page without specifying its rectangle.
ScopedFPDFAnnotation annot(
- FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE));
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_UNDERLINE));
ASSERT_TRUE(annot);
// FPDFPage_TransformAnnots() should run without errors when modifying
// annotation rectangles.
- FPDFPage_TransformAnnots(page, 1, 2, 3, 4, 5, 6);
+ FPDFPage_TransformAnnots(page.get(), 1, 2, 3, 4, 5, 6);
}
- UnloadPage(page);
}
// TODO(npm): Add tests using Japanese fonts in other OS.
@@ -3900,8 +3840,8 @@
}();
{
ASSERT_TRUE(OpenDocument("bug_779.pdf"));
- FPDF_PAGE page = LoadPage(0);
- ASSERT_NE(nullptr, page);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
+ ASSERT_NE(nullptr, page.get());
// Now add a more complex green path.
FPDF_PAGEOBJECT green_path = FPDFPageObj_CreateNewPath(20, 20);
@@ -3914,14 +3854,13 @@
EXPECT_TRUE(FPDFPath_LineTo(green_path, 133, 33));
EXPECT_TRUE(FPDFPath_BezierTo(green_path, 38, 33, 39, 36, 40, 40));
EXPECT_TRUE(FPDFPath_Close(green_path));
- FPDFPage_InsertObject(page, green_path);
- ScopedFPDFBitmap page_bitmap = RenderLoadedPage(page);
+ FPDFPage_InsertObject(page.get(), green_path);
+ ScopedFPDFBitmap page_bitmap = RenderLoadedPage(page.get());
CompareBitmap(page_bitmap.get(), 612, 792, checksum);
// Now save the result, closing the page and document
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
}
VerifySavedDocument(612, 792, checksum);
@@ -3930,24 +3869,23 @@
TEST_F(FPDFEditEmbedderTest, AddMark) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("text_in_page_marked.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- CheckMarkCounts(page, 1, 19, 8, 4, 9, 1);
+ CheckMarkCounts(page.get(), 1, 19, 8, 4, 9, 1);
// Add to the first page object a "Bounds" mark with "Position": "First".
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 0);
FPDF_PAGEOBJECTMARK mark = FPDFPageObj_AddMark(page_object, "Bounds");
EXPECT_TRUE(mark);
EXPECT_TRUE(FPDFPageObjMark_SetStringParam(document(), page_object, mark,
"Position", "First"));
- CheckMarkCounts(page, 1, 19, 8, 4, 9, 2);
+ CheckMarkCounts(page.get(), 1, 19, 8, 4, 9, 2);
// Save the file
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the new mark is present.
ASSERT_TRUE(OpenSavedDocument());
@@ -3963,18 +3901,18 @@
TEST_F(FPDFEditEmbedderTest, AddMarkCompressedStream) {
// Load document with some text in a compressed stream.
ASSERT_TRUE(OpenDocument("hello_world_compressed_stream.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Render and check there are no marks.
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, HelloWorldChecksum());
}
- CheckMarkCounts(page, 0, 2, 0, 0, 0, 0);
+ CheckMarkCounts(page.get(), 0, 2, 0, 0, 0, 0);
// Add to the first page object a "Bounds" mark with "Position": "First".
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 0);
FPDF_PAGEOBJECTMARK mark = FPDFPageObj_AddMark(page_object, "Bounds");
EXPECT_TRUE(mark);
EXPECT_TRUE(FPDFPageObjMark_SetStringParam(document(), page_object, mark,
@@ -3982,15 +3920,14 @@
// Render and check there is 1 mark.
{
- ScopedFPDFBitmap page_bitmap = RenderPage(page);
+ ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
CompareBitmap(page_bitmap.get(), 200, 200, HelloWorldChecksum());
}
- CheckMarkCounts(page, 0, 2, 0, 0, 0, 1);
+ CheckMarkCounts(page.get(), 0, 2, 0, 0, 0, 1);
// Save the file.
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and check the new mark is present.
ASSERT_TRUE(OpenSavedDocument());
@@ -4010,14 +3947,14 @@
TEST_F(FPDFEditEmbedderTest, SetMarkParam) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("text_in_page_marked.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
constexpr int kExpectedObjectCount = 19;
- CheckMarkCounts(page, 1, kExpectedObjectCount, 8, 4, 9, 1);
+ CheckMarkCounts(page.get(), 1, kExpectedObjectCount, 8, 4, 9, 1);
// Check the "Bounds" mark's "Position" param is "Last".
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 18);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 18);
FPDF_PAGEOBJECTMARK mark = FPDFPageObj_GetMark(page_object, 1);
ASSERT_TRUE(mark);
char buffer[256];
@@ -4037,12 +3974,12 @@
"Position", "End"));
// Verify the object passed must correspond to the mark passed.
- FPDF_PAGEOBJECT another_page_object = FPDFPage_GetObject(page, 17);
+ FPDF_PAGEOBJECT another_page_object = FPDFPage_GetObject(page.get(), 17);
EXPECT_FALSE(FPDFPageObjMark_SetStringParam(document(), another_page_object,
mark, "Position", "End"));
// Verify nothing else changed.
- CheckMarkCounts(page, 1, kExpectedObjectCount, 8, 4, 9, 1);
+ CheckMarkCounts(page.get(), 1, kExpectedObjectCount, 8, 4, 9, 1);
// Verify "Position" now maps to "End".
EXPECT_TRUE(FPDFPageObjMark_GetParamStringValue(
@@ -4051,9 +3988,8 @@
GetPlatformWString(reinterpret_cast<unsigned short*>(buffer)));
// Save the file
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// Re-open the file and cerify "Position" still maps to "End".
ASSERT_TRUE(OpenSavedDocument());
@@ -4186,9 +4122,9 @@
TEST_F(FPDFEditEmbedderTest, MarkGetName) {
ASSERT_TRUE(OpenDocument("text_in_page_marked.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 18);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 18);
FPDF_PAGEOBJECTMARK mark = FPDFPageObj_GetMark(page_object, 1);
ASSERT_TRUE(mark);
@@ -4213,15 +4149,13 @@
EXPECT_EQ(999u, out_len);
EXPECT_FALSE(FPDFPageObjMark_GetName(mark, buffer, sizeof(buffer), nullptr));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, MarkGetParamKey) {
ASSERT_TRUE(OpenDocument("text_in_page_marked.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 18);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 18);
FPDF_PAGEOBJECTMARK mark = FPDFPageObj_GetMark(page_object, 1);
ASSERT_TRUE(mark);
@@ -4253,15 +4187,13 @@
EXPECT_FALSE(
FPDFPageObjMark_GetParamKey(mark, 0, buffer, sizeof(buffer), nullptr));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, MarkGetIntParam) {
ASSERT_TRUE(OpenDocument("text_in_page_marked.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 8);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 8);
FPDF_PAGEOBJECTMARK mark = FPDFPageObj_GetMark(page_object, 0);
ASSERT_TRUE(mark);
@@ -4284,20 +4216,18 @@
EXPECT_FALSE(FPDFPageObjMark_GetParamIntValue(mark, "Factor", nullptr));
- page_object = FPDFPage_GetObject(page, 18);
+ page_object = FPDFPage_GetObject(page.get(), 18);
mark = FPDFPageObj_GetMark(page_object, 1);
out_value = 999;
EXPECT_FALSE(FPDFPageObjMark_GetParamIntValue(mark, "Position", &out_value));
EXPECT_EQ(999, out_value);
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, MarkGetStringParam) {
ASSERT_TRUE(OpenDocument("text_in_page_marked.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 18);
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page.get(), 18);
FPDF_PAGEOBJECTMARK mark = FPDFPageObj_GetMark(page_object, 1);
ASSERT_TRUE(mark);
@@ -4331,25 +4261,23 @@
EXPECT_FALSE(FPDFPageObjMark_GetParamStringValue(mark, "Position", buffer,
sizeof(buffer), nullptr));
- page_object = FPDFPage_GetObject(page, 8);
+ page_object = FPDFPage_GetObject(page.get(), 8);
mark = FPDFPageObj_GetMark(page_object, 0);
out_len = 999u;
EXPECT_FALSE(FPDFPageObjMark_GetParamStringValue(mark, "Factor", buffer,
sizeof(buffer), &out_len));
EXPECT_EQ(999u, out_len);
-
- UnloadPage(page);
}
// See also FPDFStructTreeEmbedderTest.GetMarkedContentID, which traverses the
// marked contents using FPDF_StructTree_GetForPage() and related API.
TEST_F(FPDFEditEmbedderTest, TraverseMarkedContentID) {
ASSERT_TRUE(OpenDocument("marked_content_id.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(2, FPDFPage_CountObjects(page));
- FPDF_PAGEOBJECT object1 = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(2, FPDFPage_CountObjects(page.get()));
+ FPDF_PAGEOBJECT object1 = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(object1);
ASSERT_EQ(1, FPDFPageObj_CountMarks(object1));
@@ -4372,7 +4300,7 @@
EXPECT_EQ(FPDF_OBJECT_NAME,
FPDFPageObjMark_GetParamValueType(mark11, "Type"));
- FPDF_PAGEOBJECT object2 = FPDFPage_GetObject(page, 1);
+ FPDF_PAGEOBJECT object2 = FPDFPage_GetObject(page.get(), 1);
ASSERT_TRUE(object2);
ASSERT_EQ(2, FPDFPageObj_CountMarks(object2));
EXPECT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(object2));
@@ -4398,22 +4326,20 @@
EXPECT_EQ(18u, len);
EXPECT_EQ(L"ClipSpan", GetPlatformWString(buf));
EXPECT_EQ(0, FPDFPageObjMark_CountParams(mark22));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetBitmap) {
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(39, FPDFPage_CountObjects(page));
+ ASSERT_EQ(39, FPDFPage_CountObjects(page.get()));
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 32);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 32);
EXPECT_NE(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
EXPECT_FALSE(FPDFImageObj_GetBitmap(obj));
{
- obj = FPDFPage_GetObject(page, 33);
+ obj = FPDFPage_GetObject(page.get(), 33);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap.get()));
@@ -4421,7 +4347,7 @@
}
{
- obj = FPDFPage_GetObject(page, 34);
+ obj = FPDFPage_GetObject(page.get(), 34);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap.get()));
@@ -4429,7 +4355,7 @@
}
{
- obj = FPDFPage_GetObject(page, 35);
+ obj = FPDFPage_GetObject(page.get(), 35);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap.get()));
@@ -4437,7 +4363,7 @@
}
{
- obj = FPDFPage_GetObject(page, 36);
+ obj = FPDFPage_GetObject(page.get(), 36);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap.get()));
@@ -4445,7 +4371,7 @@
}
{
- obj = FPDFPage_GetObject(page, 37);
+ obj = FPDFPage_GetObject(page.get(), 37);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap.get()));
@@ -4453,23 +4379,21 @@
}
{
- obj = FPDFPage_GetObject(page, 38);
+ obj = FPDFPage_GetObject(page.get(), 38);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap.get()));
CompareBitmap(bitmap.get(), 194, 119, "a8f3a126cec274dab8242fd2ccdc1b8b");
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetBitmapIgnoresSetMatrix) {
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(39, FPDFPage_CountObjects(page));
+ ASSERT_EQ(39, FPDFPage_CountObjects(page.get()));
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 33);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 33);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
{
@@ -4509,17 +4433,15 @@
EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap.get()));
CompareBitmap(bitmap.get(), 109, 88, kEmbeddedImage33Checksum);
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetBitmapForJBigImage) {
ASSERT_TRUE(OpenDocument("bug_631912.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(1, FPDFPage_CountObjects(page));
+ ASSERT_EQ(1, FPDFPage_CountObjects(page.get()));
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 0);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
{
ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
@@ -4527,62 +4449,56 @@
EXPECT_EQ(FPDFBitmap_Gray, FPDFBitmap_GetFormat(bitmap.get()));
CompareBitmap(bitmap.get(), 1152, 720, "3f6a48e2b3e91b799bf34567f55cb4de");
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetBitmapIgnoresSMask) {
ASSERT_TRUE(OpenDocument("matte.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
constexpr int kExpectedObjects = 4;
- ASSERT_EQ(kExpectedObjects, FPDFPage_CountObjects(page));
+ ASSERT_EQ(kExpectedObjects, FPDFPage_CountObjects(page.get()));
for (int i = 0; i < kExpectedObjects; ++i) {
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), i);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
ASSERT_TRUE(bitmap);
EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap.get()));
CompareBitmap(bitmap.get(), 50, 50, "46c9a1dbe0b44765ce46017ad629a2fe");
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetBitmapWithArgbImageWithPalette) {
ASSERT_TRUE(OpenDocument("bug_343075986.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
constexpr int kExpectedObjects = 2;
- ASSERT_EQ(kExpectedObjects, FPDFPage_CountObjects(page));
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 1);
+ ASSERT_EQ(kExpectedObjects, FPDFPage_CountObjects(page.get()));
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 1);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
ASSERT_TRUE(bitmap);
EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap.get()));
CompareBitmap(bitmap.get(), 4, 4, "49b4d39d3fd81c9853b493b615e475d1");
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetRenderedBitmapHandlesSetMatrix) {
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(39, FPDFPage_CountObjects(page));
+ ASSERT_EQ(39, FPDFPage_CountObjects(page.get()));
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 33);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 33);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
{
// Render `obj` as is.
ScopedFPDFBitmap bitmap(
- FPDFImageObj_GetRenderedBitmap(document(), page, obj));
+ FPDFImageObj_GetRenderedBitmap(document(), page.get(), obj));
EXPECT_EQ(FPDFBitmap_BGRA, FPDFBitmap_GetFormat(bitmap.get()));
const char* checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -4620,7 +4536,7 @@
// Render `obj` again. Note that the FPDFPageObj_SetMatrix() call has an
// effect.
ScopedFPDFBitmap bitmap(
- FPDFImageObj_GetRenderedBitmap(document(), page, obj));
+ FPDFImageObj_GetRenderedBitmap(document(), page.get(), obj));
EXPECT_EQ(FPDFBitmap_BGRA, FPDFBitmap_GetFormat(bitmap.get()));
const char* checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -4630,17 +4546,15 @@
}();
CompareBitmap(bitmap.get(), 120, 43, checksum);
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetRenderedBitmapHandlesSMask) {
ASSERT_TRUE(OpenDocument("matte.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
constexpr int kExpectedObjects = 4;
- ASSERT_EQ(kExpectedObjects, FPDFPage_CountObjects(page));
+ ASSERT_EQ(kExpectedObjects, FPDFPage_CountObjects(page.get()));
const char* smask_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -4656,10 +4570,10 @@
}();
for (int i = 0; i < kExpectedObjects; ++i) {
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), i);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ScopedFPDFBitmap bitmap(
- FPDFImageObj_GetRenderedBitmap(document(), page, obj));
+ FPDFImageObj_GetRenderedBitmap(document(), page.get(), obj));
ASSERT_TRUE(bitmap);
EXPECT_EQ(FPDFBitmap_BGRA, FPDFBitmap_GetFormat(bitmap.get()));
if (i == 0)
@@ -4667,41 +4581,38 @@
else
CompareBitmap(bitmap.get(), 40, 60, no_smask_checksum);
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetRenderedBitmapBadParams) {
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 33);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 33);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
// Test various null parameters.
EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(nullptr, nullptr, nullptr));
EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(document(), nullptr, nullptr));
- EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(nullptr, page, nullptr));
+ EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(nullptr, page.get(), nullptr));
EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(nullptr, nullptr, obj));
- EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(document(), page, nullptr));
- EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(nullptr, page, obj));
+ EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(document(), page.get(), nullptr));
+ EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(nullptr, page.get(), obj));
// Test mismatch between document and page parameters.
ScopedFPDFDocument new_document(FPDF_CreateNewDocument());
- EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(new_document.get(), page, obj));
-
- UnloadPage(page);
+ EXPECT_FALSE(
+ FPDFImageObj_GetRenderedBitmap(new_document.get(), page.get(), obj));
}
TEST_F(FPDFEditEmbedderTest, GetImageData) {
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(39, FPDFPage_CountObjects(page));
+ ASSERT_EQ(39, FPDFPage_CountObjects(page.get()));
// Retrieve an image object with flate-encoded data stream.
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 33);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 33);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
// Check that the raw image data has the correct length and hash value.
@@ -4718,7 +4629,7 @@
EXPECT_EQ(kEmbeddedImage33Checksum, GenerateMD5Base16(buf));
// Retrieve an image object with DCTDecode-encoded data stream.
- obj = FPDFPage_GetObject(page, 37);
+ obj = FPDFPage_GetObject(page.get(), 37);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
// Check that the raw image data has the correct length and hash value.
@@ -4736,20 +4647,18 @@
buf.resize(len);
EXPECT_EQ(4370u, FPDFImageObj_GetImageDataDecoded(obj, buf.data(), len));
EXPECT_EQ("6aae1f3710335023a9e12191be66b64b", GenerateMD5Base16(buf));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetImageMatrix) {
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(39, FPDFPage_CountObjects(page));
+ ASSERT_EQ(39, FPDFPage_CountObjects(page.get()));
FPDF_PAGEOBJECT obj;
FS_MATRIX matrix;
- obj = FPDFPage_GetObject(page, 33);
+ obj = FPDFPage_GetObject(page.get(), 33);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
EXPECT_TRUE(FPDFPageObj_GetMatrix(obj, &matrix));
EXPECT_FLOAT_EQ(53.0f, matrix.a);
@@ -4759,7 +4668,7 @@
EXPECT_FLOAT_EQ(72.0f, matrix.e);
EXPECT_FLOAT_EQ(646.510009765625f, matrix.f);
- obj = FPDFPage_GetObject(page, 34);
+ obj = FPDFPage_GetObject(page.get(), 34);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
EXPECT_TRUE(FPDFPageObj_GetMatrix(obj, &matrix));
EXPECT_FLOAT_EQ(70.0f, matrix.a);
@@ -4769,7 +4678,7 @@
EXPECT_FLOAT_EQ(216.0f, matrix.e);
EXPECT_FLOAT_EQ(646.510009765625f, matrix.f);
- obj = FPDFPage_GetObject(page, 35);
+ obj = FPDFPage_GetObject(page.get(), 35);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
EXPECT_TRUE(FPDFPageObj_GetMatrix(obj, &matrix));
EXPECT_FLOAT_EQ(69.0f, matrix.a);
@@ -4779,7 +4688,7 @@
EXPECT_FLOAT_EQ(360.0f, matrix.e);
EXPECT_FLOAT_EQ(646.510009765625f, matrix.f);
- obj = FPDFPage_GetObject(page, 36);
+ obj = FPDFPage_GetObject(page.get(), 36);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
EXPECT_TRUE(FPDFPageObj_GetMatrix(obj, &matrix));
EXPECT_FLOAT_EQ(59.0f, matrix.a);
@@ -4789,7 +4698,7 @@
EXPECT_FLOAT_EQ(72.0f, matrix.e);
EXPECT_FLOAT_EQ(553.510009765625f, matrix.f);
- obj = FPDFPage_GetObject(page, 37);
+ obj = FPDFPage_GetObject(page.get(), 37);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
EXPECT_TRUE(FPDFPageObj_GetMatrix(obj, &matrix));
EXPECT_FLOAT_EQ(55.94000244140625f, matrix.a);
@@ -4799,7 +4708,7 @@
EXPECT_FLOAT_EQ(216.0f, matrix.e);
EXPECT_FLOAT_EQ(552.510009765625f, matrix.f);
- obj = FPDFPage_GetObject(page, 38);
+ obj = FPDFPage_GetObject(page.get(), 38);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
EXPECT_TRUE(FPDFPageObj_GetMatrix(obj, &matrix));
EXPECT_FLOAT_EQ(70.528999328613281f, matrix.a);
@@ -4808,8 +4717,6 @@
EXPECT_FLOAT_EQ(43.149997711181641f, matrix.d);
EXPECT_FLOAT_EQ(360.0f, matrix.e);
EXPECT_FLOAT_EQ(553.3599853515625f, matrix.f);
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, DestroyPageObject) {
@@ -4822,17 +4729,17 @@
TEST_F(FPDFEditEmbedderTest, GetImageFilters) {
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Verify that retrieving the filter of a non-image object would fail.
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 32);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 32);
ASSERT_NE(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ASSERT_EQ(0, FPDFImageObj_GetImageFilterCount(obj));
EXPECT_EQ(0u, FPDFImageObj_GetImageFilter(obj, 0, nullptr, 0));
// Verify the returned filter string for an image object with a single filter.
- obj = FPDFPage_GetObject(page, 33);
+ obj = FPDFPage_GetObject(page.get(), 33);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ASSERT_EQ(1, FPDFImageObj_GetImageFilterCount(obj));
unsigned long len = FPDFImageObj_GetImageFilter(obj, 0, nullptr, 0);
@@ -4844,7 +4751,7 @@
EXPECT_EQ(0u, FPDFImageObj_GetImageFilter(obj, 1, nullptr, 0));
// Verify all the filters for an image object with a list of filters.
- obj = FPDFPage_GetObject(page, 38);
+ obj = FPDFPage_GetObject(page.get(), 38);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ASSERT_EQ(2, FPDFImageObj_GetImageFilterCount(obj));
len = FPDFImageObj_GetImageFilter(obj, 0, nullptr, 0);
@@ -4862,22 +4769,20 @@
EXPECT_EQ(sizeof(kDCTDecode),
FPDFImageObj_GetImageFilter(obj, 1, buf.data(), len));
EXPECT_STREQ(kDCTDecode, buf.data());
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetImageMetadata) {
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Check that getting the metadata of a null object would fail.
FPDF_IMAGEOBJ_METADATA metadata;
- EXPECT_FALSE(FPDFImageObj_GetImageMetadata(nullptr, page, &metadata));
+ EXPECT_FALSE(FPDFImageObj_GetImageMetadata(nullptr, page.get(), &metadata));
// Check that receiving the metadata with a null metadata object would fail.
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 35);
- EXPECT_FALSE(FPDFImageObj_GetImageMetadata(obj, page, nullptr));
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 35);
+ EXPECT_FALSE(FPDFImageObj_GetImageMetadata(obj, page.get(), nullptr));
// Check that when retrieving an image object's metadata without passing in
// |page|, all values are correct, with the last two being default values.
@@ -4892,7 +4797,7 @@
EXPECT_EQ(FPDF_COLORSPACE_UNKNOWN, metadata.colorspace);
// Verify the metadata of a bitmap image with indexed colorspace.
- ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, page, &metadata));
+ ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, page.get(), &metadata));
EXPECT_EQ(7, metadata.marked_content_id);
EXPECT_EQ(92u, metadata.width);
EXPECT_EQ(68u, metadata.height);
@@ -4902,9 +4807,9 @@
EXPECT_EQ(FPDF_COLORSPACE_INDEXED, metadata.colorspace);
// Verify the metadata of an image with RGB colorspace.
- obj = FPDFPage_GetObject(page, 37);
+ obj = FPDFPage_GetObject(page.get(), 37);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
- ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, page, &metadata));
+ ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, page.get(), &metadata));
EXPECT_EQ(9, metadata.marked_content_id);
EXPECT_EQ(126u, metadata.width);
EXPECT_EQ(106u, metadata.height);
@@ -4912,20 +4817,18 @@
EXPECT_FLOAT_EQ(162.555878f, metadata.vertical_dpi);
EXPECT_EQ(24u, metadata.bits_per_pixel);
EXPECT_EQ(FPDF_COLORSPACE_DEVICERGB, metadata.colorspace);
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetImageMetadataJpxLzw) {
ASSERT_TRUE(OpenDocument("jpx_lzw.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 0);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
FPDF_IMAGEOBJ_METADATA metadata;
- ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, page, &metadata));
+ ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, page.get(), &metadata));
EXPECT_EQ(-1, metadata.marked_content_id);
EXPECT_EQ(612u, metadata.width);
EXPECT_EQ(792u, metadata.height);
@@ -4933,13 +4836,11 @@
EXPECT_FLOAT_EQ(72.0f, metadata.vertical_dpi);
EXPECT_EQ(24u, metadata.bits_per_pixel);
EXPECT_EQ(FPDF_COLORSPACE_UNKNOWN, metadata.colorspace);
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetImagePixelSize) {
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Check that getting the size of a null object would fail.
@@ -4949,7 +4850,7 @@
// Check that receiving the size with a null width and height pointers would
// fail.
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 35);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 35);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
EXPECT_FALSE(FPDFImageObj_GetImagePixelSize(obj, nullptr, nullptr));
EXPECT_FALSE(FPDFImageObj_GetImagePixelSize(obj, nullptr, &height));
@@ -4960,26 +4861,24 @@
EXPECT_EQ(92u, width);
EXPECT_EQ(68u, height);
- obj = FPDFPage_GetObject(page, 37);
+ obj = FPDFPage_GetObject(page.get(), 37);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
ASSERT_TRUE(FPDFImageObj_GetImagePixelSize(obj, &width, &height));
EXPECT_EQ(126u, width);
EXPECT_EQ(106u, height);
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetRenderedBitmapForHelloWorldText) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object));
ScopedFPDFBitmap bitmap(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 1));
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), text_object, 1));
ASSERT_TRUE(bitmap);
const char* checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -4995,8 +4894,8 @@
}();
CompareBitmap(bitmap.get(), 64, 11, checksum);
- ScopedFPDFBitmap x2_bitmap(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 2.4f));
+ ScopedFPDFBitmap x2_bitmap(FPDFTextObj_GetRenderedBitmap(
+ document(), page.get(), text_object, 2.4f));
ASSERT_TRUE(x2_bitmap);
const char* x2_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -5013,7 +4912,7 @@
CompareBitmap(x2_bitmap.get(), 153, 25, x2_checksum);
ScopedFPDFBitmap x10_bitmap(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 10));
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), text_object, 10));
ASSERT_TRUE(x10_bitmap);
const char* x10_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -5031,11 +4930,11 @@
}
{
- FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page, 1);
+ FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page.get(), 1);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object));
ScopedFPDFBitmap bitmap(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 1));
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), text_object, 1));
ASSERT_TRUE(bitmap);
const char* checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -5051,8 +4950,8 @@
}();
CompareBitmap(bitmap.get(), 116, 16, checksum);
- ScopedFPDFBitmap x2_bitmap(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 2.4f));
+ ScopedFPDFBitmap x2_bitmap(FPDFTextObj_GetRenderedBitmap(
+ document(), page.get(), text_object, 2.4f));
ASSERT_TRUE(x2_bitmap);
const char* x2_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -5069,7 +4968,7 @@
CompareBitmap(x2_bitmap.get(), 276, 36, x2_checksum);
ScopedFPDFBitmap x10_bitmap(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 10));
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), text_object, 10));
ASSERT_TRUE(x10_bitmap);
const char* x10_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -5085,20 +4984,18 @@
}();
CompareBitmap(x10_bitmap.get(), 1143, 150, x10_checksum);
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetRenderedBitmapForRotatedText) {
ASSERT_TRUE(OpenDocument("rotated_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object));
ScopedFPDFBitmap bitmap(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 1));
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), text_object, 1));
ASSERT_TRUE(bitmap);
const char* checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -5115,7 +5012,7 @@
CompareBitmap(bitmap.get(), 29, 28, checksum);
ScopedFPDFBitmap x2_bitmap(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 2.4f));
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), text_object, 2.4f));
ASSERT_TRUE(x2_bitmap);
const char* x2_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -5132,7 +5029,7 @@
CompareBitmap(x2_bitmap.get(), 67, 67, x2_checksum);
ScopedFPDFBitmap x10_bitmap(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 10));
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), text_object, 10));
ASSERT_TRUE(x10_bitmap);
const char* x10_checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -5147,20 +5044,18 @@
return "bbd3842a4b50dbfcbce4eee2b067a297";
}();
CompareBitmap(x10_bitmap.get(), 275, 275, x10_checksum);
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetRenderedBitmapForColorText) {
ASSERT_TRUE(OpenDocument("text_color.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object));
ScopedFPDFBitmap bitmap(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 7.3f));
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), text_object, 7.3f));
ASSERT_TRUE(bitmap);
const char* checksum = []() {
if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
@@ -5169,8 +5064,6 @@
return "e8154fa8ededf4d9b8b35b5260897b6c";
}();
CompareBitmap(bitmap.get(), 120, 186, checksum);
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetRenderedBitmapForNewlyCreatedText) {
@@ -5204,36 +5097,42 @@
TEST_F(FPDFEditEmbedderTest, GetRenderedBitmapForTextWithBadParameters) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(text_object);
// Simple bad parameters testing.
EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(nullptr, nullptr, nullptr, 0));
EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(document(), nullptr, nullptr, 0));
- EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(nullptr, page, nullptr, 0));
+ EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(nullptr, page.get(), nullptr, 0));
EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(nullptr, nullptr, text_object, 0));
EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(nullptr, nullptr, nullptr, 1));
- EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(document(), page, nullptr, 0));
+ EXPECT_FALSE(
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), nullptr, 0));
EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(document(), nullptr, nullptr, 1));
- EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(nullptr, page, text_object, 0));
- EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(nullptr, page, nullptr, 1));
+ EXPECT_FALSE(
+ FPDFTextObj_GetRenderedBitmap(nullptr, page.get(), text_object, 0));
+ EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(nullptr, page.get(), nullptr, 1));
EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(nullptr, nullptr, text_object, 1));
- EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(document(), page, nullptr, 1));
- EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(nullptr, page, text_object, 1));
+ EXPECT_FALSE(
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), nullptr, 1));
+ EXPECT_FALSE(
+ FPDFTextObj_GetRenderedBitmap(nullptr, page.get(), text_object, 1));
// Test bad scale values.
- EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 0));
EXPECT_FALSE(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, -1));
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), text_object, 0));
EXPECT_FALSE(
- FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 10000));
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), text_object, -1));
+ EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(document(), page.get(),
+ text_object, 10000));
EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(
- document(), page, text_object, std::numeric_limits<float>::max()));
- EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(
- document(), page, text_object, std::numeric_limits<float>::infinity()));
+ document(), page.get(), text_object, std::numeric_limits<float>::max()));
+ EXPECT_FALSE(
+ FPDFTextObj_GetRenderedBitmap(document(), page.get(), text_object,
+ std::numeric_limits<float>::infinity()));
{
// `text_object` will render without `page`, but may not render correctly
@@ -5245,10 +5144,8 @@
// Mismatch between the document and the page fails too.
ScopedFPDFDocument empty_document(FPDF_CreateNewDocument());
- EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(empty_document.get(), page,
+ EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(empty_document.get(), page.get(),
text_object, 1));
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetRenderedBitmapForRotatedImage) {
@@ -5288,7 +5185,7 @@
TEST_F(FPDFEditEmbedderTest, MultipleGraphicsStates) {
ASSERT_TRUE(OpenDocument("multiple_graphics_states.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
@@ -5299,21 +5196,19 @@
EXPECT_TRUE(FPDFPath_LineTo(path.get(), 100, 125));
EXPECT_TRUE(FPDFPath_Close(path.get()));
- FPDFPage_InsertObject(page, path.release());
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ FPDFPage_InsertObject(page.get(), path.release());
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
}
const char* checksum = CFX_DefaultRenderDevice::UseSkiaRenderer()
? "7ebec75d95c64b522999a710de76c52c"
: "f4b36616a7fea81a4f06cc7b01a55ac1";
- ScopedFPDFBitmap bitmap = RenderPage(page);
+ ScopedFPDFBitmap bitmap = RenderPage(page.get());
CompareBitmap(bitmap.get(), 200, 300, checksum);
ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
VerifySavedDocument(200, 300, checksum);
-
- UnloadPage(page);
}
TEST_F(FPDFEditEmbedderTest, GetAndSetMatrixForFormWithText) {
@@ -5321,16 +5216,16 @@
constexpr int kExpectedHeight = 200;
OpenDocument("form_object_with_text.pdf");
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedWidth, kExpectedHeight,
HelloWorldChecksum());
}
- FPDF_PAGEOBJECT form = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT form = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(form);
ASSERT_EQ(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(form));
@@ -5345,7 +5240,7 @@
ASSERT_TRUE(FPDFPageObj_SetMatrix(form, &matrix));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedWidth, kExpectedHeight,
HelloWorldChecksum());
}
@@ -5364,21 +5259,20 @@
ASSERT_TRUE(FPDFPageObj_SetMatrix(text, &matrix));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedWidth, kExpectedHeight,
HelloWorldChecksum());
}
- ASSERT_TRUE(FPDFPage_GenerateContent(page));
+ ASSERT_TRUE(FPDFPage_GenerateContent(page.get()));
ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedWidth, kExpectedHeight,
HelloWorldChecksum());
}
- UnloadPage(page);
VerifySavedDocument(kExpectedWidth, kExpectedHeight, HelloWorldChecksum());
}
@@ -5407,11 +5301,10 @@
private:
std::string HashForPage(int page_index) {
- FPDF_PAGE page = LoadPage(page_index);
+ ScopedEmbedderTestPage page = LoadScopedPage(page_index);
EXPECT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
std::string hash = HashBitmap(bitmap.get());
- UnloadPage(page);
return hash;
}
};
diff --git a/fpdfsdk/fpdf_editimg_embeddertest.cpp b/fpdfsdk/fpdf_editimg_embeddertest.cpp
index 2c3efdb..0f26b12 100644
--- a/fpdfsdk/fpdf_editimg_embeddertest.cpp
+++ b/fpdfsdk/fpdf_editimg_embeddertest.cpp
@@ -181,16 +181,16 @@
constexpr char kExpectedChecksum[] = "617b1d57c30c516beee86e0781ff7810";
OpenDocument("bug_2132.pdf");
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedWidth, kExpectedHeight,
kExpectedChecksum);
}
- FPDF_PAGEOBJECT image = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT image = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(image);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(image));
@@ -205,21 +205,20 @@
ASSERT_TRUE(FPDFPageObj_SetMatrix(image, &matrix));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedWidth, kExpectedHeight,
kExpectedChecksum);
}
- ASSERT_TRUE(FPDFPage_GenerateContent(page));
+ ASSERT_TRUE(FPDFPage_GenerateContent(page.get()));
ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedWidth, kExpectedHeight,
kExpectedChecksum);
}
- UnloadPage(page);
VerifySavedDocument(kExpectedWidth, kExpectedHeight, kExpectedChecksum);
}
@@ -230,16 +229,16 @@
constexpr char kExpectedChecksum[] = "fcb9007fd901d2052e2bd1c147b82800";
OpenDocument("form_object_with_image.pdf");
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedWidth, kExpectedHeight,
kExpectedChecksum);
}
- FPDF_PAGEOBJECT form = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT form = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(form);
ASSERT_EQ(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(form));
@@ -254,7 +253,7 @@
ASSERT_TRUE(FPDFPageObj_SetMatrix(form, &matrix));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedWidth, kExpectedHeight,
kExpectedChecksum);
}
@@ -273,21 +272,20 @@
ASSERT_TRUE(FPDFPageObj_SetMatrix(image, &matrix));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedWidth, kExpectedHeight,
kExpectedChecksum);
}
- ASSERT_TRUE(FPDFPage_GenerateContent(page));
+ ASSERT_TRUE(FPDFPage_GenerateContent(page.get()));
ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedWidth, kExpectedHeight,
kExpectedChecksum);
}
- UnloadPage(page);
VerifySavedDocument(kExpectedWidth, kExpectedHeight, kExpectedChecksum);
}
diff --git a/fpdfsdk/fpdf_editpage_embeddertest.cpp b/fpdfsdk/fpdf_editpage_embeddertest.cpp
index 44daff9..a62cb71 100644
--- a/fpdfsdk/fpdf_editpage_embeddertest.cpp
+++ b/fpdfsdk/fpdf_editpage_embeddertest.cpp
@@ -29,37 +29,36 @@
{
ASSERT_TRUE(OpenDocument("rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Render the page as is.
- EXPECT_EQ(0, FPDFPage_GetRotation(page));
- const int page_width = static_cast<int>(FPDF_GetPageWidth(page));
- const int page_height = static_cast<int>(FPDF_GetPageHeight(page));
+ EXPECT_EQ(0, FPDFPage_GetRotation(page.get()));
+ const int page_width = static_cast<int>(FPDF_GetPageWidth(page.get()));
+ const int page_height = static_cast<int>(FPDF_GetPageHeight(page.get()));
EXPECT_EQ(200, page_width);
EXPECT_EQ(300, page_height);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), page_width, page_height,
pdfium::RectanglesChecksum());
}
- FPDFPage_SetRotation(page, 1);
+ FPDFPage_SetRotation(page.get(), 1);
{
// Render the page after rotation.
// Note that the change affects the rendering, as expected.
// It behaves just like the case below, rather than the case above.
- EXPECT_EQ(1, FPDFPage_GetRotation(page));
- const int page_width = static_cast<int>(FPDF_GetPageWidth(page));
- const int page_height = static_cast<int>(FPDF_GetPageHeight(page));
+ EXPECT_EQ(1, FPDFPage_GetRotation(page.get()));
+ const int page_width = static_cast<int>(FPDF_GetPageWidth(page.get()));
+ const int page_height = static_cast<int>(FPDF_GetPageHeight(page.get()));
EXPECT_EQ(300, page_width);
EXPECT_EQ(200, page_height);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), page_width, page_height, rotated_checksum);
}
- UnloadPage(page);
}
{
@@ -86,19 +85,17 @@
TEST_F(FPDFEditPageEmbedderTest, HasTransparencyImage) {
constexpr int kExpectedObjectCount = 39;
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(kExpectedObjectCount, FPDFPage_CountObjects(page));
+ ASSERT_EQ(kExpectedObjectCount, FPDFPage_CountObjects(page.get()));
for (int i = 0; i < kExpectedObjectCount; ++i) {
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), i);
EXPECT_FALSE(FPDFPageObj_HasTransparency(obj));
FPDFPageObj_SetFillColor(obj, 255, 0, 0, 127);
EXPECT_TRUE(FPDFPageObj_HasTransparency(obj));
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditPageEmbedderTest, HasTransparencyInvalid) {
@@ -108,50 +105,46 @@
TEST_F(FPDFEditPageEmbedderTest, HasTransparencyPath) {
constexpr int kExpectedObjectCount = 8;
ASSERT_TRUE(OpenDocument("rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(kExpectedObjectCount, FPDFPage_CountObjects(page));
+ ASSERT_EQ(kExpectedObjectCount, FPDFPage_CountObjects(page.get()));
for (int i = 0; i < kExpectedObjectCount; ++i) {
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), i);
EXPECT_FALSE(FPDFPageObj_HasTransparency(obj));
FPDFPageObj_SetStrokeColor(obj, 63, 63, 0, 127);
EXPECT_TRUE(FPDFPageObj_HasTransparency(obj));
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditPageEmbedderTest, HasTransparencyText) {
constexpr int kExpectedObjectCount = 2;
ASSERT_TRUE(OpenDocument("text_render_mode.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(kExpectedObjectCount, FPDFPage_CountObjects(page));
+ ASSERT_EQ(kExpectedObjectCount, FPDFPage_CountObjects(page.get()));
for (int i = 0; i < kExpectedObjectCount; ++i) {
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), i);
EXPECT_FALSE(FPDFPageObj_HasTransparency(obj));
FPDFPageObj_SetBlendMode(obj, "Lighten");
EXPECT_TRUE(FPDFPageObj_HasTransparency(obj));
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditPageEmbedderTest, GetFillAndStrokeForImage) {
constexpr int kExpectedObjectCount = 39;
constexpr int kImageObjectsStartIndex = 33;
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(kExpectedObjectCount, FPDFPage_CountObjects(page));
+ ASSERT_EQ(kExpectedObjectCount, FPDFPage_CountObjects(page.get()));
for (int i = kImageObjectsStartIndex; i < kExpectedObjectCount; ++i) {
- FPDF_PAGEOBJECT image = FPDFPage_GetObject(page, i);
+ FPDF_PAGEOBJECT image = FPDFPage_GetObject(page.get(), i);
ASSERT_TRUE(image);
EXPECT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(image));
@@ -162,8 +155,6 @@
EXPECT_FALSE(FPDFPageObj_GetFillColor(image, &r, &g, &b, &a));
EXPECT_FALSE(FPDFPageObj_GetStrokeColor(image, &r, &g, &b, &a));
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditPageEmbedderTest, DashingArrayAndPhase) {
@@ -193,13 +184,13 @@
constexpr int kExpectedObjectCount = 3;
ASSERT_TRUE(OpenDocument("dashed_lines.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_EQ(kExpectedObjectCount, FPDFPage_CountObjects(page));
+ ASSERT_EQ(kExpectedObjectCount, FPDFPage_CountObjects(page.get()));
{
- FPDF_PAGEOBJECT path = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT path = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(path);
EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path));
@@ -219,7 +210,7 @@
}
{
- FPDF_PAGEOBJECT path = FPDFPage_GetObject(page, 1);
+ FPDF_PAGEOBJECT path = FPDFPage_GetObject(page.get(), 1);
ASSERT_TRUE(path);
EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path));
@@ -255,7 +246,7 @@
}
{
- FPDF_PAGEOBJECT path = FPDFPage_GetObject(page, 2);
+ FPDF_PAGEOBJECT path = FPDFPage_GetObject(page.get(), 2);
ASSERT_TRUE(path);
EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path));
@@ -302,32 +293,28 @@
EXPECT_TRUE(FPDFPageObj_GetDashPhase(path, &phase));
EXPECT_FLOAT_EQ(4.0f, phase);
}
-
- UnloadPage(page);
}
TEST_F(FPDFEditPageEmbedderTest, GetRotatedBoundsBadParameters) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 0);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(obj));
FS_QUADPOINTSF quad;
ASSERT_FALSE(FPDFPageObj_GetRotatedBounds(nullptr, nullptr));
ASSERT_FALSE(FPDFPageObj_GetRotatedBounds(obj, nullptr));
ASSERT_FALSE(FPDFPageObj_GetRotatedBounds(nullptr, &quad));
-
- UnloadPage(page);
}
TEST_F(FPDFEditPageEmbedderTest, GetBoundsForNormalText) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 0);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(obj));
constexpr float kExpectedLeft = 20.348f;
@@ -355,16 +342,14 @@
EXPECT_FLOAT_EQ(kExpectedTop, quad.y3);
EXPECT_FLOAT_EQ(kExpectedLeft, quad.x4);
EXPECT_FLOAT_EQ(kExpectedTop, quad.y4);
-
- UnloadPage(page);
}
TEST_F(FPDFEditPageEmbedderTest, GetBoundsForRotatedText) {
ASSERT_TRUE(OpenDocument("rotated_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 0);
ASSERT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(obj));
constexpr float kExpectedLeft = 98.9478f;
@@ -392,16 +377,14 @@
EXPECT_FLOAT_EQ(85.447739f, quad.y3);
EXPECT_FLOAT_EQ(106.13486f, quad.x4);
EXPECT_FLOAT_EQ(kExpectedTop, quad.y4);
-
- UnloadPage(page);
}
TEST_F(FPDFEditPageEmbedderTest, GetBoundsForNormalImage) {
ASSERT_TRUE(OpenDocument("matte.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 2);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 2);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
constexpr float kExpectedLeft = 0.0f;
@@ -429,16 +412,14 @@
EXPECT_FLOAT_EQ(kExpectedTop, quad.y3);
EXPECT_FLOAT_EQ(kExpectedLeft, quad.x4);
EXPECT_FLOAT_EQ(kExpectedTop, quad.y4);
-
- UnloadPage(page);
}
TEST_F(FPDFEditPageEmbedderTest, GetBoundsForRotatedImage) {
ASSERT_TRUE(OpenDocument("rotated_image.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page.get(), 0);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
constexpr float kExpectedLeft = 100.0f;
@@ -466,8 +447,6 @@
EXPECT_FLOAT_EQ(110.0f, quad.y3);
EXPECT_FLOAT_EQ(140.0f, quad.x4);
EXPECT_FLOAT_EQ(kExpectedTop, quad.y4);
-
- UnloadPage(page);
}
TEST_F(FPDFEditPageEmbedderTest, VerifyDashArraySaved) {
diff --git a/fpdfsdk/fpdf_editpath_embeddertest.cpp b/fpdfsdk/fpdf_editpath_embeddertest.cpp
index e23d98c..b412a11 100644
--- a/fpdfsdk/fpdf_editpath_embeddertest.cpp
+++ b/fpdfsdk/fpdf_editpath_embeddertest.cpp
@@ -92,16 +92,16 @@
TEST_F(FPDFEditPathEmbedderTest, GetAndSetMatrixForPath) {
OpenDocument("rectangles_double_flipped.pdf");
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesChecksum());
}
- FPDF_PAGEOBJECT path = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT path = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(path);
ASSERT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path));
@@ -116,21 +116,20 @@
ASSERT_TRUE(FPDFPageObj_SetMatrix(path, &matrix));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesChecksum());
}
- ASSERT_TRUE(FPDFPage_GenerateContent(page));
+ ASSERT_TRUE(FPDFPage_GenerateContent(page.get()));
ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesChecksum());
}
- UnloadPage(page);
VerifySavedDocument(kExpectedRectangleWidth, kExpectedRectangleHeight,
RectanglesChecksum());
@@ -138,16 +137,16 @@
TEST_F(FPDFEditPathEmbedderTest, GetAndSetMatrixForFormWithPath) {
OpenDocument("form_object_with_path.pdf");
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesChecksum());
}
- FPDF_PAGEOBJECT form = FPDFPage_GetObject(page, 0);
+ FPDF_PAGEOBJECT form = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(form);
ASSERT_EQ(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(form));
@@ -162,7 +161,7 @@
ASSERT_TRUE(FPDFPageObj_SetMatrix(form, &matrix));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesChecksum());
}
@@ -181,21 +180,20 @@
ASSERT_TRUE(FPDFPageObj_SetMatrix(path, &matrix));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesChecksum());
}
- ASSERT_TRUE(FPDFPage_GenerateContent(page));
+ ASSERT_TRUE(FPDFPage_GenerateContent(page.get()));
ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesChecksum());
}
- UnloadPage(page);
VerifySavedDocument(kExpectedRectangleWidth, kExpectedRectangleHeight,
RectanglesChecksum());
@@ -203,35 +201,34 @@
TEST_F(FPDFEditPathEmbedderTest, AddPathToRectangles) {
OpenDocument("rectangles.pdf");
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesChecksum());
}
ScopedFPDFPageObject path = CreateBlackTriangle();
ASSERT_TRUE(path);
- FPDFPage_InsertObject(page, path.release());
+ FPDFPage_InsertObject(page.get(), path.release());
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesAndTriangleChecksum());
}
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesAndTriangleChecksum());
}
- UnloadPage(page);
VerifySavedDocument(kExpectedRectangleWidth, kExpectedRectangleHeight,
RectanglesAndTriangleChecksum());
@@ -239,35 +236,34 @@
TEST_F(FPDFEditPathEmbedderTest, AddPathToRectanglesWithLeakyCTM) {
OpenDocument("rectangles_with_leaky_ctm.pdf");
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesChecksum());
}
ScopedFPDFPageObject path = CreateBlackTriangle();
ASSERT_TRUE(path);
- FPDFPage_InsertObject(page, path.release());
+ FPDFPage_InsertObject(page.get(), path.release());
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesAndTriangleChecksum());
}
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), kExpectedRectangleWidth,
kExpectedRectangleHeight, RectanglesAndTriangleChecksum());
}
- UnloadPage(page);
VerifySavedDocument(kExpectedRectangleWidth, kExpectedRectangleHeight,
RectanglesAndTriangleChecksum());
diff --git a/fpdfsdk/fpdf_flatten_embeddertest.cpp b/fpdfsdk/fpdf_flatten_embeddertest.cpp
index f5562a7..c54c921 100644
--- a/fpdfsdk/fpdf_flatten_embeddertest.cpp
+++ b/fpdfsdk/fpdf_flatten_embeddertest.cpp
@@ -21,53 +21,49 @@
TEST_F(FPDFFlattenEmbedderTest, FlatNothing) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- EXPECT_EQ(FLATTEN_NOTHINGTODO, FPDFPage_Flatten(page, FLAT_NORMALDISPLAY));
- UnloadPage(page);
+ EXPECT_EQ(FLATTEN_NOTHINGTODO,
+ FPDFPage_Flatten(page.get(), FLAT_NORMALDISPLAY));
}
TEST_F(FPDFFlattenEmbedderTest, FlatNormal) {
ASSERT_TRUE(OpenDocument("annotiter.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_NORMALDISPLAY));
- UnloadPage(page);
+ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_NORMALDISPLAY));
}
TEST_F(FPDFFlattenEmbedderTest, FlatPrint) {
ASSERT_TRUE(OpenDocument("annotiter.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
- UnloadPage(page);
+ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_PRINT));
}
TEST_F(FPDFFlattenEmbedderTest, FlatWithBadFont) {
ASSERT_TRUE(OpenDocument("344775293.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- FORM_OnLButtonDown(form_handle(), page, 0, 20, 30);
- FORM_OnLButtonUp(form_handle(), page, 0, 20, 30);
+ FORM_OnLButtonDown(form_handle(), page.get(), 0, 20, 30);
+ FORM_OnLButtonUp(form_handle(), page.get(), 0, 20, 30);
- EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
+ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_PRINT));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
EXPECT_THAT(GetString(), Not(HasSubstr("/PDFDocEncoding")));
- UnloadPage(page);
}
TEST_F(FPDFFlattenEmbedderTest, FlatWithFontNoBaseEncoding) {
ASSERT_TRUE(OpenDocument("363015187.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
+ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_PRINT));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
EXPECT_THAT(GetString(), HasSubstr("/Differences"));
- UnloadPage(page);
}
TEST_F(FPDFFlattenEmbedderTest, Bug861842) {
@@ -87,16 +83,15 @@
}();
ASSERT_TRUE(OpenDocument("bug_861842.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 100, 120, checkbox_checksum);
- EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
+ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_PRINT));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
// TODO(crbug.com/861842): This should not render blank.
static constexpr char kBlankPageHash[] = "48400809c3862dae64b0cd00d51057a4";
@@ -138,17 +133,16 @@
}();
ASSERT_TRUE(OpenDocument("bug_889099.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// The original document has a malformed media box; the height is -400.
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 300, 400, page_checksum);
- EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
+ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_PRINT));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
VerifySavedDocument(300, 400, flattened_page_checksum);
}
@@ -161,16 +155,15 @@
return "6c674642154408e877d88c6c082d67e9";
}();
ASSERT_TRUE(OpenDocument("bug_890322.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 200, 200, checksum);
- EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
+ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_PRINT));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
VerifySavedDocument(200, 200, checksum);
}
@@ -183,16 +176,15 @@
return "f71ab085c52c8445ae785eca3ec858b1";
}();
ASSERT_TRUE(OpenDocument("bug_896366.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
+ ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, checksum);
- EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
+ EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page.get(), FLAT_PRINT));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
VerifySavedDocument(612, 792, checksum);
}
diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp
index 97e5cf6..ca23996 100644
--- a/fpdfsdk/fpdf_formfill_embeddertest.cpp
+++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp
@@ -605,9 +605,8 @@
SetDelegate(&mock);
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, Bug487928) {
@@ -615,11 +614,10 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_487928.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
DoOpenActions();
delegate.AdvanceTime(5000);
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, Bug507316) {
@@ -627,23 +625,20 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_507316.pdf"));
- FPDF_PAGE page = LoadPage(2);
+ ScopedEmbedderTestPage page = LoadScopedPage(2);
EXPECT_TRUE(page);
DoOpenActions();
delegate.AdvanceTime(4000);
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, Bug514690) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
// Test that FORM_OnMouseMove() etc. permit null HANDLES and PAGES.
- FORM_OnMouseMove(nullptr, page, 0, 10.0, 10.0);
+ FORM_OnMouseMove(nullptr, page.get(), 0, 10.0, 10.0);
FORM_OnMouseMove(form_handle(), nullptr, 0, 10.0, 10.0);
-
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, Bug900552) {
@@ -651,7 +646,7 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_900552.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
DoOpenActions();
delegate.AdvanceTime(4000);
@@ -659,9 +654,9 @@
// Simulate a repaint.
FPDF_BITMAP bitmap = FPDFBitmap_Create(512, 512, 0);
ASSERT_TRUE(bitmap);
- FPDF_RenderPageBitmap_Start(bitmap, page, 0, 0, 512, 512, 0, 0, nullptr);
+ FPDF_RenderPageBitmap_Start(bitmap, page.get(), 0, 0, 512, 512, 0, 0,
+ nullptr);
FPDFBitmap_Destroy(bitmap);
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, Bug901654Case1) {
@@ -669,7 +664,7 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_901654.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
DoOpenActions();
delegate.AdvanceTime(4000);
@@ -677,10 +672,9 @@
// Simulate a repaint.
{
ScopedFPDFBitmap bitmap(FPDFBitmap_Create(512, 512, 0));
- FPDF_RenderPageBitmap_Start(bitmap.get(), page, 0, 0, 512, 512, 0, 0,
+ FPDF_RenderPageBitmap_Start(bitmap.get(), page.get(), 0, 0, 512, 512, 0, 0,
nullptr);
}
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, Bug901654Case2) {
@@ -688,7 +682,7 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_901654_2.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
DoOpenActions();
delegate.AdvanceTime(4000);
@@ -696,17 +690,16 @@
// Simulate a repaint.
{
ScopedFPDFBitmap bitmap(FPDFBitmap_Create(512, 512, 0));
- FPDF_RenderPageBitmap_Start(bitmap.get(), page, 0, 0, 512, 512, 0, 0,
+ FPDF_RenderPageBitmap_Start(bitmap.get(), page.get(), 0, 0, 512, 512, 0, 0,
nullptr);
}
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, GetFocusedAnnotation) {
ASSERT_TRUE(OpenDocument("annotiter.pdf"));
- std::vector<FPDF_PAGE> pages;
+ std::vector<ScopedEmbedderTestPage> pages;
for (size_t i = 0; i < 3; ++i) {
- pages.push_back(LoadPage(i));
+ pages.push_back(LoadScopedPage(i));
ASSERT_TRUE(pages.back());
}
@@ -727,31 +720,29 @@
for (size_t i = 0; i < pages.size(); ++i) {
// Invoke click on the form field to bring it to focus.
- FORM_OnMouseMove(form_handle(), pages[i], 0, right_bottom_annot_point.x,
- right_bottom_annot_point.y);
- FORM_OnLButtonDown(form_handle(), pages[i], 0, right_bottom_annot_point.x,
- right_bottom_annot_point.y);
- FORM_OnLButtonUp(form_handle(), pages[i], 0, right_bottom_annot_point.x,
- right_bottom_annot_point.y);
+ FORM_OnMouseMove(form_handle(), pages[i].get(), 0,
+ right_bottom_annot_point.x, right_bottom_annot_point.y);
+ FORM_OnLButtonDown(form_handle(), pages[i].get(), 0,
+ right_bottom_annot_point.x, right_bottom_annot_point.y);
+ FORM_OnLButtonUp(form_handle(), pages[i].get(), 0,
+ right_bottom_annot_point.x, right_bottom_annot_point.y);
ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
ASSERT_TRUE(annot);
- EXPECT_EQ(kExpectedAnnotIndex, FPDFPage_GetAnnotIndex(pages[i], annot));
+ EXPECT_EQ(kExpectedAnnotIndex,
+ FPDFPage_GetAnnotIndex(pages[i].get(), annot));
EXPECT_EQ(static_cast<int>(i), page_index);
FPDFPage_CloseAnnot(annot);
}
-
- for (FPDF_PAGE page : pages)
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, SetFocusedAnnotation) {
ASSERT_TRUE(OpenDocument("annotiter.pdf"));
- std::vector<FPDF_PAGE> pages;
+ std::vector<ScopedEmbedderTestPage> pages;
for (size_t i = 0; i < 3; ++i) {
- pages.push_back(LoadPage(i));
+ pages.push_back(LoadScopedPage(i));
ASSERT_TRUE(pages.back());
}
@@ -771,132 +762,120 @@
for (size_t i = 0; i < pages.size(); ++i) {
// Setting focus on an annotation on page i.
ScopedFPDFAnnotation focused_annot(
- FPDFPage_GetAnnot(pages[i], kExpectedAnnotIndex));
+ FPDFPage_GetAnnot(pages[i].get(), kExpectedAnnotIndex));
ASSERT_TRUE(focused_annot);
ASSERT_TRUE(FORM_SetFocusedAnnot(form_handle(), focused_annot.get()));
ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
- EXPECT_EQ(kExpectedAnnotIndex, FPDFPage_GetAnnotIndex(pages[i], annot));
+ EXPECT_EQ(kExpectedAnnotIndex,
+ FPDFPage_GetAnnotIndex(pages[i].get(), annot));
EXPECT_EQ(static_cast<int>(i), page_index);
FPDFPage_CloseAnnot(annot);
}
-
- for (FPDF_PAGE page : pages)
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, FormFillFirstTab) {
ASSERT_TRUE(OpenDocument("annotiter.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Invoking first tab on the page.
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab, 0));
int page_index = -2;
FPDF_ANNOTATION annot = nullptr;
EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
EXPECT_EQ(0, page_index);
ASSERT_TRUE(annot);
- EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, annot));
+ EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page.get(), annot));
FPDFPage_CloseAnnot(annot);
-
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, FormFillFirstShiftTab) {
ASSERT_TRUE(OpenDocument("annotiter.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Invoking first shift-tab on the page.
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
FWL_EVENTFLAG_ShiftKey));
int page_index = -2;
FPDF_ANNOTATION annot = nullptr;
EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
EXPECT_EQ(0, page_index);
ASSERT_TRUE(annot);
- EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot));
+ EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page.get(), annot));
FPDFPage_CloseAnnot(annot);
-
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, FormFillContinuousTab) {
ASSERT_TRUE(OpenDocument("annotiter.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Tabs should iterate focus over annotations.
for (int expected : {1, 2, 3, 0}) {
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab, 0));
int page_index = -2;
FPDF_ANNOTATION annot = nullptr;
EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
EXPECT_EQ(0, page_index);
ASSERT_TRUE(annot);
- EXPECT_EQ(expected, FPDFPage_GetAnnotIndex(page, annot));
+ EXPECT_EQ(expected, FPDFPage_GetAnnotIndex(page.get(), annot));
FPDFPage_CloseAnnot(annot);
}
// Tab should not be handled as the last annotation of the page is in focus.
- ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
-
- UnloadPage(page);
+ ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab, 0));
}
TEST_F(FPDFFormFillEmbedderTest, FormFillContinuousShiftTab) {
ASSERT_TRUE(OpenDocument("annotiter.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Shift-tabs should iterate focus over annotations.
for (int expected : {0, 3, 2, 1}) {
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
FWL_EVENTFLAG_ShiftKey));
int page_index = -2;
FPDF_ANNOTATION annot = nullptr;
EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
EXPECT_EQ(0, page_index);
ASSERT_TRUE(annot);
- EXPECT_EQ(expected, FPDFPage_GetAnnotIndex(page, annot));
+ EXPECT_EQ(expected, FPDFPage_GetAnnotIndex(page.get(), annot));
FPDFPage_CloseAnnot(annot);
}
// Shift-tab should not be handled as the first annotation of the page is in
// focus.
- ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
+ ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
FWL_EVENTFLAG_ShiftKey));
-
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, TabWithModifiers) {
ASSERT_TRUE(OpenDocument("annotiter.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
+ ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
FWL_EVENTFLAG_ControlKey));
- ASSERT_FALSE(
- FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, FWL_EVENTFLAG_AltKey));
+ ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
+ FWL_EVENTFLAG_AltKey));
ASSERT_FALSE(
- FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
+ FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
(FWL_EVENTFLAG_ControlKey | FWL_EVENTFLAG_ShiftKey)));
- ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
+ ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
(FWL_EVENTFLAG_AltKey | FWL_EVENTFLAG_ShiftKey)));
-
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, KeyPressWithNoFocusedAnnot) {
ASSERT_TRUE(OpenDocument("annotiter.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// There should be no focused annotation to start with.
@@ -913,80 +892,70 @@
};
for (int key : kKeysToPress) {
// Pressing random keys when there is no focus should not trigger focus.
- EXPECT_FALSE(FORM_OnKeyDown(form_handle(), page, key, 0));
+ EXPECT_FALSE(FORM_OnKeyDown(form_handle(), page.get(), key, 0));
page_index = -2;
annot = nullptr;
EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
EXPECT_EQ(-1, page_index);
EXPECT_FALSE(annot);
}
-
- UnloadPage(page);
}
#ifdef PDF_ENABLE_XFA
TEST_F(FPDFFormFillEmbedderTest, XFAFormFillFirstTab) {
ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Invoking first tab on the page.
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
-
- UnloadPage(page);
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab, 0));
}
TEST_F(FPDFFormFillEmbedderTest, XFAFormFillFirstShiftTab) {
ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Invoking first shift-tab on the page.
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
FWL_EVENTFLAG_ShiftKey));
-
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, XFAFormFillContinuousTab) {
ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Invoking first tab on the page.
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab, 0));
// Subsequent tabs should move focus over annotations.
for (size_t i = 0; i < 9; ++i)
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab, 0));
// Tab should not be handled as the last annotation of the page is in focus.
- ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
-
- UnloadPage(page);
+ ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab, 0));
}
TEST_F(FPDFFormFillEmbedderTest, XFAFormFillContinuousShiftTab) {
ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Invoking first shift-tab on the page.
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
FWL_EVENTFLAG_ShiftKey));
// Subsequent shift-tabs should move focus over annotations.
for (size_t i = 0; i < 9; ++i) {
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
FWL_EVENTFLAG_ShiftKey));
}
// Shift-tab should not be handled as the first annotation of the page is in
// focus.
- ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
+ ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
FWL_EVENTFLAG_ShiftKey));
-
- UnloadPage(page);
}
#endif // PDF_ENABLE_XFA
@@ -1002,11 +971,9 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("redirect.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
DoOpenActions();
-
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, CheckReadOnlyInCheckbox) {
@@ -1014,34 +981,35 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Check for read-only checkbox.
- ScopedFPDFAnnotation focused_annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation focused_annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(FORM_SetFocusedAnnot(form_handle(), focused_annot.get()));
// Shift-tab to the previous control.
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab,
FWL_EVENTFLAG_ShiftKey));
FPDF_ANNOTATION annot = nullptr;
int page_index = -1;
ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
- EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot));
+ EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page.get(), annot));
// The read-only checkbox is initially in checked state.
EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
- EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kReturn, 0));
+ EXPECT_TRUE(
+ FORM_OnChar(form_handle(), page.get(), pdfium::ascii::kReturn, 0));
EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
- EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kSpace, 0));
+ EXPECT_TRUE(
+ FORM_OnChar(form_handle(), page.get(), pdfium::ascii::kSpace, 0));
EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
FPDFPage_CloseAnnot(annot);
}
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, CheckReadOnlyInRadiobutton) {
@@ -1049,33 +1017,34 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("click_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Check for read-only radio button.
- ScopedFPDFAnnotation focused_annot(FPDFPage_GetAnnot(page, 1));
+ ScopedFPDFAnnotation focused_annot(FPDFPage_GetAnnot(page.get(), 1));
ASSERT_TRUE(FORM_SetFocusedAnnot(form_handle(), focused_annot.get()));
// Tab to the next control.
- ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
+ ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Tab, 0));
FPDF_ANNOTATION annot = nullptr;
int page_index = -1;
ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
- EXPECT_EQ(2, FPDFPage_GetAnnotIndex(page, annot));
+ EXPECT_EQ(2, FPDFPage_GetAnnotIndex(page.get(), annot));
// The read-only radio button is initially in checked state.
EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
- EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kReturn, 0));
+ EXPECT_TRUE(
+ FORM_OnChar(form_handle(), page.get(), pdfium::ascii::kReturn, 0));
EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
- EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kSpace, 0));
+ EXPECT_TRUE(
+ FORM_OnChar(form_handle(), page.get(), pdfium::ascii::kSpace, 0));
EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
FPDFPage_CloseAnnot(annot);
}
- UnloadPage(page);
}
#ifdef PDF_ENABLE_V8
@@ -1085,7 +1054,7 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocumentWithoutJavaScript("bug_551248.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
DoOpenActions();
@@ -1106,7 +1075,6 @@
EXPECT_EQ(0U, alerts.size()); // nothing fired.
delegate.AdvanceTime(1000);
EXPECT_EQ(0U, alerts.size()); // nothing fired.
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, DocumentAActions) {
@@ -1114,7 +1082,7 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("document_aactions.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
const auto& alerts = delegate.GetAlerts();
@@ -1124,7 +1092,6 @@
FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DS);
FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_WP);
FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DP);
- UnloadPage(page);
ASSERT_EQ(4U, alerts.size());
EXPECT_EQ(L"Will Save", alerts[0].message);
@@ -1138,7 +1105,7 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocumentWithoutJavaScript("document_aactions.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
const auto& alerts = delegate.GetAlerts();
@@ -1148,7 +1115,6 @@
FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DS);
FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_WP);
FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DP);
- UnloadPage(page);
ASSERT_EQ(0U, alerts.size());
}
@@ -1159,7 +1125,7 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_551248.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
DoOpenActions();
@@ -1180,7 +1146,6 @@
EXPECT_EQ(4U, alerts.size()); // interval fired again.
delegate.AdvanceTime(1000);
EXPECT_EQ(4U, alerts.size()); // nothing fired.
- UnloadPage(page);
ASSERT_EQ(4U, alerts.size()); // nothing else fired.
@@ -1211,11 +1176,10 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_620428.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
DoOpenActions();
delegate.AdvanceTime(5000);
- UnloadPage(page);
const auto& alerts = delegate.GetAlerts();
ASSERT_EQ(1U, alerts.size());
@@ -1228,7 +1192,7 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_634394.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
DoOpenActions();
@@ -1239,7 +1203,6 @@
delegate.AdvanceTime(1000);
delegate.AdvanceTime(1000);
delegate.AdvanceTime(1000);
- UnloadPage(page);
const auto& alerts = delegate.GetAlerts();
EXPECT_EQ(2U, alerts.size());
@@ -1250,7 +1213,7 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_634716.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
DoOpenActions();
@@ -1261,7 +1224,6 @@
delegate.AdvanceTime(1000);
delegate.AdvanceTime(1000);
delegate.AdvanceTime(1000);
- UnloadPage(page);
const auto& alerts = delegate.GetAlerts();
EXPECT_EQ(2U, alerts.size());
@@ -1272,13 +1234,12 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_679649.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
delegate.SetFailNextTimer();
DoOpenActions();
delegate.AdvanceTime(2000);
- UnloadPage(page);
const auto& alerts = delegate.GetAlerts();
EXPECT_EQ(0u, alerts.size());
@@ -1289,14 +1250,13 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_707673.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
DoOpenActions();
- FORM_OnLButtonDown(form_handle(), page, 0, 140, 590);
- FORM_OnLButtonUp(form_handle(), page, 0, 140, 590);
+ FORM_OnLButtonDown(form_handle(), page.get(), 0, 140, 590);
+ FORM_OnLButtonUp(form_handle(), page.get(), 0, 140, 590);
delegate.AdvanceTime(1000);
- UnloadPage(page);
const auto& alerts = delegate.GetAlerts();
EXPECT_EQ(0u, alerts.size());
@@ -1304,13 +1264,12 @@
TEST_F(FPDFFormFillEmbedderTest, Bug765384) {
ASSERT_TRUE(OpenDocument("bug_765384.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
DoOpenActions();
- FORM_OnLButtonDown(form_handle(), page, 0, 140, 590);
- FORM_OnLButtonUp(form_handle(), page, 0, 140, 590);
- UnloadPage(page);
+ FORM_OnLButtonDown(form_handle(), page.get(), 0, 140, 590);
+ FORM_OnLButtonUp(form_handle(), page.get(), 0, 140, 590);
}
// Test passes if DCHECK() not hit.
@@ -1319,13 +1278,12 @@
SetDelegate(&delegate);
ASSERT_TRUE(OpenDocument("bug_1477093.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
DoOpenActions();
delegate.AdvanceTime(1000);
delegate.AdvanceTime(1000);
- UnloadPage(page);
}
#endif // PDF_ENABLE_V8
@@ -1365,46 +1323,44 @@
}();
{
ASSERT_TRUE(OpenDocument("text_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap1 = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap1 = RenderLoadedPage(page.get());
CompareBitmap(bitmap1.get(), 300, 300, TextFormChecksum());
// Click on the textfield
- EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
- FPDFPage_HasFormFieldAtPoint(form_handle(), page, 120.0, 120.0));
EXPECT_EQ(
- 0, FPDFPage_FormFieldZOrderAtPoint(form_handle(), page, 120.0, 120.0));
- FORM_OnMouseMove(form_handle(), page, 0, 120.0, 120.0);
- FORM_OnLButtonDown(form_handle(), page, 0, 120.0, 120.0);
- FORM_OnLButtonUp(form_handle(), page, 0, 120.0, 120.0);
+ FPDF_FORMFIELD_TEXTFIELD,
+ FPDFPage_HasFormFieldAtPoint(form_handle(), page.get(), 120.0, 120.0));
+ EXPECT_EQ(0, FPDFPage_FormFieldZOrderAtPoint(form_handle(), page.get(),
+ 120.0, 120.0));
+ FORM_OnMouseMove(form_handle(), page.get(), 0, 120.0, 120.0);
+ FORM_OnLButtonDown(form_handle(), page.get(), 0, 120.0, 120.0);
+ FORM_OnLButtonUp(form_handle(), page.get(), 0, 120.0, 120.0);
// Write "ABC"
- FORM_OnChar(form_handle(), page, 'A', 0);
- FORM_OnChar(form_handle(), page, 'B', 0);
- FORM_OnChar(form_handle(), page, 'C', 0);
- ScopedFPDFBitmap bitmap2 = RenderLoadedPage(page);
+ FORM_OnChar(form_handle(), page.get(), 'A', 0);
+ FORM_OnChar(form_handle(), page.get(), 'B', 0);
+ FORM_OnChar(form_handle(), page.get(), 'C', 0);
+ ScopedFPDFBitmap bitmap2 = RenderLoadedPage(page.get());
CompareBitmap(bitmap2.get(), 300, 300, focused_text_form_with_abc_checksum);
// Focus remains despite right clicking out of the textfield
- FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
- FORM_OnRButtonDown(form_handle(), page, 0, 15.0, 15.0);
- FORM_OnRButtonUp(form_handle(), page, 0, 15.0, 15.0);
- ScopedFPDFBitmap bitmap3 = RenderLoadedPage(page);
+ FORM_OnMouseMove(form_handle(), page.get(), 0, 15.0, 15.0);
+ FORM_OnRButtonDown(form_handle(), page.get(), 0, 15.0, 15.0);
+ FORM_OnRButtonUp(form_handle(), page.get(), 0, 15.0, 15.0);
+ ScopedFPDFBitmap bitmap3 = RenderLoadedPage(page.get());
CompareBitmap(bitmap3.get(), 300, 300, focused_text_form_with_abc_checksum);
// Take out focus by clicking out of the textfield
- FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
- FORM_OnLButtonDown(form_handle(), page, 0, 15.0, 15.0);
- FORM_OnLButtonUp(form_handle(), page, 0, 15.0, 15.0);
- ScopedFPDFBitmap bitmap4 = RenderLoadedPage(page);
+ FORM_OnMouseMove(form_handle(), page.get(), 0, 15.0, 15.0);
+ FORM_OnLButtonDown(form_handle(), page.get(), 0, 15.0, 15.0);
+ FORM_OnLButtonUp(form_handle(), page.get(), 0, 15.0, 15.0);
+ ScopedFPDFBitmap bitmap4 = RenderLoadedPage(page.get());
CompareBitmap(bitmap4.get(), 300, 300,
unfocused_text_form_with_abc_checksum);
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
-
- // Close page
- UnloadPage(page);
}
// Check saved document
VerifySavedDocument(300, 300, unfocused_text_form_with_abc_checksum);
@@ -1421,18 +1377,16 @@
}();
ASSERT_TRUE(OpenDocument("bug_890322.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap_normal = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap_normal = RenderLoadedPage(page.get());
CompareBitmap(bitmap_normal.get(), 200, 200, pdfium::Bug890322Checksum());
ScopedFPDFBitmap bitmap_reverse_byte_order =
- RenderLoadedPageWithFlags(page, FPDF_REVERSE_BYTE_ORDER);
+ RenderLoadedPageWithFlags(page.get(), FPDF_REVERSE_BYTE_ORDER);
CompareBitmap(bitmap_reverse_byte_order.get(), 200, 200,
reverse_byte_order_checksum);
-
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, Bug1302455RenderOnly) {
@@ -1444,15 +1398,14 @@
}();
{
ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 300, 300, checksum);
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
}
VerifySavedDocument(300, 300, checksum);
}
@@ -1476,23 +1429,23 @@
}();
{
ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
- FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 110));
- FORM_OnMouseMove(form_handle(), page, 0, 110, 110);
- FORM_OnLButtonDown(form_handle(), page, 0, 110, 110);
- FORM_OnLButtonUp(form_handle(), page, 0, 110, 110);
- FORM_OnChar(form_handle(), page, 'A', 0);
+ EXPECT_EQ(
+ FPDF_FORMFIELD_TEXTFIELD,
+ FPDFPage_HasFormFieldAtPoint(form_handle(), page.get(), 110, 110));
+ FORM_OnMouseMove(form_handle(), page.get(), 0, 110, 110);
+ FORM_OnLButtonDown(form_handle(), page.get(), 0, 110, 110);
+ FORM_OnLButtonUp(form_handle(), page.get(), 0, 110, 110);
+ FORM_OnChar(form_handle(), page.get(), 'A', 0);
FORM_ForceToKillFocus(form_handle());
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 300, 300, checksum);
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
}
VerifySavedDocument(300, 300, checksum);
}
@@ -1516,23 +1469,23 @@
}();
{
ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
- FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 170));
- FORM_OnMouseMove(form_handle(), page, 0, 110, 170);
- FORM_OnLButtonDown(form_handle(), page, 0, 110, 170);
- FORM_OnLButtonUp(form_handle(), page, 0, 110, 170);
- FORM_OnChar(form_handle(), page, 'B', 0);
+ EXPECT_EQ(
+ FPDF_FORMFIELD_TEXTFIELD,
+ FPDFPage_HasFormFieldAtPoint(form_handle(), page.get(), 110, 170));
+ FORM_OnMouseMove(form_handle(), page.get(), 0, 110, 170);
+ FORM_OnLButtonDown(form_handle(), page.get(), 0, 110, 170);
+ FORM_OnLButtonUp(form_handle(), page.get(), 0, 110, 170);
+ FORM_OnChar(form_handle(), page.get(), 'B', 0);
FORM_ForceToKillFocus(form_handle());
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 300, 300, checksum);
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
}
VerifySavedDocument(300, 300, checksum);
}
@@ -1556,30 +1509,31 @@
}();
{
ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
- FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 110));
- FORM_OnMouseMove(form_handle(), page, 0, 110, 110);
- FORM_OnLButtonDown(form_handle(), page, 0, 110, 110);
- FORM_OnLButtonUp(form_handle(), page, 0, 110, 110);
- FORM_OnChar(form_handle(), page, 'A', 0);
+ EXPECT_EQ(
+ FPDF_FORMFIELD_TEXTFIELD,
+ FPDFPage_HasFormFieldAtPoint(form_handle(), page.get(), 110, 110));
+ FORM_OnMouseMove(form_handle(), page.get(), 0, 110, 110);
+ FORM_OnLButtonDown(form_handle(), page.get(), 0, 110, 110);
+ FORM_OnLButtonUp(form_handle(), page.get(), 0, 110, 110);
+ FORM_OnChar(form_handle(), page.get(), 'A', 0);
- EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
- FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 170));
- FORM_OnMouseMove(form_handle(), page, 0, 110, 170);
- FORM_OnLButtonDown(form_handle(), page, 0, 110, 170);
- FORM_OnLButtonUp(form_handle(), page, 0, 110, 170);
- FORM_OnChar(form_handle(), page, 'B', 0);
+ EXPECT_EQ(
+ FPDF_FORMFIELD_TEXTFIELD,
+ FPDFPage_HasFormFieldAtPoint(form_handle(), page.get(), 110, 170));
+ FORM_OnMouseMove(form_handle(), page.get(), 0, 110, 170);
+ FORM_OnLButtonDown(form_handle(), page.get(), 0, 110, 170);
+ FORM_OnLButtonUp(form_handle(), page.get(), 0, 110, 170);
+ FORM_OnChar(form_handle(), page.get(), 'B', 0);
FORM_ForceToKillFocus(form_handle());
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 300, 300, checksum);
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- UnloadPage(page);
}
VerifySavedDocument(300, 300, checksum);
}
@@ -1603,22 +1557,20 @@
}();
ASSERT_TRUE(OpenDocument("text_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap1 = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap1 = RenderLoadedPage(page.get());
CompareBitmap(bitmap1.get(), 300, 300, TextFormChecksum());
// Removing the highlight changes the rendering.
FPDF_RemoveFormFieldHighlight(form_handle());
- ScopedFPDFBitmap bitmap2 = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap2 = RenderLoadedPage(page.get());
CompareBitmap(bitmap2.get(), 300, 300, no_highlight_checksum);
// Restoring it gives the original rendering.
SetInitialFormFieldHighlight(form_handle());
- ScopedFPDFBitmap bitmap3 = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap3 = RenderLoadedPage(page.get());
CompareBitmap(bitmap3.get(), 300, 300, TextFormChecksum());
-
- UnloadPage(page);
}
TEST_F(FPDFFormFillEmbedderTest, HasFormInfoNone) {
@@ -1643,53 +1595,48 @@
TEST_F(FPDFFormFillEmbedderTest, BadApiInputsText) {
ASSERT_TRUE(OpenDocument("text_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
EXPECT_FALSE(FORM_SetIndexSelected(nullptr, nullptr, 0, true));
- EXPECT_FALSE(FORM_SetIndexSelected(nullptr, page, 0, true));
+ EXPECT_FALSE(FORM_SetIndexSelected(nullptr, page.get(), 0, true));
EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), nullptr, 0, true));
- EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, -1, true));
+ EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page.get(), -1, true));
EXPECT_FALSE(FORM_IsIndexSelected(nullptr, nullptr, 0));
- EXPECT_FALSE(FORM_IsIndexSelected(nullptr, page, 0));
+ EXPECT_FALSE(FORM_IsIndexSelected(nullptr, page.get(), 0));
EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), nullptr, 0));
- EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, -1));
-
- UnloadPage(page);
+ EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page.get(), -1));
}
TEST_F(FPDFFormFillEmbedderTest, BadApiInputsComboBox) {
ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, -1, true));
- EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, 100, true));
- EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, -1));
- EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, 100));
-
- UnloadPage(page);
+ EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page.get(), -1, true));
+ EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page.get(), 100, true));
+ EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page.get(), -1));
+ EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page.get(), 100));
}
TEST_F(FPDFFormFillEmbedderTest, BadApiInputsListBox) {
ASSERT_TRUE(OpenDocument("listbox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, -1, true));
- EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, 100, true));
- EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, -1));
- EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, 100));
-
- UnloadPage(page);
+ EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page.get(), -1, true));
+ EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page.get(), 100, true));
+ EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page.get(), -1));
+ EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page.get(), 100));
}
TEST_F(FPDFFormFillEmbedderTest, HasFormFieldAtPointForXFADoc) {
ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(-1, FPDFPage_HasFormFieldAtPoint(form_handle(), page, 612, 792));
+ EXPECT_EQ(-1,
+ FPDFPage_HasFormFieldAtPoint(form_handle(), page.get(), 612, 792));
#ifdef PDF_ENABLE_XFA
constexpr int kExpectedFieldType = FPDF_FORMFIELD_XFA_TEXTFIELD;
@@ -1697,47 +1644,43 @@
constexpr int kExpectedFieldType = -1;
#endif
EXPECT_EQ(kExpectedFieldType,
- FPDFPage_HasFormFieldAtPoint(form_handle(), page, 50, 30));
-
- UnloadPage(page);
+ FPDFPage_HasFormFieldAtPoint(form_handle(), page.get(), 50, 30));
}
TEST_F(FPDFFormFillEmbedderTest, SelectAllText) {
ASSERT_TRUE(OpenDocument("text_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Test bad arguments.
EXPECT_FALSE(FORM_SelectAllText(nullptr, nullptr));
EXPECT_FALSE(FORM_SelectAllText(form_handle(), nullptr));
- EXPECT_FALSE(FORM_SelectAllText(nullptr, page));
+ EXPECT_FALSE(FORM_SelectAllText(nullptr, page.get()));
// Focus on the text field and add some text.
- EXPECT_TRUE(FORM_OnFocus(form_handle(), page, 0, 115, 115));
+ EXPECT_TRUE(FORM_OnFocus(form_handle(), page.get(), 0, 115, 115));
ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
- FORM_ReplaceSelection(form_handle(), page, text_to_insert.get());
+ FORM_ReplaceSelection(form_handle(), page.get(), text_to_insert.get());
// Sanity check text field data.
uint16_t buffer[6];
- ASSERT_EQ(12u, FORM_GetFocusedText(form_handle(), page, nullptr, 0));
- ASSERT_EQ(12u,
- FORM_GetFocusedText(form_handle(), page, buffer, sizeof(buffer)));
+ ASSERT_EQ(12u, FORM_GetFocusedText(form_handle(), page.get(), nullptr, 0));
+ ASSERT_EQ(12u, FORM_GetFocusedText(form_handle(), page.get(), buffer,
+ sizeof(buffer)));
EXPECT_EQ("Hello", GetPlatformString(buffer));
// Check there is no selection.
- ASSERT_EQ(2u, FORM_GetSelectedText(form_handle(), page, nullptr, 0));
- ASSERT_EQ(2u,
- FORM_GetSelectedText(form_handle(), page, buffer, sizeof(buffer)));
+ ASSERT_EQ(2u, FORM_GetSelectedText(form_handle(), page.get(), nullptr, 0));
+ ASSERT_EQ(2u, FORM_GetSelectedText(form_handle(), page.get(), buffer,
+ sizeof(buffer)));
EXPECT_EQ("", GetPlatformString(buffer));
// Check FORM_SelectAllText() works.
- EXPECT_TRUE(FORM_SelectAllText(form_handle(), page));
- ASSERT_EQ(12u, FORM_GetSelectedText(form_handle(), page, nullptr, 0));
- ASSERT_EQ(12u,
- FORM_GetSelectedText(form_handle(), page, buffer, sizeof(buffer)));
+ EXPECT_TRUE(FORM_SelectAllText(form_handle(), page.get()));
+ ASSERT_EQ(12u, FORM_GetSelectedText(form_handle(), page.get(), nullptr, 0));
+ ASSERT_EQ(12u, FORM_GetSelectedText(form_handle(), page.get(), buffer,
+ sizeof(buffer)));
EXPECT_EQ("Hello", GetPlatformString(buffer));
-
- UnloadPage(page);
}
TEST_F(FPDFFormFillTextFormEmbedderTest, GetSelectedTextEmptyAndBasicKeyboard) {
diff --git a/fpdfsdk/fpdf_ppo_embeddertest.cpp b/fpdfsdk/fpdf_ppo_embeddertest.cpp
index 6a77d5a..0ab907b 100644
--- a/fpdfsdk/fpdf_ppo_embeddertest.cpp
+++ b/fpdfsdk/fpdf_ppo_embeddertest.cpp
@@ -91,7 +91,7 @@
TEST_F(FPDFPPOEmbedderTest, ImportPagesByIndex) {
ASSERT_TRUE(OpenDocument("viewer_ref.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
ScopedFPDFDocument output_doc(FPDF_CreateNewDocument());
@@ -102,14 +102,12 @@
EXPECT_TRUE(FPDF_ImportPagesByIndex(
output_doc.get(), document(), kPageIndices, std::size(kPageIndices), 0));
EXPECT_EQ(1, FPDF_GetPageCount(output_doc.get()));
-
- UnloadPage(page);
}
TEST_F(FPDFPPOEmbedderTest, ImportPages) {
ASSERT_TRUE(OpenDocument("viewer_ref.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
ScopedFPDFDocument output_doc(FPDF_CreateNewDocument());
@@ -117,8 +115,6 @@
EXPECT_TRUE(FPDF_CopyViewerPreferences(output_doc.get(), document()));
EXPECT_TRUE(FPDF_ImportPages(output_doc.get(), document(), "1", 0));
EXPECT_EQ(1, FPDF_GetPageCount(output_doc.get()));
-
- UnloadPage(page);
}
TEST_F(FPDFPPOEmbedderTest, ImportNPages) {
@@ -294,11 +290,11 @@
FPDF_XOBJECT xobject = FPDF_NewXObjectFromPage(document(), document(), 0);
ASSERT_TRUE(xobject);
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 200, 300, pdfium::RectanglesChecksum());
}
@@ -309,11 +305,11 @@
static constexpr FS_MATRIX kMatrix = {0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f};
EXPECT_TRUE(FPDFPageObj_SetMatrix(page_object, &kMatrix));
- FPDFPage_InsertObject(page, page_object);
- EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ FPDFPage_InsertObject(page.get(), page_object);
+ EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
{
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 200, 300, checksum);
}
@@ -321,8 +317,6 @@
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
VerifySavedDocument(200, 300, checksum);
-
- UnloadPage(page);
}
TEST_F(FPDFPPOEmbedderTest, XObjectNullParams) {
@@ -370,10 +364,9 @@
// Show all pages render the same.
ASSERT_EQ(kPageCount, FPDF_GetPageCount(document()));
for (int i = 0; i < kPageCount; ++i) {
- FPDF_PAGE page = LoadPage(0);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 792, 612, kRectsChecksum);
- UnloadPage(page);
}
// Create a 2-up PDF.
@@ -458,7 +451,7 @@
TEST_F(FPDFPPOEmbedderTest, BadIndices) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
ScopedFPDFDocument output_doc(FPDF_CreateNewDocument());
@@ -479,14 +472,12 @@
static constexpr int kBadIndices4[] = {42};
EXPECT_FALSE(FPDF_ImportPagesByIndex(
output_doc.get(), document(), kBadIndices4, std::size(kBadIndices4), 0));
-
- UnloadPage(page);
}
TEST_F(FPDFPPOEmbedderTest, GoodIndices) {
ASSERT_TRUE(OpenDocument("viewer_ref.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
ScopedFPDFDocument output_doc(FPDF_CreateNewDocument());
@@ -520,14 +511,12 @@
EXPECT_TRUE(
FPDF_ImportPagesByIndex(output_doc.get(), document(), nullptr, 0, 0));
EXPECT_EQ(14, FPDF_GetPageCount(output_doc.get()));
-
- UnloadPage(page);
}
TEST_F(FPDFPPOEmbedderTest, BadRanges) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
ScopedFPDFDocument output_doc(FPDF_CreateNewDocument());
@@ -542,14 +531,12 @@
EXPECT_FALSE(FPDF_ImportPages(output_doc.get(), document(), "1-", 0));
EXPECT_FALSE(FPDF_ImportPages(output_doc.get(), document(), "-1", 0));
EXPECT_FALSE(FPDF_ImportPages(output_doc.get(), document(), "-,0,,,1-", 0));
-
- UnloadPage(page);
}
TEST_F(FPDFPPOEmbedderTest, GoodRanges) {
ASSERT_TRUE(OpenDocument("viewer_ref.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
ScopedFPDFDocument output_doc(FPDF_CreateNewDocument());
@@ -563,15 +550,13 @@
EXPECT_EQ(6, FPDF_GetPageCount(output_doc.get()));
EXPECT_TRUE(FPDF_ImportPages(output_doc.get(), document(), "2-4", 0));
EXPECT_EQ(9, FPDF_GetPageCount(output_doc.get()));
-
- UnloadPage(page);
}
TEST_F(FPDFPPOEmbedderTest, Bug664284) {
ASSERT_TRUE(OpenDocument("bug_664284.pdf"));
- FPDF_PAGE page = LoadPage(0);
- ASSERT_NE(nullptr, page);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
+ ASSERT_NE(nullptr, page.get());
ScopedFPDFDocument output_doc(FPDF_CreateNewDocument());
EXPECT_TRUE(output_doc);
@@ -579,8 +564,6 @@
static constexpr int kIndices[] = {0};
EXPECT_TRUE(FPDF_ImportPagesByIndex(output_doc.get(), document(), kIndices,
std::size(kIndices), 0));
-
- UnloadPage(page);
}
TEST_F(FPDFPPOEmbedderTest, Bug750568) {
@@ -588,12 +571,11 @@
ASSERT_EQ(4, FPDF_GetPageCount(document()));
for (size_t i = 0; i < 4; ++i) {
- FPDF_PAGE page = LoadPage(i);
+ ScopedEmbedderTestPage page = LoadScopedPage(i);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 200, 200, Bug750568PageHash(i));
- UnloadPage(page);
}
ScopedFPDFDocument output_doc(FPDF_CreateNewDocument());
@@ -614,12 +596,11 @@
TEST_F(FPDFPPOEmbedderTest, ImportWithZeroLengthStream) {
ASSERT_TRUE(OpenDocument("zero_length_stream.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), 200, 200, pdfium::HelloWorldChecksum());
- UnloadPage(page);
ScopedFPDFDocument new_doc(FPDF_CreateNewDocument());
ASSERT_TRUE(new_doc);
@@ -686,18 +667,16 @@
}();
const char new_page_2_checksum[] = "39336760026e7f3d26135e3b765125c3";
{
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderPage(page);
+ ScopedFPDFBitmap bitmap = RenderPage(page.get());
CompareBitmap(bitmap.get(), 200, 300, new_page_1_checksum);
- UnloadPage(page);
}
{
- FPDF_PAGE page = LoadPage(1);
+ ScopedEmbedderTestPage page = LoadScopedPage(1);
ASSERT_TRUE(page);
- ScopedFPDFBitmap bitmap = RenderPage(page);
+ ScopedFPDFBitmap bitmap = RenderPage(page.get());
CompareBitmap(bitmap.get(), 200, 100, new_page_2_checksum);
- UnloadPage(page);
}
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
diff --git a/fpdfsdk/fpdf_searchex_embeddertest.cpp b/fpdfsdk/fpdf_searchex_embeddertest.cpp
index 5740789..8562d69 100644
--- a/fpdfsdk/fpdf_searchex_embeddertest.cpp
+++ b/fpdfsdk/fpdf_searchex_embeddertest.cpp
@@ -10,11 +10,11 @@
TEST_F(FPDFSearchExEmbedderTest, GetCharIndexFromTextIndex) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFTextPage textpage(FPDFText_LoadPage(page));
+ ScopedFPDFTextPage textpage(FPDFText_LoadPage(page.get()));
ASSERT_TRUE(textpage);
EXPECT_EQ(-2, FPDFText_GetCharIndexFromTextIndex(textpage.get(), -2));
@@ -27,18 +27,16 @@
EXPECT_EQ(29, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 29));
EXPECT_EQ(-1, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 30));
}
-
- UnloadPage(page);
}
TEST_F(FPDFSearchExEmbedderTest,
GetCharIndexFromTextIndexWithNonPrintableChar) {
ASSERT_TRUE(OpenDocument("bug_1139.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFTextPage textpage(FPDFText_LoadPage(page));
+ ScopedFPDFTextPage textpage(FPDFText_LoadPage(page.get()));
ASSERT_TRUE(textpage);
EXPECT_EQ(-1, FPDFText_GetCharIndexFromTextIndex(textpage.get(), -2));
@@ -52,8 +50,6 @@
EXPECT_EQ(-1, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 30));
EXPECT_EQ(-1, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 31));
}
-
- UnloadPage(page);
}
TEST_F(FPDFSearchExEmbedderTest, GetCharIndexFromTextIndexInvalid) {
@@ -66,11 +62,11 @@
TEST_F(FPDFSearchExEmbedderTest, GetTextIndexFromCharIndex) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFTextPage textpage(FPDFText_LoadPage(page));
+ ScopedFPDFTextPage textpage(FPDFText_LoadPage(page.get()));
ASSERT_TRUE(textpage);
EXPECT_EQ(-1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), -2));
@@ -83,18 +79,16 @@
EXPECT_EQ(29, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 29));
EXPECT_EQ(-1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 30));
}
-
- UnloadPage(page);
}
TEST_F(FPDFSearchExEmbedderTest,
GetTextIndexFromCharIndexWithNonPrintableChar) {
ASSERT_TRUE(OpenDocument("bug_1139.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFTextPage textpage(FPDFText_LoadPage(page));
+ ScopedFPDFTextPage textpage(FPDFText_LoadPage(page.get()));
ASSERT_TRUE(textpage);
EXPECT_EQ(-1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), -2));
@@ -108,8 +102,6 @@
EXPECT_EQ(29, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 30));
EXPECT_EQ(-1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 31));
}
-
- UnloadPage(page);
}
TEST_F(FPDFSearchExEmbedderTest, GetTextIndexFromCharIndexInvalid) {
diff --git a/fpdfsdk/fpdf_structtree_embeddertest.cpp b/fpdfsdk/fpdf_structtree_embeddertest.cpp
index f5a8b0f..b455bde 100644
--- a/fpdfsdk/fpdf_structtree_embeddertest.cpp
+++ b/fpdfsdk/fpdf_structtree_embeddertest.cpp
@@ -16,11 +16,11 @@
TEST_F(FPDFStructTreeEmbedderTest, GetAltText) {
ASSERT_TRUE(OpenDocument("tagged_alt_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -73,17 +73,15 @@
FPDF_StructElement_GetChildAtIndex(gchild_element, 0);
EXPECT_FALSE(ggchild_element);
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetActualText) {
ASSERT_TRUE(OpenDocument("tagged_actual_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -118,17 +116,15 @@
sizeof(buffer)));
EXPECT_EQ(L"Actual Text", GetPlatformWString(buffer));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetStringAttribute) {
ASSERT_TRUE(OpenDocument("tagged_table.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -181,17 +177,15 @@
EXPECT_EQ(0U, FPDF_StructElement_GetStringAttribute(nullptr, "Other",
buffer, kBufLen));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetStringAttributeBadStructElement) {
ASSERT_TRUE(OpenDocument("tagged_table_bad_elem.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -221,17 +215,15 @@
FPDF_STRUCTELEMENT row = FPDF_StructElement_GetChildAtIndex(table, 0);
EXPECT_TRUE(row);
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetID) {
ASSERT_TRUE(OpenDocument("tagged_table.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -266,17 +258,15 @@
ASSERT_TRUE(row);
EXPECT_EQ(2U, FPDF_StructElement_GetID(row, buffer, kBufLen));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetLang) {
ASSERT_TRUE(OpenDocument("tagged_table.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -314,19 +304,17 @@
ASSERT_TRUE(row);
EXPECT_EQ(0U, FPDF_StructElement_GetLang(row, buffer, kBufLen));
}
-
- UnloadPage(page);
}
// See also FPDFEditEmbedderTest.TraverseMarkedContentID, which traverses the
// marked contents using FPDFPageObj_GetMark() and related API.
TEST_F(FPDFStructTreeEmbedderTest, GetMarkedContentID) {
ASSERT_TRUE(OpenDocument("marked_content_id.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -334,17 +322,15 @@
FPDF_StructTree_GetChildAtIndex(struct_tree.get(), 0);
EXPECT_EQ(0, FPDF_StructElement_GetMarkedContentID(element));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetMarkedContentIdAtIndex) {
ASSERT_TRUE(OpenDocument("tagged_marked_content.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(4, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -388,8 +374,6 @@
EXPECT_EQ(-1, FPDF_StructElement_GetMarkedContentIdCount(child4));
EXPECT_EQ(-1, FPDF_StructElement_GetMarkedContentIdAtIndex(child4, 0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetChildMarkedContentID) {
@@ -397,9 +381,9 @@
// Using the loop to make difference clear
for (int page_i : {0, 1}) {
- FPDF_PAGE page = LoadPage(page_i);
+ ScopedEmbedderTestPage page = LoadScopedPage(page_i);
ASSERT_TRUE(page);
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -435,17 +419,16 @@
EXPECT_EQ(-1, FPDF_StructElement_GetChildMarkedContentID(struct_doc, 2));
// Invalid element
EXPECT_EQ(-1, FPDF_StructElement_GetChildMarkedContentID(nullptr, 0));
- UnloadPage(page);
}
}
TEST_F(FPDFStructTreeEmbedderTest, GetType) {
ASSERT_TRUE(OpenDocument("tagged_alt_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -469,17 +452,15 @@
ASSERT_EQ(18U, FPDF_StructElement_GetType(element, buffer, sizeof(buffer)));
EXPECT_EQ(L"Document", GetPlatformWString(buffer));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetObjType) {
ASSERT_TRUE(OpenDocument("tagged_table_bad_elem.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -522,17 +503,15 @@
// Reading bad elem also works.
EXPECT_EQ(L"NotStructElem", GetPlatformWString(buffer));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetParent) {
ASSERT_TRUE(OpenDocument("tagged_alt_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -554,17 +533,15 @@
// We currently handle this case by returning a nullptr.
ASSERT_EQ(nullptr, FPDF_StructElement_GetParent(parent));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetTitle) {
ASSERT_TRUE(OpenDocument("tagged_alt_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -599,17 +576,15 @@
sizeof(buffer)));
EXPECT_EQ(L"symbol: 100k", GetPlatformWString(buffer));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetAttributes) {
ASSERT_TRUE(OpenDocument("tagged_table.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -786,17 +761,15 @@
}
}
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetAttributesFromChildAttributes) {
ASSERT_TRUE(OpenDocument("tagged_actual_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -870,30 +843,27 @@
EXPECT_EQ(FPDF_OBJECT_NUMBER,
FPDF_StructElement_Attr_GetType(nested_attr_value3));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, GetStructTreeForNestedTaggedPDF) {
ASSERT_TRUE(OpenDocument("tagged_nested.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// This call should not crash. https://crbug.com/pdfium/1480
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
}
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, MarkedContentReferenceAndObjectReference) {
ASSERT_TRUE(OpenDocument("tagged_mcr_objr.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -969,17 +939,15 @@
// TODO(crbug.com/pdfium/672): Fetch this child element.
EXPECT_FALSE(FPDF_StructElement_GetChildAtIndex(object15, 0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, Bug1768) {
ASSERT_TRUE(OpenDocument("bug_1768.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
@@ -988,37 +956,31 @@
// fetched correctly as well.
EXPECT_FALSE(FPDF_StructTree_GetChildAtIndex(struct_tree.get(), 0));
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, Bug1296920) {
ASSERT_TRUE(OpenDocument("bug_1296920.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
// Destroying this tree should not crash.
}
-
- UnloadPage(page);
}
TEST_F(FPDFStructTreeEmbedderTest, Bug1443100) {
ASSERT_TRUE(OpenDocument("tagged_table_bad_parent.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Calling these APIs should not trigger a dangling pointer.
- ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page));
+ ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page.get()));
ASSERT_TRUE(struct_tree);
ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get()));
}
-
- UnloadPage(page);
}
diff --git a/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp b/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp
index 9751bfb..6f0a1aa 100644
--- a/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp
+++ b/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp
@@ -127,26 +127,23 @@
ASSERT_TRUE(OpenDocument("bug_972518.pdf"));
ASSERT_EQ(1, FPDF_GetPageCount(document()));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- UnloadPage(page);
}
TEST_F(FPDFSysFontInfoEmbedderTest, DefaultSystemFontInfo) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
ASSERT_EQ(1, FPDF_GetPageCount(document()));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
{
// Not checking the rendering because it will depend on the fonts installed.
- ScopedFPDFBitmap bitmap = RenderPage(page);
+ ScopedFPDFBitmap bitmap = RenderPage(page.get());
ASSERT_EQ(200, FPDFBitmap_GetWidth(bitmap.get()));
ASSERT_EQ(200, FPDFBitmap_GetHeight(bitmap.get()));
}
-
- UnloadPage(page);
}
TEST_F(FPDFSysFontInfoEmbedderTest, DefaultTTFMap) {
diff --git a/fpdfsdk/fpdf_text_embeddertest.cpp b/fpdfsdk/fpdf_text_embeddertest.cpp
index 2b0c7da..d17c0c8 100644
--- a/fpdfsdk/fpdf_text_embeddertest.cpp
+++ b/fpdfsdk/fpdf_text_embeddertest.cpp
@@ -49,10 +49,10 @@
TEST_F(FPDFTextEmbedderTest, Text) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
unsigned short buffer[128];
@@ -232,15 +232,14 @@
EXPECT_EQ(0xbdbd, buffer[10]);
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, TextVertical) {
ASSERT_TRUE(OpenDocument("vertical_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
EXPECT_EQ(12.0, FPDFText_GetFontSize(textpage, 0));
@@ -269,7 +268,6 @@
EXPECT_NEAR(159.292, rect.top, 0.001);
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, TextHebrewMirrored) {
@@ -301,10 +299,10 @@
TEST_F(FPDFTextEmbedderTest, TextSearch) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
ScopedFPDFWideString nope = GetFPDFWideString(L"nope");
@@ -412,15 +410,14 @@
}
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, TextSearchConsecutive) {
ASSERT_TRUE(OpenDocument("find_text_consecutive.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
ScopedFPDFWideString aaaa = GetFPDFWideString(L"aaaa");
@@ -496,7 +493,6 @@
}
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, TextSearchTermAtEnd) {
@@ -600,10 +596,10 @@
#endif
TEST_F(FPDFTextEmbedderTest, MAYBE_TextSearchLatinExtended) {
ASSERT_TRUE(OpenDocument("latin_extended.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
// Upper/lowercase 'a' with breve.
@@ -628,29 +624,27 @@
}
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
// Test that the page has characters despite a bad stream length.
TEST_F(FPDFTextEmbedderTest, StreamLengthPastEndOfFile) {
ASSERT_TRUE(OpenDocument("bug_57.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
EXPECT_EQ(13, FPDFText_CountChars(textpage));
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, WebLinks) {
ASSERT_TRUE(OpenDocument("weblinks.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
{
@@ -753,15 +747,14 @@
FPDFLink_CloseWebLinks(pagelink);
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, WebLinksAcrossLines) {
ASSERT_TRUE(OpenDocument("weblinks_across_lines.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
FPDF_PAGELINK pagelink = FPDFLink_LoadWebLinks(textpage);
@@ -792,15 +785,14 @@
FPDFLink_CloseWebLinks(pagelink);
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, WebLinksAcrossLinesBug) {
ASSERT_TRUE(OpenDocument("bug_650.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
FPDF_PAGELINK pagelink = FPDFLink_LoadWebLinks(textpage);
@@ -818,15 +810,14 @@
FPDFLink_CloseWebLinks(pagelink);
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, WebLinksCharRanges) {
ASSERT_TRUE(OpenDocument("weblinks.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page.get());
ASSERT_TRUE(text_page);
FPDF_PAGELINK page_link = FPDFLink_LoadWebLinks(text_page);
@@ -866,20 +857,19 @@
FPDFLink_CloseWebLinks(page_link);
FPDFText_ClosePage(text_page);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, AnnotLinks) {
ASSERT_TRUE(OpenDocument("annots.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Get link count via checking annotation subtype
- int annot_count = FPDFPage_GetAnnotCount(page);
+ int annot_count = FPDFPage_GetAnnotCount(page.get());
ASSERT_EQ(9, annot_count);
int annot_subtype_link_count = 0;
for (int i = 0; i < annot_count; ++i) {
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page.get(), i));
if (FPDFAnnot_GetSubtype(annot.get()) == FPDF_ANNOT_LINK) {
++annot_subtype_link_count;
}
@@ -890,7 +880,7 @@
int start_pos = 0;
FPDF_LINK link_annot;
int link_count = 0;
- while (FPDFLink_Enumerate(page, &start_pos, &link_annot)) {
+ while (FPDFLink_Enumerate(page.get(), &start_pos, &link_annot)) {
ASSERT_TRUE(link_annot);
if (start_pos == 1 || start_pos == 2) {
// First two links point to first and second page within the document
@@ -930,16 +920,14 @@
++link_count;
}
EXPECT_EQ(annot_subtype_link_count, link_count);
-
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, GetFontSize) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
constexpr auto kExpectedFontsSizes = fxcrt::ToArray<const double>(
@@ -952,15 +940,14 @@
EXPECT_EQ(kExpectedFontsSizes[i], FPDFText_GetFontSize(textpage, i)) << i;
}
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, GetFontInfo) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
std::vector<char> font_name;
size_t num_chars1 = strlen("Hello, world!");
@@ -1034,22 +1021,20 @@
font_name.size(), nullptr));
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, ToUnicode) {
ASSERT_TRUE(OpenDocument("bug_583.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
ASSERT_EQ(1, FPDFText_CountChars(textpage));
EXPECT_EQ(0U, FPDFText_GetUnicode(textpage, 0));
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, IsGenerated) {
@@ -1134,10 +1119,10 @@
TEST_F(FPDFTextEmbedderTest, Bug921) {
ASSERT_TRUE(OpenDocument("bug_921.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
static constexpr auto kData = fxcrt::ToArray<const unsigned int>(
@@ -1161,15 +1146,14 @@
EXPECT_EQ(0, buffer[kData.size()]);
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, GetTextWithHyphen) {
ASSERT_TRUE(OpenDocument("bug_781804.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
// Check that soft hyphens are not included
@@ -1206,26 +1190,24 @@
}
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, Bug782596) {
// If there is a regression in this test, it will only fail under ASAN
ASSERT_TRUE(OpenDocument("bug_782596.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, ControlCharacters) {
ASSERT_TRUE(OpenDocument("control_characters.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
// Should not include the control characters in the output
@@ -1250,17 +1232,16 @@
sizeof(expected_substring)));
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
// Testing that hyphen makers (0x0002) are replacing hard hyphens when
// the word contains non-ASCII characters.
TEST_F(FPDFTextEmbedderTest, Bug1029) {
ASSERT_TRUE(OpenDocument("bug_1029.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
constexpr int page_range_offset = 171;
@@ -1293,15 +1274,14 @@
}
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, CountRects) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page.get());
ASSERT_TRUE(textpage);
// Sanity check hello_world.pdf.
@@ -1365,19 +1345,18 @@
}
FPDFText_ClosePage(textpage);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, GetText) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page.get());
ASSERT_TRUE(text_page);
- EXPECT_EQ(2, FPDFPage_CountObjects(page));
- FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page, 0);
+ EXPECT_EQ(2, FPDFPage_CountObjects(page.get()));
+ FPDF_PAGEOBJECT text_object = FPDFPage_GetObject(page.get(), 0);
ASSERT_TRUE(text_object);
// Positive testing.
@@ -1409,7 +1388,6 @@
ASSERT_EQ('\0', buffer[1]);
FPDFText_ClosePage(text_page);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, CroppedText) {
@@ -1467,10 +1445,10 @@
TEST_F(FPDFTextEmbedderTest, Bug1139) {
ASSERT_TRUE(OpenDocument("bug_1139.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page.get());
ASSERT_TRUE(text_page);
// -1 for CountChars not including the \0, but +1 for the extra control
@@ -1485,7 +1463,6 @@
EXPECT_TRUE(
check_unsigned_shorts(kHelloGoodbyeText, buffer, kHelloGoodbyeTextSize));
FPDFText_ClosePage(text_page);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, Bug642) {
@@ -1511,10 +1488,10 @@
TEST_F(FPDFTextEmbedderTest, GetCharAngle) {
ASSERT_TRUE(OpenDocument("rotated_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page.get());
ASSERT_TRUE(text_page);
static constexpr int kSubstringsSize[] = {
@@ -1544,15 +1521,14 @@
0.001);
FPDFText_ClosePage(text_page);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, GetFontWeight) {
ASSERT_TRUE(OpenDocument("font_weight.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page.get());
ASSERT_TRUE(text_page);
EXPECT_EQ(2, FPDFText_CountChars(text_page));
@@ -1571,7 +1547,6 @@
EXPECT_EQ(410, FPDFText_GetFontWeight(text_page, 1));
FPDFText_ClosePage(text_page);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, GetTextRenderMode) {
@@ -1603,10 +1578,10 @@
TEST_F(FPDFTextEmbedderTest, GetFillColor) {
ASSERT_TRUE(OpenDocument("text_color.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page.get());
ASSERT_TRUE(text_page);
ASSERT_EQ(1, FPDFText_CountChars(text_page));
@@ -1631,15 +1606,14 @@
ASSERT_EQ(0xffu, a);
FPDFText_ClosePage(text_page);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, GetStrokeColor) {
ASSERT_TRUE(OpenDocument("text_color.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
+ FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page.get());
ASSERT_TRUE(text_page);
ASSERT_EQ(1, FPDFText_CountChars(text_page));
@@ -1664,7 +1638,6 @@
ASSERT_EQ(0xffu, a);
FPDFText_ClosePage(text_page);
- UnloadPage(page);
}
TEST_F(FPDFTextEmbedderTest, GetMatrix) {
diff --git a/fpdfsdk/fpdf_thumbnail_embeddertest.cpp b/fpdfsdk/fpdf_thumbnail_embeddertest.cpp
index 023e8ba..8566b5f 100644
--- a/fpdfsdk/fpdf_thumbnail_embeddertest.cpp
+++ b/fpdfsdk/fpdf_thumbnail_embeddertest.cpp
@@ -26,38 +26,36 @@
const char kHashedDecodedData[] = "7902d0be831c9024960f4ebd5d7df1f7";
const unsigned long kExpectedSize = 1138u;
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
unsigned long length_bytes =
- FPDFPage_GetDecodedThumbnailData(page, nullptr, 0);
+ FPDFPage_GetDecodedThumbnailData(page.get(), nullptr, 0);
ASSERT_EQ(kExpectedSize, length_bytes);
std::vector<uint8_t> thumb_buf(length_bytes);
EXPECT_EQ(kExpectedSize, FPDFPage_GetDecodedThumbnailData(
- page, thumb_buf.data(), length_bytes));
+ page.get(), thumb_buf.data(), length_bytes));
EXPECT_EQ(kHashedDecodedData, GenerateMD5Base16(thumb_buf));
- UnloadPage(page);
}
{
const char kHashedDecodedData[] = "e81123a573378ba1ea80461d25cc41f6";
const unsigned long kExpectedSize = 1110u;
- FPDF_PAGE page = LoadPage(1);
+ ScopedEmbedderTestPage page = LoadScopedPage(1);
ASSERT_TRUE(page);
unsigned long length_bytes =
- FPDFPage_GetDecodedThumbnailData(page, nullptr, 0);
+ FPDFPage_GetDecodedThumbnailData(page.get(), nullptr, 0);
ASSERT_EQ(kExpectedSize, length_bytes);
std::vector<uint8_t> thumb_buf(length_bytes);
EXPECT_EQ(kExpectedSize, FPDFPage_GetDecodedThumbnailData(
- page, thumb_buf.data(), length_bytes));
+ page.get(), thumb_buf.data(), length_bytes));
EXPECT_EQ(kHashedDecodedData, GenerateMD5Base16(thumb_buf));
- UnloadPage(page);
}
}
@@ -67,31 +65,27 @@
const unsigned long kExpectedSize = 301u;
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
unsigned long length_bytes =
- FPDFPage_GetDecodedThumbnailData(page, nullptr, 0);
+ FPDFPage_GetDecodedThumbnailData(page.get(), nullptr, 0);
ASSERT_EQ(kExpectedSize, length_bytes);
std::vector<uint8_t> thumb_buf(length_bytes);
EXPECT_EQ(kExpectedSize, FPDFPage_GetDecodedThumbnailData(
- page, thumb_buf.data(), length_bytes));
+ page.get(), thumb_buf.data(), length_bytes));
EXPECT_EQ(kThumbnailWithNoFiltersChecksum, GenerateMD5Base16(thumb_buf));
-
- UnloadPage(page);
}
TEST_F(FPDFThumbnailEmbedderTest,
GetDecodedThumbnailDataFromPageWithNoThumbnails) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(0u, FPDFPage_GetDecodedThumbnailData(page, nullptr, 0));
-
- UnloadPage(page);
+ EXPECT_EQ(0u, FPDFPage_GetDecodedThumbnailData(page.get(), nullptr, 0));
}
TEST_F(FPDFThumbnailEmbedderTest, GetDecodedThumbnailDataFromPageNullPage) {
@@ -104,36 +98,36 @@
{
const unsigned long kExpectedSize = 1851u;
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- unsigned long length_bytes = FPDFPage_GetRawThumbnailData(page, nullptr, 0);
+ unsigned long length_bytes =
+ FPDFPage_GetRawThumbnailData(page.get(), nullptr, 0);
ASSERT_EQ(kExpectedSize, length_bytes);
std::vector<uint8_t> thumb_buf(length_bytes);
EXPECT_EQ(kExpectedSize, FPDFPage_GetRawThumbnailData(
- page, thumb_buf.data(), length_bytes));
+ page.get(), thumb_buf.data(), length_bytes));
EXPECT_EQ(kSimpleThumbnailChecksum, GenerateMD5Base16(thumb_buf));
- UnloadPage(page);
}
{
const char kHashedRawData[] = "c7558a461d5ecfb1d4757218b473afc0";
const unsigned long kExpectedSize = 1792u;
- FPDF_PAGE page = LoadPage(1);
+ ScopedEmbedderTestPage page = LoadScopedPage(1);
ASSERT_TRUE(page);
- unsigned long length_bytes = FPDFPage_GetRawThumbnailData(page, nullptr, 0);
+ unsigned long length_bytes =
+ FPDFPage_GetRawThumbnailData(page.get(), nullptr, 0);
ASSERT_EQ(kExpectedSize, length_bytes);
std::vector<uint8_t> thumb_buf(length_bytes);
EXPECT_EQ(kExpectedSize, FPDFPage_GetRawThumbnailData(
- page, thumb_buf.data(), length_bytes));
+ page.get(), thumb_buf.data(), length_bytes));
EXPECT_EQ(kHashedRawData, GenerateMD5Base16(thumb_buf));
- UnloadPage(page);
}
}
@@ -142,29 +136,26 @@
const unsigned long kExpectedSize = 301u;
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- unsigned long length_bytes = FPDFPage_GetRawThumbnailData(page, nullptr, 0);
+ unsigned long length_bytes =
+ FPDFPage_GetRawThumbnailData(page.get(), nullptr, 0);
ASSERT_EQ(kExpectedSize, length_bytes);
std::vector<uint8_t> thumb_buf(length_bytes);
- EXPECT_EQ(kExpectedSize,
- FPDFPage_GetRawThumbnailData(page, thumb_buf.data(), length_bytes));
+ EXPECT_EQ(kExpectedSize, FPDFPage_GetRawThumbnailData(
+ page.get(), thumb_buf.data(), length_bytes));
EXPECT_EQ(kThumbnailWithNoFiltersChecksum, GenerateMD5Base16(thumb_buf));
-
- UnloadPage(page);
}
TEST_F(FPDFThumbnailEmbedderTest, GetRawThumbnailDataFromPageWithNoThumbnails) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(0u, FPDFPage_GetRawThumbnailData(page, nullptr, 0));
-
- UnloadPage(page);
+ EXPECT_EQ(0u, FPDFPage_GetRawThumbnailData(page.get(), nullptr, 0));
}
TEST_F(FPDFThumbnailEmbedderTest, GetRawThumbnailDataFromPageNullPage) {
@@ -175,10 +166,10 @@
ASSERT_TRUE(OpenDocument("simple_thumbnail.pdf"));
{
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page));
+ ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page.get()));
EXPECT_EQ(50, FPDFBitmap_GetWidth(thumb_bitmap.get()));
EXPECT_EQ(50, FPDFBitmap_GetHeight(thumb_bitmap.get()));
@@ -186,14 +177,13 @@
CompareBitmap(thumb_bitmap.get(), 50, 50,
"52b75451e396f55e95d1cb68e6018226");
- UnloadPage(page);
}
{
- FPDF_PAGE page = LoadPage(1);
+ ScopedEmbedderTestPage page = LoadScopedPage(1);
ASSERT_TRUE(page);
- ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page));
+ ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page.get()));
EXPECT_EQ(50, FPDFBitmap_GetWidth(thumb_bitmap.get()));
EXPECT_EQ(50, FPDFBitmap_GetHeight(thumb_bitmap.get()));
@@ -201,7 +191,6 @@
CompareBitmap(thumb_bitmap.get(), 50, 50,
"1f448be08c6e6043ccd0bad8ecc2a351");
- UnloadPage(page);
}
}
@@ -209,43 +198,37 @@
GetThumbnailAsBitmapFromPageWithoutThumbnail) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page));
+ ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page.get()));
ASSERT_EQ(nullptr, thumb_bitmap.get());
-
- UnloadPage(page);
}
TEST_F(FPDFThumbnailEmbedderTest,
GetThumbnailAsBitmapFromThumbnailWithEmptyStream) {
ASSERT_TRUE(OpenDocument("thumbnail_with_empty_stream.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page));
+ ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page.get()));
ASSERT_EQ(nullptr, thumb_bitmap.get());
-
- UnloadPage(page);
}
TEST_F(FPDFThumbnailEmbedderTest,
GetThumbnailAsBitmapFromThumbnailWithNoFilters) {
ASSERT_TRUE(OpenDocument("thumbnail_with_no_filters.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page));
+ ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page.get()));
EXPECT_EQ(10, FPDFBitmap_GetWidth(thumb_bitmap.get()));
EXPECT_EQ(10, FPDFBitmap_GetHeight(thumb_bitmap.get()));
EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(thumb_bitmap.get()));
CompareBitmap(thumb_bitmap.get(), 10, 10, "fe02583f9e6d094042a942ff686e9936");
-
- UnloadPage(page);
}
TEST_F(FPDFThumbnailEmbedderTest, GetThumbnailDoesNotAlterPage) {
@@ -253,20 +236,20 @@
const unsigned long kExpectedRawSize = 1851u;
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Get the raw data
- unsigned long raw_size = FPDFPage_GetRawThumbnailData(page, nullptr, 0);
+ unsigned long raw_size = FPDFPage_GetRawThumbnailData(page.get(), nullptr, 0);
ASSERT_EQ(kExpectedRawSize, raw_size);
std::vector<uint8_t> raw_thumb_buf(raw_size);
- EXPECT_EQ(kExpectedRawSize,
- FPDFPage_GetRawThumbnailData(page, raw_thumb_buf.data(), raw_size));
+ EXPECT_EQ(kExpectedRawSize, FPDFPage_GetRawThumbnailData(
+ page.get(), raw_thumb_buf.data(), raw_size));
EXPECT_EQ(kSimpleThumbnailChecksum, GenerateMD5Base16(raw_thumb_buf));
// Get the thumbnail
- ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page));
+ ScopedFPDFBitmap thumb_bitmap(FPDFPage_GetThumbnailAsBitmap(page.get()));
EXPECT_EQ(50, FPDFBitmap_GetWidth(thumb_bitmap.get()));
EXPECT_EQ(50, FPDFBitmap_GetHeight(thumb_bitmap.get()));
@@ -274,16 +257,15 @@
CompareBitmap(thumb_bitmap.get(), 50, 50, "52b75451e396f55e95d1cb68e6018226");
// Get the raw data again
- unsigned long new_raw_size = FPDFPage_GetRawThumbnailData(page, nullptr, 0);
+ unsigned long new_raw_size =
+ FPDFPage_GetRawThumbnailData(page.get(), nullptr, 0);
ASSERT_EQ(kExpectedRawSize, new_raw_size);
std::vector<uint8_t> new_raw_thumb_buf(new_raw_size);
EXPECT_EQ(kExpectedRawSize,
- FPDFPage_GetRawThumbnailData(page, new_raw_thumb_buf.data(),
+ FPDFPage_GetRawThumbnailData(page.get(), new_raw_thumb_buf.data(),
new_raw_size));
EXPECT_EQ(kSimpleThumbnailChecksum, GenerateMD5Base16(new_raw_thumb_buf));
-
- UnloadPage(page);
}
TEST_F(FPDFThumbnailEmbedderTest, GetThumbnailAsBitmapFromPageNullPage) {
diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp
index 789b641..bffe29c 100644
--- a/fpdfsdk/fpdf_view_embeddertest.cpp
+++ b/fpdfsdk/fpdf_view_embeddertest.cpp
@@ -365,7 +365,7 @@
// Test for conversion of a point in page coordinates to device coordinates.
TEST_F(FPDFViewEmbedderTest, PageCoordinatesToDeviceCoordinates) {
ASSERT_TRUE(OpenDocument("about_blank.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
// Display bounds in device coordinates
@@ -383,30 +383,30 @@
int device_x = 0;
int device_y = 0;
- EXPECT_TRUE(FPDF_PageToDevice(page, start_x, start_y, size_x, size_y, rotate,
- page_x, page_y, &device_x, &device_y));
+ EXPECT_TRUE(FPDF_PageToDevice(page.get(), start_x, start_y, size_x, size_y,
+ rotate, page_x, page_y, &device_x, &device_y));
EXPECT_EQ(9, device_x);
EXPECT_EQ(10, device_y);
// Rotate 90 degrees clockwise
rotate = 1;
- EXPECT_TRUE(FPDF_PageToDevice(page, start_x, start_y, size_x, size_y, rotate,
- page_x, page_y, &device_x, &device_y));
+ EXPECT_TRUE(FPDF_PageToDevice(page.get(), start_x, start_y, size_x, size_y,
+ rotate, page_x, page_y, &device_x, &device_y));
EXPECT_EQ(626, device_x);
EXPECT_EQ(7, device_y);
// Rotate 180 degrees
rotate = 2;
- EXPECT_TRUE(FPDF_PageToDevice(page, start_x, start_y, size_x, size_y, rotate,
- page_x, page_y, &device_x, &device_y));
+ EXPECT_TRUE(FPDF_PageToDevice(page.get(), start_x, start_y, size_x, size_y,
+ rotate, page_x, page_y, &device_x, &device_y));
EXPECT_EQ(631, device_x);
EXPECT_EQ(470, device_y);
// Rotate 90 degrees counter-clockwise
rotate = 3;
- EXPECT_TRUE(FPDF_PageToDevice(page, start_x, start_y, size_x, size_y, rotate,
- page_x, page_y, &device_x, &device_y));
+ EXPECT_TRUE(FPDF_PageToDevice(page.get(), start_x, start_y, size_x, size_y,
+ rotate, page_x, page_y, &device_x, &device_y));
EXPECT_EQ(14, device_x);
EXPECT_EQ(473, device_y);
@@ -414,16 +414,16 @@
// modulo by 4. A value of 4 is expected to be converted into 0 (normal
// rotation)
rotate = 4;
- EXPECT_TRUE(FPDF_PageToDevice(page, start_x, start_y, size_x, size_y, rotate,
- page_x, page_y, &device_x, &device_y));
+ EXPECT_TRUE(FPDF_PageToDevice(page.get(), start_x, start_y, size_x, size_y,
+ rotate, page_x, page_y, &device_x, &device_y));
EXPECT_EQ(9, device_x);
EXPECT_EQ(10, device_y);
// FPDF_PageToDevice() returns untransformed coordinates if |rotate| % 4 is
// negative.
rotate = -1;
- EXPECT_TRUE(FPDF_PageToDevice(page, start_x, start_y, size_x, size_y, rotate,
- page_x, page_y, &device_x, &device_y));
+ EXPECT_TRUE(FPDF_PageToDevice(page.get(), start_x, start_y, size_x, size_y,
+ rotate, page_x, page_y, &device_x, &device_y));
EXPECT_EQ(start_x, device_x);
EXPECT_EQ(start_y, device_y);
@@ -437,10 +437,8 @@
EXPECT_EQ(5678, device_y);
// Negative case - invalid output parameters
- EXPECT_FALSE(FPDF_PageToDevice(page, start_x, start_y, size_x, size_y, rotate,
- page_x, page_y, nullptr, nullptr));
-
- UnloadPage(page);
+ EXPECT_FALSE(FPDF_PageToDevice(page.get(), start_x, start_y, size_x, size_y,
+ rotate, page_x, page_y, nullptr, nullptr));
}
TEST_F(FPDFViewEmbedderTest, MultipleInitDestroy) {
@@ -633,14 +631,14 @@
TEST_F(FPDFViewEmbedderTest, Page) {
ASSERT_TRUE(OpenDocument("about_blank.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- EXPECT_FLOAT_EQ(612.0f, FPDF_GetPageWidthF(page));
- EXPECT_FLOAT_EQ(792.0f, FPDF_GetPageHeightF(page));
+ EXPECT_FLOAT_EQ(612.0f, FPDF_GetPageWidthF(page.get()));
+ EXPECT_FLOAT_EQ(792.0f, FPDF_GetPageHeightF(page.get()));
FS_RECTF rect;
- EXPECT_TRUE(FPDF_GetPageBoundingBox(page, &rect));
+ EXPECT_TRUE(FPDF_GetPageBoundingBox(page.get(), &rect));
EXPECT_EQ(0.0, rect.left);
EXPECT_EQ(0.0, rect.bottom);
EXPECT_EQ(612.0, rect.right);
@@ -650,10 +648,9 @@
EXPECT_EQ(0.0, FPDF_GetPageWidth(nullptr));
EXPECT_EQ(0.0, FPDF_GetPageHeight(nullptr));
EXPECT_FALSE(FPDF_GetPageBoundingBox(nullptr, &rect));
- EXPECT_FALSE(FPDF_GetPageBoundingBox(page, nullptr));
+ EXPECT_FALSE(FPDF_GetPageBoundingBox(page.get(), nullptr));
- UnloadPage(page);
- EXPECT_FALSE(LoadPage(1));
+ EXPECT_FALSE(LoadScopedPage(1));
}
TEST_F(FPDFViewEmbedderTest, ViewerRefDummy) {
@@ -1053,15 +1050,15 @@
"c901239d17d84ac84cb6f2124da71b0d";
ASSERT_TRUE(OpenDocument("rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- const float page_width = FPDF_GetPageWidthF(page);
- const float page_height = FPDF_GetPageHeightF(page);
+ const float page_width = FPDF_GetPageWidthF(page.get());
+ const float page_height = FPDF_GetPageHeightF(page.get());
EXPECT_FLOAT_EQ(200, page_width);
EXPECT_FLOAT_EQ(300, page_height);
using pdfium::RectanglesChecksum;
- ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get());
CompareBitmap(bitmap.get(), page_width, page_height, RectanglesChecksum());
FS_RECTF page_rect{0, 0, page_width, page_height};
@@ -1069,56 +1066,58 @@
// Try rendering with an identity matrix. The output should be the same as
// the RenderLoadedPage() output.
FS_MATRIX identity_matrix{1, 0, 0, 1, 0, 0};
- TestRenderPageBitmapWithMatrix(page, page_width, page_height, identity_matrix,
- page_rect, RectanglesChecksum());
+ TestRenderPageBitmapWithMatrix(page.get(), page_width, page_height,
+ identity_matrix, page_rect,
+ RectanglesChecksum());
// Again render with an identity matrix but with a smaller clipping rect.
FS_RECTF middle_of_page_rect{page_width / 4, page_height / 4,
page_width * 3 / 4, page_height * 3 / 4};
- TestRenderPageBitmapWithMatrix(page, page_width, page_height, identity_matrix,
- middle_of_page_rect, clipped_checksum);
+ TestRenderPageBitmapWithMatrix(page.get(), page_width, page_height,
+ identity_matrix, middle_of_page_rect,
+ clipped_checksum);
// Now render again with the image scaled smaller.
FS_MATRIX half_scale_matrix{0.5, 0, 0, 0.5, 0, 0};
- TestRenderPageBitmapWithMatrix(page, page_width, page_height,
+ TestRenderPageBitmapWithMatrix(page.get(), page_width, page_height,
half_scale_matrix, page_rect,
top_left_quarter_checksum);
// Now render again with the image scaled larger horizontally (the right half
// will be clipped).
FS_MATRIX stretch_x_matrix{2, 0, 0, 1, 0, 0};
- TestRenderPageBitmapWithMatrix(page, page_width, page_height,
+ TestRenderPageBitmapWithMatrix(page.get(), page_width, page_height,
stretch_x_matrix, page_rect,
kHoriStretchedChecksum);
// Try a 90 degree rotation clockwise but with the same bitmap size, so part
// will be clipped.
FS_MATRIX rotate_90_matrix{0, 1, -1, 0, page_width, 0};
- TestRenderPageBitmapWithMatrix(page, page_width, page_height,
+ TestRenderPageBitmapWithMatrix(page.get(), page_width, page_height,
rotate_90_matrix, page_rect,
rotated_90_clockwise_checksum);
// 180 degree rotation clockwise.
FS_MATRIX rotate_180_matrix{-1, 0, 0, -1, page_width, page_height};
- TestRenderPageBitmapWithMatrix(page, page_width, page_height,
+ TestRenderPageBitmapWithMatrix(page.get(), page_width, page_height,
rotate_180_matrix, page_rect,
rotated_180_clockwise_checksum);
// 270 degree rotation clockwise.
FS_MATRIX rotate_270_matrix{0, -1, 1, 0, 0, page_width};
- TestRenderPageBitmapWithMatrix(page, page_width, page_height,
+ TestRenderPageBitmapWithMatrix(page.get(), page_width, page_height,
rotate_270_matrix, page_rect,
rotated_270_clockwise_checksum);
// Mirror horizontally.
FS_MATRIX mirror_hori_matrix{-1, 0, 0, 1, page_width, 0};
- TestRenderPageBitmapWithMatrix(page, page_width, page_height,
+ TestRenderPageBitmapWithMatrix(page.get(), page_width, page_height,
mirror_hori_matrix, page_rect,
mirror_hori_checksum);
// Mirror vertically.
FS_MATRIX mirror_vert_matrix{1, 0, 0, -1, 0, page_height};
- TestRenderPageBitmapWithMatrix(page, page_width, page_height,
+ TestRenderPageBitmapWithMatrix(page.get(), page_width, page_height,
mirror_vert_matrix, page_rect,
mirror_vert_checksum);
@@ -1128,27 +1127,27 @@
// Render using an identity matrix and the whole bitmap area as clipping rect.
FS_RECTF bitmap_rect{0, 0, bitmap_width, bitmap_height};
- TestRenderPageBitmapWithMatrix(page, bitmap_width, bitmap_height,
+ TestRenderPageBitmapWithMatrix(page.get(), bitmap_width, bitmap_height,
identity_matrix, bitmap_rect,
larger_top_left_quarter_checksum);
// Render using a scaling matrix to fill the larger bitmap.
FS_MATRIX double_scale_matrix{2, 0, 0, 2, 0, 0};
- TestRenderPageBitmapWithMatrix(page, bitmap_width, bitmap_height,
+ TestRenderPageBitmapWithMatrix(page.get(), bitmap_width, bitmap_height,
double_scale_matrix, bitmap_rect,
kLargerChecksum);
// Render the larger image again but with clipping.
FS_RECTF middle_of_bitmap_rect{bitmap_width / 4, bitmap_height / 4,
bitmap_width * 3 / 4, bitmap_height * 3 / 4};
- TestRenderPageBitmapWithMatrix(page, bitmap_width, bitmap_height,
+ TestRenderPageBitmapWithMatrix(page.get(), bitmap_width, bitmap_height,
double_scale_matrix, middle_of_bitmap_rect,
kLargerClippedChecksum);
// On the larger bitmap, try a 90 degree rotation but with the same bitmap
// size, so part will be clipped.
FS_MATRIX rotate_90_scale_2_matrix{0, 2, -2, 0, bitmap_width, 0};
- TestRenderPageBitmapWithMatrix(page, bitmap_width, bitmap_height,
+ TestRenderPageBitmapWithMatrix(page.get(), bitmap_width, bitmap_height,
rotate_90_scale_2_matrix, bitmap_rect,
kLargerRotatedChecksum);
@@ -1161,7 +1160,7 @@
FS_MATRIX landscape_rotate_90_scale_2_matrix{
0, 2, -2, 0, landscape_bitmap_width, 0};
TestRenderPageBitmapWithMatrix(
- page, landscape_bitmap_width, landscape_bitmap_height,
+ page.get(), landscape_bitmap_width, landscape_bitmap_height,
landscape_rotate_90_scale_2_matrix, landscape_bitmap_rect,
kLargerRotatedLandscapeChecksum);
@@ -1174,7 +1173,7 @@
diagonal_bitmap_size};
FS_MATRIX rotate_45_scale_2_matrix{
sqrt2, sqrt2, -sqrt2, sqrt2, bitmap_height / sqrt2, 0};
- TestRenderPageBitmapWithMatrix(page, diagonal_bitmap_size,
+ TestRenderPageBitmapWithMatrix(page.get(), diagonal_bitmap_size,
diagonal_bitmap_size, rotate_45_scale_2_matrix,
diagonal_bitmap_rect,
larger_rotated_diagonal_checksum);
@@ -1193,11 +1192,9 @@
scale,
-tile_x * tile_bitmap_size,
-tile_y * tile_bitmap_size};
- TestRenderPageBitmapWithMatrix(page, tile_bitmap_size, tile_bitmap_size,
+ TestRenderPageBitmapWithMatrix(page.get(), tile_bitmap_size, tile_bitmap_size,
tile_2_1_matrix, tile_bitmap_rect,
tile_checksum);
-
- UnloadPage(page);
}
TEST_F(FPDFViewEmbedderTest, FPDFGetPageSizeByIndexF) {
@@ -1227,12 +1224,11 @@
#endif // PDF_ENABLE_XFA
// Double-check against values from when page is actually parsed.
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_FLOAT_EQ(size.width, FPDF_GetPageWidthF(page));
- EXPECT_FLOAT_EQ(size.height, FPDF_GetPageHeightF(page));
+ EXPECT_FLOAT_EQ(size.width, FPDF_GetPageWidthF(page.get()));
+ EXPECT_FLOAT_EQ(size.height, FPDF_GetPageHeightF(page.get()));
EXPECT_EQ(1u, pDoc->GetParsedPageCountForTesting());
- UnloadPage(page);
}
TEST_F(FPDFViewEmbedderTest, FPDFGetPageSizeByIndex) {
@@ -1265,12 +1261,11 @@
#endif // PDF_ENABLE_XFA
// Double-check against values from when page is actually parsed.
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- EXPECT_EQ(width, FPDF_GetPageWidth(page));
- EXPECT_EQ(height, FPDF_GetPageHeight(page));
+ EXPECT_EQ(width, FPDF_GetPageWidth(page.get()));
+ EXPECT_EQ(height, FPDF_GetPageHeight(page.get()));
EXPECT_EQ(1u, pDoc->GetParsedPageCountForTesting());
- UnloadPage(page);
}
TEST_F(FPDFViewEmbedderTest, GetXFAArrayData) {
@@ -1472,14 +1467,12 @@
static const char kNoNativeTextChecksum[] =
"288502887ffc63291f35a0573b944375";
ASSERT_TRUE(OpenDocument("bug_664284.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- TestRenderPageBitmapWithFlags(page, 0, original_checksum);
- TestRenderPageBitmapWithFlags(page, FPDF_NO_NATIVETEXT,
+ TestRenderPageBitmapWithFlags(page.get(), 0, original_checksum);
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_NO_NATIVETEXT,
kNoNativeTextChecksum);
-
- UnloadPage(page);
}
TEST_F(FPDFViewEmbedderTest, RenderAnnotationWithPrintingFlag) {
@@ -1491,16 +1484,15 @@
}();
static const char kPrintingChecksum[] = "3e235b9f88f652f2b97b1fc393924849";
ASSERT_TRUE(OpenDocument("bug_1658.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// A yellow highlight is rendered with `FPDF_ANNOT` flag.
- TestRenderPageBitmapWithFlags(page, FPDF_ANNOT, annotation_checksum);
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_ANNOT, annotation_checksum);
// After adding `FPDF_PRINTING` flag, the yellow highlight is not rendered.
- TestRenderPageBitmapWithFlags(page, FPDF_PRINTING | FPDF_ANNOT,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_PRINTING | FPDF_ANNOT,
kPrintingChecksum);
- UnloadPage(page);
}
// TODO(crbug.com/pdfium/1955): Remove this test once pixel tests can pass with
@@ -1523,27 +1515,26 @@
static const char kGrayscaleChecksum[] = "fe45ad56efe868ba82285fa5ffedc0cb";
ASSERT_TRUE(OpenDocument("jpx_lzw.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- TestRenderPageBitmapWithFlags(page, 0, kNormalChecksum);
- TestRenderPageBitmapWithFlags(page, FPDF_ANNOT, kNormalChecksum);
- TestRenderPageBitmapWithFlags(page, FPDF_LCD_TEXT, kNormalChecksum);
- TestRenderPageBitmapWithFlags(page, FPDF_NO_NATIVETEXT, kNormalChecksum);
- TestRenderPageBitmapWithFlags(page, FPDF_GRAYSCALE, kGrayscaleChecksum);
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_LIMITEDIMAGECACHE,
+ TestRenderPageBitmapWithFlags(page.get(), 0, kNormalChecksum);
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_ANNOT, kNormalChecksum);
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_LCD_TEXT, kNormalChecksum);
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_NO_NATIVETEXT,
kNormalChecksum);
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_FORCEHALFTONE,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_GRAYSCALE, kGrayscaleChecksum);
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_LIMITEDIMAGECACHE,
kNormalChecksum);
- TestRenderPageBitmapWithFlags(page, FPDF_PRINTING, kNormalChecksum);
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHTEXT,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_FORCEHALFTONE,
kNormalChecksum);
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHIMAGE,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_PRINTING, kNormalChecksum);
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_NO_SMOOTHTEXT,
kNormalChecksum);
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHPATH,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_NO_SMOOTHIMAGE,
kNormalChecksum);
-
- UnloadPage(page);
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_NO_SMOOTHPATH,
+ kNormalChecksum);
}
TEST_F(FPDFViewEmbedderTest, RenderManyRectanglesWithFlags) {
@@ -1561,33 +1552,34 @@
}();
ASSERT_TRUE(OpenDocument("many_rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- TestRenderPageBitmapWithFlags(page, 0, ManyRectanglesChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_ANNOT, ManyRectanglesChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_LCD_TEXT, ManyRectanglesChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_NO_NATIVETEXT,
+ TestRenderPageBitmapWithFlags(page.get(), 0, ManyRectanglesChecksum());
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_ANNOT,
ManyRectanglesChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_GRAYSCALE, grayscale_checksum);
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_LIMITEDIMAGECACHE,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_LCD_TEXT,
ManyRectanglesChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_FORCEHALFTONE,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_NO_NATIVETEXT,
ManyRectanglesChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_PRINTING, ManyRectanglesChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHTEXT,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_GRAYSCALE, grayscale_checksum);
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_LIMITEDIMAGECACHE,
ManyRectanglesChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHIMAGE,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_FORCEHALFTONE,
ManyRectanglesChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHPATH,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_PRINTING,
+ ManyRectanglesChecksum());
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_NO_SMOOTHTEXT,
+ ManyRectanglesChecksum());
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_NO_SMOOTHIMAGE,
+ ManyRectanglesChecksum());
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_NO_SMOOTHPATH,
no_smoothpath_checksum);
-
- UnloadPage(page);
}
TEST_F(FPDFViewEmbedderTest, RenderManyRectanglesWithAndWithoutExternalMemory) {
ASSERT_TRUE(OpenDocument("many_rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
const char* bgr_checksum = []() {
@@ -1597,11 +1589,13 @@
return "ab6312e04c0d3f4e46fb302a45173d05";
}();
static constexpr int kBgrStride = 600; // Width of 200 * 24 bits per pixel.
- TestRenderPageBitmapWithInternalMemory(page, FPDFBitmap_BGR, bgr_checksum);
- TestRenderPageBitmapWithInternalMemoryAndStride(page, FPDFBitmap_BGR,
+ TestRenderPageBitmapWithInternalMemory(page.get(), FPDFBitmap_BGR,
+ bgr_checksum);
+ TestRenderPageBitmapWithInternalMemoryAndStride(page.get(), FPDFBitmap_BGR,
kBgrStride, bgr_checksum);
- TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_BGR, bgr_checksum);
- TestRenderPageBitmapWithExternalMemoryAndNoStride(page, FPDFBitmap_BGR,
+ TestRenderPageBitmapWithExternalMemory(page.get(), FPDFBitmap_BGR,
+ bgr_checksum);
+ TestRenderPageBitmapWithExternalMemoryAndNoStride(page.get(), FPDFBitmap_BGR,
bgr_checksum);
const char* gray_checksum = []() {
@@ -1611,53 +1605,55 @@
return "b561c11edc44dc3972125a9b8744fa2f";
}();
- TestRenderPageBitmapWithInternalMemory(page, FPDFBitmap_Gray, gray_checksum);
+ TestRenderPageBitmapWithInternalMemory(page.get(), FPDFBitmap_Gray,
+ gray_checksum);
static constexpr int kGrayStride = 200; // Width of 200 * 8 bits per pixel.
- TestRenderPageBitmapWithInternalMemoryAndStride(page, FPDFBitmap_Gray,
+ TestRenderPageBitmapWithInternalMemoryAndStride(page.get(), FPDFBitmap_Gray,
kGrayStride, gray_checksum);
- TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_Gray, gray_checksum);
- TestRenderPageBitmapWithExternalMemoryAndNoStride(page, FPDFBitmap_Gray,
+ TestRenderPageBitmapWithExternalMemory(page.get(), FPDFBitmap_Gray,
+ gray_checksum);
+ TestRenderPageBitmapWithExternalMemoryAndNoStride(page.get(), FPDFBitmap_Gray,
gray_checksum);
static constexpr int kBgrxStride = 800; // Width of 200 * 32 bits per pixel.
- TestRenderPageBitmapWithInternalMemory(page, FPDFBitmap_BGRx,
+ TestRenderPageBitmapWithInternalMemory(page.get(), FPDFBitmap_BGRx,
ManyRectanglesChecksum());
TestRenderPageBitmapWithInternalMemoryAndStride(
- page, FPDFBitmap_BGRx, kBgrxStride, ManyRectanglesChecksum());
- TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_BGRx,
+ page.get(), FPDFBitmap_BGRx, kBgrxStride, ManyRectanglesChecksum());
+ TestRenderPageBitmapWithExternalMemory(page.get(), FPDFBitmap_BGRx,
ManyRectanglesChecksum());
- TestRenderPageBitmapWithExternalMemoryAndNoStride(page, FPDFBitmap_BGRx,
+ TestRenderPageBitmapWithExternalMemoryAndNoStride(page.get(), FPDFBitmap_BGRx,
ManyRectanglesChecksum());
- TestRenderPageBitmapWithInternalMemory(page, FPDFBitmap_BGRA,
+ TestRenderPageBitmapWithInternalMemory(page.get(), FPDFBitmap_BGRA,
ManyRectanglesChecksum());
TestRenderPageBitmapWithInternalMemoryAndStride(
- page, FPDFBitmap_BGRA, kBgrxStride, ManyRectanglesChecksum());
- TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_BGRA,
+ page.get(), FPDFBitmap_BGRA, kBgrxStride, ManyRectanglesChecksum());
+ TestRenderPageBitmapWithExternalMemory(page.get(), FPDFBitmap_BGRA,
ManyRectanglesChecksum());
- TestRenderPageBitmapWithExternalMemoryAndNoStride(page, FPDFBitmap_BGRA,
+ TestRenderPageBitmapWithExternalMemoryAndNoStride(page.get(), FPDFBitmap_BGRA,
ManyRectanglesChecksum());
-
- UnloadPage(page);
}
TEST_F(FPDFViewEmbedderTest, RenderHelloWorldWithFlags) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
using pdfium::HelloWorldChecksum;
- TestRenderPageBitmapWithFlags(page, 0, HelloWorldChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_ANNOT, HelloWorldChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_GRAYSCALE, HelloWorldChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_LIMITEDIMAGECACHE,
+ TestRenderPageBitmapWithFlags(page.get(), 0, HelloWorldChecksum());
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_ANNOT, HelloWorldChecksum());
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_GRAYSCALE,
HelloWorldChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_FORCEHALFTONE,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_LIMITEDIMAGECACHE,
HelloWorldChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_PRINTING, HelloWorldChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHIMAGE,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_FORCEHALFTONE,
HelloWorldChecksum());
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHPATH,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_PRINTING,
+ HelloWorldChecksum());
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_NO_SMOOTHIMAGE,
+ HelloWorldChecksum());
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_NO_SMOOTHPATH,
HelloWorldChecksum());
const char* lcd_text_checksum = []() {
@@ -1693,16 +1689,15 @@
#endif
}();
- TestRenderPageBitmapWithFlags(page, FPDF_LCD_TEXT, lcd_text_checksum);
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHTEXT,
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_LCD_TEXT, lcd_text_checksum);
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_NO_SMOOTHTEXT,
no_smoothtext_checksum);
// For text rendering, When anti-aliasing is disabled, LCD Optimization flag
// will be ignored.
- TestRenderPageBitmapWithFlags(page, FPDF_LCD_TEXT | FPDF_RENDER_NO_SMOOTHTEXT,
+ TestRenderPageBitmapWithFlags(page.get(),
+ FPDF_LCD_TEXT | FPDF_RENDER_NO_SMOOTHTEXT,
no_smoothtext_checksum);
-
- UnloadPage(page);
}
// Deliberately disabled because this test case renders a large bitmap, which is
@@ -1716,32 +1711,29 @@
static const char kChecksum[] = "a6056db6961f4e65c42ab2e246171fe1";
ASSERT_TRUE(OpenDocument("bug_1646.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
constexpr int kWidth = 40000;
constexpr int kHeight = 100;
- TestRenderPageBitmapWithMatrix(page, kWidth, kHeight, {1000, 0, 0, 1, 0, 0},
- {0, 0, kWidth, kHeight}, kChecksum);
-
- UnloadPage(page);
+ TestRenderPageBitmapWithMatrix(page.get(), kWidth, kHeight,
+ {1000, 0, 0, 1, 0, 0}, {0, 0, kWidth, kHeight},
+ kChecksum);
}
#if BUILDFLAG(IS_WIN)
TEST_F(FPDFViewEmbedderTest, FPDFRenderPageEmf) {
ASSERT_TRUE(OpenDocument("rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- std::vector<uint8_t> emf_normal = RenderPageWithFlagsToEmf(page, 0);
+ std::vector<uint8_t> emf_normal = RenderPageWithFlagsToEmf(page.get(), 0);
EXPECT_EQ(3772u, emf_normal.size());
// FPDF_REVERSE_BYTE_ORDER is ignored since EMFs are always BGR.
std::vector<uint8_t> emf_reverse_byte_order =
- RenderPageWithFlagsToEmf(page, FPDF_REVERSE_BYTE_ORDER);
+ RenderPageWithFlagsToEmf(page.get(), FPDF_REVERSE_BYTE_ORDER);
EXPECT_EQ(emf_normal, emf_reverse_byte_order);
-
- UnloadPage(page);
}
class PostScriptRenderEmbedderTestBase : public FPDFViewEmbedderTest {
@@ -1783,36 +1775,32 @@
TEST_F(PostScriptLevel2EmbedderTest, Rectangles) {
ASSERT_TRUE(OpenDocument("rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- std::vector<uint8_t> emf_normal = RenderPageWithFlagsToEmf(page, 0);
+ std::vector<uint8_t> emf_normal = RenderPageWithFlagsToEmf(page.get(), 0);
std::string ps_data = GetPostScriptFromEmf(emf_normal);
EXPECT_EQ(kExpectedRectanglePostScript, ps_data);
// FPDF_REVERSE_BYTE_ORDER is ignored since PostScript is not bitmap-based.
std::vector<uint8_t> emf_reverse_byte_order =
- RenderPageWithFlagsToEmf(page, FPDF_REVERSE_BYTE_ORDER);
+ RenderPageWithFlagsToEmf(page.get(), FPDF_REVERSE_BYTE_ORDER);
EXPECT_EQ(emf_normal, emf_reverse_byte_order);
-
- UnloadPage(page);
}
TEST_F(PostScriptLevel3EmbedderTest, Rectangles) {
ASSERT_TRUE(OpenDocument("rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- std::vector<uint8_t> emf_normal = RenderPageWithFlagsToEmf(page, 0);
+ std::vector<uint8_t> emf_normal = RenderPageWithFlagsToEmf(page.get(), 0);
std::string ps_data = GetPostScriptFromEmf(emf_normal);
EXPECT_EQ(kExpectedRectanglePostScript, ps_data);
// FPDF_REVERSE_BYTE_ORDER is ignored since PostScript is not bitmap-based.
std::vector<uint8_t> emf_reverse_byte_order =
- RenderPageWithFlagsToEmf(page, FPDF_REVERSE_BYTE_ORDER);
+ RenderPageWithFlagsToEmf(page.get(), FPDF_REVERSE_BYTE_ORDER);
EXPECT_EQ(emf_normal, emf_reverse_byte_order);
-
- UnloadPage(page);
}
TEST_F(PostScriptLevel2EmbedderTest, Image) {
@@ -1878,14 +1866,12 @@
"restore\n";
ASSERT_TRUE(OpenDocument("tagged_alt_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- std::vector<uint8_t> emf = RenderPageWithFlagsToEmf(page, 0);
+ std::vector<uint8_t> emf = RenderPageWithFlagsToEmf(page.get(), 0);
std::string ps_data = GetPostScriptFromEmf(emf);
EXPECT_EQ(kExpected, ps_data);
-
- UnloadPage(page);
}
TEST_F(PostScriptLevel3EmbedderTest, Image) {
@@ -1922,32 +1908,29 @@
)";
ASSERT_TRUE(OpenDocument("tagged_alt_text.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- std::vector<uint8_t> emf = RenderPageWithFlagsToEmf(page, 0);
+ std::vector<uint8_t> emf = RenderPageWithFlagsToEmf(page.get(), 0);
std::string ps_data = GetPostScriptFromEmf(emf);
EXPECT_EQ(kExpected, ps_data);
-
- UnloadPage(page);
}
TEST_F(FPDFViewEmbedderTest, ImageMask) {
ASSERT_TRUE(OpenDocument("bug_674771.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Render the page with more efficient processing of image masks.
FPDF_SetPrintMode(FPDF_PRINTMODE_EMF_IMAGE_MASKS);
- std::vector<uint8_t> emf_image_masks = RenderPageWithFlagsToEmf(page, 0);
+ std::vector<uint8_t> emf_image_masks =
+ RenderPageWithFlagsToEmf(page.get(), 0);
// Render the page normally.
FPDF_SetPrintMode(FPDF_PRINTMODE_EMF);
- std::vector<uint8_t> emf_normal = RenderPageWithFlagsToEmf(page, 0);
+ std::vector<uint8_t> emf_normal = RenderPageWithFlagsToEmf(page.get(), 0);
EXPECT_LT(emf_image_masks.size(), emf_normal.size());
-
- UnloadPage(page);
}
#endif // BUILDFLAG(IS_WIN)
@@ -2037,13 +2020,12 @@
TEST_F(FPDFViewEmbedderTest, RenderXfaPage) {
ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Should always be blank, as we're not testing `FPDF_FFLDraw()` here.
- TestRenderPageBitmapWithFlags(page, 0, pdfium::kBlankPage612By792Checksum);
-
- UnloadPage(page);
+ TestRenderPageBitmapWithFlags(page.get(), 0,
+ pdfium::kBlankPage612By792Checksum);
}
#if defined(PDF_USE_SKIA)
@@ -2054,12 +2036,10 @@
ASSERT_TRUE(OpenDocument("rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
- TestRenderPageSkp(page, pdfium::RectanglesChecksum());
-
- UnloadPage(page);
+ TestRenderPageSkp(page.get(), pdfium::RectanglesChecksum());
}
TEST_F(FPDFViewEmbedderTest, RenderXfaPageToSkp) {
@@ -2069,13 +2049,11 @@
ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
// Should always be blank, as we're not testing `FPDF_FFLRecord()` here.
- TestRenderPageSkp(page, pdfium::kBlankPage612By792Checksum);
-
- UnloadPage(page);
+ TestRenderPageSkp(page.get(), pdfium::kBlankPage612By792Checksum);
}
TEST_F(FPDFViewEmbedderTest, Bug2087) {
@@ -2091,14 +2069,13 @@
.m_RendererType = FPDF_RENDERERTYPE_AGG,
};
FPDF_InitLibraryWithConfig(&kAggConfig);
+ ASSERT_TRUE(OpenDocument("rectangles.pdf"));
{
- ASSERT_TRUE(OpenDocument("rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
- ScopedFPDFBitmap bitmap = RenderPage(page);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
+ ScopedFPDFBitmap bitmap = RenderPage(page.get());
agg_checksum = HashBitmap(bitmap.get());
- UnloadPage(page);
- CloseDocument();
}
+ CloseDocument();
FPDF_DestroyLibrary();
std::string skia_checksum;
@@ -2109,14 +2086,13 @@
.m_v8EmbedderSlot = 0,
};
FPDF_InitLibraryWithConfig(&kSkiaConfig);
+ ASSERT_TRUE(OpenDocument("rectangles.pdf"));
{
- ASSERT_TRUE(OpenDocument("rectangles.pdf"));
- FPDF_PAGE page = LoadPage(0);
- ScopedFPDFBitmap bitmap = RenderPage(page);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
+ ScopedFPDFBitmap bitmap = RenderPage(page.get());
skia_checksum = HashBitmap(bitmap.get());
- UnloadPage(page);
- CloseDocument();
}
+ CloseDocument();
EXPECT_NE(agg_checksum, skia_checksum);
@@ -2127,7 +2103,7 @@
TEST_F(FPDFViewEmbedderTest, NoSmoothTextItalicOverlappingGlyphs) {
ASSERT_TRUE(OpenDocument("bug_1919.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
const char* checksum = []() {
@@ -2143,8 +2119,8 @@
return "5f99e2fa2bad09393d6428e105a83c96";
}();
- TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHTEXT, checksum);
- UnloadPage(page);
+ TestRenderPageBitmapWithFlags(page.get(), FPDF_RENDER_NO_SMOOTHTEXT,
+ checksum);
}
TEST_F(FPDFViewEmbedderTest, RenderTransparencyOnWhiteBackground) {
diff --git a/fxjs/cjs_publicmethods_embeddertest.cpp b/fxjs/cjs_publicmethods_embeddertest.cpp
index 121896e..505dcf9 100644
--- a/fxjs/cjs_publicmethods_embeddertest.cpp
+++ b/fxjs/cjs_publicmethods_embeddertest.cpp
@@ -187,7 +187,7 @@
v8::Context::Scope context_scope(GetV8Context());
ASSERT_TRUE(OpenDocument("calculate.pdf"));
- auto* page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
CJS_Runtime runtime(
@@ -206,7 +206,6 @@
params.push_back(ary);
CJS_Result ret = CJS_PublicMethods::AFSimple_Calculate(&runtime, params);
- UnloadPage(page);
runtime.GetCurrentEventContext()->SetValueForTest(nullptr);
@@ -221,7 +220,7 @@
v8::Context::Scope context_scope(GetV8Context());
ASSERT_TRUE(OpenDocument("calculate.pdf"));
- auto* page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
ASSERT_TRUE(page);
CJS_Runtime runtime(
@@ -251,7 +250,6 @@
EXPECT_TRUE(!ret.HasError());
EXPECT_TRUE(!ret.HasReturn());
- UnloadPage(page);
// Keep the *SAN bots happy. One of these is an UnownedPtr, another seems to
// used during destruction. Clear them all to be safe and consistent.
diff --git a/xfa/fxfa/layout/cxfa_layoutitem_embeddertest.cpp b/xfa/fxfa/layout/cxfa_layoutitem_embeddertest.cpp
index feb24de..8831a68 100644
--- a/xfa/fxfa/layout/cxfa_layoutitem_embeddertest.cpp
+++ b/xfa/fxfa/layout/cxfa_layoutitem_embeddertest.cpp
@@ -9,43 +9,37 @@
TEST_F(CXFALayoutItemEmbedderTest, Bug1265) {
ASSERT_TRUE(OpenDocument("bug_1265.pdf"));
- FPDF_PAGE page0 = LoadPage(0);
- FPDF_PAGE page1 = LoadPage(1);
- EXPECT_TRUE(page0);
- EXPECT_FALSE(page1);
- UnloadPage(page0);
+ ScopedEmbedderTestPage page0 = LoadScopedPage(0);
+ ScopedEmbedderTestPage page1 = LoadScopedPage(1);
+ EXPECT_TRUE(page0.get());
+ EXPECT_FALSE(page1.get());
}
TEST_F(CXFALayoutItemEmbedderTest, Bug1301) {
ASSERT_TRUE(OpenDocument("bug_1301.pdf"));
- FPDF_PAGE page0 = LoadPage(0);
- FPDF_PAGE page1 = LoadPage(1);
- FPDF_PAGE page2 = LoadPage(2);
- EXPECT_TRUE(page0);
- EXPECT_TRUE(page1);
- EXPECT_FALSE(page2);
- UnloadPage(page0);
- UnloadPage(page1);
+ ScopedEmbedderTestPage page0 = LoadScopedPage(0);
+ ScopedEmbedderTestPage page1 = LoadScopedPage(1);
+ ScopedEmbedderTestPage page2 = LoadScopedPage(2);
+ EXPECT_TRUE(page0.get());
+ EXPECT_TRUE(page1.get());
+ EXPECT_FALSE(page2.get());
}
TEST_F(CXFALayoutItemEmbedderTest, Bug306123) {
ASSERT_TRUE(OpenDocument("bug_306123.pdf"));
- FPDF_PAGE page0 = LoadPage(0);
- FPDF_PAGE page1 = LoadPage(1);
- FPDF_PAGE page2 = LoadPage(2);
- EXPECT_TRUE(page0);
- EXPECT_TRUE(page1);
- EXPECT_FALSE(page2);
- UnloadPage(page0);
- UnloadPage(page1);
+ ScopedEmbedderTestPage page0 = LoadScopedPage(0);
+ ScopedEmbedderTestPage page1 = LoadScopedPage(1);
+ ScopedEmbedderTestPage page2 = LoadScopedPage(2);
+ EXPECT_TRUE(page0.get());
+ EXPECT_TRUE(page1.get());
+ EXPECT_FALSE(page2.get());
}
TEST_F(CXFALayoutItemEmbedderTest, BreakBeforeAfter) {
static constexpr int kExpectedPageCount = 10;
ASSERT_TRUE(OpenDocument("xfa/xfa_break_before_after.pdf"));
for (int i = 0; i < kExpectedPageCount; ++i) {
- FPDF_PAGE page = LoadPage(i);
+ ScopedEmbedderTestPage page = LoadScopedPage(i);
EXPECT_TRUE(page);
- UnloadPage(page);
}
}
diff --git a/xfa/fxfa/parser/cxfa_document_builder_embeddertest.cpp b/xfa/fxfa/parser/cxfa_document_builder_embeddertest.cpp
index dea2d73..0c28bb3 100644
--- a/xfa/fxfa/parser/cxfa_document_builder_embeddertest.cpp
+++ b/xfa/fxfa/parser/cxfa_document_builder_embeddertest.cpp
@@ -9,14 +9,12 @@
TEST_F(CXFASimpleParserEmbedderTest, Bug216) {
ASSERT_TRUE(OpenDocument("bug_216.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- UnloadPage(page);
}
TEST_F(CXFASimpleParserEmbedderTest, Bug709793) {
ASSERT_TRUE(OpenDocument("bug_709793.pdf"));
- FPDF_PAGE page = LoadPage(0);
+ ScopedEmbedderTestPage page = LoadScopedPage(0);
EXPECT_TRUE(page);
- UnloadPage(page);
}