diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/src/fpdfdoc_embeddertest.cpp | 38 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfview_embeddertest.cpp | 37 |
2 files changed, 75 insertions, 0 deletions
diff --git a/fpdfsdk/src/fpdfdoc_embeddertest.cpp b/fpdfsdk/src/fpdfdoc_embeddertest.cpp new file mode 100644 index 0000000000..dadaf1d809 --- /dev/null +++ b/fpdfsdk/src/fpdfdoc_embeddertest.cpp @@ -0,0 +1,38 @@ +// Copyright 2015 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 "../../testing/embedder_test.h" +#include "../../fpdfsdk/include/fpdfview.h" +#include "../../fpdfsdk/include/fpdfdoc.h" +#include "testing/gtest/include/gtest/gtest.h" + +class FPDFDocEmbeddertest : public EmbedderTest { +}; + +TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { + EXPECT_TRUE(OpenDocument("testing/resources/named_dests.pdf")); + + // NULL FPDF_DEST case. + EXPECT_EQ(0, FPDFDest_GetPageIndex(document(), nullptr)); + + // Page number directly in item from Dests NameTree. + FPDF_DEST dest = FPDF_GetNamedDestByName(document(), "First"); + EXPECT_NE(nullptr, dest); + EXPECT_EQ(1, FPDFDest_GetPageIndex(document(), dest)); + + // Page number via object reference in item from Dests NameTree. + dest = FPDF_GetNamedDestByName(document(), "Next"); + EXPECT_NE(nullptr, dest); + EXPECT_EQ(1, FPDFDest_GetPageIndex(document(), dest)); + + // Page number directly in item from Dests dictionary. + dest = FPDF_GetNamedDestByName(document(), "FirstAlternate"); + EXPECT_NE(nullptr, dest); + EXPECT_EQ(11, FPDFDest_GetPageIndex(document(), dest)); + + // Invalid object reference in item from Dests NameTree. + dest = FPDF_GetNamedDestByName(document(), "LastAlternate"); + EXPECT_NE(nullptr, dest); + EXPECT_EQ(0, FPDFDest_GetPageIndex(document(), dest)); +} diff --git a/fpdfsdk/src/fpdfview_embeddertest.cpp b/fpdfsdk/src/fpdfview_embeddertest.cpp index 55c159a42c..ee32727ace 100644 --- a/fpdfsdk/src/fpdfview_embeddertest.cpp +++ b/fpdfsdk/src/fpdfview_embeddertest.cpp @@ -140,3 +140,40 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) { EXPECT_EQ(nullptr, dest); EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified. } + +TEST_F(FPDFViewEmbeddertest, NamedDestsByName) { + EXPECT_TRUE(OpenDocument("testing/resources/named_dests.pdf")); + + // Null pointer returns NULL. + FPDF_DEST dest = FPDF_GetNamedDestByName(document(), nullptr); + EXPECT_EQ(nullptr, dest); + + // Empty string returns NULL. + dest = FPDF_GetNamedDestByName(document(), ""); + EXPECT_EQ(nullptr, dest); + + // Item from Dests NameTree. + dest = FPDF_GetNamedDestByName(document(), "First"); + EXPECT_NE(nullptr, dest); + + long ignore_len = 0; + FPDF_DEST dest_by_index = + FPDF_GetNamedDest(document(), 0, nullptr, ignore_len); + EXPECT_EQ(dest_by_index, dest); + + // Item from Dests dictionary. + dest = FPDF_GetNamedDestByName(document(), "FirstAlternate"); + EXPECT_NE(nullptr, dest); + + ignore_len = 0; + dest_by_index = FPDF_GetNamedDest(document(), 4, nullptr, ignore_len); + EXPECT_EQ(dest_by_index, dest); + + // Bad value type for item from Dests NameTree array. + dest = FPDF_GetNamedDestByName(document(), "WrongType"); + EXPECT_EQ(nullptr, dest); + + // No such destination in either Dest NameTree or dictionary. + dest = FPDF_GetNamedDestByName(document(), "Bogus"); + EXPECT_EQ(nullptr, dest); +} |