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" |
| 11 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 11 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 12 #include "core/fpdfapi/parser/cpdf_linearized.h" | |
| 12 #include "core/fpdfapi/parser/cpdf_parser.h" | 13 #include "core/fpdfapi/parser/cpdf_parser.h" |
| 13 #include "core/fxcrt/fx_memory.h" | 14 #include "core/fxcrt/fx_memory.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 using ScopedDictionary = | 19 using ScopedDictionary = |
| 19 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>; | 20 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>; |
| 20 | 21 |
| 21 CPDF_Dictionary* CreatePageTreeNode(CPDF_Array* kids, | 22 CPDF_Dictionary* CreatePageTreeNode(CPDF_Array* kids, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 m_pOwnedRootDict->SetReferenceFor("Pages", this, | 73 m_pOwnedRootDict->SetReferenceFor("Pages", this, |
| 73 AddIndirectObject(pagesDict)); | 74 AddIndirectObject(pagesDict)); |
| 74 m_pRootDict = m_pOwnedRootDict.get(); | 75 m_pRootDict = m_pOwnedRootDict.get(); |
| 75 m_PageList.SetSize(7); | 76 m_PageList.SetSize(7); |
| 76 } | 77 } |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> | 80 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> |
| 80 m_pOwnedRootDict; | 81 m_pOwnedRootDict; |
| 81 }; | 82 }; |
| 83 | |
| 84 class TestLinearized : public CPDF_Linearized { | |
| 85 public: | |
| 86 TestLinearized(CPDF_Dictionary* dict) : CPDF_Linearized(dict) {} | |
|
Lei Zhang
2016/11/04 23:02:15
add "explicit"
snake
2016/11/04 23:27:36
Done.
| |
| 87 }; | |
| 82 } // namespace | 88 } // namespace |
| 83 | 89 |
| 84 class cpdf_document_test : public testing::Test { | 90 class cpdf_document_test : public testing::Test { |
| 85 public: | 91 public: |
| 86 void SetUp() override { | 92 void SetUp() override { |
| 87 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); | 93 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); |
| 88 module_mgr->InitPageModule(); | 94 module_mgr->InitPageModule(); |
| 89 } | 95 } |
| 90 void TearDown() override {} | 96 void TearDown() override {} |
| 91 }; | 97 }; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 114 } | 120 } |
| 115 CPDF_Dictionary* page = document->GetPage(7); | 121 CPDF_Dictionary* page = document->GetPage(7); |
| 116 EXPECT_FALSE(page); | 122 EXPECT_FALSE(page); |
| 117 } | 123 } |
| 118 | 124 |
| 119 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { | 125 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { |
| 120 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict | 126 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict |
| 121 // can be not exists in this case. | 127 // can be not exists in this case. |
| 122 // (case, when hint table is used to page check in CPDF_DataAvail). | 128 // (case, when hint table is used to page check in CPDF_DataAvail). |
| 123 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); | 129 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); |
| 124 ScopedDictionary dict(new CPDF_Dictionary()); | 130 UniqueDictionary dict(new CPDF_Dictionary()); |
|
Lei Zhang
2016/11/04 23:02:15
pdfium::MakeUnique<CPDF_Dictionary>()
snake
2016/11/04 23:27:36
CPDF_Dictionary should use custom deleter.
| |
| 131 dict->SetBooleanFor("Linearized", true); | |
| 125 const int page_count = 100; | 132 const int page_count = 100; |
| 126 dict->SetIntegerFor("N", page_count); | 133 dict->SetIntegerFor("N", page_count); |
| 127 document.LoadLinearizedDoc(dict.get()); | 134 TestLinearized linearized(dict.get()); |
| 135 document.LoadLinearizedDoc(&linearized); | |
| 128 ASSERT_EQ(page_count, document.GetPageCount()); | 136 ASSERT_EQ(page_count, document.GetPageCount()); |
| 129 CPDF_Object* page_stub = new CPDF_Dictionary(); | 137 CPDF_Object* page_stub = new CPDF_Dictionary(); |
| 130 const uint32_t obj_num = document.AddIndirectObject(page_stub); | 138 const uint32_t obj_num = document.AddIndirectObject(page_stub); |
| 131 const int test_page_num = 33; | 139 const int test_page_num = 33; |
| 132 | 140 |
| 133 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); | 141 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); |
| 134 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); | 142 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); |
| 135 | 143 |
| 136 document.SetPageObjNum(test_page_num, obj_num); | 144 document.SetPageObjNum(test_page_num, obj_num); |
| 137 | 145 |
| 138 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); | 146 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); |
| 139 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); | 147 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); |
| 140 } | 148 } |
| OLD | NEW |