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" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 CPDF_Dictionary* pagesDict = CreatePageTreeNode(allPages, this, 7); | 69 CPDF_Dictionary* pagesDict = CreatePageTreeNode(allPages, this, 7); |
70 | 70 |
71 m_pOwnedRootDict.reset(new CPDF_Dictionary()); | 71 m_pOwnedRootDict.reset(new CPDF_Dictionary()); |
72 m_pOwnedRootDict->SetReferenceFor("Pages", this, | 72 m_pOwnedRootDict->SetReferenceFor("Pages", this, |
73 AddIndirectObject(pagesDict)); | 73 AddIndirectObject(pagesDict)); |
74 m_pRootDict = m_pOwnedRootDict.get(); | 74 m_pRootDict = m_pOwnedRootDict.get(); |
75 m_PageList.SetSize(7); | 75 m_PageList.SetSize(7); |
76 } | 76 } |
77 | 77 |
78 private: | 78 private: |
79 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> | 79 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict; |
80 m_pOwnedRootDict; | |
81 }; | 80 }; |
82 } // namespace | 81 } // namespace |
83 | 82 |
84 class cpdf_document_test : public testing::Test { | 83 class cpdf_document_test : public testing::Test { |
85 public: | 84 public: |
86 void SetUp() override { | 85 void SetUp() override { |
87 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); | 86 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); |
88 module_mgr->InitPageModule(); | 87 module_mgr->InitPageModule(); |
89 } | 88 } |
90 void TearDown() override {} | 89 void TearDown() override {} |
(...skipping 23 matching lines...) Expand all Loading... |
114 } | 113 } |
115 CPDF_Dictionary* page = document->GetPage(7); | 114 CPDF_Dictionary* page = document->GetPage(7); |
116 EXPECT_FALSE(page); | 115 EXPECT_FALSE(page); |
117 } | 116 } |
118 | 117 |
119 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { | 118 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { |
120 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict | 119 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict |
121 // can be not exists in this case. | 120 // can be not exists in this case. |
122 // (case, when hint table is used to page check in CPDF_DataAvail). | 121 // (case, when hint table is used to page check in CPDF_DataAvail). |
123 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); | 122 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); |
124 ScopedDictionary dict(new CPDF_Dictionary()); | 123 std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary()); |
125 const int page_count = 100; | 124 const int page_count = 100; |
126 dict->SetIntegerFor("N", page_count); | 125 dict->SetIntegerFor("N", page_count); |
127 document.LoadLinearizedDoc(dict.get()); | 126 document.LoadLinearizedDoc(dict.get()); |
128 ASSERT_EQ(page_count, document.GetPageCount()); | 127 ASSERT_EQ(page_count, document.GetPageCount()); |
129 CPDF_Object* page_stub = new CPDF_Dictionary(); | 128 CPDF_Object* page_stub = new CPDF_Dictionary(); |
130 const uint32_t obj_num = document.AddIndirectObject(page_stub); | 129 const uint32_t obj_num = document.AddIndirectObject(page_stub); |
131 const int test_page_num = 33; | 130 const int test_page_num = 33; |
132 | 131 |
133 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); | 132 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); |
134 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); | 133 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); |
135 | 134 |
136 document.SetPageObjNum(test_page_num, obj_num); | 135 document.SetPageObjNum(test_page_num, obj_num); |
137 | 136 |
138 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); | 137 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); |
139 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); | 138 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); |
140 } | 139 } |
OLD | NEW |