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

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

Issue 2498223005: Make CPDF_Array take unique_ptrs (Closed)
Patch Set: nits 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_object_unittest.cpp » ('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_header.h" 12 #include "core/fpdfapi/parser/cpdf_linearized_header.h"
13 #include "core/fpdfapi/parser/cpdf_parser.h" 13 #include "core/fpdfapi/parser/cpdf_parser.h"
14 #include "core/fpdfapi/parser/cpdf_reference.h"
14 #include "core/fxcrt/fx_memory.h" 15 #include "core/fxcrt/fx_memory.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/base/ptr_util.h" 17 #include "third_party/base/ptr_util.h"
17 18
18 namespace { 19 namespace {
19 20
20 CPDF_Dictionary* CreatePageTreeNode(std::unique_ptr<CPDF_Array> kids, 21 CPDF_Dictionary* CreatePageTreeNode(std::unique_ptr<CPDF_Array> kids,
21 CPDF_Document* pDoc, 22 CPDF_Document* pDoc,
22 int count) { 23 int count) {
23 CPDF_Array* pUnowned = pDoc->AddIndirectObject(std::move(kids))->AsArray(); 24 CPDF_Array* pUnowned = pDoc->AddIndirectObject(std::move(kids))->AsArray();
(...skipping 11 matching lines...) Expand all
35 page->SetStringFor("Type", "Page"); 36 page->SetStringFor("Type", "Page");
36 page->SetIntegerFor("PageNumbering", number); 37 page->SetIntegerFor("PageNumbering", number);
37 return page; 38 return page;
38 } 39 }
39 40
40 class CPDF_TestDocumentForPages : public CPDF_Document { 41 class CPDF_TestDocumentForPages : public CPDF_Document {
41 public: 42 public:
42 CPDF_TestDocumentForPages() : CPDF_Document(nullptr) { 43 CPDF_TestDocumentForPages() : CPDF_Document(nullptr) {
43 // Set up test 44 // Set up test
44 auto zeroToTwo = pdfium::MakeUnique<CPDF_Array>(); 45 auto zeroToTwo = pdfium::MakeUnique<CPDF_Array>();
45 zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(0))); 46 zeroToTwo->AddNew<CPDF_Reference>(
46 zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(1))); 47 this, AddIndirectObject(CreateNumberedPage(0))->GetObjNum());
47 zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(2))); 48 zeroToTwo->AddNew<CPDF_Reference>(
49 this, AddIndirectObject(CreateNumberedPage(1))->GetObjNum());
50 zeroToTwo->AddNew<CPDF_Reference>(
51 this, AddIndirectObject(CreateNumberedPage(2))->GetObjNum());
48 CPDF_Dictionary* branch1 = 52 CPDF_Dictionary* branch1 =
49 CreatePageTreeNode(std::move(zeroToTwo), this, 3); 53 CreatePageTreeNode(std::move(zeroToTwo), this, 3);
50 54
51 auto zeroToThree = pdfium::MakeUnique<CPDF_Array>(); 55 auto zeroToThree = pdfium::MakeUnique<CPDF_Array>();
52 zeroToThree->AddReference(this, branch1->GetObjNum()); 56 zeroToThree->AddNew<CPDF_Reference>(this, branch1->GetObjNum());
53 zeroToThree->AddReference(this, AddIndirectObject(CreateNumberedPage(3))); 57 zeroToThree->AddNew<CPDF_Reference>(
58 this, AddIndirectObject(CreateNumberedPage(3))->GetObjNum());
54 CPDF_Dictionary* branch2 = 59 CPDF_Dictionary* branch2 =
55 CreatePageTreeNode(std::move(zeroToThree), this, 4); 60 CreatePageTreeNode(std::move(zeroToThree), this, 4);
56 61
57 auto fourFive = pdfium::MakeUnique<CPDF_Array>(); 62 auto fourFive = pdfium::MakeUnique<CPDF_Array>();
58 fourFive->AddReference(this, AddIndirectObject(CreateNumberedPage(4))); 63 fourFive->AddNew<CPDF_Reference>(
59 fourFive->AddReference(this, AddIndirectObject(CreateNumberedPage(5))); 64 this, AddIndirectObject(CreateNumberedPage(4))->GetObjNum());
65 fourFive->AddNew<CPDF_Reference>(
66 this, AddIndirectObject(CreateNumberedPage(5))->GetObjNum());
60 CPDF_Dictionary* branch3 = CreatePageTreeNode(std::move(fourFive), this, 2); 67 CPDF_Dictionary* branch3 = CreatePageTreeNode(std::move(fourFive), this, 2);
61 68
62 auto justSix = pdfium::MakeUnique<CPDF_Array>(); 69 auto justSix = pdfium::MakeUnique<CPDF_Array>();
63 justSix->AddReference(this, AddIndirectObject(CreateNumberedPage(6))); 70 justSix->AddNew<CPDF_Reference>(
71 this, AddIndirectObject(CreateNumberedPage(6))->GetObjNum());
64 CPDF_Dictionary* branch4 = CreatePageTreeNode(std::move(justSix), this, 1); 72 CPDF_Dictionary* branch4 = CreatePageTreeNode(std::move(justSix), this, 1);
65 73
66 auto allPages = pdfium::MakeUnique<CPDF_Array>(); 74 auto allPages = pdfium::MakeUnique<CPDF_Array>();
67 allPages->AddReference(this, branch2); 75 allPages->AddNew<CPDF_Reference>(this, branch2->GetObjNum());
68 allPages->AddReference(this, branch3); 76 allPages->AddNew<CPDF_Reference>(this, branch3->GetObjNum());
69 allPages->AddReference(this, branch4); 77 allPages->AddNew<CPDF_Reference>(this, branch4->GetObjNum());
70 CPDF_Dictionary* pagesDict = 78 CPDF_Dictionary* pagesDict =
71 CreatePageTreeNode(std::move(allPages), this, 7); 79 CreatePageTreeNode(std::move(allPages), this, 7);
72 80
73 m_pOwnedRootDict = pdfium::MakeUnique<CPDF_Dictionary>(); 81 m_pOwnedRootDict = pdfium::MakeUnique<CPDF_Dictionary>();
74 m_pOwnedRootDict->SetReferenceFor("Pages", this, pagesDict); 82 m_pOwnedRootDict->SetReferenceFor("Pages", this, pagesDict);
75 m_pRootDict = m_pOwnedRootDict.get(); 83 m_pRootDict = m_pOwnedRootDict.get();
76 m_PageList.SetSize(7); 84 m_PageList.SetSize(7);
77 } 85 }
78 86
79 private: 87 private:
80 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict; 88 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict;
81 }; 89 };
82 90
83 class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document { 91 class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document {
84 public: 92 public:
85 CPDF_TestDocumentWithPageWithoutPageNum() : CPDF_Document(nullptr) { 93 CPDF_TestDocumentWithPageWithoutPageNum() : CPDF_Document(nullptr) {
86 // Set up test 94 // Set up test
87 auto allPages = pdfium::MakeUnique<CPDF_Array>(); 95 auto allPages = pdfium::MakeUnique<CPDF_Array>();
88 allPages->AddReference(this, AddIndirectObject(CreateNumberedPage(0))); 96 allPages->AddNew<CPDF_Reference>(
89 allPages->AddReference(this, AddIndirectObject(CreateNumberedPage(1))); 97 this, AddIndirectObject(CreateNumberedPage(0))->GetObjNum());
98 allPages->AddNew<CPDF_Reference>(
99 this, AddIndirectObject(CreateNumberedPage(1))->GetObjNum());
90 // Page without pageNum. 100 // Page without pageNum.
91 allPages->Add(CreateNumberedPage(2).release()); 101 allPages->Add(CreateNumberedPage(2));
92 CPDF_Dictionary* pagesDict = 102 CPDF_Dictionary* pagesDict =
93 CreatePageTreeNode(std::move(allPages), this, 3); 103 CreatePageTreeNode(std::move(allPages), this, 3);
94 m_pOwnedRootDict.reset(new CPDF_Dictionary()); 104 m_pOwnedRootDict.reset(new CPDF_Dictionary());
95 m_pOwnedRootDict->SetReferenceFor("Pages", this, pagesDict->GetObjNum()); 105 m_pOwnedRootDict->SetReferenceFor("Pages", this, pagesDict->GetObjNum());
96 m_pRootDict = m_pOwnedRootDict.get(); 106 m_pRootDict = m_pOwnedRootDict.get();
97 m_PageList.SetSize(3); 107 m_PageList.SetSize(3);
98 } 108 }
99 109
100 private: 110 private:
101 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict; 111 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 const uint32_t obj_num = page_stub->GetObjNum(); 204 const uint32_t obj_num = page_stub->GetObjNum();
195 const int test_page_num = 33; 205 const int test_page_num = 33;
196 206
197 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); 207 EXPECT_FALSE(document.IsPageLoaded(test_page_num));
198 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); 208 EXPECT_EQ(nullptr, document.GetPage(test_page_num));
199 209
200 document.SetPageObjNum(test_page_num, obj_num); 210 document.SetPageObjNum(test_page_num, obj_num);
201 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); 211 EXPECT_TRUE(document.IsPageLoaded(test_page_num));
202 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); 212 EXPECT_EQ(page_stub, document.GetPage(test_page_num));
203 } 213 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_document.cpp ('k') | core/fpdfapi/parser/cpdf_object_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698