1 // Copyright 2017 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "core/fpdfapi/parser/cpdf_hint_tables.h" 6 7 #include <memory> 8 #include <string> 9 #include <utility> 10 11 #include "core/fpdfapi/cpdf_modulemgr.h" 12 #include "core/fpdfapi/parser/cpdf_data_avail.h" 13 #include "core/fxcrt/fx_stream.h" 14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/utils/path_service.h" 17 #include "third_party/base/ptr_util.h" 18 19 namespace { 20 21 std::unique_ptr<CPDF_DataAvail> MakeDataAvailFromFile( 22 const std::string& file_name) { 23 std::string file_path; 24 if (!PathService::GetTestFilePath(file_name, &file_path)) 25 return nullptr; 26 return pdfium::MakeUnique<CPDF_DataAvail>( 27 nullptr, IFX_SeekableReadStream::CreateFromFilename(file_path.c_str()), 28 true); 29 } 30 31 } // namespace 32 33 class CPDF_HintTablesTest : public testing::Test { 34 public: 35 CPDF_HintTablesTest() { 36 // Needs for encoding Hint table stream. 37 CPDF_ModuleMgr::Get()->Init(); 38 } 39 40 ~CPDF_HintTablesTest() override { CPDF_ModuleMgr::Destroy(); } 41 }; 42 43 TEST_F(CPDF_HintTablesTest, Load) { 44 auto data_avail = MakeDataAvailFromFile("feature_linearized_loading.pdf"); 45 ASSERT_EQ(CPDF_DataAvail::DocAvailStatus::DataAvailable, 46 data_avail->IsDocAvail(nullptr)); 47 48 ASSERT_TRUE(data_avail->GetHintTables()); 49 50 const CPDF_HintTables* hint_tables = data_avail->GetHintTables(); 51 FX_FILESIZE page_start = 0; 52 FX_FILESIZE page_length = 0; 53 uint32_t page_obj_num = 0; 54 55 ASSERT_TRUE( 56 hint_tables->GetPagePos(0, &page_start, &page_length, &page_obj_num)); 57 EXPECT_EQ(777, page_start); 58 EXPECT_EQ(4328, page_length); 59 EXPECT_EQ(39u, page_obj_num); 60 61 ASSERT_TRUE( 62 hint_tables->GetPagePos(1, &page_start, &page_length, &page_obj_num)); 63 EXPECT_EQ(5105, page_start); 64 EXPECT_EQ(767, page_length); 65 EXPECT_EQ(1u, page_obj_num); 66 67 ASSERT_FALSE( 68 hint_tables->GetPagePos(2, &page_start, &page_length, &page_obj_num)); 69 } 70