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

Side by Side Diff: testing/embedder_test.cpp

Issue 1353093003: Support linearized loading (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
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
« no previous file with comments | « testing/embedder_test.h ('k') | testing/resources/feature_linearized_loading.pdf » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "embedder_test.h" 5 #include "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>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "../public/fpdf_dataavail.h"
14 #include "../public/fpdf_text.h" 15 #include "../public/fpdf_text.h"
15 #include "../public/fpdfview.h" 16 #include "../public/fpdfview.h"
16 #include "test_support.h" 17 #include "test_support.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 19
19 #ifdef PDF_ENABLE_V8 20 #ifdef PDF_ENABLE_V8
20 #include "v8/include/libplatform/libplatform.h" 21 #include "v8/include/libplatform/libplatform.h"
21 #include "v8/include/v8.h" 22 #include "v8/include/v8.h"
22 #endif // PDF_ENABLE_V8 23 #endif // PDF_ENABLE_V8
23 24
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 85
85 #ifdef PDF_ENABLE_V8 86 #ifdef PDF_ENABLE_V8
86 v8::V8::ShutdownPlatform(); 87 v8::V8::ShutdownPlatform();
87 delete platform_; 88 delete platform_;
88 #endif // PDF_ENABLE_V8 89 #endif // PDF_ENABLE_V8
89 90
90 delete loader_; 91 delete loader_;
91 free(file_contents_); 92 free(file_contents_);
92 } 93 }
93 94
94 bool EmbedderTest::OpenDocument(const std::string& filename) { 95 bool EmbedderTest::OpenDocument(const std::string& filename,
96 bool must_linearize) {
95 file_contents_ = GetFileContents(filename.c_str(), &file_length_); 97 file_contents_ = GetFileContents(filename.c_str(), &file_length_);
96 if (!file_contents_) 98 if (!file_contents_)
97 return false; 99 return false;
98 100
99 loader_ = new TestLoader(file_contents_, file_length_); 101 loader_ = new TestLoader(file_contents_, file_length_);
100 file_access_.m_FileLen = static_cast<unsigned long>(file_length_); 102 file_access_.m_FileLen = static_cast<unsigned long>(file_length_);
101 file_access_.m_GetBlock = TestLoader::GetBlock; 103 file_access_.m_GetBlock = TestLoader::GetBlock;
102 file_access_.m_Param = loader_; 104 file_access_.m_Param = loader_;
103 105
104 file_avail_.version = 1; 106 file_avail_.version = 1;
105 file_avail_.IsDataAvail = Is_Data_Avail; 107 file_avail_.IsDataAvail = Is_Data_Avail;
106 108
107 hints_.version = 1; 109 hints_.version = 1;
108 hints_.AddSegment = Add_Segment; 110 hints_.AddSegment = Add_Segment;
109 111
110 avail_ = FPDFAvail_Create(&file_avail_, &file_access_); 112 avail_ = FPDFAvail_Create(&file_avail_, &file_access_);
111 (void)FPDFAvail_IsDocAvail(avail_, &hints_);
112 113
113 if (!FPDFAvail_IsLinearized(avail_)) 114 if (FPDFAvail_IsLinearized(avail_) == PDF_LINEARIZED) {
115 document_ = FPDFAvail_GetDocument(avail_, nullptr);
116 if (!document_) {
117 return false;
118 }
119 int32_t nRet = PDF_DATA_NOTAVAIL;
120 while (nRet == PDF_DATA_NOTAVAIL) {
121 nRet = FPDFAvail_IsDocAvail(avail_, &hints_);
122 }
123 if (nRet == PDF_DATA_ERROR) {
124 return false;
125 }
126 nRet = FPDFAvail_IsFormAvail(avail_, &hints_);
127 if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) {
128 return false;
129 }
130 int page_count = FPDF_GetPageCount(document_);
131 for (int i = 0; i < page_count; ++i) {
132 nRet = PDF_DATA_NOTAVAIL;
133 while (nRet == PDF_DATA_NOTAVAIL) {
134 nRet = FPDFAvail_IsPageAvail(avail_, i, &hints_);
135 }
136 if (nRet == PDF_DATA_ERROR) {
137 return false;
138 }
139 }
140 } else {
141 if (must_linearize) {
142 return false;
143 }
114 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); 144 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr);
115 else 145 if (!document_) {
116 document_ = FPDFAvail_GetDocument(avail_, nullptr); 146 return false;
117 147 }
118 if (!document_) 148 }
119 return false;
120 149
121 (void)FPDF_GetDocPermissions(document_); 150 (void)FPDF_GetDocPermissions(document_);
122 (void)FPDFAvail_IsFormAvail(avail_, &hints_);
123 151
124 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); 152 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
125 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); 153 memset(platform, 0, sizeof(IPDF_JSPLATFORM));
126 platform->version = 2; 154 platform->version = 2;
127 platform->app_alert = AlertTrampoline; 155 platform->app_alert = AlertTrampoline;
128 156
129 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); 157 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this);
130 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); 158 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO));
131 formfillinfo->version = 1; 159 formfillinfo->version = 1;
132 formfillinfo->FFI_SetTimer = SetTimerTrampoline; 160 formfillinfo->FFI_SetTimer = SetTimerTrampoline;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 279 }
252 280
253 // Can't use gtest-provided main since we need to stash the path to the 281 // Can't use gtest-provided main since we need to stash the path to the
254 // executable in order to find the external V8 binary data files. 282 // executable in order to find the external V8 binary data files.
255 int main(int argc, char** argv) { 283 int main(int argc, char** argv) {
256 g_exe_path_ = argv[0]; 284 g_exe_path_ = argv[0];
257 testing::InitGoogleTest(&argc, argv); 285 testing::InitGoogleTest(&argc, argv);
258 testing::InitGoogleMock(&argc, argv); 286 testing::InitGoogleMock(&argc, argv);
259 return RUN_ALL_TESTS(); 287 return RUN_ALL_TESTS();
260 } 288 }
OLDNEW
« no previous file with comments | « testing/embedder_test.h ('k') | testing/resources/feature_linearized_loading.pdf » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698