diff options
author | Henrique Nakashima <hnakashima@chromium.org> | 2018-04-16 20:58:47 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-16 20:58:47 +0000 |
commit | c49e62e40ed87cdcab08b8975b7822727ba9dd72 (patch) | |
tree | a111530d85d0b55bd905334e2ba88c71e807c0ff /fpdfsdk | |
parent | 33906880888288fa552137fb43bf21bdc19cb187 (diff) | |
download | pdfium-c49e62e40ed87cdcab08b8975b7822727ba9dd72.tar.xz |
Add test for saving after adding or removing page objects.
pdfium:1051 reported an issue with saving after calling
FPDFPage_RemoveObject. This test reproduces the issue.
It is left disabled since it's failing.
Bug: pdfium:1051
Change-Id: I238a95e8ea7cf5f0cee7f06419f5468f3208c939
Reviewed-on: https://pdfium-review.googlesource.com/30800
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdf_edit_embeddertest.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index 074bb40592..80191556f3 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -509,6 +509,65 @@ TEST_F(FPDFEditEmbeddertest, RemoveMarkedObjectsPrime) { UnloadPage(page); } +// Fails due to pdfium:1051. +TEST_F(FPDFEditEmbeddertest, DISABLED_RemoveExistingPageObject) { + // Load document with some text. + EXPECT_TRUE(OpenDocument("hello_world.pdf")); + FPDF_PAGE page = LoadPage(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_TRUE(page_object); + EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object)); + + // Verify the "Hello, world!" text is gone. + ASSERT_EQ(1, FPDFPage_CountObjects(page)); + + // Save the file + EXPECT_TRUE(FPDFPage_GenerateContent(page)); + 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. + OpenSavedDocument(); + FPDF_PAGE saved_page = LoadSavedPage(0); + EXPECT_EQ(1, FPDFPage_CountObjects(saved_page)); + CloseSavedPage(saved_page); + CloseSavedDocument(); +} + +TEST_F(FPDFEditEmbeddertest, InsertPageObjectAndSave) { + // Load document with some text. + EXPECT_TRUE(OpenDocument("hello_world.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Add a red rectangle. + ASSERT_EQ(2, FPDFPage_CountObjects(page)); + FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(20, 100, 50, 50); + EXPECT_TRUE(FPDFPath_SetFillColor(red_rect, 255, 0, 0, 255)); + EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); + FPDFPage_InsertObject(page, red_rect); + + // Verify the red rectangle was added. + ASSERT_EQ(3, FPDFPage_CountObjects(page)); + + // Save the file + EXPECT_TRUE(FPDFPage_GenerateContent(page)); + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + UnloadPage(page); + + // Re-open the file and check the page object count is still 3. + OpenSavedDocument(); + FPDF_PAGE saved_page = LoadSavedPage(0); + EXPECT_EQ(3, FPDFPage_CountObjects(saved_page)); + CloseSavedPage(saved_page); + CloseSavedDocument(); +} + TEST_F(FPDFEditEmbeddertest, AddAndRemovePaths) { // Start with a blank page. FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792); |