diff options
author | Nicolas Pena <npm@chromium.org> | 2017-06-29 11:01:46 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-29 15:15:40 +0000 |
commit | a0b48aa8043be95e5c6b602e0e261fb163282536 (patch) | |
tree | 7b7bf875387f7b0bc2beba8bfec91f43e47cbc08 /fpdfsdk/fpdfedit_embeddertest.cpp | |
parent | 580c159e8b8b1d38454f98276a57caf1acce98e6 (diff) | |
download | pdfium-a0b48aa8043be95e5c6b602e0e261fb163282536.tar.xz |
Add TestSaved helper method in FPDFEditEmbeddertest
The saving testing is used in multiple methods. This CL adds a helper
to reduce duplicated code.
Change-Id: I5a36d41b5fc03a63092eaf642c3461695b5b9805
Reviewed-on: https://pdfium-review.googlesource.com/7091
Commit-Queue: Nicolás Peña <npm@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfedit_embeddertest.cpp')
-rw-r--r-- | fpdfsdk/fpdfedit_embeddertest.cpp | 147 |
1 files changed, 35 insertions, 112 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index 727306a96e..c527f08168 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -120,6 +120,26 @@ 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_; }; @@ -214,27 +234,8 @@ TEST_F(FPDFEditEmbeddertest, RasterizePDF) { // Get the generated content. Make sure it is at least as big as the original // PDF. - std::string new_file = GetString(); - EXPECT_GT(new_file.size(), 923U); - - // 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, 612, 792, kAllBlackMd5sum); - FPDF_ClosePage(new_page); - FPDF_CloseDocument(new_doc); - FPDFBitmap_Destroy(new_bitmap); - } + EXPECT_GT(GetString().size(), 923U); + TestSaved(612, 792, kAllBlackMd5sum); } TEST_F(FPDFEditEmbeddertest, AddPaths) { @@ -304,31 +305,17 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) { EXPECT_TRUE(FPDFPath_Close(blue_path)); FPDFPage_InsertObject(page, blue_path); page_bitmap = RenderPage(page); - CompareBitmap(page_bitmap, 612, 792, "9823e1a21bd9b72b6a442ba4f12af946"); + const char last_md5[] = "9823e1a21bd9b72b6a442ba4f12af946"; + CompareBitmap(page_bitmap, 612, 792, last_md5); FPDFBitmap_Destroy(page_bitmap); // Now save the result, closing the page and document EXPECT_TRUE(FPDFPage_GenerateContent(page)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); FPDF_ClosePage(page); - std::string new_file = GetString(); // Render the saved result - 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, "9823e1a21bd9b72b6a442ba4f12af946"); - FPDFBitmap_Destroy(new_bitmap); - FPDF_ClosePage(new_page); - FPDF_CloseDocument(new_doc); + TestSaved(612, 792, last_md5); } TEST_F(FPDFEditEmbeddertest, PathOnTopOfText) { @@ -391,7 +378,8 @@ TEST_F(FPDFEditEmbeddertest, EditOverExistingContent) { EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); FPDF_ClosePage(page); - // Render the saved result + // 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)); @@ -420,7 +408,8 @@ TEST_F(FPDFEditEmbeddertest, EditOverExistingContent) { EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect2, FPDF_FILLMODE_ALTERNATE, 0)); FPDFPage_InsertObject(new_page, green_rect2); new_bitmap = RenderPage(new_page); - CompareBitmap(new_bitmap, 612, 792, "4b5b00f824620f8c9b8801ebb98e1cdd"); + const char last_md5[] = "4b5b00f824620f8c9b8801ebb98e1cdd"; + CompareBitmap(new_bitmap, 612, 792, last_md5); FPDFBitmap_Destroy(new_bitmap); EXPECT_TRUE(FPDFPage_GenerateContent(new_page)); @@ -430,22 +419,7 @@ TEST_F(FPDFEditEmbeddertest, EditOverExistingContent) { FPDF_CloseDocument(new_doc); // Render the saved result - new_file = GetString(); - 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; - new_doc = FPDF_LoadCustomDocument(&file_access, nullptr); - ASSERT_NE(nullptr, new_doc); - EXPECT_EQ(1, FPDF_GetPageCount(new_doc)); - new_page = FPDF_LoadPage(new_doc, 0); - ASSERT_NE(nullptr, new_page); - new_bitmap = RenderPage(new_page); - CompareBitmap(new_bitmap, 612, 792, "4b5b00f824620f8c9b8801ebb98e1cdd"); - FPDFBitmap_Destroy(new_bitmap); - - FPDF_ClosePage(new_page); - FPDF_CloseDocument(new_doc); + TestSaved(612, 792, last_md5); } TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) { @@ -878,24 +852,7 @@ TEST_F(FPDFEditEmbeddertest, AddTrueTypeFontText) { EXPECT_TRUE(FPDFPage_GenerateContent(page)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); FPDF_ClosePage(page); - std::string new_file = GetString(); - - // Render the saved result - 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, md5_2); - FPDFBitmap_Destroy(new_bitmap); - FPDF_ClosePage(new_page); - FPDF_CloseDocument(new_doc); + TestSaved(612, 792, md5_2); } TEST_F(FPDFEditEmbeddertest, TransformAnnot) { @@ -969,29 +926,12 @@ TEST_F(FPDFEditEmbeddertest, AddCIDFontText) { EXPECT_TRUE(FPDFPage_GenerateContent(page)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); FPDF_ClosePage(page); - std::string new_file = GetString(); - - // Render the saved result - 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, md5); - FPDFBitmap_Destroy(new_bitmap); - FPDF_ClosePage(new_page); - FPDF_CloseDocument(new_doc); + TestSaved(612, 792, md5); } #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ TEST_F(FPDFEditEmbeddertest, SaveAndRender) { - const char embMD5[] = "3c20472b0552c0c22b88ab1ed8c6202b"; + const char md5[] = "3c20472b0552c0c22b88ab1ed8c6202b"; { EXPECT_TRUE(OpenDocument("bug_779.pdf")); FPDF_PAGE page = LoadPage(0); @@ -1010,7 +950,7 @@ TEST_F(FPDFEditEmbeddertest, SaveAndRender) { EXPECT_TRUE(FPDFPath_Close(green_path)); FPDFPage_InsertObject(page, green_path); FPDF_BITMAP page_bitmap = RenderPage(page); - CompareBitmap(page_bitmap, 612, 792, embMD5); + CompareBitmap(page_bitmap, 612, 792, md5); FPDFBitmap_Destroy(page_bitmap); // Now save the result, closing the page and document @@ -1018,22 +958,5 @@ TEST_F(FPDFEditEmbeddertest, SaveAndRender) { EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); UnloadPage(page); } - - // Render the saved result - 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, embMD5); - FPDFBitmap_Destroy(new_bitmap); - FPDF_ClosePage(new_page); - FPDF_CloseDocument(new_doc); + TestSaved(612, 792, md5); } |