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

Side by Side Diff: fpdfsdk/fpdfdoc_unittest.cpp

Issue 2334323005: Rename dictionary set and get methods (Closed)
Patch Set: Created 4 years, 3 months 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 | « fpdfsdk/fpdfdoc.cpp ('k') | fpdfsdk/fpdfeditpage.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 "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/fpdf_parser/include/cpdf_document.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // No bookmark information. 97 // No bookmark information.
98 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 98 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
99 GetFPDFWideString(L""); 99 GetFPDFWideString(L"");
100 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 100 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
101 101
102 title = GetFPDFWideString(L"Preface"); 102 title = GetFPDFWideString(L"Preface");
103 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 103 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
104 } 104 }
105 { 105 {
106 // Empty bookmark tree. 106 // Empty bookmark tree.
107 m_pRootObj->SetAt("Outlines", new CPDF_Dictionary()); 107 m_pRootObj->SetFor("Outlines", new CPDF_Dictionary());
108 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 108 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
109 GetFPDFWideString(L""); 109 GetFPDFWideString(L"");
110 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 110 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
111 111
112 title = GetFPDFWideString(L"Preface"); 112 title = GetFPDFWideString(L"Preface");
113 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 113 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
114 } 114 }
115 { 115 {
116 // Check on a regular bookmark tree. 116 // Check on a regular bookmark tree.
117 auto bookmarks = CreateDictObjs(3); 117 auto bookmarks = CreateDictObjs(3);
118 118
119 bookmarks[1].obj->SetAt("Title", new CPDF_String(L"Chapter 1")); 119 bookmarks[1].obj->SetFor("Title", new CPDF_String(L"Chapter 1"));
120 bookmarks[1].obj->SetAt( 120 bookmarks[1].obj->SetFor(
121 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 121 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
122 bookmarks[1].obj->SetAt( 122 bookmarks[1].obj->SetFor(
123 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 123 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
124 124
125 bookmarks[2].obj->SetAt("Title", new CPDF_String(L"Chapter 2")); 125 bookmarks[2].obj->SetFor("Title", new CPDF_String(L"Chapter 2"));
126 bookmarks[2].obj->SetAt( 126 bookmarks[2].obj->SetFor(
127 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 127 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
128 bookmarks[2].obj->SetAt( 128 bookmarks[2].obj->SetFor(
129 "Prev", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 129 "Prev", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
130 130
131 bookmarks[0].obj->SetAt("Type", new CPDF_Name("Outlines")); 131 bookmarks[0].obj->SetFor("Type", new CPDF_Name("Outlines"));
132 bookmarks[0].obj->SetAt("Count", new CPDF_Number(2)); 132 bookmarks[0].obj->SetFor("Count", new CPDF_Number(2));
133 bookmarks[0].obj->SetAt( 133 bookmarks[0].obj->SetFor(
134 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 134 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
135 bookmarks[0].obj->SetAt( 135 bookmarks[0].obj->SetFor(
136 "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 136 "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
137 137
138 m_pRootObj->SetAt("Outlines", 138 m_pRootObj->SetFor("Outlines",
139 new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 139 new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
140 140
141 // Title with no match. 141 // Title with no match.
142 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 142 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
143 GetFPDFWideString(L"Chapter 3"); 143 GetFPDFWideString(L"Chapter 3");
144 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 144 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
145 145
146 // Title with partial match only. 146 // Title with partial match only.
147 title = GetFPDFWideString(L"Chapter"); 147 title = GetFPDFWideString(L"Chapter");
148 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 148 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
149 149
150 // Title with a match. 150 // Title with a match.
151 title = GetFPDFWideString(L"Chapter 2"); 151 title = GetFPDFWideString(L"Chapter 2");
152 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); 152 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
153 153
154 // Title match is case insensitive. 154 // Title match is case insensitive.
155 title = GetFPDFWideString(L"cHaPter 2"); 155 title = GetFPDFWideString(L"cHaPter 2");
156 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); 156 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
157 } 157 }
158 { 158 {
159 // Circular bookmarks in depth. 159 // Circular bookmarks in depth.
160 auto bookmarks = CreateDictObjs(3); 160 auto bookmarks = CreateDictObjs(3);
161 161
162 bookmarks[1].obj->SetAt("Title", new CPDF_String(L"Chapter 1")); 162 bookmarks[1].obj->SetFor("Title", new CPDF_String(L"Chapter 1"));
163 bookmarks[1].obj->SetAt( 163 bookmarks[1].obj->SetFor(
164 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 164 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
165 bookmarks[1].obj->SetAt( 165 bookmarks[1].obj->SetFor(
166 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 166 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
167 167
168 bookmarks[2].obj->SetAt("Title", new CPDF_String(L"Chapter 2")); 168 bookmarks[2].obj->SetFor("Title", new CPDF_String(L"Chapter 2"));
169 bookmarks[2].obj->SetAt( 169 bookmarks[2].obj->SetFor(
170 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 170 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
171 bookmarks[2].obj->SetAt( 171 bookmarks[2].obj->SetFor(
172 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 172 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
173 173
174 bookmarks[0].obj->SetAt("Type", new CPDF_Name("Outlines")); 174 bookmarks[0].obj->SetFor("Type", new CPDF_Name("Outlines"));
175 bookmarks[0].obj->SetAt("Count", new CPDF_Number(2)); 175 bookmarks[0].obj->SetFor("Count", new CPDF_Number(2));
176 bookmarks[0].obj->SetAt( 176 bookmarks[0].obj->SetFor(
177 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 177 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
178 bookmarks[0].obj->SetAt( 178 bookmarks[0].obj->SetFor(
179 "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 179 "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
180 180
181 m_pRootObj->SetAt("Outlines", 181 m_pRootObj->SetFor("Outlines",
182 new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 182 new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
183 183
184 // Title with no match. 184 // Title with no match.
185 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 185 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
186 GetFPDFWideString(L"Chapter 3"); 186 GetFPDFWideString(L"Chapter 3");
187 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 187 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
188 188
189 // Title with a match. 189 // Title with a match.
190 title = GetFPDFWideString(L"Chapter 2"); 190 title = GetFPDFWideString(L"Chapter 2");
191 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); 191 EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
192 } 192 }
193 { 193 {
194 // Circular bookmarks in breadth. 194 // Circular bookmarks in breadth.
195 auto bookmarks = CreateDictObjs(4); 195 auto bookmarks = CreateDictObjs(4);
196 196
197 bookmarks[1].obj->SetAt("Title", new CPDF_String(L"Chapter 1")); 197 bookmarks[1].obj->SetFor("Title", new CPDF_String(L"Chapter 1"));
198 bookmarks[1].obj->SetAt( 198 bookmarks[1].obj->SetFor(
199 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 199 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
200 bookmarks[1].obj->SetAt( 200 bookmarks[1].obj->SetFor(
201 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 201 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
202 202
203 bookmarks[2].obj->SetAt("Title", new CPDF_String(L"Chapter 2")); 203 bookmarks[2].obj->SetFor("Title", new CPDF_String(L"Chapter 2"));
204 bookmarks[2].obj->SetAt( 204 bookmarks[2].obj->SetFor(
205 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 205 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
206 bookmarks[2].obj->SetAt( 206 bookmarks[2].obj->SetFor(
207 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[3].num)); 207 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[3].num));
208 208
209 bookmarks[3].obj->SetAt("Title", new CPDF_String(L"Chapter 3")); 209 bookmarks[3].obj->SetFor("Title", new CPDF_String(L"Chapter 3"));
210 bookmarks[3].obj->SetAt( 210 bookmarks[3].obj->SetFor(
211 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 211 "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
212 bookmarks[3].obj->SetAt( 212 bookmarks[3].obj->SetFor(
213 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 213 "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
214 214
215 bookmarks[0].obj->SetAt("Type", new CPDF_Name("Outlines")); 215 bookmarks[0].obj->SetFor("Type", new CPDF_Name("Outlines"));
216 bookmarks[0].obj->SetAt("Count", new CPDF_Number(2)); 216 bookmarks[0].obj->SetFor("Count", new CPDF_Number(2));
217 bookmarks[0].obj->SetAt( 217 bookmarks[0].obj->SetFor(
218 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num)); 218 "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
219 bookmarks[0].obj->SetAt( 219 bookmarks[0].obj->SetFor(
220 "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num)); 220 "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
221 221
222 m_pRootObj->SetAt("Outlines", 222 m_pRootObj->SetFor("Outlines",
223 new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num)); 223 new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
224 224
225 // Title with no match. 225 // Title with no match.
226 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 226 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
227 GetFPDFWideString(L"Chapter 8"); 227 GetFPDFWideString(L"Chapter 8");
228 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 228 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
229 229
230 // Title with a match. 230 // Title with a match.
231 title = GetFPDFWideString(L"Chapter 3"); 231 title = GetFPDFWideString(L"Chapter 3");
232 EXPECT_EQ(bookmarks[3].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); 232 EXPECT_EQ(bookmarks[3].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
233 } 233 }
234 } 234 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdfdoc.cpp ('k') | fpdfsdk/fpdfeditpage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698