summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2018-06-26 16:28:48 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-26 16:28:48 +0000
commit20582f797f3fdc6308141dbed5eed7d3f84619c9 (patch)
tree54e4c21a84b95e83b3c955cd5dc21376c1fcf321 /core
parente3d3ce04e585c4a6c5596056bdf1ced639c763d7 (diff)
downloadpdfium-20582f797f3fdc6308141dbed5eed7d3f84619c9.tar.xz
Add test which verify, that "Info" from linearized doc is correctly saved.
Change-Id: Ib0ee1c2b0a2def650711c87b4eb04a9f88470944 Reviewed-on: https://pdfium-review.googlesource.com/35550 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/edit/cpdf_creator_embeddertest.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp b/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp
index f8520c4238..2d431b8424 100644
--- a/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp
+++ b/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp
@@ -13,8 +13,47 @@
#include "public/fpdf_edit.h"
#include "public/fpdfview.h"
#include "testing/embedder_test.h"
+#include "testing/fake_file_access.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/utils/path_service.h"
+
+namespace {
+
+class FileAccess : public FPDF_FILEACCESS {
+ public:
+ explicit FileAccess(const std::string& file_name) {
+ std::string file_path;
+ if (!PathService::GetTestFilePath(file_name, &file_path))
+ return;
+
+ file_contents_ = GetFileContents(file_path.c_str(), &file_length_);
+ if (!file_contents_)
+ return;
+
+ m_FileLen = static_cast<unsigned long>(file_length_);
+ m_GetBlock = SGetBlock;
+ m_Param = this;
+ }
+
+ private:
+ int GetBlockImpl(unsigned long pos, unsigned char* pBuf, unsigned long size) {
+ memcpy(pBuf, file_contents_.get() + pos, size);
+ return size;
+ }
+
+ static int SGetBlock(void* param,
+ unsigned long pos,
+ unsigned char* pBuf,
+ unsigned long size) {
+ return static_cast<FileAccess*>(param)->GetBlockImpl(pos, pBuf, size);
+ }
+
+ size_t file_length_;
+ std::unique_ptr<char, pdfium::FreeDeleter> file_contents_;
+};
+
+} // namespace
class CPDF_CreatorEmbedderTest : public EmbedderTest {};
@@ -62,3 +101,30 @@ TEST_F(CPDF_CreatorEmbedderTest, BUG_873) {
std::string data_after_second_id = saved_data.substr(trailer_continuation);
EXPECT_THAT(data_after_second_id, testing::StartsWith(">]>>\r\n"));
}
+
+TEST_F(CPDF_CreatorEmbedderTest, SaveLinearizedInfo) {
+ FileAccess file_acc("linearized.pdf");
+ FakeFileAccess fake_acc(&file_acc);
+
+ avail_ = FPDFAvail_Create(fake_acc.GetFileAvail(), fake_acc.GetFileAccess());
+ while (PDF_DATA_AVAIL !=
+ FPDFAvail_IsDocAvail(avail_, fake_acc.GetDownloadHints())) {
+ fake_acc.SetRequestedDataAvailable();
+ }
+
+ document_ = FPDFAvail_GetDocument(avail_, nullptr);
+ ASSERT_TRUE(document_);
+
+ // Load second page, to parse additional crossref sections.
+ while (PDF_DATA_AVAIL !=
+ FPDFAvail_IsPageAvail(avail_, 1, fake_acc.GetDownloadHints())) {
+ fake_acc.SetRequestedDataAvailable();
+ }
+ // Simulate downloading of whole file.
+ fake_acc.SetWholeFileAvailable();
+ // Save document.
+ EXPECT_TRUE(FPDF_SaveAsCopy(document_, this, 0));
+ const std::string saved_doc = GetString();
+
+ EXPECT_THAT(saved_doc, ::testing::HasSubstr("/Info"));
+}