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

Side by Side Diff: testing/embedder_test.cpp

Issue 1412083010: Merge to XFA: Support linearized loading (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 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 (c) 2015 PDFium Authors. All rights reserved. 1 // Copyright (c) 2015 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 "testing/embedder_test.h" 5 #include "testing/embedder_test.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <list> 9 #include <list>
10 #include <string> 10 #include <string>
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 #ifdef PDF_ENABLE_V8 91 #ifdef PDF_ENABLE_V8
92 v8::V8::ShutdownPlatform(); 92 v8::V8::ShutdownPlatform();
93 delete platform_; 93 delete platform_;
94 #endif // PDF_ENABLE_V8 94 #endif // PDF_ENABLE_V8
95 95
96 delete loader_; 96 delete loader_;
97 free(file_contents_); 97 free(file_contents_);
98 } 98 }
99 99
100 bool EmbedderTest::OpenDocument(const std::string& filename) { 100 bool EmbedderTest::OpenDocument(const std::string& filename,
101 bool must_linearize) {
101 std::string file_path; 102 std::string file_path;
102 if (!PathService::GetTestFilePath(filename, &file_path)) 103 if (!PathService::GetTestFilePath(filename, &file_path))
103 return false; 104 return false;
104 file_contents_ = GetFileContents(file_path.c_str(), &file_length_); 105 file_contents_ = GetFileContents(file_path.c_str(), &file_length_);
105 if (!file_contents_) 106 if (!file_contents_)
106 return false; 107 return false;
107 108
108 loader_ = new TestLoader(file_contents_, file_length_); 109 loader_ = new TestLoader(file_contents_, file_length_);
109 file_access_.m_FileLen = static_cast<unsigned long>(file_length_); 110 file_access_.m_FileLen = static_cast<unsigned long>(file_length_);
110 file_access_.m_GetBlock = TestLoader::GetBlock; 111 file_access_.m_GetBlock = TestLoader::GetBlock;
111 file_access_.m_Param = loader_; 112 file_access_.m_Param = loader_;
112 113
113 file_avail_.version = 1; 114 file_avail_.version = 1;
114 file_avail_.IsDataAvail = Is_Data_Avail; 115 file_avail_.IsDataAvail = Is_Data_Avail;
115 116
116 hints_.version = 1; 117 hints_.version = 1;
117 hints_.AddSegment = Add_Segment; 118 hints_.AddSegment = Add_Segment;
118 119
119 avail_ = FPDFAvail_Create(&file_avail_, &file_access_); 120 avail_ = FPDFAvail_Create(&file_avail_, &file_access_);
120 (void)FPDFAvail_IsDocAvail(avail_, &hints_);
121 121
122 if (!FPDFAvail_IsLinearized(avail_)) 122 if (FPDFAvail_IsLinearized(avail_) == PDF_LINEARIZED) {
123 document_ = FPDFAvail_GetDocument(avail_, nullptr);
124 if (!document_) {
125 return false;
126 }
127 int32_t nRet = PDF_DATA_NOTAVAIL;
128 while (nRet == PDF_DATA_NOTAVAIL) {
129 nRet = FPDFAvail_IsDocAvail(avail_, &hints_);
130 }
131 if (nRet == PDF_DATA_ERROR) {
132 return false;
133 }
134 nRet = FPDFAvail_IsFormAvail(avail_, &hints_);
135 if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) {
136 return false;
137 }
138 int page_count = FPDF_GetPageCount(document_);
139 for (int i = 0; i < page_count; ++i) {
140 nRet = PDF_DATA_NOTAVAIL;
141 while (nRet == PDF_DATA_NOTAVAIL) {
142 nRet = FPDFAvail_IsPageAvail(avail_, i, &hints_);
143 }
144 if (nRet == PDF_DATA_ERROR) {
145 return false;
146 }
147 }
148 } else {
149 if (must_linearize) {
150 return false;
151 }
123 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); 152 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr);
124 else 153 if (!document_) {
125 document_ = FPDFAvail_GetDocument(avail_, nullptr); 154 return false;
126 155 }
127 if (!document_) 156 }
128 return false;
129 157
130 int docType = DOCTYPE_PDF; 158 int docType = DOCTYPE_PDF;
131 if (FPDF_HasXFAField(document_, &docType)) { 159 if (FPDF_HasXFAField(document_, &docType)) {
132 if (docType != DOCTYPE_PDF) 160 if (docType != DOCTYPE_PDF)
133 (void)FPDF_LoadXFA(document_); 161 (void)FPDF_LoadXFA(document_);
134 } 162 }
135 163
136 (void)FPDF_GetDocPermissions(document_); 164 (void)FPDF_GetDocPermissions(document_);
137 (void)FPDFAvail_IsFormAvail(avail_, &hints_);
138 165
139 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); 166 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
140 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); 167 memset(platform, 0, sizeof(IPDF_JSPLATFORM));
141 platform->version = 2; 168 platform->version = 2;
142 platform->app_alert = AlertTrampoline; 169 platform->app_alert = AlertTrampoline;
143 170
144 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); 171 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this);
145 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); 172 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO));
146 #ifdef PDF_ENABLE_XFA 173 #ifdef PDF_ENABLE_XFA
147 formfillinfo->version = 2; 174 formfillinfo->version = 2;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 297 }
271 298
272 // Can't use gtest-provided main since we need to stash the path to the 299 // Can't use gtest-provided main since we need to stash the path to the
273 // executable in order to find the external V8 binary data files. 300 // executable in order to find the external V8 binary data files.
274 int main(int argc, char** argv) { 301 int main(int argc, char** argv) {
275 g_exe_path_ = argv[0]; 302 g_exe_path_ = argv[0];
276 testing::InitGoogleTest(&argc, argv); 303 testing::InitGoogleTest(&argc, argv);
277 testing::InitGoogleMock(&argc, argv); 304 testing::InitGoogleMock(&argc, argv);
278 return RUN_ALL_TESTS(); 305 return RUN_ALL_TESTS();
279 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698