| 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" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 void TearDown() override {} | 89 void TearDown() override {} |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 TEST_F(cpdf_document_test, GetPages) { | 92 TEST_F(cpdf_document_test, GetPages) { |
| 93 std::unique_ptr<CPDF_TestDocumentForPages> document = | 93 std::unique_ptr<CPDF_TestDocumentForPages> document = |
| 94 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); | 94 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); |
| 95 for (int i = 0; i < 7; i++) { | 95 for (int i = 0; i < 7; i++) { |
| 96 CPDF_Dictionary* page = document->GetPage(i); | 96 CPDF_Dictionary* page = document->GetPage(i); |
| 97 ASSERT_TRUE(page); | 97 ASSERT_TRUE(page); |
| 98 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); | 98 ASSERT_TRUE(page->KeyExist("PageNumbering")); |
| 99 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); | 99 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); |
| 100 } | 100 } |
| 101 CPDF_Dictionary* page = document->GetPage(7); | 101 CPDF_Dictionary* page = document->GetPage(7); |
| 102 EXPECT_FALSE(page); | 102 EXPECT_FALSE(page); |
| 103 } | 103 } |
| 104 | 104 |
| 105 TEST_F(cpdf_document_test, GetPagesReverseOrder) { | 105 TEST_F(cpdf_document_test, GetPagesReverseOrder) { |
| 106 std::unique_ptr<CPDF_TestDocumentForPages> document = | 106 std::unique_ptr<CPDF_TestDocumentForPages> document = |
| 107 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); | 107 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); |
| 108 for (int i = 6; i >= 0; i--) { | 108 for (int i = 6; i >= 0; i--) { |
| 109 CPDF_Dictionary* page = document->GetPage(i); | 109 CPDF_Dictionary* page = document->GetPage(i); |
| 110 ASSERT_TRUE(page); | 110 ASSERT_TRUE(page); |
| 111 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); | 111 ASSERT_TRUE(page->KeyExist("PageNumbering")); |
| 112 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); | 112 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); |
| 113 } | 113 } |
| 114 CPDF_Dictionary* page = document->GetPage(7); | 114 CPDF_Dictionary* page = document->GetPage(7); |
| 115 EXPECT_FALSE(page); | 115 EXPECT_FALSE(page); |
| 116 } | 116 } |
| 117 | 117 |
| 118 TEST(cpdf_document, GetPagesInDisorder) { |
| 119 std::unique_ptr<CPDF_TestDocumentForPages> document = |
| 120 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); |
| 121 |
| 122 CPDF_Dictionary* page = document->GetPage(1); |
| 123 ASSERT_TRUE(page); |
| 124 ASSERT_TRUE(page->KeyExist("PageNumbering")); |
| 125 EXPECT_EQ(1, page->GetIntegerFor("PageNumbering")); |
| 126 |
| 127 page = document->GetPage(3); |
| 128 ASSERT_TRUE(page); |
| 129 ASSERT_TRUE(page->KeyExist("PageNumbering")); |
| 130 EXPECT_EQ(3, page->GetIntegerFor("PageNumbering")); |
| 131 |
| 132 page = document->GetPage(7); |
| 133 EXPECT_FALSE(page); |
| 134 |
| 135 page = document->GetPage(6); |
| 136 ASSERT_TRUE(page); |
| 137 ASSERT_TRUE(page->KeyExist("PageNumbering")); |
| 138 EXPECT_EQ(6, page->GetIntegerFor("PageNumbering")); |
| 139 } |
| 140 |
| 118 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { | 141 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { |
| 119 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict | 142 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict |
| 120 // can be not exists in this case. | 143 // can be not exists in this case. |
| 121 // (case, when hint table is used to page check in CPDF_DataAvail). | 144 // (case, when hint table is used to page check in CPDF_DataAvail). |
| 122 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); | 145 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); |
| 123 std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary()); | 146 std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary()); |
| 124 const int page_count = 100; | 147 const int page_count = 100; |
| 125 dict->SetIntegerFor("N", page_count); | 148 dict->SetIntegerFor("N", page_count); |
| 126 document.LoadLinearizedDoc(dict.get()); | 149 document.LoadLinearizedDoc(dict.get()); |
| 127 ASSERT_EQ(page_count, document.GetPageCount()); | 150 ASSERT_EQ(page_count, document.GetPageCount()); |
| 128 CPDF_Object* page_stub = new CPDF_Dictionary(); | 151 CPDF_Object* page_stub = new CPDF_Dictionary(); |
| 129 const uint32_t obj_num = document.AddIndirectObject(page_stub); | 152 const uint32_t obj_num = document.AddIndirectObject(page_stub); |
| 130 const int test_page_num = 33; | 153 const int test_page_num = 33; |
| 131 | 154 |
| 132 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); | 155 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); |
| 133 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); | 156 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); |
| 134 | 157 |
| 135 document.SetPageObjNum(test_page_num, obj_num); | 158 document.SetPageObjNum(test_page_num, obj_num); |
| 136 | 159 |
| 137 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); | 160 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); |
| 138 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); | 161 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); |
| 139 } | 162 } |
| OLD | NEW |