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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 68 |
71 m_pOwnedRootDict.reset(new CPDF_Dictionary()); | 69 m_pOwnedRootDict.reset(new CPDF_Dictionary()); |
72 m_pOwnedRootDict->SetReferenceFor("Pages", this, pagesDict->GetObjNum()); | 70 m_pOwnedRootDict->SetReferenceFor("Pages", this, pagesDict->GetObjNum()); |
73 m_pRootDict = m_pOwnedRootDict.get(); | 71 m_pRootDict = m_pOwnedRootDict.get(); |
74 m_PageList.SetSize(7); | 72 m_PageList.SetSize(7); |
75 } | 73 } |
76 | 74 |
77 private: | 75 private: |
78 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict; | 76 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict; |
79 }; | 77 }; |
| 78 |
| 79 class TestLinearized : public CPDF_Linearized { |
| 80 public: |
| 81 explicit TestLinearized(CPDF_Dictionary* dict) : CPDF_Linearized(dict) {} |
| 82 }; |
80 } // namespace | 83 } // namespace |
81 | 84 |
82 class cpdf_document_test : public testing::Test { | 85 class cpdf_document_test : public testing::Test { |
83 public: | 86 public: |
84 void SetUp() override { | 87 void SetUp() override { |
85 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); | 88 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); |
86 module_mgr->InitPageModule(); | 89 module_mgr->InitPageModule(); |
87 } | 90 } |
88 void TearDown() override {} | 91 void TearDown() override {} |
89 }; | 92 }; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 ASSERT_TRUE(page); | 138 ASSERT_TRUE(page); |
136 ASSERT_TRUE(page->KeyExist("PageNumbering")); | 139 ASSERT_TRUE(page->KeyExist("PageNumbering")); |
137 EXPECT_EQ(6, page->GetIntegerFor("PageNumbering")); | 140 EXPECT_EQ(6, page->GetIntegerFor("PageNumbering")); |
138 } | 141 } |
139 | 142 |
140 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { | 143 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { |
141 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict | 144 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict |
142 // can be not exists in this case. | 145 // can be not exists in this case. |
143 // (case, when hint table is used to page check in CPDF_DataAvail). | 146 // (case, when hint table is used to page check in CPDF_DataAvail). |
144 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); | 147 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); |
145 std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary()); | 148 auto dict = pdfium::MakeUnique<CPDF_Dictionary>(); |
| 149 dict->SetBooleanFor("Linearized", true); |
146 const int page_count = 100; | 150 const int page_count = 100; |
147 dict->SetIntegerFor("N", page_count); | 151 dict->SetIntegerFor("N", page_count); |
148 document.LoadLinearizedDoc(dict.get()); | 152 TestLinearized linearized(dict.get()); |
| 153 document.LoadLinearizedDoc(&linearized); |
149 ASSERT_EQ(page_count, document.GetPageCount()); | 154 ASSERT_EQ(page_count, document.GetPageCount()); |
150 CPDF_Object* page_stub = new CPDF_Dictionary(); | 155 CPDF_Object* page_stub = new CPDF_Dictionary(); |
151 const uint32_t obj_num = document.AddIndirectObject(page_stub); | 156 const uint32_t obj_num = document.AddIndirectObject(page_stub); |
152 const int test_page_num = 33; | 157 const int test_page_num = 33; |
153 | 158 |
154 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); | 159 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); |
155 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); | 160 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); |
156 | 161 |
157 document.SetPageObjNum(test_page_num, obj_num); | 162 document.SetPageObjNum(test_page_num, obj_num); |
158 | 163 |
159 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); | 164 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); |
160 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); | 165 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); |
161 } | 166 } |
OLD | NEW |