Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "public/fpdf_doc.h" |
| 6 | |
| 7 | #include <memory> |
| 8 | #include <vector> |
| 9 | |
dsinclair | 39c62fd | 2016-09-29 12:49:17 -0700 | [diff] [blame] | 10 | #include "core/fpdfapi/cpdf_modulemgr.h" |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 11 | #include "core/fpdfapi/parser/cpdf_array.h" |
Lei Zhang | 8153561 | 2018-10-09 21:15:17 +0000 | [diff] [blame] | 12 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
| 14 | #include "core/fpdfapi/parser/cpdf_name.h" |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 15 | #include "core/fpdfapi/parser/cpdf_null.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 16 | #include "core/fpdfapi/parser/cpdf_number.h" |
| 17 | #include "core/fpdfapi/parser/cpdf_parser.h" |
| 18 | #include "core/fpdfapi/parser/cpdf_reference.h" |
| 19 | #include "core/fpdfapi/parser/cpdf_string.h" |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 20 | #include "core/fpdfdoc/cpdf_dest.h" |
Tom Sepez | a1d3442 | 2018-04-24 20:54:41 +0000 | [diff] [blame] | 21 | #include "fpdfsdk/cpdfsdk_helpers.h" |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 22 | #include "public/cpp/fpdf_scopers.h" |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 23 | #include "testing/gtest/include/gtest/gtest.h" |
| 24 | #include "testing/test_support.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 25 | #include "third_party/base/ptr_util.h" |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 26 | |
Tom Sepez | 5586545 | 2018-08-27 20:18:04 +0000 | [diff] [blame] | 27 | class CPDF_TestDocument final : public CPDF_Document { |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 28 | public: |
Artem Strygin | 20eca1e | 2018-06-27 18:15:10 +0000 | [diff] [blame] | 29 | CPDF_TestDocument() : CPDF_Document() {} |
thestig | 931bf37 | 2016-04-26 22:24:30 -0700 | [diff] [blame] | 30 | |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 31 | void SetRoot(CPDF_Dictionary* root) { m_pRootDict = root; } |
| 32 | CPDF_IndirectObjectHolder* GetHolder() { return this; } |
| 33 | }; |
| 34 | |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 35 | class PDFDocTest : public testing::Test { |
| 36 | public: |
| 37 | struct DictObjInfo { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 38 | uint32_t num; |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 39 | CPDF_Dictionary* obj; |
| 40 | }; |
| 41 | |
| 42 | void SetUp() override { |
Lei Zhang | 76020fc | 2017-05-18 15:51:20 -0700 | [diff] [blame] | 43 | CPDF_ModuleMgr::Get()->Init(); |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 44 | auto pTestDoc = pdfium::MakeUnique<CPDF_TestDocument>(); |
| 45 | m_pIndirectObjs = pTestDoc->GetHolder(); |
Tom Sepez | b865442 | 2018-06-26 15:19:38 +0000 | [diff] [blame] | 46 | m_pRootObj = m_pIndirectObjs->NewIndirect<CPDF_Dictionary>(); |
| 47 | pTestDoc->SetRoot(m_pRootObj.Get()); |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 48 | m_pDoc.reset(FPDFDocumentFromCPDFDocument(pTestDoc.release())); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 49 | } |
| 50 | |
thestig | fd36b8f | 2016-07-11 10:43:48 -0700 | [diff] [blame] | 51 | void TearDown() override { |
Tom Sepez | b865442 | 2018-06-26 15:19:38 +0000 | [diff] [blame] | 52 | m_pRootObj = nullptr; |
thestig | fd36b8f | 2016-07-11 10:43:48 -0700 | [diff] [blame] | 53 | m_pIndirectObjs = nullptr; |
| 54 | m_pDoc.reset(); |
| 55 | CPDF_ModuleMgr::Destroy(); |
| 56 | } |
| 57 | |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 58 | std::vector<DictObjInfo> CreateDictObjs(int num) { |
| 59 | std::vector<DictObjInfo> info; |
| 60 | for (int i = 0; i < num; ++i) { |
| 61 | // Objects created will be released by the document. |
tsepez | 70c4afd | 2016-11-15 11:33:44 -0800 | [diff] [blame] | 62 | CPDF_Dictionary* obj = m_pIndirectObjs->NewIndirect<CPDF_Dictionary>(); |
| 63 | info.push_back({obj->GetObjNum(), obj}); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 64 | } |
| 65 | return info; |
| 66 | } |
| 67 | |
| 68 | protected: |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 69 | ScopedFPDFDocument m_pDoc; |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 70 | UnownedPtr<CPDF_IndirectObjectHolder> m_pIndirectObjs; |
Tom Sepez | b865442 | 2018-06-26 15:19:38 +0000 | [diff] [blame] | 71 | UnownedPtr<CPDF_Dictionary> m_pRootObj; |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | TEST_F(PDFDocTest, FindBookmark) { |
| 75 | { |
| 76 | // No bookmark information. |
| 77 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = |
| 78 | GetFPDFWideString(L""); |
| 79 | EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); |
| 80 | |
| 81 | title = GetFPDFWideString(L"Preface"); |
| 82 | EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); |
| 83 | } |
| 84 | { |
| 85 | // Empty bookmark tree. |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 86 | m_pRootObj->SetNewFor<CPDF_Dictionary>("Outlines"); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 87 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = |
| 88 | GetFPDFWideString(L""); |
| 89 | EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); |
| 90 | |
| 91 | title = GetFPDFWideString(L"Preface"); |
| 92 | EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); |
| 93 | } |
| 94 | { |
| 95 | // Check on a regular bookmark tree. |
| 96 | auto bookmarks = CreateDictObjs(3); |
| 97 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 98 | bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1"); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 99 | bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 100 | bookmarks[0].num); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 101 | bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 102 | bookmarks[2].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 103 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 104 | bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2"); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 105 | bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 106 | bookmarks[0].num); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 107 | bookmarks[2].obj->SetNewFor<CPDF_Reference>("Prev", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 108 | bookmarks[1].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 109 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 110 | bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines"); |
| 111 | bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 112 | bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 113 | bookmarks[1].num); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 114 | bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 115 | bookmarks[2].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 116 | |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 117 | m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 118 | bookmarks[0].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 119 | |
| 120 | // Title with no match. |
| 121 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = |
| 122 | GetFPDFWideString(L"Chapter 3"); |
| 123 | EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); |
| 124 | |
| 125 | // Title with partial match only. |
| 126 | title = GetFPDFWideString(L"Chapter"); |
| 127 | EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); |
| 128 | |
| 129 | // Title with a match. |
| 130 | title = GetFPDFWideString(L"Chapter 2"); |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 131 | EXPECT_EQ(FPDFBookmarkFromCPDFDictionary(bookmarks[2].obj), |
| 132 | FPDFBookmark_Find(m_pDoc.get(), title.get())); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 133 | |
| 134 | // Title match is case insensitive. |
| 135 | title = GetFPDFWideString(L"cHaPter 2"); |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 136 | EXPECT_EQ(FPDFBookmarkFromCPDFDictionary(bookmarks[2].obj), |
| 137 | FPDFBookmark_Find(m_pDoc.get(), title.get())); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 138 | } |
| 139 | { |
| 140 | // Circular bookmarks in depth. |
| 141 | auto bookmarks = CreateDictObjs(3); |
| 142 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 143 | bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1"); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 144 | bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 145 | bookmarks[0].num); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 146 | bookmarks[1].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 147 | bookmarks[2].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 148 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 149 | bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2"); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 150 | bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 151 | bookmarks[1].num); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 152 | bookmarks[2].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 153 | bookmarks[1].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 154 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 155 | bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines"); |
| 156 | bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 157 | bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 158 | bookmarks[1].num); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 159 | bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 160 | bookmarks[2].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 161 | |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 162 | m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 163 | bookmarks[0].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 164 | |
| 165 | // Title with no match. |
| 166 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = |
| 167 | GetFPDFWideString(L"Chapter 3"); |
| 168 | EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); |
| 169 | |
| 170 | // Title with a match. |
| 171 | title = GetFPDFWideString(L"Chapter 2"); |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 172 | EXPECT_EQ(FPDFBookmarkFromCPDFDictionary(bookmarks[2].obj), |
| 173 | FPDFBookmark_Find(m_pDoc.get(), title.get())); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 174 | } |
| 175 | { |
| 176 | // Circular bookmarks in breadth. |
| 177 | auto bookmarks = CreateDictObjs(4); |
| 178 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 179 | bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1"); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 180 | bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 181 | bookmarks[0].num); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 182 | bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 183 | bookmarks[2].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 184 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 185 | bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2"); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 186 | bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 187 | bookmarks[0].num); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 188 | bookmarks[2].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 189 | bookmarks[3].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 190 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 191 | bookmarks[3].obj->SetNewFor<CPDF_String>("Title", L"Chapter 3"); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 192 | bookmarks[3].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 193 | bookmarks[0].num); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 194 | bookmarks[3].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 195 | bookmarks[1].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 196 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 197 | bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines"); |
| 198 | bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 199 | bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 200 | bookmarks[1].num); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 201 | bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 202 | bookmarks[2].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 203 | |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 204 | m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 205 | bookmarks[0].num); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 206 | |
| 207 | // Title with no match. |
| 208 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = |
| 209 | GetFPDFWideString(L"Chapter 8"); |
| 210 | EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); |
| 211 | |
| 212 | // Title with a match. |
| 213 | title = GetFPDFWideString(L"Chapter 3"); |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 214 | EXPECT_EQ(FPDFBookmarkFromCPDFDictionary(bookmarks[3].obj), |
| 215 | FPDFBookmark_Find(m_pDoc.get(), title.get())); |
Wei Li | 5227e57 | 2016-03-04 15:49:17 -0800 | [diff] [blame] | 216 | } |
| 217 | } |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 218 | |
| 219 | TEST_F(PDFDocTest, GetLocationInPage) { |
| 220 | auto array = pdfium::MakeUnique<CPDF_Array>(); |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 221 | array->AddNew<CPDF_Number>(0); // Page Index. |
| 222 | array->AddNew<CPDF_Name>("XYZ"); |
| 223 | array->AddNew<CPDF_Number>(4); // X |
| 224 | array->AddNew<CPDF_Number>(5); // Y |
| 225 | array->AddNew<CPDF_Number>(6); // Zoom. |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 226 | |
| 227 | FPDF_BOOL hasX; |
| 228 | FPDF_BOOL hasY; |
| 229 | FPDF_BOOL hasZoom; |
| 230 | FS_FLOAT x; |
| 231 | FS_FLOAT y; |
| 232 | FS_FLOAT zoom; |
| 233 | |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 234 | EXPECT_TRUE(FPDFDest_GetLocationInPage(FPDFDestFromCPDFArray(array.get()), |
| 235 | &hasX, &hasY, &hasZoom, &x, &y, |
| 236 | &zoom)); |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 237 | EXPECT_TRUE(hasX); |
| 238 | EXPECT_TRUE(hasY); |
| 239 | EXPECT_TRUE(hasZoom); |
| 240 | EXPECT_EQ(4, x); |
| 241 | EXPECT_EQ(5, y); |
| 242 | EXPECT_EQ(6, zoom); |
| 243 | |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 244 | array->SetNewAt<CPDF_Null>(2); |
| 245 | array->SetNewAt<CPDF_Null>(3); |
| 246 | array->SetNewAt<CPDF_Null>(4); |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 247 | EXPECT_TRUE(FPDFDest_GetLocationInPage(FPDFDestFromCPDFArray(array.get()), |
| 248 | &hasX, &hasY, &hasZoom, &x, &y, |
| 249 | &zoom)); |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 250 | EXPECT_FALSE(hasX); |
| 251 | EXPECT_FALSE(hasY); |
| 252 | EXPECT_FALSE(hasZoom); |
| 253 | |
| 254 | array = pdfium::MakeUnique<CPDF_Array>(); |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 255 | EXPECT_FALSE(FPDFDest_GetLocationInPage(FPDFDestFromCPDFArray(array.get()), |
| 256 | &hasX, &hasY, &hasZoom, &x, &y, |
| 257 | &zoom)); |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 258 | } |