Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: core/fpdfapi/parser/cpdf_document_unittest.cpp

Issue 2491583002: Fix receiving page, if it have not obj num. (Closed)
Patch Set: Fix review issues Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/parser/cpdf_document.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 m_pOwnedRootDict.reset(new CPDF_Dictionary()); 69 m_pOwnedRootDict.reset(new CPDF_Dictionary());
70 m_pOwnedRootDict->SetReferenceFor("Pages", this, pagesDict->GetObjNum()); 70 m_pOwnedRootDict->SetReferenceFor("Pages", this, pagesDict->GetObjNum());
71 m_pRootDict = m_pOwnedRootDict.get(); 71 m_pRootDict = m_pOwnedRootDict.get();
72 m_PageList.SetSize(7); 72 m_PageList.SetSize(7);
73 } 73 }
74 74
75 private: 75 private:
76 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict; 76 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict;
77 }; 77 };
78 78
79 class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document {
80 public:
81 CPDF_TestDocumentWithPageWithoutPageNum() : CPDF_Document(nullptr) {
82 // Set up test
83 CPDF_Array* allPages = new CPDF_Array();
84 allPages->AddReference(this, AddIndirectObject(CreateNumberedPage(0)));
85 allPages->AddReference(this, AddIndirectObject(CreateNumberedPage(1)));
86 // Page without pageNum.
87 allPages->Add(CreateNumberedPage(2));
88 CPDF_Dictionary* pagesDict = CreatePageTreeNode(allPages, this, 3);
89
90 m_pOwnedRootDict.reset(new CPDF_Dictionary());
91 m_pOwnedRootDict->SetReferenceFor("Pages", this, pagesDict->GetObjNum());
92 m_pRootDict = m_pOwnedRootDict.get();
93 m_PageList.SetSize(3);
94 }
95
96 private:
97 std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict;
98 };
99
79 class TestLinearized : public CPDF_LinearizedHeader { 100 class TestLinearized : public CPDF_LinearizedHeader {
80 public: 101 public:
81 explicit TestLinearized(CPDF_Dictionary* dict) 102 explicit TestLinearized(CPDF_Dictionary* dict)
82 : CPDF_LinearizedHeader(dict) {} 103 : CPDF_LinearizedHeader(dict) {}
83 }; 104 };
84 } // namespace 105 } // namespace
85 106
86 class cpdf_document_test : public testing::Test { 107 class cpdf_document_test : public testing::Test {
87 public: 108 public:
88 void SetUp() override { 109 void SetUp() override {
89 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); 110 CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get();
90 module_mgr->InitPageModule(); 111 module_mgr->InitPageModule();
91 } 112 }
92 void TearDown() override {} 113 void TearDown() override {}
93 }; 114 };
94 115
95 TEST_F(cpdf_document_test, GetPages) { 116 TEST_F(cpdf_document_test, GetPages) {
96 std::unique_ptr<CPDF_TestDocumentForPages> document = 117 std::unique_ptr<CPDF_TestDocumentForPages> document =
97 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); 118 pdfium::MakeUnique<CPDF_TestDocumentForPages>();
98 for (int i = 0; i < 7; i++) { 119 for (int i = 0; i < 7; i++) {
99 CPDF_Dictionary* page = document->GetPage(i); 120 CPDF_Dictionary* page = document->GetPage(i);
100 ASSERT_TRUE(page); 121 ASSERT_TRUE(page);
101 ASSERT_TRUE(page->KeyExist("PageNumbering")); 122 ASSERT_TRUE(page->KeyExist("PageNumbering"));
102 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); 123 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering"));
103 } 124 }
104 CPDF_Dictionary* page = document->GetPage(7); 125 CPDF_Dictionary* page = document->GetPage(7);
105 EXPECT_FALSE(page); 126 EXPECT_FALSE(page);
106 } 127 }
107 128
129 TEST_F(cpdf_document_test, GetPageWithoutObjNumTwice) {
130 std::unique_ptr<CPDF_TestDocumentWithPageWithoutPageNum> document =
131 pdfium::MakeUnique<CPDF_TestDocumentWithPageWithoutPageNum>();
132 const CPDF_Dictionary* page = document->GetPage(2);
133 ASSERT_TRUE(page);
134 // This is page without obj num.
135 ASSERT_EQ(0ul, page->GetObjNum());
136 const CPDF_Dictionary* second_call_page = document->GetPage(2);
137 EXPECT_TRUE(second_call_page);
138 EXPECT_EQ(page, second_call_page);
139 }
140
108 TEST_F(cpdf_document_test, GetPagesReverseOrder) { 141 TEST_F(cpdf_document_test, GetPagesReverseOrder) {
109 std::unique_ptr<CPDF_TestDocumentForPages> document = 142 std::unique_ptr<CPDF_TestDocumentForPages> document =
110 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); 143 pdfium::MakeUnique<CPDF_TestDocumentForPages>();
111 for (int i = 6; i >= 0; i--) { 144 for (int i = 6; i >= 0; i--) {
112 CPDF_Dictionary* page = document->GetPage(i); 145 CPDF_Dictionary* page = document->GetPage(i);
113 ASSERT_TRUE(page); 146 ASSERT_TRUE(page);
114 ASSERT_TRUE(page->KeyExist("PageNumbering")); 147 ASSERT_TRUE(page->KeyExist("PageNumbering"));
115 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); 148 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering"));
116 } 149 }
117 CPDF_Dictionary* page = document->GetPage(7); 150 CPDF_Dictionary* page = document->GetPage(7);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 const int test_page_num = 33; 191 const int test_page_num = 33;
159 192
160 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); 193 EXPECT_FALSE(document.IsPageLoaded(test_page_num));
161 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); 194 EXPECT_EQ(nullptr, document.GetPage(test_page_num));
162 195
163 document.SetPageObjNum(test_page_num, obj_num); 196 document.SetPageObjNum(test_page_num, obj_num);
164 197
165 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); 198 EXPECT_TRUE(document.IsPageLoaded(test_page_num));
166 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); 199 EXPECT_EQ(page_stub, document.GetPage(test_page_num));
167 } 200 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_document.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698