summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-07-05 11:55:35 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-05 17:08:57 +0000
commit3ff54008a163eea3158a7c107595daf79ccc7d44 (patch)
treef460b4f50863e65922799970208bf93bd845a7d8 /fpdfsdk
parentfb00ec2af390ccfe8f5e81f49b9113e044f5e5ad (diff)
downloadpdfium-3ff54008a163eea3158a7c107595daf79ccc7d44.tar.xz
Allow EmbedderTest to test saving
This CL adds helper methods for EmbedderTest to save. This means that TestSaver is no longer needed and all the methods it uses are moved to the EmbedderTest. Change-Id: I740f29699bfd8c6b570cb1fd85e7aab9bc1d3f6f Reviewed-on: https://pdfium-review.googlesource.com/7171 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdf_dataavail_embeddertest.cpp8
-rw-r--r--fpdfsdk/fpdf_structtree_embeddertest.cpp2
-rw-r--r--fpdfsdk/fpdfannot_embeddertest.cpp47
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp67
-rw-r--r--fpdfsdk/fpdfformfill.cpp1
-rw-r--r--fpdfsdk/fpdfformfill_embeddertest.cpp21
-rw-r--r--fpdfsdk/fpdfppo_embeddertest.cpp1
-rw-r--r--fpdfsdk/fpdfsave_embeddertest.cpp2
8 files changed, 38 insertions, 111 deletions
diff --git a/fpdfsdk/fpdf_dataavail_embeddertest.cpp b/fpdfsdk/fpdf_dataavail_embeddertest.cpp
index c226a31b8e..8f37984c9b 100644
--- a/fpdfsdk/fpdf_dataavail_embeddertest.cpp
+++ b/fpdfsdk/fpdf_dataavail_embeddertest.cpp
@@ -194,9 +194,9 @@ TEST_F(FPDFDataAvailEmbeddertest, LoadUsingHintTables) {
// No new data available, to prevent load "Pages" node.
loader.set_is_new_data_available(false);
- FPDF_PAGE page = LoadPage(1);
+ FPDF_PAGE page = FPDF_LoadPage(document(), 1);
EXPECT_TRUE(page);
- UnloadPage(page);
+ FPDF_ClosePage(page);
}
TEST_F(FPDFDataAvailEmbeddertest,
@@ -234,7 +234,7 @@ TEST_F(FPDFDataAvailEmbeddertest,
// Prevent loading data, while page loading.
loader.set_is_new_data_available(false);
- FPDF_PAGE page = LoadPage(first_page_num);
+ FPDF_PAGE page = FPDF_LoadPage(document(), first_page_num);
EXPECT_TRUE(page);
- UnloadPage(page);
+ FPDF_ClosePage(page);
}
diff --git a/fpdfsdk/fpdf_structtree_embeddertest.cpp b/fpdfsdk/fpdf_structtree_embeddertest.cpp
index 3110988d82..43a4d0159f 100644
--- a/fpdfsdk/fpdf_structtree_embeddertest.cpp
+++ b/fpdfsdk/fpdf_structtree_embeddertest.cpp
@@ -7,7 +7,7 @@
#include "testing/embedder_test.h"
#include "testing/test_support.h"
-class FPDFStructTreeEmbeddertest : public EmbedderTest, public TestSaver {};
+class FPDFStructTreeEmbeddertest : public EmbedderTest {};
TEST_F(FPDFStructTreeEmbeddertest, GetAltText) {
ASSERT_TRUE(OpenDocument("tagged_alt_text.pdf"));
diff --git a/fpdfsdk/fpdfannot_embeddertest.cpp b/fpdfsdk/fpdfannot_embeddertest.cpp
index c08460e745..6c56c06396 100644
--- a/fpdfsdk/fpdfannot_embeddertest.cpp
+++ b/fpdfsdk/fpdfannot_embeddertest.cpp
@@ -13,7 +13,7 @@
#include "testing/embedder_test.h"
#include "testing/gtest/include/gtest/gtest.h"
-class FPDFAnnotEmbeddertest : public EmbedderTest, public TestSaver {};
+class FPDFAnnotEmbeddertest : public EmbedderTest {};
TEST_F(FPDFAnnotEmbeddertest, RenderAnnotWithOnlyRolloverAP) {
// Open a file with one annotation and load its first page.
@@ -25,7 +25,7 @@ TEST_F(FPDFAnnotEmbeddertest, RenderAnnotWithOnlyRolloverAP) {
// normal appearance defined, only its rollover appearance. In this case, its
// normal appearance should be generated, allowing the highlight annotation to
// still display.
- FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
+ FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle(), FPDF_ANNOT);
CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
FPDFBitmap_Destroy(bitmap);
@@ -279,23 +279,15 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) {
FPDF_ClosePage(page);
// Open the saved document.
- std::string new_file = GetString();
- FPDF_FILEACCESS file_access;
- memset(&file_access, 0, sizeof(file_access));
- file_access.m_FileLen = new_file.size();
- file_access.m_GetBlock = GetBlockFromString;
- file_access.m_Param = &new_file;
- FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr);
- ASSERT_TRUE(new_doc);
- FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0);
- ASSERT_TRUE(new_page);
+ const char md5[] = "184b67b322edaee27994b3232544b8b3";
+ TestSaved(612, 792, md5);
// Check that the saved document has 2 annotations on the first page
- EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(m_SavedPage));
// Check that the second annotation is an underline annotation and verify
// its quadpoints.
- FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(new_page, 1);
+ FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(m_SavedPage, 1);
ASSERT_TRUE(new_annot);
EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot));
FS_QUADPOINTSF new_quadpoints = FPDFAnnot_GetAttachmentPoints(new_annot);
@@ -305,8 +297,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) {
EXPECT_NEAR(quadpoints.y4, new_quadpoints.y4, 0.001f);
FPDFPage_CloseAnnot(new_annot);
- FPDF_ClosePage(new_page);
- FPDF_CloseDocument(new_doc);
+ CloseSaved();
}
TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) {
@@ -433,6 +424,7 @@ TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) {
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
FPDF_ClosePage(page);
+ // TODO(npm): TestSaved changes annot rect dimensions by 1??
// Open the saved document.
std::string new_file = GetString();
FPDF_FILEACCESS file_access;
@@ -545,20 +537,11 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) {
FPDF_ClosePage(page);
// Open the saved document.
- std::string new_file = GetString();
- FPDF_FILEACCESS file_access;
- memset(&file_access, 0, sizeof(file_access));
- file_access.m_FileLen = new_file.size();
- file_access.m_GetBlock = GetBlockFromString;
- file_access.m_Param = &new_file;
- FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr);
- ASSERT_TRUE(new_doc);
- FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0);
- ASSERT_TRUE(new_page);
+ TestSaved(595, 842, md5_3);
// Check that the saved document has a correct count of annotations and paths.
- EXPECT_EQ(3, FPDFPage_GetAnnotCount(new_page));
- annot = FPDFPage_GetAnnot(new_page, 2);
+ EXPECT_EQ(3, FPDFPage_GetAnnotCount(m_SavedPage));
+ annot = FPDFPage_GetAnnot(m_SavedPage, 2);
ASSERT_TRUE(annot);
EXPECT_EQ(1, FPDFAnnot_GetPathObjectCount(annot));
@@ -569,12 +552,6 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) {
EXPECT_EQ(rect.right, new_rect.right);
EXPECT_EQ(rect.top, new_rect.top);
- // Check that the saved page renders correctly.
- bitmap = RenderPageWithFlags(new_page, nullptr, FPDF_ANNOT);
- CompareBitmap(bitmap, 595, 842, md5_3);
- FPDFBitmap_Destroy(bitmap);
-
FPDFPage_CloseAnnot(annot);
- FPDF_ClosePage(new_page);
- FPDF_CloseDocument(new_doc);
+ CloseSaved();
}
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index c527f08168..a461f37440 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -23,7 +23,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"
-class FPDFEditEmbeddertest : public EmbedderTest, public TestSaver {
+class FPDFEditEmbeddertest : public EmbedderTest {
protected:
FPDF_DOCUMENT CreateNewDocument() {
document_ = FPDF_CreateNewDocument();
@@ -120,26 +120,6 @@ class FPDFEditEmbeddertest : public EmbedderTest, public TestSaver {
}
CPDF_Document* cpdf_doc() { return cpdf_doc_; }
- void TestSaved(int width, int height, const char* md5) {
- std::string new_file = GetString();
- // Read |new_file| in, and verify its rendered bitmap.
- FPDF_FILEACCESS file_access;
- memset(&file_access, 0, sizeof(file_access));
- file_access.m_FileLen = new_file.size();
- file_access.m_GetBlock = GetBlockFromString;
- file_access.m_Param = &new_file;
-
- FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr);
- EXPECT_EQ(1, FPDF_GetPageCount(document_));
- FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0);
- EXPECT_NE(nullptr, new_page);
- FPDF_BITMAP new_bitmap = RenderPage(new_page);
- CompareBitmap(new_bitmap, width, height, md5);
- FPDFBitmap_Destroy(new_bitmap);
- FPDF_ClosePage(new_page);
- FPDF_CloseDocument(new_doc);
- }
-
private:
CPDF_Document* cpdf_doc_;
};
@@ -235,7 +215,7 @@ TEST_F(FPDFEditEmbeddertest, RasterizePDF) {
// Get the generated content. Make sure it is at least as big as the original
// PDF.
EXPECT_GT(GetString().size(), 923U);
- TestSaved(612, 792, kAllBlackMd5sum);
+ TestAndCloseSaved(612, 792, kAllBlackMd5sum);
}
TEST_F(FPDFEditEmbeddertest, AddPaths) {
@@ -315,7 +295,7 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) {
FPDF_ClosePage(page);
// Render the saved result
- TestSaved(612, 792, last_md5);
+ TestAndCloseSaved(612, 792, last_md5);
}
TEST_F(FPDFEditEmbeddertest, PathOnTopOfText) {
@@ -376,50 +356,35 @@ TEST_F(FPDFEditEmbeddertest, EditOverExistingContent) {
// Now save the result, closing the page and document
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- FPDF_ClosePage(page);
+ UnloadPage(page);
- // Render the saved result. Not calling TestSaved because we don't want to
- // close the page and document yet.
- std::string new_file = GetString();
- FPDF_FILEACCESS file_access;
- memset(&file_access, 0, sizeof(file_access));
- file_access.m_FileLen = new_file.size();
- file_access.m_GetBlock = GetBlockFromString;
- file_access.m_Param = &new_file;
- FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr);
- ASSERT_NE(nullptr, new_doc);
- EXPECT_EQ(1, FPDF_GetPageCount(new_doc));
- FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0);
- ASSERT_NE(nullptr, new_page);
- FPDF_BITMAP new_bitmap = RenderPage(new_page);
- CompareBitmap(new_bitmap, 612, 792, "ad04e5bd0f471a9a564fb034bd0fb073");
- FPDFBitmap_Destroy(new_bitmap);
+ // Render the saved result without closing the page and document
+ TestSaved(612, 792, "ad04e5bd0f471a9a564fb034bd0fb073");
ClearString();
// Add another opaque rectangle on top of the existing content
FPDF_PAGEOBJECT green_rect = FPDFPageObj_CreateNewRect(150, 700, 25, 50);
EXPECT_TRUE(FPDFPath_SetFillColor(green_rect, 0, 255, 0, 255));
EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect, FPDF_FILLMODE_ALTERNATE, 0));
- FPDFPage_InsertObject(new_page, green_rect);
+ FPDFPage_InsertObject(m_SavedPage, green_rect);
// Add another transparent rectangle on top of existing content
FPDF_PAGEOBJECT green_rect2 = FPDFPageObj_CreateNewRect(175, 700, 25, 50);
EXPECT_TRUE(FPDFPath_SetFillColor(green_rect2, 0, 255, 0, 100));
EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect2, FPDF_FILLMODE_ALTERNATE, 0));
- FPDFPage_InsertObject(new_page, green_rect2);
- new_bitmap = RenderPage(new_page);
+ FPDFPage_InsertObject(m_SavedPage, green_rect2);
+ FPDF_BITMAP new_bitmap = RenderPageWithFlags(m_SavedPage, m_SavedForm, 0);
const char last_md5[] = "4b5b00f824620f8c9b8801ebb98e1cdd";
CompareBitmap(new_bitmap, 612, 792, last_md5);
FPDFBitmap_Destroy(new_bitmap);
- EXPECT_TRUE(FPDFPage_GenerateContent(new_page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(m_SavedPage));
// Now save the result, closing the page and document
- EXPECT_TRUE(FPDF_SaveAsCopy(new_doc, this, 0));
- FPDF_ClosePage(new_page);
- FPDF_CloseDocument(new_doc);
+ EXPECT_TRUE(FPDF_SaveAsCopy(m_SavedDocument, this, 0));
+ CloseSaved();
// Render the saved result
- TestSaved(612, 792, last_md5);
+ TestAndCloseSaved(612, 792, last_md5);
}
TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) {
@@ -852,7 +817,7 @@ TEST_F(FPDFEditEmbeddertest, AddTrueTypeFontText) {
EXPECT_TRUE(FPDFPage_GenerateContent(page));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
FPDF_ClosePage(page);
- TestSaved(612, 792, md5_2);
+ TestAndCloseSaved(612, 792, md5_2);
}
TEST_F(FPDFEditEmbeddertest, TransformAnnot) {
@@ -926,7 +891,7 @@ TEST_F(FPDFEditEmbeddertest, AddCIDFontText) {
EXPECT_TRUE(FPDFPage_GenerateContent(page));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
FPDF_ClosePage(page);
- TestSaved(612, 792, md5);
+ TestAndCloseSaved(612, 792, md5);
}
#endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_
@@ -958,5 +923,5 @@ TEST_F(FPDFEditEmbeddertest, SaveAndRender) {
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
UnloadPage(page);
}
- TestSaved(612, 792, md5);
+ TestAndCloseSaved(612, 792, md5);
}
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index 12feb791be..6f63f0e2fa 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -278,7 +278,6 @@ FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
if (pFormFillEnv->GetXFAContext())
pFormFillEnv->GetXFAContext()->SetFormFillEnv(nullptr);
#endif // PDF_ENABLE_XFA
-
delete pFormFillEnv;
}
diff --git a/fpdfsdk/fpdfformfill_embeddertest.cpp b/fpdfsdk/fpdfformfill_embeddertest.cpp
index 7779ed25a7..83e560a60c 100644
--- a/fpdfsdk/fpdfformfill_embeddertest.cpp
+++ b/fpdfsdk/fpdfformfill_embeddertest.cpp
@@ -20,7 +20,7 @@
using testing::_;
using testing::Return;
-class FPDFFormFillEmbeddertest : public EmbedderTest, public TestSaver {
+class FPDFFormFillEmbeddertest : public EmbedderTest {
protected:
void TypeTextIntoTextfield(FPDF_PAGE page,
int num_chars,
@@ -366,26 +366,11 @@ TEST_F(FPDFFormFillEmbeddertest, FormText) {
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
- // Close everything
+ // Close page
UnloadPage(page);
- FPDFDOC_ExitFormFillEnvironment(form_handle_);
- FPDF_CloseDocument(document_);
}
// Check saved document
- std::string new_file = GetString();
- FPDF_FILEACCESS file_access;
- memset(&file_access, 0, sizeof(file_access));
- file_access.m_FileLen = new_file.size();
- file_access.m_GetBlock = GetBlockFromString;
- file_access.m_Param = &new_file;
- document_ = FPDF_LoadCustomDocument(&file_access, nullptr);
- SetupFormFillEnvironment();
- EXPECT_EQ(1, FPDF_GetPageCount(document_));
- std::unique_ptr<void, FPDFPageDeleter> new_page(FPDF_LoadPage(document_, 0));
- ASSERT_TRUE(new_page.get());
- std::unique_ptr<void, FPDFBitmapDeleter> new_bitmap(
- RenderPage(new_page.get()));
- CompareBitmap(new_bitmap.get(), 300, 300, md5_3);
+ TestAndCloseSaved(300, 300, md5_3);
}
TEST_F(FPDFFormFillEmbeddertest, GetSelectedTextEmptyAndBasicKeyboard) {
diff --git a/fpdfsdk/fpdfppo_embeddertest.cpp b/fpdfsdk/fpdfppo_embeddertest.cpp
index 7e6ff33fc3..b6b9167f10 100644
--- a/fpdfsdk/fpdfppo_embeddertest.cpp
+++ b/fpdfsdk/fpdfppo_embeddertest.cpp
@@ -6,6 +6,7 @@
#include "core/fxcrt/fx_basic.h"
#include "public/fpdf_edit.h"
#include "public/fpdf_ppo.h"
+#include "public/fpdf_save.h"
#include "public/fpdfview.h"
#include "testing/embedder_test.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/fpdfsdk/fpdfsave_embeddertest.cpp b/fpdfsdk/fpdfsave_embeddertest.cpp
index e5d05c98df..260fe0c2a6 100644
--- a/fpdfsdk/fpdfsave_embeddertest.cpp
+++ b/fpdfsdk/fpdfsave_embeddertest.cpp
@@ -15,7 +15,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"
-class FPDFSaveEmbedderTest : public EmbedderTest, public TestSaver {};
+class FPDFSaveEmbedderTest : public EmbedderTest {};
TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) {
EXPECT_TRUE(OpenDocument("hello_world.pdf"));