diff options
author | Tom Sepez <tsepez@chromium.org> | 2016-01-05 14:48:31 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2016-01-05 14:48:31 -0800 |
commit | 9eb811f7884db1ce0c145d2f90fa512283d7599b (patch) | |
tree | 47425f5ea0669b1ca19aaa6ee4c150dd2020bd8a | |
parent | c009e8e6bfefa4f77bc02ac0b359b9fe58af384f (diff) | |
download | pdfium-9eb811f7884db1ce0c145d2f90fa512283d7599b.tar.xz |
Merge to XFA: Add embedder test for fpdfsave.cpp and bug 342
Original Review URL: https://codereview.chromium.org/1556033002 .
(cherry picked from commit 603533fb0e5968923d67c1d8f2e00a640f41b5e5)
TBR=thestig@chromium.org
Review URL: https://codereview.chromium.org/1563483003 .
-rw-r--r-- | BUILD.gn | 1 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfsave_embeddertest.cpp | 72 | ||||
-rw-r--r-- | pdfium.gyp | 1 |
3 files changed, 74 insertions, 0 deletions
@@ -1499,6 +1499,7 @@ test("pdfium_embeddertests") { "fpdfsdk/src/fpdfdoc_embeddertest.cpp", "fpdfsdk/src/fpdfext_embeddertest.cpp", "fpdfsdk/src/fpdfformfill_embeddertest.cpp", + "fpdfsdk/src/fpdfsave_embeddertest.cpp", "fpdfsdk/src/fpdftext_embeddertest.cpp", "fpdfsdk/src/fpdfview_c_api_test.c", "fpdfsdk/src/fpdfview_c_api_test.h", diff --git a/fpdfsdk/src/fpdfsave_embeddertest.cpp b/fpdfsdk/src/fpdfsave_embeddertest.cpp new file mode 100644 index 0000000000..bee452beaf --- /dev/null +++ b/fpdfsdk/src/fpdfsave_embeddertest.cpp @@ -0,0 +1,72 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <string.h> + +#include "core/include/fxcrt/fx_string.h" +#include "public/fpdf_save.h" +#include "public/fpdfview.h" +#include "testing/embedder_test.h" +#include "testing/fx_string_testhelpers.h" +#include "testing/gtest/include/gtest/gtest.h" + +class FPDFSaveEmbedderTest : public EmbedderTest, public FPDF_FILEWRITE { + public: + FPDFSaveEmbedderTest() { + FPDF_FILEWRITE::version = 1; + FPDF_FILEWRITE::WriteBlock = WriteBlockCallback; + } + bool SaveDocumentToString() { + m_String.clear(); + return FPDF_SaveAsCopy(document(), this, 0); + } + bool SaveDocumentWithVersionToString(int version) { + m_String.clear(); + return FPDF_SaveWithVersion(document(), this, 0, version); + } + const std::string& GetString() const { return m_String; } + + private: + static int WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, + const void* data, + unsigned long size) { + FPDFSaveEmbedderTest* pThis = + static_cast<FPDFSaveEmbedderTest*>(pFileWrite); + pThis->m_String.append(static_cast<const char*>(data), size); + return 1; + } + + std::string m_String; +}; + +TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) { + EXPECT_TRUE(OpenDocument("hello_world.pdf")); + EXPECT_TRUE(SaveDocumentToString()); + EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); + EXPECT_EQ(843, GetString().length()); +} + +TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithVersion) { + EXPECT_TRUE(OpenDocument("hello_world.pdf")); + EXPECT_TRUE(SaveDocumentWithVersionToString(14)); + EXPECT_EQ("%PDF-1.4\r\n", GetString().substr(0, 10)); + EXPECT_EQ(843, GetString().length()); +} + +TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) { + EXPECT_TRUE(OpenDocument("hello_world.pdf")); + EXPECT_TRUE(SaveDocumentWithVersionToString(-1)); + EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); + EXPECT_TRUE(SaveDocumentWithVersionToString(0)); + EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); + EXPECT_TRUE(SaveDocumentWithVersionToString(18)); + EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); +} + +TEST_F(FPDFSaveEmbedderTest, BUG_342) { + EXPECT_TRUE(OpenDocument("hello_world.pdf")); + EXPECT_TRUE(SaveDocumentToString()); + EXPECT_EQ(std::string::npos, GetString().find("0000000000 65536 f\r\n")); + EXPECT_NE(std::string::npos, GetString().find("0000000000 65535 f\r\n")); +} diff --git a/pdfium.gyp b/pdfium.gyp index 782cd68967..812ecf8574 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -800,6 +800,7 @@ 'fpdfsdk/src/fpdfdoc_embeddertest.cpp', 'fpdfsdk/src/fpdfext_embeddertest.cpp', 'fpdfsdk/src/fpdfformfill_embeddertest.cpp', + 'fpdfsdk/src/fpdfsave_embeddertest.cpp', 'fpdfsdk/src/fpdftext_embeddertest.cpp', 'fpdfsdk/src/fpdfview_c_api_test.c', 'fpdfsdk/src/fpdfview_c_api_test.h', |