From 7c2e8a32c34e0a258963daf6483d5af1695a3dba Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Wed, 6 Jun 2018 19:17:34 +0000 Subject: Embedder tests can write saved PDFs to a file for debugging. Before calling a method that use EmbedderTest as FPDF_FILEWRITE (usually calling FPDF_SaveAsCopy()), call: OpenPDFFileForWrite("Filename.pdf"); After the write, close the stream with: ClosePDFFileForWrite(); Change-Id: Id1e7f778a9ff2b2b5bf976d49b485d5cb15f94bd Reviewed-on: https://pdfium-review.googlesource.com/34150 Reviewed-by: Lei Zhang Commit-Queue: Henrique Nakashima --- testing/embedder_test.cpp | 13 +++++++++++++ testing/embedder_test.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index 03eebe3abc..e4ac4ad2c7 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp @@ -546,7 +546,12 @@ int EmbedderTest::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, const void* data, unsigned long size) { EmbedderTest* pThis = static_cast(pFileWrite); + pThis->data_string_.append(static_cast(data), size); + + if (pThis->filestream_.is_open()) + pThis->filestream_.write(static_cast(data), size); + return 1; } @@ -587,3 +592,11 @@ int EmbedderTest::GetPageNumberForLoadedPage(FPDF_PAGE page) const { int EmbedderTest::GetPageNumberForSavedPage(FPDF_PAGE page) const { return GetPageNumberForPage(saved_page_map_, page); } + +void EmbedderTest::OpenPDFFileForWrite(const char* filename) { + filestream_.open(filename, std::ios_base::binary); +} + +void EmbedderTest::ClosePDFFileForWrite() { + filestream_.close(); +} diff --git a/testing/embedder_test.h b/testing/embedder_test.h index 8156dd2353..e8f76c058f 100644 --- a/testing/embedder_test.h +++ b/testing/embedder_test.h @@ -5,6 +5,7 @@ #ifndef TESTING_EMBEDDER_TEST_H_ #define TESTING_EMBEDDER_TEST_H_ +#include #include #include #include @@ -204,6 +205,9 @@ class EmbedderTest : public ::testing::Test, void SetWholeFileAvailable(); + void OpenPDFFileForWrite(const char* filename); + void ClosePDFFileForWrite(); + std::unique_ptr default_delegate_; Delegate* delegate_; @@ -256,6 +260,7 @@ class EmbedderTest : public ::testing::Test, int GetPageNumberForSavedPage(FPDF_PAGE page) const; std::string data_string_; + std::ofstream filestream_; }; #endif // TESTING_EMBEDDER_TEST_H_ -- cgit v1.2.3