Chromium Code Reviews| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 for (int i = 6; i >= 0; i--) { | 109 for (int i = 6; i >= 0; i--) { |
| 110 CPDF_Dictionary* page = document->GetPage(i); | 110 CPDF_Dictionary* page = document->GetPage(i); |
| 111 ASSERT_TRUE(page); | 111 ASSERT_TRUE(page); |
| 112 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); | 112 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); |
| 113 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); | 113 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); |
| 114 } | 114 } |
| 115 CPDF_Dictionary* page = document->GetPage(7); | 115 CPDF_Dictionary* page = document->GetPage(7); |
| 116 EXPECT_FALSE(page); | 116 EXPECT_FALSE(page); |
| 117 } | 117 } |
| 118 | 118 |
| 119 TEST(cpdf_document, GetPagesInDisorder) { | |
| 120 std::unique_ptr<CPDF_TestDocumentForPages> document = | |
| 121 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); | |
| 122 | |
| 123 CPDF_Dictionary* page = document->GetPage(1); | |
| 124 ASSERT_TRUE(page); | |
| 125 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); | |
|
Lei Zhang
2016/11/04 01:38:52
Since you are not grabbing the actual object here,
npm
2016/11/04 19:33:33
Done.
| |
| 126 EXPECT_EQ(1, page->GetIntegerFor("PageNumbering")); | |
| 127 | |
| 128 page = document->GetPage(3); | |
| 129 ASSERT_TRUE(page); | |
| 130 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); | |
| 131 EXPECT_EQ(3, page->GetIntegerFor("PageNumbering")); | |
| 132 | |
| 133 page = document->GetPage(7); | |
| 134 EXPECT_FALSE(page); | |
| 135 | |
| 136 page = document->GetPage(6); | |
| 137 ASSERT_TRUE(page); | |
| 138 ASSERT_TRUE(page->GetObjectFor("PageNumbering")); | |
| 139 EXPECT_EQ(6, page->GetIntegerFor("PageNumbering")); | |
| 140 } | |
| 141 | |
| 119 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { | 142 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { |
| 120 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict | 143 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict |
| 121 // can be not exists in this case. | 144 // can be not exists in this case. |
| 122 // (case, when hint table is used to page check in CPDF_DataAvail). | 145 // (case, when hint table is used to page check in CPDF_DataAvail). |
| 123 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); | 146 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); |
| 124 ScopedDictionary dict(new CPDF_Dictionary()); | 147 ScopedDictionary dict(new CPDF_Dictionary()); |
| 125 const int page_count = 100; | 148 const int page_count = 100; |
| 126 dict->SetIntegerFor("N", page_count); | 149 dict->SetIntegerFor("N", page_count); |
| 127 document.LoadLinearizedDoc(dict.get()); | 150 document.LoadLinearizedDoc(dict.get()); |
| 128 ASSERT_EQ(page_count, document.GetPageCount()); | 151 ASSERT_EQ(page_count, document.GetPageCount()); |
| 129 CPDF_Object* page_stub = new CPDF_Dictionary(); | 152 CPDF_Object* page_stub = new CPDF_Dictionary(); |
| 130 const uint32_t obj_num = document.AddIndirectObject(page_stub); | 153 const uint32_t obj_num = document.AddIndirectObject(page_stub); |
| 131 const int test_page_num = 33; | 154 const int test_page_num = 33; |
| 132 | 155 |
| 133 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); | 156 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); |
| 134 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); | 157 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); |
| 135 | 158 |
| 136 document.SetPageObjNum(test_page_num, obj_num); | 159 document.SetPageObjNum(test_page_num, obj_num); |
| 137 | 160 |
| 138 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); | 161 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); |
| 139 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); | 162 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); |
| 140 } | 163 } |
| OLD | NEW |