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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 file_access_.m_GetBlock = Get_Block; | 208 file_access_.m_GetBlock = Get_Block; |
209 file_access_.m_Param = loader_; | 209 file_access_.m_Param = loader_; |
210 | 210 |
211 file_avail_.version = 1; | 211 file_avail_.version = 1; |
212 file_avail_.IsDataAvail = Is_Data_Avail; | 212 file_avail_.IsDataAvail = Is_Data_Avail; |
213 | 213 |
214 hints_.version = 1; | 214 hints_.version = 1; |
215 hints_.AddSegment = Add_Segment; | 215 hints_.AddSegment = Add_Segment; |
216 | 216 |
217 avail_ = FPDFAvail_Create(&file_avail_, &file_access_); | 217 avail_ = FPDFAvail_Create(&file_avail_, &file_access_); |
218 (void)FPDFAvail_IsDocAvail(avail_, &hints_); | 218 if (FPDFAvail_IsLinearized(avail_) == PDF_LINEARIZED) { |
219 | 219 document_ = FPDFAvail_GetDocument(avail_, nullptr); |
220 if (!FPDFAvail_IsLinearized(avail_)) { | 220 if (!document_) { |
| 221 return false; |
| 222 } |
| 223 int32_t nRet = PDF_DATA_NOTAVAIL; |
| 224 while (nRet == PDF_DATA_NOTAVAIL) { |
| 225 nRet = FPDFAvail_IsDocAvail(avail_, &hints_); |
| 226 } |
| 227 if (nRet == PDF_DATA_NOTAVAIL) { |
| 228 return false; |
| 229 } |
| 230 if (FPDFAvail_IsFormAvail(avail_, &hints_) == PDF_FORM_NOTAVAIL) { |
| 231 return false; |
| 232 } |
| 233 int page_count = FPDF_GetPageCount(document_); |
| 234 for (int i = 0; i < page_count; ++i) { |
| 235 nRet = PDF_DATA_NOTAVAIL; |
| 236 while (nRet == PDF_DATA_NOTAVAIL) { |
| 237 nRet = FPDFAvail_IsPageAvail(avail_, i, &hints_); |
| 238 } |
| 239 if (nRet == PDF_DATA_ERROR) { |
| 240 return false; |
| 241 } |
| 242 } |
| 243 } else { |
221 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); | 244 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); |
222 } else { | 245 if (!document_) { |
223 document_ = FPDFAvail_GetDocument(avail_, nullptr); | 246 return false; |
| 247 } |
224 } | 248 } |
225 | 249 |
226 (void)FPDF_GetDocPermissions(document_); | 250 (void)FPDF_GetDocPermissions(document_); |
227 (void)FPDFAvail_IsFormAvail(avail_, &hints_); | |
228 | 251 |
229 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); | 252 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); |
230 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); | 253 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); |
231 platform->version = 2; | 254 platform->version = 2; |
232 platform->app_alert = AlertTrampoline; | 255 platform->app_alert = AlertTrampoline; |
233 | 256 |
234 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); | 257 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); |
235 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); | 258 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); |
236 formfillinfo->version = 1; | 259 formfillinfo->version = 1; |
237 formfillinfo->FFI_SetTimer = SetTimerTrampoline; | 260 formfillinfo->FFI_SetTimer = SetTimerTrampoline; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } | 379 } |
357 | 380 |
358 // Can't use gtest-provided main since we need to stash the path to the | 381 // 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. | 382 // executable in order to find the external V8 binary data files. |
360 int main(int argc, char** argv) { | 383 int main(int argc, char** argv) { |
361 g_exe_path_ = argv[0]; | 384 g_exe_path_ = argv[0]; |
362 testing::InitGoogleTest(&argc, argv); | 385 testing::InitGoogleTest(&argc, argv); |
363 testing::InitGoogleMock(&argc, argv); | 386 testing::InitGoogleMock(&argc, argv); |
364 return RUN_ALL_TESTS(); | 387 return RUN_ALL_TESTS(); |
365 } | 388 } |
OLD | NEW |