diff options
author | tsepez <tsepez@chromium.org> | 2016-11-11 17:23:48 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-11 17:23:48 -0800 |
commit | 211d4edbe2f71ca62c76f36ce25090342c58e43c (patch) | |
tree | 645a4823ce6df9021333552b55288cd13344a4f9 /fpdfsdk | |
parent | 8f3eb6051c0465923d6694bd0f0b6dc5bb51cbe3 (diff) | |
download | pdfium-211d4edbe2f71ca62c76f36ce25090342c58e43c.tar.xz |
Add fpdfppo_embeddertest.cpp.
The lack of coverage of the fpdfppo APIs was noticed while
trying to diagnose another issue. Adding basic calls to
these APIs then kicked out an assert in XFA, where duplicate
global CFXA_TimeZoneProviders were not expected. These are
cheap to create except for the global C RTL tzset() call, so
keep track of that and make these on demand.
Review-Url: https://codereview.chromium.org/2488403004
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdfppo_embeddertest.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfppo_embeddertest.cpp b/fpdfsdk/fpdfppo_embeddertest.cpp new file mode 100644 index 0000000000..3149f072f5 --- /dev/null +++ b/fpdfsdk/fpdfppo_embeddertest.cpp @@ -0,0 +1,92 @@ +// 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 "public/fpdf_ppo.h" + +#include "core/fxcrt/fx_basic.h" +#include "public/fpdf_edit.h" +#include "public/fpdfview.h" +#include "testing/embedder_test.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" + +namespace { + +class FPDFPPOEmbeddertest : public EmbedderTest {}; + +} // namespace + +TEST_F(FPDFPPOEmbeddertest, NoViewerPreferences) { + EXPECT_TRUE(OpenDocument("hello_world.pdf")); + + FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); + EXPECT_TRUE(output_doc); + EXPECT_FALSE(FPDF_CopyViewerPreferences(output_doc, document())); + FPDF_CloseDocument(output_doc); +} + +TEST_F(FPDFPPOEmbeddertest, ViewerPreferences) { + EXPECT_TRUE(OpenDocument("viewer_ref.pdf")); + + FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); + EXPECT_TRUE(output_doc); + EXPECT_TRUE(FPDF_CopyViewerPreferences(output_doc, document())); + FPDF_CloseDocument(output_doc); +} + +TEST_F(FPDFPPOEmbeddertest, ImportPages) { + EXPECT_TRUE(OpenDocument("viewer_ref.pdf")); + + FPDF_PAGE page = LoadPage(0); + EXPECT_TRUE(page); + + FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); + EXPECT_TRUE(output_doc); + EXPECT_TRUE(FPDF_CopyViewerPreferences(output_doc, document())); + EXPECT_TRUE(FPDF_ImportPages(output_doc, document(), "1", 0)); + EXPECT_EQ(1, FPDF_GetPageCount(output_doc)); + FPDF_CloseDocument(output_doc); + + UnloadPage(page); +} + +TEST_F(FPDFPPOEmbeddertest, BadRanges) { + EXPECT_TRUE(OpenDocument("viewer_ref.pdf")); + + FPDF_PAGE page = LoadPage(0); + EXPECT_TRUE(page); + + FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); + EXPECT_TRUE(output_doc); + EXPECT_FALSE(FPDF_ImportPages(output_doc, document(), "clams", 0)); + EXPECT_FALSE(FPDF_ImportPages(output_doc, document(), "0", 0)); + EXPECT_FALSE(FPDF_ImportPages(output_doc, document(), "42", 0)); + EXPECT_FALSE(FPDF_ImportPages(output_doc, document(), "1,2", 0)); + EXPECT_FALSE(FPDF_ImportPages(output_doc, document(), "1-2", 0)); + EXPECT_FALSE(FPDF_ImportPages(output_doc, document(), ",1", 0)); + EXPECT_FALSE(FPDF_ImportPages(output_doc, document(), "1,", 0)); + EXPECT_FALSE(FPDF_ImportPages(output_doc, document(), "1-", 0)); + EXPECT_FALSE(FPDF_ImportPages(output_doc, document(), "-1", 0)); + EXPECT_FALSE(FPDF_ImportPages(output_doc, document(), "-,0,,,1-", 0)); + FPDF_CloseDocument(output_doc); + + UnloadPage(page); +} + +TEST_F(FPDFPPOEmbeddertest, GoodRanges) { + EXPECT_TRUE(OpenDocument("viewer_ref.pdf")); + + FPDF_PAGE page = LoadPage(0); + EXPECT_TRUE(page); + + FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); + EXPECT_TRUE(output_doc); + EXPECT_TRUE(FPDF_CopyViewerPreferences(output_doc, document())); + EXPECT_TRUE(FPDF_ImportPages(output_doc, document(), "1,1,1,1", 0)); + EXPECT_TRUE(FPDF_ImportPages(output_doc, document(), "1-1", 0)); + EXPECT_EQ(5, FPDF_GetPageCount(output_doc)); + FPDF_CloseDocument(output_doc); + + UnloadPage(page); +} |