OLD | NEW |
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/fpdf_parser/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/cpdf_document.h" |
12 #include "core/fpdfapi/fpdf_parser/cpdf_name.h" | 12 #include "core/fpdfapi/fpdf_parser/cpdf_name.h" |
13 #include "core/fpdfapi/fpdf_parser/cpdf_number.h" | 13 #include "core/fpdfapi/fpdf_parser/cpdf_number.h" |
14 #include "core/fpdfapi/fpdf_parser/cpdf_parser.h" | 14 #include "core/fpdfapi/fpdf_parser/cpdf_parser.h" |
15 #include "core/fpdfapi/fpdf_parser/cpdf_reference.h" | 15 #include "core/fpdfapi/fpdf_parser/cpdf_reference.h" |
16 #include "core/fpdfapi/fpdf_parser/cpdf_string.h" | 16 #include "core/fpdfapi/fpdf_parser/cpdf_string.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "testing/test_support.h" | 18 #include "testing/test_support.h" |
| 19 #include "third_party/base/ptr_util.h" |
19 | 20 |
20 #ifdef PDF_ENABLE_XFA | 21 #ifdef PDF_ENABLE_XFA |
21 #include "fpdfsdk/fpdfxfa/fpdfxfa_app.h" | 22 #include "fpdfsdk/fpdfxfa/fpdfxfa_app.h" |
22 #include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h" | 23 #include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h" |
23 #endif // PDF_ENABLE_XFA | 24 #endif // PDF_ENABLE_XFA |
24 | 25 |
25 class CPDF_TestDocument : public CPDF_Document { | 26 class CPDF_TestDocument : public CPDF_Document { |
26 public: | 27 public: |
27 CPDF_TestDocument() : CPDF_Document(std::unique_ptr<CPDF_Parser>()) {} | 28 CPDF_TestDocument() : CPDF_Document(std::unique_ptr<CPDF_Parser>()) {} |
28 | 29 |
29 void SetRoot(CPDF_Dictionary* root) { m_pRootDict = root; } | 30 void SetRoot(CPDF_Dictionary* root) { m_pRootDict = root; } |
30 CPDF_IndirectObjectHolder* GetHolder() { return this; } | 31 CPDF_IndirectObjectHolder* GetHolder() { return this; } |
31 }; | 32 }; |
32 | 33 |
33 #ifdef PDF_ENABLE_XFA | 34 #ifdef PDF_ENABLE_XFA |
34 class CPDF_TestXFADocument : public CPDFXFA_Document { | 35 class CPDF_TestXFADocument : public CPDFXFA_Document { |
35 public: | 36 public: |
36 CPDF_TestXFADocument() | 37 CPDF_TestXFADocument() |
37 : CPDFXFA_Document(WrapUnique(new CPDF_TestDocument()), | 38 : CPDFXFA_Document(pdfium::MakeUnique<CPDF_TestDocument>(), |
38 CPDFXFA_App::GetInstance()) {} | 39 CPDFXFA_App::GetInstance()) {} |
39 | 40 |
40 void SetRoot(CPDF_Dictionary* root) { | 41 void SetRoot(CPDF_Dictionary* root) { |
41 reinterpret_cast<CPDF_TestDocument*>(GetPDFDoc())->SetRoot(root); | 42 reinterpret_cast<CPDF_TestDocument*>(GetPDFDoc())->SetRoot(root); |
42 } | 43 } |
43 | 44 |
44 CPDF_IndirectObjectHolder* GetHolder() { return GetPDFDoc(); } | 45 CPDF_IndirectObjectHolder* GetHolder() { return GetPDFDoc(); } |
45 }; | 46 }; |
46 using CPDF_TestPdfDocument = CPDF_TestXFADocument; | 47 using CPDF_TestPdfDocument = CPDF_TestXFADocument; |
47 #else // PDF_ENABLE_XFA | 48 #else // PDF_ENABLE_XFA |
48 using CPDF_TestPdfDocument = CPDF_TestDocument; | 49 using CPDF_TestPdfDocument = CPDF_TestDocument; |
49 #endif // PDF_ENABLE_XFA | 50 #endif // PDF_ENABLE_XFA |
50 | 51 |
51 class PDFDocTest : public testing::Test { | 52 class PDFDocTest : public testing::Test { |
52 public: | 53 public: |
53 struct DictObjInfo { | 54 struct DictObjInfo { |
54 uint32_t num; | 55 uint32_t num; |
55 CPDF_Dictionary* obj; | 56 CPDF_Dictionary* obj; |
56 }; | 57 }; |
57 | 58 |
58 void SetUp() override { | 59 void SetUp() override { |
59 // We don't need page module or render module, but | 60 // We don't need page module or render module, but |
60 // initialize them to keep the code sane. | 61 // initialize them to keep the code sane. |
61 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); | 62 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); |
62 module_mgr->InitPageModule(); | 63 module_mgr->InitPageModule(); |
63 | 64 |
64 m_pDoc = WrapUnique(new CPDF_TestPdfDocument()); | 65 m_pDoc = pdfium::MakeUnique<CPDF_TestPdfDocument>(); |
65 m_pIndirectObjs = m_pDoc->GetHolder(); | 66 m_pIndirectObjs = m_pDoc->GetHolder(); |
66 // Setup the root directory. | 67 // Setup the root directory. |
67 m_pRootObj.reset(new CPDF_Dictionary()); | 68 m_pRootObj.reset(new CPDF_Dictionary()); |
68 m_pDoc->SetRoot(m_pRootObj.get()); | 69 m_pDoc->SetRoot(m_pRootObj.get()); |
69 } | 70 } |
70 | 71 |
71 void TearDown() override { | 72 void TearDown() override { |
72 m_pRootObj.reset(); | 73 m_pRootObj.reset(); |
73 m_pIndirectObjs = nullptr; | 74 m_pIndirectObjs = nullptr; |
74 m_pDoc.reset(); | 75 m_pDoc.reset(); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // Title with no match. | 225 // Title with no match. |
225 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = | 226 std::unique_ptr<unsigned short, pdfium::FreeDeleter> title = |
226 GetFPDFWideString(L"Chapter 8"); | 227 GetFPDFWideString(L"Chapter 8"); |
227 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); | 228 EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); |
228 | 229 |
229 // Title with a match. | 230 // Title with a match. |
230 title = GetFPDFWideString(L"Chapter 3"); | 231 title = GetFPDFWideString(L"Chapter 3"); |
231 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())); |
232 } | 233 } |
233 } | 234 } |
OLD | NEW |