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

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

Issue 2478253002: Revert of Remove CPDF_Object::Release() in favor of direct delete (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
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"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
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> m_pOwnedRootDict; 79 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>
80 m_pOwnedRootDict;
80 }; 81 };
81 } // namespace 82 } // namespace
82 83
83 class cpdf_document_test : public testing::Test { 84 class cpdf_document_test : public testing::Test {
84 public: 85 public:
85 void SetUp() override { 86 void SetUp() override {
86 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); 87 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get();
87 module_mgr->InitPageModule(); 88 module_mgr->InitPageModule();
88 } 89 }
89 void TearDown() override {} 90 void TearDown() override {}
(...skipping 23 matching lines...) Expand all
113 } 114 }
114 CPDF_Dictionary* page = document->GetPage(7); 115 CPDF_Dictionary* page = document->GetPage(7);
115 EXPECT_FALSE(page); 116 EXPECT_FALSE(page);
116 } 117 }
117 118
118 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { 119 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) {
119 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict 120 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict
120 // can be not exists in this case. 121 // can be not exists in this case.
121 // (case, when hint table is used to page check in CPDF_DataAvail). 122 // (case, when hint table is used to page check in CPDF_DataAvail).
122 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); 123 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>());
123 std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary()); 124 ScopedDictionary dict(new CPDF_Dictionary());
124 const int page_count = 100; 125 const int page_count = 100;
125 dict->SetIntegerFor("N", page_count); 126 dict->SetIntegerFor("N", page_count);
126 document.LoadLinearizedDoc(dict.get()); 127 document.LoadLinearizedDoc(dict.get());
127 ASSERT_EQ(page_count, document.GetPageCount()); 128 ASSERT_EQ(page_count, document.GetPageCount());
128 CPDF_Object* page_stub = new CPDF_Dictionary(); 129 CPDF_Object* page_stub = new CPDF_Dictionary();
129 const uint32_t obj_num = document.AddIndirectObject(page_stub); 130 const uint32_t obj_num = document.AddIndirectObject(page_stub);
130 const int test_page_num = 33; 131 const int test_page_num = 33;
131 132
132 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); 133 EXPECT_FALSE(document.IsPageLoaded(test_page_num));
133 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); 134 EXPECT_EQ(nullptr, document.GetPage(test_page_num));
134 135
135 document.SetPageObjNum(test_page_num, obj_num); 136 document.SetPageObjNum(test_page_num, obj_num);
136 137
137 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); 138 EXPECT_TRUE(document.IsPageLoaded(test_page_num));
138 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); 139 EXPECT_EQ(page_stub, document.GetPage(test_page_num));
139 } 140 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_document.cpp ('k') | core/fpdfapi/parser/cpdf_indirect_object_holder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698