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

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

Issue 2466023002: Unify some code (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
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"
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 115 }
115 CPDF_Dictionary* page = document->GetPage(7); 116 CPDF_Dictionary* page = document->GetPage(7);
116 EXPECT_FALSE(page); 117 EXPECT_FALSE(page);
117 } 118 }
118 119
119 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { 120 TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) {
120 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict 121 // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict
121 // can be not exists in this case. 122 // can be not exists in this case.
122 // (case, when hint table is used to page check in CPDF_DataAvail). 123 // (case, when hint table is used to page check in CPDF_DataAvail).
123 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>()); 124 CPDF_Document document(pdfium::MakeUnique<CPDF_Parser>());
124 ScopedDictionary dict(new CPDF_Dictionary()); 125 CPDF_Dictionary* dict = new CPDF_Dictionary();
125 const int page_count = 100; 126 const int page_count = 100;
126 dict->SetIntegerFor("N", page_count); 127 dict->SetIntegerFor("N", page_count);
127 document.LoadLinearizedDoc(dict.get()); 128 dict->SetBooleanFor("Linearized", true);
129 auto linearized = CPDF_Linearized::CreateForObject(UniqueObject(dict));
130 document.LoadLinearizedDoc(linearized.get());
128 ASSERT_EQ(page_count, document.GetPageCount()); 131 ASSERT_EQ(page_count, document.GetPageCount());
129 CPDF_Object* page_stub = new CPDF_Dictionary(); 132 CPDF_Object* page_stub = new CPDF_Dictionary();
130 const uint32_t obj_num = document.AddIndirectObject(page_stub); 133 const uint32_t obj_num = document.AddIndirectObject(page_stub);
131 const int test_page_num = 33; 134 const int test_page_num = 33;
132 135
133 EXPECT_FALSE(document.IsPageLoaded(test_page_num)); 136 EXPECT_FALSE(document.IsPageLoaded(test_page_num));
134 EXPECT_EQ(nullptr, document.GetPage(test_page_num)); 137 EXPECT_EQ(nullptr, document.GetPage(test_page_num));
135 138
136 document.SetPageObjNum(test_page_num, obj_num); 139 document.SetPageObjNum(test_page_num, obj_num);
137 140
138 EXPECT_TRUE(document.IsPageLoaded(test_page_num)); 141 EXPECT_TRUE(document.IsPageLoaded(test_page_num));
139 EXPECT_EQ(page_stub, document.GetPage(test_page_num)); 142 EXPECT_EQ(page_stub, document.GetPage(test_page_num));
140 } 143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698