summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.h2
-rw-r--r--core/fpdfapi/parser/cpdf_hint_tables.cpp7
-rw-r--r--core/fpdfapi/parser/cpdf_hint_tables.h4
-rw-r--r--core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp69
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));
+}