| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/fpdfapi/parser/cpdf_document.h" | 5 #include "core/fpdfapi/parser/cpdf_document.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "core/fpdfapi/cpdf_modulemgr.h" | 9 #include "core/fpdfapi/cpdf_modulemgr.h" |
| 10 #include "core/fpdfapi/parser/cpdf_array.h" | 10 #include "core/fpdfapi/parser/cpdf_array.h" |
| 11 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 11 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 12 #include "core/fpdfapi/parser/cpdf_linearized.h" |
| 12 #include "core/fpdfapi/parser/cpdf_parser.h" | 13 #include "core/fpdfapi/parser/cpdf_parser.h" |
| 13 #include "core/fxcrt/fx_memory.h" | 14 #include "core/fxcrt/fx_memory.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 using ScopedDictionary = | |
| 19 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>; | |
| 20 | |
| 21 CPDF_Dictionary* CreatePageTreeNode(CPDF_Array* kids, | 19 CPDF_Dictionary* CreatePageTreeNode(CPDF_Array* kids, |
| 22 CPDF_Document* pDoc, | 20 CPDF_Document* pDoc, |
| 23 int count) { | 21 int count) { |
| 24 CPDF_Dictionary* pageNode = new CPDF_Dictionary(); | 22 CPDF_Dictionary* pageNode = new CPDF_Dictionary(); |
| 25 pageNode->SetStringFor("Type", "Pages"); | 23 pageNode->SetStringFor("Type", "Pages"); |
| 26 pageNode->SetReferenceFor("Kids", pDoc, pDoc->AddIndirectObject(kids)); | 24 pageNode->SetReferenceFor("Kids", pDoc, pDoc->AddIndirectObject(kids)); |
| 27 pageNode->SetIntegerFor("Count", count); | 25 pageNode->SetIntegerFor("Count", count); |
| 28 uint32_t pageNodeRef = pDoc->AddIndirectObject(pageNode); | 26 uint32_t pageNodeRef = pDoc->AddIndirectObject(pageNode); |
| 29 for (size_t i = 0; i < kids->GetCount(); i++) | 27 for (size_t i = 0; i < kids->GetCount(); i++) |
| 30 kids->GetDictAt(i)->SetReferenceFor("Parent", pDoc, pageNodeRef); | 28 kids->GetDictAt(i)->SetReferenceFor("Parent", pDoc, pageNodeRef); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 m_pOwnedRootDict->SetReferenceFor("Pages", this, | 70 m_pOwnedRootDict->SetReferenceFor("Pages", this, |
| 73 AddIndirectObject(pagesDict)); | 71 AddIndirectObject(pagesDict)); |
| 74 m_pRootDict = m_pOwnedRootDict.get(); | 72 m_pRootDict = m_pOwnedRootDict.get(); |
| 75 m_PageList.SetSize(7); | 73 m_PageList.SetSize(7); |
| 76 } | 74 } |
| 77 | 75 |
| 78 private: | 76 private: |
| 79 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> | 77 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> |
| 80 m_pOwnedRootDict; | 78 m_pOwnedRootDict; |
| 81 }; | 79 }; |
| 80 |
| 81 class TestLinearized : public CPDF_Linearized { |
| 82 public: |
| 83 explicit TestLinearized(CPDF_Dictionary* dict) : CPDF_Linearized(dict) {} |
| 84 }; |
| 82 } // namespace | 85 } // namespace |
| 83 | 86 |
| 84 class cpdf_document_test : public testing::Test { | 87 class cpdf_document_test : public testing::Test { |
| 85 public: | 88 public: |
| 86 void SetUp() override { | 89 void SetUp() override { |
| 87 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); | 90 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); |
| 88 module_mgr->InitPageModule(); | 91 module_mgr->InitPageModule(); |
| 89 } | 92 } |
| 90 void TearDown() override {} | 93 void TearDown() override {} |
| 91 }; | 94 }; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 114 } | 117 } |
| 115 CPDF_Dictionary* page = document->GetPage(7); | 118 CPDF_Dictionary* page = document->GetPage(7); |
| 116 EXPECT_FALSE(page); | 119 EXPECT_FALSE(page); |
| 117 } | 120 } |
| 118 | 121 |
| 119 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { | 122 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { |
| 120 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict | 123 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict |
| 121 // can be not exists in this case. | 124 // can be not exists in this case. |
| 122 // (case, when hint table is used to page check in CPDF_DataAvail). | 125 // (case, when hint table is used to page check in CPDF_DataAvail). |
| 123 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); | 126 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); |
| 124 ScopedDictionary dict(new CPDF_Dictionary()); | 127 UniqueDictionary dict(new CPDF_Dictionary()); |
| 128 dict->SetBooleanFor("Linearized", true); |
| 125 const int page_count = 100; | 129 const int page_count = 100; |
| 126 dict->SetIntegerFor("N", page_count); | 130 dict->SetIntegerFor("N", page_count); |
| 127 document.LoadLinearizedDoc(dict.get()); | 131 TestLinearized linearized(dict.get()); |
| 132 document.LoadLinearizedDoc(&linearized); |
| 128 ASSERT_EQ(page_count, document.GetPageCount()); | 133 ASSERT_EQ(page_count, document.GetPageCount()); |
| 129 CPDF_Object* page_stub = new CPDF_Dictionary(); | 134 CPDF_Object* page_stub = new CPDF_Dictionary(); |
| 130 const uint32_t obj_num = document.AddIndirectObject(page_stub); | 135 const uint32_t obj_num = document.AddIndirectObject(page_stub); |
| 131 const int test_page_num = 33; | 136 const int test_page_num = 33; |
| 132 | 137 |
| 133 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); | 138 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); |
| 134 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); | 139 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); |
| 135 | 140 |
| 136 document.SetPageObjNum(test_page_num, obj_num); | 141 document.SetPageObjNum(test_page_num, obj_num); |
| 137 | 142 |
| 138 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); | 143 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); |
| 139 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); | 144 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); |
| 140 } | 145 } |
| OLD | NEW |