From 742977f943b30638427d1ef6532acbc3d1c36bff Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Thu, 13 Apr 2017 15:28:20 -0400 Subject: Add embeddertest for form text rendering and saving MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL adds an embeddertest that adds text to a textfield and saves it. It also adds a new 'charcode' option for .evt files in pdfium_test. Change-Id: I14fbf50e2b1d5ae0bdc68d1dd25dc4f889c49bfb Reviewed-on: https://pdfium-review.googlesource.com/4150 Commit-Queue: Nicolás Peña Commit-Queue: dsinclair Reviewed-by: Tom Sepez Reviewed-by: dsinclair --- fpdfsdk/fpdfedit_embeddertest.cpp | 16 -------- fpdfsdk/fpdfformfill_embeddertest.cpp | 69 ++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 17 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index 6454c34df1..952564db49 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -164,22 +164,6 @@ const char kExpectedPDF[] = "379\r\n" "%%EOF\r\n"; -int GetBlockFromString(void* param, - unsigned long pos, - unsigned char* buf, - unsigned long size) { - std::string* new_file = static_cast(param); - if (!new_file || pos + size < pos) - return 0; - - unsigned long file_size = new_file->size(); - if (pos + size > file_size) - return 0; - - memcpy(buf, new_file->data() + pos, size); - return 1; -} - } // namespace TEST_F(FPDFEditEmbeddertest, EmptyCreation) { diff --git a/fpdfsdk/fpdfformfill_embeddertest.cpp b/fpdfsdk/fpdfformfill_embeddertest.cpp index 47f1a75efb..631a6a2e7c 100644 --- a/fpdfsdk/fpdfformfill_embeddertest.cpp +++ b/fpdfsdk/fpdfformfill_embeddertest.cpp @@ -2,6 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include +#include + +#include "core/fxcrt/fx_system.h" +#include "public/cpp/fpdf_deleters.h" #include "public/fpdf_formfill.h" #include "testing/embedder_test.h" #include "testing/embedder_test_mock_delegate.h" @@ -12,7 +17,7 @@ using testing::_; using testing::Return; -class FPDFFormFillEmbeddertest : public EmbedderTest {}; +class FPDFFormFillEmbeddertest : public EmbedderTest, public TestSaver {}; TEST_F(FPDFFormFillEmbeddertest, FirstTest) { EmbedderTestMockDelegate mock; @@ -197,3 +202,65 @@ TEST_F(FPDFFormFillEmbeddertest, BUG_679649) { } #endif // PDF_ENABLE_V8 + +TEST_F(FPDFFormFillEmbeddertest, FormText) { +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + const char md5_1[] = "5f11dbe575fe197a37c3fb422559f8ff"; + const char md5_2[] = "35b1a4b679eafc749a0b6fda750c0e8d"; + const char md5_3[] = "65c64a7c355388f719a752aa1e23f6fe"; +#else + const char md5_1[] = "23baecc6e94d4c8b894cd39aa04c584c"; + const char md5_2[] = "499df95d477dfe35ee65b823c69743b5"; + const char md5_3[] = "8f91b62895fc505d9e17ff2d633756d4"; +#endif + { + EXPECT_TRUE(OpenDocument("text_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + std::unique_ptr bitmap1(RenderPage(page)); + CompareBitmap(bitmap1.get(), 300, 300, md5_1); + + // Click on the textfield + EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD, + FPDFPage_HasFormFieldAtPoint(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); + + // Write "ABC" + FORM_OnChar(form_handle(), page, 65, 0); + FORM_OnChar(form_handle(), page, 66, 0); + FORM_OnChar(form_handle(), page, 67, 0); + std::unique_ptr bitmap2(RenderPage(page)); + CompareBitmap(bitmap2.get(), 300, 300, md5_2); + + // 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); + std::unique_ptr bitmap3(RenderPage(page)); + CompareBitmap(bitmap3.get(), 300, 300, md5_3); + + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + + // Close everything + 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 new_page(FPDF_LoadPage(document_, 0)); + ASSERT_TRUE(new_page.get()); + std::unique_ptr new_bitmap( + RenderPage(new_page.get())); + CompareBitmap(new_bitmap.get(), 300, 300, md5_3); +} -- cgit v1.2.3