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

Side by Side Diff: fpdfsdk/fpdfdoc_unittest.cpp

Issue 2481743004: Add FPDFDest_GetLocationInPage API (Closed)
Patch Set: Review feedback 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 | « fpdfsdk/fpdfdoc_embeddertest.cpp ('k') | fpdfsdk/fpdfview_c_api_test.c » ('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/cpdf_modulemgr.h" 10 #include "core/fpdfapi/cpdf_modulemgr.h"
11 #include "core/fpdfapi/parser/cpdf_array.h"
11 #include "core/fpdfapi/parser/cpdf_document.h" 12 #include "core/fpdfapi/parser/cpdf_document.h"
12 #include "core/fpdfapi/parser/cpdf_name.h" 13 #include "core/fpdfapi/parser/cpdf_name.h"
14 #include "core/fpdfapi/parser/cpdf_null.h"
13 #include "core/fpdfapi/parser/cpdf_number.h" 15 #include "core/fpdfapi/parser/cpdf_number.h"
14 #include "core/fpdfapi/parser/cpdf_parser.h" 16 #include "core/fpdfapi/parser/cpdf_parser.h"
15 #include "core/fpdfapi/parser/cpdf_reference.h" 17 #include "core/fpdfapi/parser/cpdf_reference.h"
16 #include "core/fpdfapi/parser/cpdf_string.h" 18 #include "core/fpdfapi/parser/cpdf_string.h"
19 #include "core/fpdfdoc/cpdf_dest.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
18 #include "testing/test_support.h" 21 #include "testing/test_support.h"
19 #include "third_party/base/ptr_util.h" 22 #include "third_party/base/ptr_util.h"
20 23
21 #ifdef PDF_ENABLE_XFA 24 #ifdef PDF_ENABLE_XFA
22 #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" 25 #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
23 #endif // PDF_ENABLE_XFA 26 #endif // PDF_ENABLE_XFA
24 27
25 class CPDF_TestDocument : public CPDF_Document { 28 class CPDF_TestDocument : public CPDF_Document {
26 public: 29 public:
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // Title with no match. 226 // Title with no match.
224 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = 227 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
225 GetFPDFWideString(L"Chapter 8"); 228 GetFPDFWideString(L"Chapter 8");
226 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); 229 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
227 230
228 // Title with a match. 231 // Title with a match.
229 title = GetFPDFWideString(L"Chapter 3"); 232 title = GetFPDFWideString(L"Chapter 3");
230 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()));
231 } 234 }
232 } 235 }
236
237 TEST_F(PDFDocTest, GetLocationInPage) {
238 auto array = pdfium::MakeUnique<CPDF_Array>();
239 array->AddInteger(0); // Page Index.
240 array->AddName("XYZ");
241 array->AddNumber(4); // X
242 array->AddNumber(5); // Y
243 array->AddNumber(6); // Zoom.
244
245 FPDF_BOOL hasX;
246 FPDF_BOOL hasY;
247 FPDF_BOOL hasZoom;
248 FS_FLOAT x;
249 FS_FLOAT y;
250 FS_FLOAT zoom;
251
252 EXPECT_TRUE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
253 &x, &y, &zoom));
254 EXPECT_TRUE(hasX);
255 EXPECT_TRUE(hasY);
256 EXPECT_TRUE(hasZoom);
257 EXPECT_EQ(4, x);
258 EXPECT_EQ(5, y);
259 EXPECT_EQ(6, zoom);
260
261 array->SetAt(2, new CPDF_Null);
262 array->SetAt(3, new CPDF_Null);
263 array->SetAt(4, new CPDF_Null);
264 EXPECT_TRUE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
265 &x, &y, &zoom));
266 EXPECT_FALSE(hasX);
267 EXPECT_FALSE(hasY);
268 EXPECT_FALSE(hasZoom);
269
270 array = pdfium::MakeUnique<CPDF_Array>();
271 EXPECT_FALSE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
272 &x, &y, &zoom));
273 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdfdoc_embeddertest.cpp ('k') | fpdfsdk/fpdfview_c_api_test.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698