| 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 "core/fpdfapi/parser/cpdf_document.h" | 5 #include "core/fpdfapi/parser/cpdf_document.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "core/fpdfapi/cpdf_modulemgr.h" | 9 #include "core/fpdfapi/cpdf_modulemgr.h" |
| 10 #include "core/fpdfapi/parser/cpdf_array.h" | 10 #include "core/fpdfapi/parser/cpdf_array.h" |
| 11 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 11 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 12 #include "core/fpdfapi/parser/cpdf_parser.h" | 12 #include "core/fpdfapi/parser/cpdf_parser.h" |
| 13 #include "core/fxcrt/fx_memory.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 CPDF_Dictionary* CreatePageTreeNode(CPDF_Array* kids, | 18 CPDF_Dictionary* CreatePageTreeNode(CPDF_Array* kids, |
| 18 CPDF_Document* pDoc, | 19 CPDF_Document* pDoc, |
| 19 int count) { | 20 int count) { |
| 20 CPDF_Dictionary* pageNode = new CPDF_Dictionary(); | 21 CPDF_Dictionary* pageNode = new CPDF_Dictionary(); |
| 21 pageNode->SetStringFor("Type", "Pages"); | 22 pageNode->SetStringFor("Type", "Pages"); |
| 22 pageNode->SetReferenceFor("Kids", pDoc, pDoc->AddIndirectObject(kids)); | 23 pageNode->SetReferenceFor("Kids", pDoc, pDoc->AddIndirectObject(kids)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 CPDF_Array* justSix = new CPDF_Array(); | 62 CPDF_Array* justSix = new CPDF_Array(); |
| 62 justSix->AddReference(this, AddIndirectObject(CreateNumberedPage(6))); | 63 justSix->AddReference(this, AddIndirectObject(CreateNumberedPage(6))); |
| 63 CPDF_Dictionary* branch4 = CreatePageTreeNode(justSix, this, 1); | 64 CPDF_Dictionary* branch4 = CreatePageTreeNode(justSix, this, 1); |
| 64 | 65 |
| 65 CPDF_Array* allPages = new CPDF_Array(); | 66 CPDF_Array* allPages = new CPDF_Array(); |
| 66 allPages->AddReference(this, branch2->GetObjNum()); | 67 allPages->AddReference(this, branch2->GetObjNum()); |
| 67 allPages->AddReference(this, branch3->GetObjNum()); | 68 allPages->AddReference(this, branch3->GetObjNum()); |
| 68 allPages->AddReference(this, branch4->GetObjNum()); | 69 allPages->AddReference(this, branch4->GetObjNum()); |
| 69 CPDF_Dictionary* pagesDict = CreatePageTreeNode(allPages, this, 7); | 70 CPDF_Dictionary* pagesDict = CreatePageTreeNode(allPages, this, 7); |
| 70 | 71 |
| 71 CPDF_Dictionary* root = new CPDF_Dictionary(); | 72 m_pOwnedRootDict.reset(new CPDF_Dictionary()); |
| 72 root->SetReferenceFor("Pages", this, AddIndirectObject(pagesDict)); | 73 m_pOwnedRootDict->SetReferenceFor("Pages", this, |
| 73 m_pRootDict = root; | 74 AddIndirectObject(pagesDict)); |
| 75 m_pRootDict = m_pOwnedRootDict.get(); |
| 74 m_PageList.SetSize(7); | 76 m_PageList.SetSize(7); |
| 75 } | 77 } |
| 78 |
| 79 private: |
| 80 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> |
| 81 m_pOwnedRootDict; |
| 76 }; | 82 }; |
| 77 | 83 |
| 78 TEST(cpdf_document, GetPages) { | 84 TEST(cpdf_document, GetPages) { |
| 79 std::unique_ptr<CPDF_TestDocumentForPages> document = | 85 std::unique_ptr<CPDF_TestDocumentForPages> document = |
| 80 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); | 86 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); |
| 81 for (int i = 0; i < 7; i++) { | 87 for (int i = 0; i < 7; i++) { |
| 82 CPDF_Dictionary* page = document->GetPage(i); | 88 CPDF_Dictionary* page = document->GetPage(i); |
| 83 ASSERT_TRUE(page); | 89 ASSERT_TRUE(page); |
| 84 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); | 90 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); |
| 85 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); | 91 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); |
| 86 } | 92 } |
| 87 CPDF_Dictionary* page = document->GetPage(7); | 93 CPDF_Dictionary* page = document->GetPage(7); |
| 88 EXPECT_FALSE(page); | 94 EXPECT_FALSE(page); |
| 89 } | 95 } |
| 90 | 96 |
| 91 TEST(cpdf_document, GetPagesReverseOrder) { | 97 TEST(cpdf_document, GetPagesReverseOrder) { |
| 92 std::unique_ptr<CPDF_TestDocumentForPages> document = | 98 std::unique_ptr<CPDF_TestDocumentForPages> document = |
| 93 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); | 99 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); |
| 94 for (int i = 6; i >= 0; i--) { | 100 for (int i = 6; i >= 0; i--) { |
| 95 CPDF_Dictionary* page = document->GetPage(i); | 101 CPDF_Dictionary* page = document->GetPage(i); |
| 96 ASSERT_TRUE(page); | 102 ASSERT_TRUE(page); |
| 97 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); | 103 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); |
| 98 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); | 104 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); |
| 99 } | 105 } |
| 100 CPDF_Dictionary* page = document->GetPage(7); | 106 CPDF_Dictionary* page = document->GetPage(7); |
| 101 EXPECT_FALSE(page); | 107 EXPECT_FALSE(page); |
| 102 } | 108 } |
| OLD | NEW |