OLD | NEW |
---|---|
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 "embedder_test.h" | 5 #include "embedder_test.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include <list> | 12 #include <list> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "../public/fpdf_dataavail.h" | |
17 #include "../public/fpdf_text.h" | 18 #include "../public/fpdf_text.h" |
18 #include "../public/fpdfview.h" | |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 | 20 |
21 #ifdef PDF_ENABLE_V8 | 21 #ifdef PDF_ENABLE_V8 |
22 #include "v8/include/libplatform/libplatform.h" | 22 #include "v8/include/libplatform/libplatform.h" |
23 #include "v8/include/v8.h" | 23 #include "v8/include/v8.h" |
24 #endif // PDF_ENABLE_V8 | 24 #endif // PDF_ENABLE_V8 |
25 | 25 |
26 #ifdef _WIN32 | 26 #ifdef _WIN32 |
27 #define snprintf _snprintf | 27 #define snprintf _snprintf |
28 #define PATH_SEPARATOR '\\' | 28 #define PATH_SEPARATOR '\\' |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 | 190 |
191 #ifdef PDF_ENABLE_V8 | 191 #ifdef PDF_ENABLE_V8 |
192 v8::V8::ShutdownPlatform(); | 192 v8::V8::ShutdownPlatform(); |
193 delete platform_; | 193 delete platform_; |
194 #endif // PDF_ENABLE_V8 | 194 #endif // PDF_ENABLE_V8 |
195 | 195 |
196 delete loader_; | 196 delete loader_; |
197 free(file_contents_); | 197 free(file_contents_); |
198 } | 198 } |
199 | 199 |
200 bool EmbedderTest::OpenDocument(const std::string& filename) { | 200 bool EmbedderTest::OpenDocument(const std::string& filename, |
201 const bool must_linearize) { | |
201 file_contents_ = GetFileContents(filename.c_str(), &file_length_); | 202 file_contents_ = GetFileContents(filename.c_str(), &file_length_); |
202 if (!file_contents_) { | 203 if (!file_contents_) { |
203 return false; | 204 return false; |
204 } | 205 } |
205 | 206 |
206 loader_ = new TestLoader(file_contents_, file_length_); | 207 loader_ = new TestLoader(file_contents_, file_length_); |
207 file_access_.m_FileLen = static_cast<unsigned long>(file_length_); | 208 file_access_.m_FileLen = static_cast<unsigned long>(file_length_); |
208 file_access_.m_GetBlock = Get_Block; | 209 file_access_.m_GetBlock = Get_Block; |
209 file_access_.m_Param = loader_; | 210 file_access_.m_Param = loader_; |
210 | 211 |
211 file_avail_.version = 1; | 212 file_avail_.version = 1; |
212 file_avail_.IsDataAvail = Is_Data_Avail; | 213 file_avail_.IsDataAvail = Is_Data_Avail; |
213 | 214 |
214 hints_.version = 1; | 215 hints_.version = 1; |
215 hints_.AddSegment = Add_Segment; | 216 hints_.AddSegment = Add_Segment; |
216 | 217 |
217 avail_ = FPDFAvail_Create(&file_avail_, &file_access_); | 218 avail_ = FPDFAvail_Create(&file_avail_, &file_access_); |
218 (void)FPDFAvail_IsDocAvail(avail_, &hints_); | 219 if (FPDFAvail_IsLinearized(avail_) == PDF_LINEARIZED || must_linearize) { |
219 | 220 document_ = FPDFAvail_GetDocument(avail_, nullptr); |
220 if (!FPDFAvail_IsLinearized(avail_)) { | 221 if (!document_) { |
222 return false; | |
223 } | |
224 int32_t nRet = PDF_DATA_NOTAVAIL; | |
225 while (nRet == PDF_DATA_NOTAVAIL) { | |
226 nRet = FPDFAvail_IsDocAvail(avail_, &hints_); | |
227 } | |
228 if (nRet == PDF_DATA_ERROR) { | |
229 return false; | |
230 } | |
231 if (FPDFAvail_IsFormAvail(avail_, &hints_) == PDF_FORM_NOTAVAIL) { | |
232 return false; | |
233 } | |
234 int page_count = FPDF_GetPageCount(document_); | |
235 for (int i = 0; i < page_count; ++i) { | |
236 nRet = PDF_DATA_NOTAVAIL; | |
237 while (nRet == PDF_DATA_NOTAVAIL) { | |
238 nRet = FPDFAvail_IsPageAvail(avail_, i, &hints_); | |
239 } | |
240 if (nRet == PDF_DATA_ERROR) { | |
241 return false; | |
242 } | |
243 } | |
244 } else { | |
Tom Sepez
2015/10/21 17:53:08
I'd imagine you would wait til here to check must_
| |
221 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); | 245 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); |
222 } else { | 246 if (!document_) { |
223 document_ = FPDFAvail_GetDocument(avail_, nullptr); | 247 return false; |
248 } | |
224 } | 249 } |
225 | 250 |
226 (void)FPDF_GetDocPermissions(document_); | 251 (void)FPDF_GetDocPermissions(document_); |
227 (void)FPDFAvail_IsFormAvail(avail_, &hints_); | |
228 | 252 |
229 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); | 253 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); |
230 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); | 254 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); |
231 platform->version = 2; | 255 platform->version = 2; |
232 platform->app_alert = AlertTrampoline; | 256 platform->app_alert = AlertTrampoline; |
233 | 257 |
234 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); | 258 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); |
235 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); | 259 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); |
236 formfillinfo->version = 1; | 260 formfillinfo->version = 1; |
237 formfillinfo->FFI_SetTimer = SetTimerTrampoline; | 261 formfillinfo->FFI_SetTimer = SetTimerTrampoline; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 } | 380 } |
357 | 381 |
358 // Can't use gtest-provided main since we need to stash the path to the | 382 // Can't use gtest-provided main since we need to stash the path to the |
359 // executable in order to find the external V8 binary data files. | 383 // executable in order to find the external V8 binary data files. |
360 int main(int argc, char** argv) { | 384 int main(int argc, char** argv) { |
361 g_exe_path_ = argv[0]; | 385 g_exe_path_ = argv[0]; |
362 testing::InitGoogleTest(&argc, argv); | 386 testing::InitGoogleTest(&argc, argv); |
363 testing::InitGoogleMock(&argc, argv); | 387 testing::InitGoogleMock(&argc, argv); |
364 return RUN_ALL_TESTS(); | 388 return RUN_ALL_TESTS(); |
365 } | 389 } |
OLD | NEW |