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 | 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 Loading... | |
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 || must_linearize) { |
Tom Sepez
2015/10/29 16:20:17
Actually, we want to test if FPDFAvail_IsLinearize
jun_fang
2015/10/30 06:02:43
Acknowledged.
| |
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 if (FPDFAvail_IsFormAvail(avail_, &hints_) == PDF_FORM_NOTAVAIL) { | |
127 return false; | |
128 } | |
129 int page_count = FPDF_GetPageCount(document_); | |
130 for (int i = 0; i < page_count; ++i) { | |
131 nRet = PDF_DATA_NOTAVAIL; | |
132 while (nRet == PDF_DATA_NOTAVAIL) { | |
133 nRet = FPDFAvail_IsPageAvail(avail_, i, &hints_); | |
134 } | |
135 if (nRet == PDF_DATA_ERROR) { | |
136 return false; | |
137 } | |
138 } | |
139 } else { | |
114 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); | 140 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); |
Tom Sepez
2015/10/29 16:20:17
However, if we came here, and must_linearize was s
jun_fang
2015/10/30 06:02:43
Acknowledged.
| |
115 else | 141 if (!document_) { |
116 document_ = FPDFAvail_GetDocument(avail_, nullptr); | 142 return false; |
117 | 143 } |
118 if (!document_) | 144 } |
119 return false; | |
120 | 145 |
121 (void)FPDF_GetDocPermissions(document_); | 146 (void)FPDF_GetDocPermissions(document_); |
122 (void)FPDFAvail_IsFormAvail(avail_, &hints_); | |
123 | 147 |
124 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); | 148 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); |
125 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); | 149 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); |
126 platform->version = 2; | 150 platform->version = 2; |
127 platform->app_alert = AlertTrampoline; | 151 platform->app_alert = AlertTrampoline; |
128 | 152 |
129 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); | 153 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); |
130 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); | 154 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); |
131 formfillinfo->version = 1; | 155 formfillinfo->version = 1; |
132 formfillinfo->FFI_SetTimer = SetTimerTrampoline; | 156 formfillinfo->FFI_SetTimer = SetTimerTrampoline; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 } | 275 } |
252 | 276 |
253 // Can't use gtest-provided main since we need to stash the path to the | 277 // 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. | 278 // executable in order to find the external V8 binary data files. |
255 int main(int argc, char** argv) { | 279 int main(int argc, char** argv) { |
256 g_exe_path_ = argv[0]; | 280 g_exe_path_ = argv[0]; |
257 testing::InitGoogleTest(&argc, argv); | 281 testing::InitGoogleTest(&argc, argv); |
258 testing::InitGoogleMock(&argc, argv); | 282 testing::InitGoogleMock(&argc, argv); |
259 return RUN_ALL_TESTS(); | 283 return RUN_ALL_TESTS(); |
260 } | 284 } |
OLD | NEW |