diff options
author | Artem Strygin <art-snake@yandex-team.ru> | 2017-10-30 10:44:01 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-10-30 10:44:01 +0000 |
commit | 7170226d20208e6286057e5c0804e0b549ae33bc (patch) | |
tree | 691ae1c1c1e78370843db1dd968b2660a34367df /core | |
parent | 09b419242ed85acb6ddf64cddfaa7ca8fbb07b1a (diff) | |
download | pdfium-7170226d20208e6286057e5c0804e0b549ae33bc.tar.xz |
Add test for CPDF_HintsTable.
Change-Id: Ibda8e140791215faec52e6dbc33adea732373f6c
Reviewed-on: https://pdfium-review.googlesource.com/15810
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_hint_tables.cpp | 7 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_hint_tables.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp | 69 |
4 files changed, 78 insertions, 4 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index 1ebee8768a..7737ec0c3a 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -109,6 +109,8 @@ class CPDF_DataAvail final { CPDF_Dictionary* GetPage(int index); RetainPtr<CPDF_ReadValidator> GetValidator() const; + const CPDF_HintTables* GetHintTables() const { return m_pHintTables.get(); } + protected: class PageNode { public: diff --git a/core/fpdfapi/parser/cpdf_hint_tables.cpp b/core/fpdfapi/parser/cpdf_hint_tables.cpp index e88da2eea8..2b58e9d8f3 100644 --- a/core/fpdfapi/parser/cpdf_hint_tables.cpp +++ b/core/fpdfapi/parser/cpdf_hint_tables.cpp @@ -49,7 +49,7 @@ CPDF_HintTables::~CPDF_HintTables() {} uint32_t CPDF_HintTables::GetItemLength( uint32_t index, - const std::vector<FX_FILESIZE>& szArray) { + const std::vector<FX_FILESIZE>& szArray) const { if (szArray.size() < 2 || index > szArray.size() - 2 || szArray[index] > szArray[index + 1]) { return 0; @@ -373,7 +373,10 @@ bool CPDF_HintTables::ReadSharedObjHintTable(CFX_BitStream* hStream, bool CPDF_HintTables::GetPagePos(uint32_t index, FX_FILESIZE* szPageStartPos, FX_FILESIZE* szPageLength, - uint32_t* dwObjNum) { + uint32_t* dwObjNum) const { + if (index >= m_pLinearized->GetPageCount()) + return false; + *szPageStartPos = m_szPageOffsetArray[index]; *szPageLength = GetItemLength(index, m_szPageOffsetArray); diff --git a/core/fpdfapi/parser/cpdf_hint_tables.h b/core/fpdfapi/parser/cpdf_hint_tables.h index a9aa5d42d9..d5feb4638c 100644 --- a/core/fpdfapi/parser/cpdf_hint_tables.h +++ b/core/fpdfapi/parser/cpdf_hint_tables.h @@ -27,7 +27,7 @@ class CPDF_HintTables { bool GetPagePos(uint32_t index, FX_FILESIZE* szPageStartPos, FX_FILESIZE* szPageLength, - uint32_t* dwObjNum); + uint32_t* dwObjNum) const; CPDF_DataAvail::DocAvailStatus CheckPage(uint32_t index); @@ -47,7 +47,7 @@ class CPDF_HintTables { virtual int ReadPrimaryHintStreamLength() const; uint32_t GetItemLength(uint32_t index, - const std::vector<FX_FILESIZE>& szArray); + const std::vector<FX_FILESIZE>& szArray) const; // Owned by |m_pDataAvail|. UnownedPtr<CPDF_ReadValidator> m_pValidator; diff --git a/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp b/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp new file mode 100644 index 0000000000..e45722950e --- /dev/null +++ b/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp @@ -0,0 +1,69 @@ +// Copyright 2017 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 "core/fpdfapi/parser/cpdf_hint_tables.h" + +#include <memory> +#include <string> +#include <utility> + +#include "core/fpdfapi/cpdf_modulemgr.h" +#include "core/fpdfapi/parser/cpdf_data_avail.h" +#include "core/fxcrt/fx_stream.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/utils/path_service.h" +#include "third_party/base/ptr_util.h" + +namespace { + +std::unique_ptr<CPDF_DataAvail> MakeDataAvailFromFile( + const std::string& file_name) { + std::string file_path; + if (!PathService::GetTestFilePath(file_name, &file_path)) + return nullptr; + return pdfium::MakeUnique<CPDF_DataAvail>( + nullptr, IFX_SeekableReadStream::CreateFromFilename(file_path.c_str()), + true); +} + +} // namespace + +class CPDF_HintTablesTest : public testing::Test { + public: + CPDF_HintTablesTest() { + // Needs for encoding Hint table stream. + CPDF_ModuleMgr::Get()->Init(); + } + + ~CPDF_HintTablesTest() override { CPDF_ModuleMgr::Destroy(); } +}; + +TEST_F(CPDF_HintTablesTest, Load) { + auto data_avail = MakeDataAvailFromFile("feature_linearized_loading.pdf"); + ASSERT_EQ(CPDF_DataAvail::DocAvailStatus::DataAvailable, + data_avail->IsDocAvail(nullptr)); + + ASSERT_TRUE(data_avail->GetHintTables()); + + const CPDF_HintTables* hint_tables = data_avail->GetHintTables(); + FX_FILESIZE page_start = 0; + FX_FILESIZE page_length = 0; + uint32_t page_obj_num = 0; + + ASSERT_TRUE( + hint_tables->GetPagePos(0, &page_start, &page_length, &page_obj_num)); + EXPECT_EQ(777, page_start); + EXPECT_EQ(4328, page_length); + EXPECT_EQ(39u, page_obj_num); + + ASSERT_TRUE( + hint_tables->GetPagePos(1, &page_start, &page_length, &page_obj_num)); + EXPECT_EQ(5105, page_start); + EXPECT_EQ(767, page_length); + EXPECT_EQ(1u, page_obj_num); + + ASSERT_FALSE( + hint_tables->GetPagePos(2, &page_start, &page_length, &page_obj_num)); +} |