Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: core/fpdfapi/parser/cpdf_document_unittest.cpp

Issue 2474283005: Revert of Unify some code (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/parser/cpdf_document.cpp ('k') | core/fpdfapi/parser/cpdf_hint_tables.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
13 #include "core/fpdfapi/parser/cpdf_parser.h" 12 #include "core/fpdfapi/parser/cpdf_parser.h"
14 #include "core/fxcrt/fx_memory.h" 13 #include "core/fxcrt/fx_memory.h"
15 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
16 15
17 namespace { 16 namespace {
18 17
18 using ScopedDictionary =
19 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>;
20
19 CPDF_Dictionary* CreatePageTreeNode(CPDF_Array* kids, 21 CPDF_Dictionary* CreatePageTreeNode(CPDF_Array* kids,
20 CPDF_Document* pDoc, 22 CPDF_Document* pDoc,
21 int count) { 23 int count) {
22 CPDF_Dictionary* pageNode = new CPDF_Dictionary(); 24 CPDF_Dictionary* pageNode = new CPDF_Dictionary();
23 pageNode->SetStringFor("Type", "Pages"); 25 pageNode->SetStringFor("Type", "Pages");
24 pageNode->SetReferenceFor("Kids", pDoc, pDoc->AddIndirectObject(kids)); 26 pageNode->SetReferenceFor("Kids", pDoc, pDoc->AddIndirectObject(kids));
25 pageNode->SetIntegerFor("Count", count); 27 pageNode->SetIntegerFor("Count", count);
26 uint32_t pageNodeRef = pDoc->AddIndirectObject(pageNode); 28 uint32_t pageNodeRef = pDoc->AddIndirectObject(pageNode);
27 for (size_t i = 0; i < kids->GetCount(); i++) 29 for (size_t i = 0; i < kids->GetCount(); i++)
28 kids->GetDictAt(i)->SetReferenceFor("Parent", pDoc, pageNodeRef); 30 kids->GetDictAt(i)->SetReferenceFor("Parent", pDoc, pageNodeRef);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 70
69 m_pOwnedRootDict.reset(new CPDF_Dictionary()); 71 m_pOwnedRootDict.reset(new CPDF_Dictionary());
70 m_pOwnedRootDict->SetReferenceFor("Pages", this, pagesDict->GetObjNum()); 72 m_pOwnedRootDict->SetReferenceFor("Pages", this, pagesDict->GetObjNum());
71 m_pRootDict = m_pOwnedRootDict.get(); 73 m_pRootDict = m_pOwnedRootDict.get();
72 m_PageList.SetSize(7); 74 m_PageList.SetSize(7);
73 } 75 }
74 76
75 private: 77 private:
76 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict; 78 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict;
77 }; 79 };
78
79 class TestLinearized : public CPDF_Linearized {
80 public:
81 explicit TestLinearized(CPDF_Dictionary* dict) : CPDF_Linearized(dict) {}
82 };
83 } // namespace 80 } // namespace
84 81
85 class cpdf_document_test : public testing::Test { 82 class cpdf_document_test : public testing::Test {
86 public: 83 public:
87 void SetUp() override { 84 void SetUp() override {
88 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); 85 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get();
89 module_mgr->InitPageModule(); 86 module_mgr->InitPageModule();
90 } 87 }
91 void TearDown() override {} 88 void TearDown() override {}
92 }; 89 };
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ASSERT_TRUE(page); 135 ASSERT_TRUE(page);
139 ASSERT_TRUE(page->KeyExist("PageNumbering")); 136 ASSERT_TRUE(page->KeyExist("PageNumbering"));
140 EXPECT_EQ(6, page->GetIntegerFor("PageNumbering")); 137 EXPECT_EQ(6, page->GetIntegerFor("PageNumbering"));
141 } 138 }
142 139
143 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { 140 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) {
144 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict 141 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict
145 // can be not exists in this case. 142 // can be not exists in this case.
146 // (case, when hint table is used to page check in CPDF_DataAvail). 143 // (case, when hint table is used to page check in CPDF_DataAvail).
147 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); 144 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>());
148 auto dict = pdfium::MakeUnique<CPDF_Dictionary>(); 145 std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary());
149 dict->SetBooleanFor("Linearized", true);
150 const int page_count = 100; 146 const int page_count = 100;
151 dict->SetIntegerFor("N", page_count); 147 dict->SetIntegerFor("N", page_count);
152 TestLinearized linearized(dict.get()); 148 document.LoadLinearizedDoc(dict.get());
153 document.LoadLinearizedDoc(&linearized);
154 ASSERT_EQ(page_count, document.GetPageCount()); 149 ASSERT_EQ(page_count, document.GetPageCount());
155 CPDF_Object* page_stub = new CPDF_Dictionary(); 150 CPDF_Object* page_stub = new CPDF_Dictionary();
156 const uint32_t obj_num = document.AddIndirectObject(page_stub); 151 const uint32_t obj_num = document.AddIndirectObject(page_stub);
157 const int test_page_num = 33; 152 const int test_page_num = 33;
158 153
159 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); 154 EXPECT_FALSE(document.IsPageLoaded(test_page_num));
160 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); 155 EXPECT_EQ(nullptr, document.GetPage(test_page_num));
161 156
162 document.SetPageObjNum(test_page_num, obj_num); 157 document.SetPageObjNum(test_page_num, obj_num);
163 158
164 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); 159 EXPECT_TRUE(document.IsPageLoaded(test_page_num));
165 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); 160 EXPECT_EQ(page_stub, document.GetPage(test_page_num));
166 } 161 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_document.cpp ('k') | core/fpdfapi/parser/cpdf_hint_tables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698