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

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

Issue 2445753002: Fix root dictionary leak in cpdf_document_unittest (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 | « no previous file | no next file » | 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_parser.h" 12 #include "core/fpdfapi/parser/cpdf_parser.h"
13 #include "core/fxcrt/fx_memory.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace { 16 namespace {
16 17
17 CPDF_Dictionary* CreatePageTreeNode(CPDF_Array* kids, 18 CPDF_Dictionary* CreatePageTreeNode(CPDF_Array* kids,
18 CPDF_Document* pDoc, 19 CPDF_Document* pDoc,
19 int count) { 20 int count) {
20 CPDF_Dictionary* pageNode = new CPDF_Dictionary(); 21 CPDF_Dictionary* pageNode = new CPDF_Dictionary();
21 pageNode->SetStringFor("Type", "Pages"); 22 pageNode->SetStringFor("Type", "Pages");
22 pageNode->SetReferenceFor("Kids", pDoc, pDoc->AddIndirectObject(kids)); 23 pageNode->SetReferenceFor("Kids", pDoc, pDoc->AddIndirectObject(kids));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 CPDF_Array* justSix = new CPDF_Array(); 62 CPDF_Array* justSix = new CPDF_Array();
62 justSix->AddReference(this, AddIndirectObject(CreateNumberedPage(6))); 63 justSix->AddReference(this, AddIndirectObject(CreateNumberedPage(6)));
63 CPDF_Dictionary* branch4 = CreatePageTreeNode(justSix, this, 1); 64 CPDF_Dictionary* branch4 = CreatePageTreeNode(justSix, this, 1);
64 65
65 CPDF_Array* allPages = new CPDF_Array(); 66 CPDF_Array* allPages = new CPDF_Array();
66 allPages->AddReference(this, branch2->GetObjNum()); 67 allPages->AddReference(this, branch2->GetObjNum());
67 allPages->AddReference(this, branch3->GetObjNum()); 68 allPages->AddReference(this, branch3->GetObjNum());
68 allPages->AddReference(this, branch4->GetObjNum()); 69 allPages->AddReference(this, branch4->GetObjNum());
69 CPDF_Dictionary* pagesDict = CreatePageTreeNode(allPages, this, 7); 70 CPDF_Dictionary* pagesDict = CreatePageTreeNode(allPages, this, 7);
70 71
71 CPDF_Dictionary* root = new CPDF_Dictionary(); 72 rootDict.reset(new CPDF_Dictionary());
72 root->SetReferenceFor("Pages", this, AddIndirectObject(pagesDict)); 73 rootDict->SetReferenceFor("Pages", this, AddIndirectObject(pagesDict));
73 m_pRootDict = root; 74 m_pRootDict = rootDict.get();
74 m_PageList.SetSize(7); 75 m_PageList.SetSize(7);
75 } 76 }
77
78 private:
79 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> rootDict;
Tom Sepez 2016/10/24 16:09:52 nit: how about root_dict_ to go with the chromium
npm 2016/10/24 16:17:34 Done.
76 }; 80 };
77 81
78 TEST(cpdf_document, GetPages) { 82 TEST(cpdf_document, GetPages) {
79 std::unique_ptr<CPDF_TestDocumentForPages> document = 83 std::unique_ptr<CPDF_TestDocumentForPages> document =
80 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); 84 pdfium::MakeUnique<CPDF_TestDocumentForPages>();
81 for (int i = 0; i < 7; i++) { 85 for (int i = 0; i < 7; i++) {
82 CPDF_Dictionary* page = document->GetPage(i); 86 CPDF_Dictionary* page = document->GetPage(i);
83 ASSERT_TRUE(page); 87 ASSERT_TRUE(page);
84 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); 88 ASSERT_TRUE(page->GetObjectFor("PageNumbering"));
85 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); 89 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering"));
86 } 90 }
87 CPDF_Dictionary* page = document->GetPage(7); 91 CPDF_Dictionary* page = document->GetPage(7);
88 EXPECT_FALSE(page); 92 EXPECT_FALSE(page);
89 } 93 }
90 94
91 TEST(cpdf_document, GetPagesReverseOrder) { 95 TEST(cpdf_document, GetPagesReverseOrder) {
92 std::unique_ptr<CPDF_TestDocumentForPages> document = 96 std::unique_ptr<CPDF_TestDocumentForPages> document =
93 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); 97 pdfium::MakeUnique<CPDF_TestDocumentForPages>();
94 for (int i = 6; i >= 0; i--) { 98 for (int i = 6; i >= 0; i--) {
95 CPDF_Dictionary* page = document->GetPage(i); 99 CPDF_Dictionary* page = document->GetPage(i);
96 ASSERT_TRUE(page); 100 ASSERT_TRUE(page);
97 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); 101 ASSERT_TRUE(page->GetObjectFor("PageNumbering"));
98 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); 102 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering"));
99 } 103 }
100 CPDF_Dictionary* page = document->GetPage(7); 104 CPDF_Dictionary* page = document->GetPage(7);
101 EXPECT_FALSE(page); 105 EXPECT_FALSE(page);
102 } 106 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698