OLD | NEW |
(Empty) | |
| 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 "core/fpdfapi/parser/cpdf_document.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "core/fpdfapi/parser/cpdf_parser.h" |
| 10 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 11 #include "core/fxcrt/fx_memory.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 using ScopedDictionary = |
| 17 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>; |
| 18 |
| 19 } // namespace |
| 20 |
| 21 TEST(cpdf_document, UseCachedPageObjNumIfHaveNotPagesDict) { |
| 22 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict |
| 23 // can be not exists in this case. |
| 24 // (case, when hint table is used to page check in CPDF_DataAvail). |
| 25 CPDF_Document document(std::make_unique<CPDF_Parser>()); |
| 26 ScopedDictionary dict(new CPDF_Dictionary()); |
| 27 const int page_count = 100; |
| 28 dict->SetIntegerFor("N", page_count); |
| 29 document.LoadLinearizedDoc(dict.get()); |
| 30 ASSERT_EQ(page_count, document.GetPageCount()); |
| 31 CPDF_Object* page_stub = new CPDF_Dictionary(); |
| 32 const uint32_t obj_num = document.AddIndirectObject(page_stub); |
| 33 const int test_page_num = 33; |
| 34 |
| 35 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); |
| 36 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); |
| 37 |
| 38 document.SetPageObjNum(test_page_num, obj_num); |
| 39 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); |
| 40 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); |
| 41 } |
OLD | NEW |