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

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 signed/unsigned comparison 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
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 25 matching lines...) Expand all
36 return page; 36 return page;
37 } 37 }
38 38
39 class CPDF_TestDocumentForPages : public CPDF_Document { 39 class CPDF_TestDocumentForPages : public CPDF_Document {
40 public: 40 public:
41 CPDF_TestDocumentForPages() : CPDF_Document(nullptr) { 41 CPDF_TestDocumentForPages() : CPDF_Document(nullptr) {
42 // Set up test 42 // Set up test
43 CPDF_Array* zeroToTwo = new CPDF_Array(); 43 CPDF_Array* zeroToTwo = new CPDF_Array();
44 zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(0))); 44 zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(0)));
45 zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(1))); 45 zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(1)));
46 zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(2))); 46 // Page without pageNum.
47 zeroToTwo->Add(CreateNumberedPage(2));
47 CPDF_Dictionary* branch1 = CreatePageTreeNode(zeroToTwo, this, 3); 48 CPDF_Dictionary* branch1 = CreatePageTreeNode(zeroToTwo, this, 3);
48 49
49 CPDF_Array* zeroToThree = new CPDF_Array(); 50 CPDF_Array* zeroToThree = new CPDF_Array();
50 zeroToThree->AddReference(this, branch1->GetObjNum()); 51 zeroToThree->AddReference(this, branch1->GetObjNum());
51 zeroToThree->AddReference(this, AddIndirectObject(CreateNumberedPage(3))); 52 zeroToThree->AddReference(this, AddIndirectObject(CreateNumberedPage(3)));
52 CPDF_Dictionary* branch2 = CreatePageTreeNode(zeroToThree, this, 4); 53 CPDF_Dictionary* branch2 = CreatePageTreeNode(zeroToThree, this, 4);
53 54
54 CPDF_Array* fourFive = new CPDF_Array(); 55 CPDF_Array* fourFive = new CPDF_Array();
55 fourFive->AddReference(this, AddIndirectObject(CreateNumberedPage(4))); 56 fourFive->AddReference(this, AddIndirectObject(CreateNumberedPage(4)));
56 fourFive->AddReference(this, AddIndirectObject(CreateNumberedPage(5))); 57 fourFive->AddReference(this, AddIndirectObject(CreateNumberedPage(5)));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 for (int i = 0; i < 7; i++) { 99 for (int i = 0; i < 7; i++) {
99 CPDF_Dictionary* page = document->GetPage(i); 100 CPDF_Dictionary* page = document->GetPage(i);
100 ASSERT_TRUE(page); 101 ASSERT_TRUE(page);
101 ASSERT_TRUE(page->KeyExist("PageNumbering")); 102 ASSERT_TRUE(page->KeyExist("PageNumbering"));
102 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); 103 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering"));
103 } 104 }
104 CPDF_Dictionary* page = document->GetPage(7); 105 CPDF_Dictionary* page = document->GetPage(7);
105 EXPECT_FALSE(page); 106 EXPECT_FALSE(page);
106 } 107 }
107 108
109 TEST_F(cpdf_document_test, GetPageWithoutObjNumTwice) {
110 std::unique_ptr<CPDF_TestDocumentForPages> document =
111 pdfium::MakeUnique<CPDF_TestDocumentForPages>();
112 const auto page = document->GetPage(2);
Lei Zhang 2016/11/09 20:19:41 There's room on this line, so let's write const CP
snake 2016/11/09 20:30:41 Done.
113 ASSERT_TRUE(page);
114 // This is page without obj num.
115 ASSERT_EQ(0ul, page->GetObjNum());
116 const auto second_call_page = document->GetPage(2);
117 EXPECT_TRUE(second_call_page);
118 EXPECT_EQ(page, second_call_page);
119 }
120
108 TEST_F(cpdf_document_test, GetPagesReverseOrder) { 121 TEST_F(cpdf_document_test, GetPagesReverseOrder) {
109 std::unique_ptr<CPDF_TestDocumentForPages> document = 122 std::unique_ptr<CPDF_TestDocumentForPages> document =
110 pdfium::MakeUnique<CPDF_TestDocumentForPages>(); 123 pdfium::MakeUnique<CPDF_TestDocumentForPages>();
111 for (int i = 6; i >= 0; i--) { 124 for (int i = 6; i >= 0; i--) {
112 CPDF_Dictionary* page = document->GetPage(i); 125 CPDF_Dictionary* page = document->GetPage(i);
113 ASSERT_TRUE(page); 126 ASSERT_TRUE(page);
114 ASSERT_TRUE(page->KeyExist("PageNumbering")); 127 ASSERT_TRUE(page->KeyExist("PageNumbering"));
115 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering")); 128 EXPECT_EQ(i, page->GetIntegerFor("PageNumbering"));
116 } 129 }
117 CPDF_Dictionary* page = document->GetPage(7); 130 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; 171 const int test_page_num = 33;
159 172
160 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); 173 EXPECT_FALSE(document.IsPageLoaded(test_page_num));
161 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); 174 EXPECT_EQ(nullptr, document.GetPage(test_page_num));
162 175
163 document.SetPageObjNum(test_page_num, obj_num); 176 document.SetPageObjNum(test_page_num, obj_num);
164 177
165 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); 178 EXPECT_TRUE(document.IsPageLoaded(test_page_num));
166 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); 179 EXPECT_EQ(page_stub, document.GetPage(test_page_num));
167 } 180 }
OLDNEW
« core/fpdfapi/parser/cpdf_document.cpp ('K') | « core/fpdfapi/parser/cpdf_document.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698