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

Side by Side Diff: fpdfsdk/fpdfdoc_unittest.cpp

Issue 2510223002: Make CPDF_Dictionary use unique pointers. (Closed)
Patch Set: Plug leaks 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 "public/fpdf_doc.h" 5 #include "public/fpdf_doc.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "core/fpdfapi/cpdf_modulemgr.h" 10 #include "core/fpdfapi/cpdf_modulemgr.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // No bookmark information. 98 // No bookmark information.
99 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 99 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
100 GetFPDFWideString(L""); 100 GetFPDFWideString(L"");
101 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 101 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
102 102
103 title = GetFPDFWideString(L"Preface"); 103 title = GetFPDFWideString(L"Preface");
104 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 104 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
105 } 105 }
106 { 106 {
107 // Empty bookmark tree. 107 // Empty bookmark tree.
108 m_pRootObj->SetFor("Outlines", new CPDF_Dictionary()); 108 m_pRootObj->SetNewFor<CPDF_Dictionary>("Outlines");
109 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 109 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
110 GetFPDFWideString(L""); 110 GetFPDFWideString(L"");
111 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 111 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
112 112
113 title = GetFPDFWideString(L"Preface"); 113 title = GetFPDFWideString(L"Preface");
114 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 114 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
115 } 115 }
116 { 116 {
117 // Check on a regular bookmark tree. 117 // Check on a regular bookmark tree.
118 auto bookmarks = CreateDictObjs(3); 118 auto bookmarks = CreateDictObjs(3);
119 119
120 bookmarks[1].obj->SetFor("Title", new CPDF_String(L"Chapter 1")); 120 bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1");
121 bookmarks[1].obj->SetFor( 121 bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
122 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 122 bookmarks[0].num);
123 bookmarks[1].obj->SetFor( 123 bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
124 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 124 bookmarks[2].num);
125 125
126 bookmarks[2].obj->SetFor("Title", new CPDF_String(L"Chapter 2")); 126 bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2");
127 bookmarks[2].obj->SetFor( 127 bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
128 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 128 bookmarks[0].num);
129 bookmarks[2].obj->SetFor( 129 bookmarks[2].obj->SetNewFor<CPDF_Reference>("Prev", m_pIndirectObjs,
130 "Prev", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 130 bookmarks[1].num);
131 131
132 bookmarks[0].obj->SetFor("Type", new CPDF_Name(nullptr, "Outlines")); 132 bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines");
133 bookmarks[0].obj->SetFor("Count", new CPDF_Number(2)); 133 bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2);
134 bookmarks[0].obj->SetFor( 134 bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
135 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 135 bookmarks[1].num);
136 bookmarks[0].obj->SetFor( 136 bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs,
137 "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 137 bookmarks[2].num);
138 138
139 m_pRootObj->SetFor("Outlines", 139 m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs,
140 new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 140 bookmarks[0].num);
141 141
142 // Title with no match. 142 // Title with no match.
143 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 143 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
144 GetFPDFWideString(L"Chapter 3"); 144 GetFPDFWideString(L"Chapter 3");
145 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 145 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
146 146
147 // Title with partial match only. 147 // Title with partial match only.
148 title = GetFPDFWideString(L"Chapter"); 148 title = GetFPDFWideString(L"Chapter");
149 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 149 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
150 150
151 // Title with a match. 151 // Title with a match.
152 title = GetFPDFWideString(L"Chapter 2"); 152 title = GetFPDFWideString(L"Chapter 2");
153 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); 153 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
154 154
155 // Title match is case insensitive. 155 // Title match is case insensitive.
156 title = GetFPDFWideString(L"cHaPter 2"); 156 title = GetFPDFWideString(L"cHaPter 2");
157 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); 157 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
158 } 158 }
159 { 159 {
160 // Circular bookmarks in depth. 160 // Circular bookmarks in depth.
161 auto bookmarks = CreateDictObjs(3); 161 auto bookmarks = CreateDictObjs(3);
162 162
163 bookmarks[1].obj->SetFor("Title", new CPDF_String(L"Chapter 1")); 163 bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1");
164 bookmarks[1].obj->SetFor( 164 bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
165 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 165 bookmarks[0].num);
166 bookmarks[1].obj->SetFor( 166 bookmarks[1].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
167 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 167 bookmarks[2].num);
168 168
169 bookmarks[2].obj->SetFor("Title", new CPDF_String(L"Chapter 2")); 169 bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2");
170 bookmarks[2].obj->SetFor( 170 bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
171 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 171 bookmarks[1].num);
172 bookmarks[2].obj->SetFor( 172 bookmarks[2].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
173 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 173 bookmarks[1].num);
174 174
175 bookmarks[0].obj->SetFor("Type", new CPDF_Name(nullptr, "Outlines")); 175 bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines");
176 bookmarks[0].obj->SetFor("Count", new CPDF_Number(2)); 176 bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2);
177 bookmarks[0].obj->SetFor( 177 bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
178 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 178 bookmarks[1].num);
179 bookmarks[0].obj->SetFor( 179 bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs,
180 "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 180 bookmarks[2].num);
181 181
182 m_pRootObj->SetFor("Outlines", 182 m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs,
183 new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 183 bookmarks[0].num);
184 184
185 // Title with no match. 185 // Title with no match.
186 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 186 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
187 GetFPDFWideString(L"Chapter 3"); 187 GetFPDFWideString(L"Chapter 3");
188 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 188 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
189 189
190 // Title with a match. 190 // Title with a match.
191 title = GetFPDFWideString(L"Chapter 2"); 191 title = GetFPDFWideString(L"Chapter 2");
192 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); 192 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
193 } 193 }
194 { 194 {
195 // Circular bookmarks in breadth. 195 // Circular bookmarks in breadth.
196 auto bookmarks = CreateDictObjs(4); 196 auto bookmarks = CreateDictObjs(4);
197 197
198 bookmarks[1].obj->SetFor("Title", new CPDF_String(L"Chapter 1")); 198 bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1");
199 bookmarks[1].obj->SetFor( 199 bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
200 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 200 bookmarks[0].num);
201 bookmarks[1].obj->SetFor( 201 bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
202 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 202 bookmarks[2].num);
203 203
204 bookmarks[2].obj->SetFor("Title", new CPDF_String(L"Chapter 2")); 204 bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2");
205 bookmarks[2].obj->SetFor( 205 bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
206 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 206 bookmarks[0].num);
207 bookmarks[2].obj->SetFor( 207 bookmarks[2].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
208 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[3].num)); 208 bookmarks[3].num);
209 209
210 bookmarks[3].obj->SetFor("Title", new CPDF_String(L"Chapter 3")); 210 bookmarks[3].obj->SetNewFor<CPDF_String>("Title", L"Chapter 3");
211 bookmarks[3].obj->SetFor( 211 bookmarks[3].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
212 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 212 bookmarks[0].num);
213 bookmarks[3].obj->SetFor( 213 bookmarks[3].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
214 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 214 bookmarks[1].num);
215 215
216 bookmarks[0].obj->SetFor("Type", new CPDF_Name(nullptr, "Outlines")); 216 bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines");
217 bookmarks[0].obj->SetFor("Count", new CPDF_Number(2)); 217 bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2);
218 bookmarks[0].obj->SetFor( 218 bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
219 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 219 bookmarks[1].num);
220 bookmarks[0].obj->SetFor( 220 bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs,
221 "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 221 bookmarks[2].num);
222 222
223 m_pRootObj->SetFor("Outlines", 223 m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs,
224 new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 224 bookmarks[0].num);
225 225
226 // Title with no match. 226 // Title with no match.
227 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 227 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
228 GetFPDFWideString(L"Chapter 8"); 228 GetFPDFWideString(L"Chapter 8");
229 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 229 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
230 230
231 // Title with a match. 231 // Title with a match.
232 title = GetFPDFWideString(L"Chapter 3"); 232 title = GetFPDFWideString(L"Chapter 3");
233 EXPECT_EQ(bookmarks[3].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); 233 EXPECT_EQ(bookmarks[3].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
234 } 234 }
(...skipping 29 matching lines...) Expand all
264 EXPECT_TRUE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom, 264 EXPECT_TRUE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
265 &x, &y, &zoom)); 265 &x, &y, &zoom));
266 EXPECT_FALSE(hasX); 266 EXPECT_FALSE(hasX);
267 EXPECT_FALSE(hasY); 267 EXPECT_FALSE(hasY);
268 EXPECT_FALSE(hasZoom); 268 EXPECT_FALSE(hasZoom);
269 269
270 array = pdfium::MakeUnique<CPDF_Array>(); 270 array = pdfium::MakeUnique<CPDF_Array>();
271 EXPECT_FALSE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom, 271 EXPECT_FALSE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
272 &x, &y, &zoom)); 272 &x, &y, &zoom));
273 } 273 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698