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> |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 const char* g_exe_path_ = nullptr; | 33 const char* g_exe_path_ = nullptr; |
34 | 34 |
35 // Reads the entire contents of a file into a newly malloc'd buffer. | 35 // Reads the entire contents of a file into a newly malloc'd buffer. |
36 static char* GetFileContents(const char* filename, size_t* retlen) { | 36 static char* GetFileContents(const char* filename, size_t* retlen) { |
37 FILE* file = fopen(filename, "rb"); | 37 FILE* file = fopen(filename, "rb"); |
38 if (!file) { | 38 if (!file) { |
39 fprintf(stderr, "Failed to open: %s\n", filename); | 39 fprintf(stderr, "Failed to open: %s\n", filename); |
40 return NULL; | 40 return nullptr; |
41 } | 41 } |
42 (void) fseek(file, 0, SEEK_END); | 42 (void) fseek(file, 0, SEEK_END); |
43 size_t file_length = ftell(file); | 43 size_t file_length = ftell(file); |
44 if (!file_length) { | 44 if (!file_length) { |
45 return NULL; | 45 return nullptr; |
46 } | 46 } |
47 (void) fseek(file, 0, SEEK_SET); | 47 (void) fseek(file, 0, SEEK_SET); |
48 char* buffer = (char*) malloc(file_length); | 48 char* buffer = (char*) malloc(file_length); |
49 if (!buffer) { | 49 if (!buffer) { |
50 return NULL; | 50 return nullptr; |
51 } | 51 } |
52 size_t bytes_read = fread(buffer, 1, file_length, file); | 52 size_t bytes_read = fread(buffer, 1, file_length, file); |
53 (void) fclose(file); | 53 (void) fclose(file); |
54 if (bytes_read != file_length) { | 54 if (bytes_read != file_length) { |
55 fprintf(stderr, "Failed to read: %s\n", filename); | 55 fprintf(stderr, "Failed to read: %s\n", filename); |
56 free(buffer); | 56 free(buffer); |
57 return NULL; | 57 return nullptr; |
58 } | 58 } |
59 *retlen = bytes_read; | 59 *retlen = bytes_read; |
60 return buffer; | 60 return buffer; |
61 } | 61 } |
62 | 62 |
63 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 63 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
64 // Returns the full path for an external V8 data file based on either | 64 // Returns the full path for an external V8 data file based on either |
65 // the currect exectuable path or an explicit override. | 65 // the currect exectuable path or an explicit override. |
66 static std::string GetFullPathForSnapshotFile(const std::string& exe_path, | 66 static std::string GetFullPathForSnapshotFile(const std::string& exe_path, |
67 const std::string& filename) { | 67 const std::string& filename) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 FPDF_InitLibrary(); | 208 FPDF_InitLibrary(); |
209 | 209 |
210 UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(this); | 210 UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(this); |
211 memset(info, 0, sizeof(UNSUPPORT_INFO)); | 211 memset(info, 0, sizeof(UNSUPPORT_INFO)); |
212 info->version = 1; | 212 info->version = 1; |
213 info->FSDK_UnSupport_Handler = UnsupportedHandlerTrampoline; | 213 info->FSDK_UnSupport_Handler = UnsupportedHandlerTrampoline; |
214 FSDK_SetUnSpObjProcessHandler(info); | 214 FSDK_SetUnSpObjProcessHandler(info); |
215 } | 215 } |
216 | 216 |
217 void EmbedderTest::TearDown() { | 217 void EmbedderTest::TearDown() { |
218 if (form_handle_) { | 218 if (document_) { |
219 FORM_DoDocumentAAction(form_handle_, FPDFDOC_AACTION_WC); | 219 FORM_DoDocumentAAction(form_handle_, FPDFDOC_AACTION_WC); |
| 220 FPDF_CloseDocument(document_); |
220 FPDFDOC_ExitFormFillEnvironment(form_handle_); | 221 FPDFDOC_ExitFormFillEnvironment(form_handle_); |
221 } | 222 } |
222 if (document_) { | |
223 FPDF_CloseDocument(document_); | |
224 } | |
225 FPDFAvail_Destroy(avail_); | 223 FPDFAvail_Destroy(avail_); |
226 FPDF_DestroyLibrary(); | 224 FPDF_DestroyLibrary(); |
227 if (loader_) { | 225 delete loader_; |
228 delete loader_; | 226 free(file_contents_); |
229 } | |
230 if (file_contents_) { | |
231 free(file_contents_); | |
232 } | |
233 v8::V8::ShutdownPlatform(); | 227 v8::V8::ShutdownPlatform(); |
234 } | 228 } |
235 | 229 |
236 bool EmbedderTest::OpenDocument(const std::string& filename) { | 230 bool EmbedderTest::OpenDocument(const std::string& filename) { |
237 file_contents_ = GetFileContents(filename.c_str(), &file_length_); | 231 file_contents_ = GetFileContents(filename.c_str(), &file_length_); |
238 if (!file_contents_) { | 232 if (!file_contents_) { |
239 return false; | 233 return false; |
240 } | 234 } |
241 | 235 |
242 loader_ = new TestLoader(file_contents_, file_length_); | 236 loader_ = new TestLoader(file_contents_, file_length_); |
243 file_access_.m_FileLen = static_cast<unsigned long>(file_length_); | 237 file_access_.m_FileLen = static_cast<unsigned long>(file_length_); |
244 file_access_.m_GetBlock = Get_Block; | 238 file_access_.m_GetBlock = Get_Block; |
245 file_access_.m_Param = loader_; | 239 file_access_.m_Param = loader_; |
246 | 240 |
247 file_avail_.version = 1; | 241 file_avail_.version = 1; |
248 file_avail_.IsDataAvail = Is_Data_Avail; | 242 file_avail_.IsDataAvail = Is_Data_Avail; |
249 | 243 |
250 hints_.version = 1; | 244 hints_.version = 1; |
251 hints_.AddSegment = Add_Segment; | 245 hints_.AddSegment = Add_Segment; |
252 | 246 |
253 avail_ = FPDFAvail_Create(&file_avail_, &file_access_); | 247 avail_ = FPDFAvail_Create(&file_avail_, &file_access_); |
254 (void) FPDFAvail_IsDocAvail(avail_, &hints_); | 248 (void) FPDFAvail_IsDocAvail(avail_, &hints_); |
255 | 249 |
256 if (!FPDFAvail_IsLinearized(avail_)) { | 250 if (!FPDFAvail_IsLinearized(avail_)) { |
257 document_ = FPDF_LoadCustomDocument(&file_access_, NULL); | 251 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); |
258 } else { | 252 } else { |
259 document_ = FPDFAvail_GetDocument(avail_, NULL); | 253 document_ = FPDFAvail_GetDocument(avail_, nullptr); |
260 } | 254 } |
261 if (!document_) { | 255 if (!document_) { |
262 return false; | 256 return false; |
263 } | 257 } |
264 int docType = DOCTYPE_PDF; | 258 int docType = DOCTYPE_PDF; |
265 if (FPDF_HasXFAField(document_, &docType)) | 259 if (FPDF_HasXFAField(document_, &docType)) |
266 { | 260 { |
267 if (docType != DOCTYPE_PDF) | 261 if (docType != DOCTYPE_PDF) |
268 (void) FPDF_LoadXFA(document_); | 262 (void) FPDF_LoadXFA(document_); |
269 } | 263 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 } | 344 } |
351 | 345 |
352 // Can't use gtest-provided main since we need to stash the path to the | 346 // Can't use gtest-provided main since we need to stash the path to the |
353 // executable in order to find the external V8 binary data files. | 347 // executable in order to find the external V8 binary data files. |
354 int main(int argc, char** argv) { | 348 int main(int argc, char** argv) { |
355 g_exe_path_ = argv[0]; | 349 g_exe_path_ = argv[0]; |
356 testing::InitGoogleTest(&argc, argv); | 350 testing::InitGoogleTest(&argc, argv); |
357 testing::InitGoogleMock(&argc, argv); | 351 testing::InitGoogleMock(&argc, argv); |
358 return RUN_ALL_TESTS(); | 352 return RUN_ALL_TESTS(); |
359 } | 353 } |
OLD | NEW |