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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 free(buffer); | 53 free(buffer); |
54 return NULL; | 54 return NULL; |
55 } | 55 } |
56 *retlen = bytes_read; | 56 *retlen = bytes_read; |
57 return buffer; | 57 return buffer; |
58 } | 58 } |
59 | 59 |
60 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 60 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
61 // Returns the full path for an external V8 data file based on either | 61 // Returns the full path for an external V8 data file based on either |
62 // the currect exectuable path or an explicit override. | 62 // the currect exectuable path or an explicit override. |
63 static std::string GetFullPathForSnapshotFile(const Options& options, | 63 static std::string GetFullPathForSnapshotFile(const std::string& exe_path, |
64 const std::string& filename) { | 64 const std::string& filename) { |
65 std::string result; | 65 std::string result; |
66 if (!options.bin_directory.empty()) { | 66 if (!exe_path.empty()) { |
67 result = options.bin_directory; | 67 size_t last_separator = exe_path.rfind(PATH_SEPARATOR); |
68 if (*options.bin_directory.rbegin() != PATH_SEPARATOR) { | |
69 result += PATH_SEPARATOR; | |
70 } | |
71 } else if (!options.exe_path.empty()) { | |
72 size_t last_separator = options.exe_path.rfind(PATH_SEPARATOR); | |
73 if (last_separator != std::string::npos) { | 68 if (last_separator != std::string::npos) { |
74 result = options.exe_path.substr(0, last_separator + 1); | 69 result = exe_path.substr(0, last_separator + 1); |
75 } | 70 } |
76 } | 71 } |
77 result += filename; | 72 result += filename; |
78 return result; | 73 return result; |
79 } | 74 } |
80 | 75 |
81 // Reads an extenal V8 data file from the |options|-indicated location, | 76 // Reads an extenal V8 data file from the |options|-indicated location, |
82 // returing true on success and false on error. | 77 // returing true on success and false on error. |
83 static bool GetExternalData(const Options& options, | 78 static bool GetExternalData(const std::string& exe_path, |
84 const std::string& bin_filename, | 79 const std::string& filename, |
85 v8::StartupData* result_data) { | 80 v8::StartupData* result_data) { |
86 std::string full_path = GetFullPathForSnapshotFile(options, bin_filename); | 81 std::string full_path = GetFullPathForSnapshotFile(exe_path, filename); |
87 size_t data_length = 0; | 82 size_t data_length = 0; |
88 char* data_buffer = GetFileContents(full_path.c_str(), &data_length); | 83 char* data_buffer = GetFileContents(full_path.c_str(), &data_length); |
89 if (!data_buffer) { | 84 if (!data_buffer) { |
90 return false; | 85 return false; |
91 } | 86 } |
92 result_data->data = const_cast<const char*>(data_buffer); | 87 result_data->data = const_cast<const char*>(data_buffer); |
93 result_data->raw_size = data_length; | 88 result_data->raw_size = data_length; |
94 return true; | 89 return true; |
95 } | 90 } |
96 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 91 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return 1; | 161 return 1; |
167 } | 162 } |
168 | 163 |
169 bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { | 164 bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { |
170 return true; | 165 return true; |
171 } | 166 } |
172 | 167 |
173 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { | 168 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { |
174 } | 169 } |
175 | 170 |
| 171 // static |
| 172 const char* EmbedderTest::g_exe_path_ = nullptr; |
| 173 |
| 174 // static |
| 175 void EmbedderTest::SetExePath(const char* exe_path) { |
| 176 g_exe_path_ = exe_path; |
| 177 } |
| 178 |
176 void EmbedderTest::SetUp() { | 179 void EmbedderTest::SetUp() { |
177 v8::V8::InitializeICU(); | 180 v8::V8::InitializeICU(); |
178 | 181 |
179 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 182 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
180 ASSERT_TRUE(GetExternalData(options, "natives_blob.bin", &natives_)); | 183 ASSERT_TRUE(GetExternalData(g_exe_path_, "natives_blob.bin", &natives_)); |
181 ASSERT_TRUE(GetExternalData(options, "snapshot_blob.bin", &snapshot_)); | 184 ASSERT_TRUE(GetExternalData(g_exe_path_, "snapshot_blob.bin", &snapshot_)); |
182 v8::V8::SetNativesDataBlob(&natives); | 185 v8::V8::SetNativesDataBlob(&natives_); |
183 v8::V8::SetSnapshotDataBlob(&snapshot); | 186 v8::V8::SetSnapshotDataBlob(&snapshot_); |
184 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 187 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
185 | 188 |
186 FPDF_InitLibrary(); | 189 FPDF_InitLibrary(); |
187 | 190 |
188 UNSUPPORT_INFO unsuppored_info; | 191 UNSUPPORT_INFO unsuppored_info; |
189 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); | 192 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); |
190 unsuppored_info.version = 1; | 193 unsuppored_info.version = 1; |
191 unsuppored_info.FSDK_UnSupport_Handler = Unsupported_Handler; | 194 unsuppored_info.FSDK_UnSupport_Handler = Unsupported_Handler; |
192 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); | 195 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); |
193 } | 196 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); | 300 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); |
298 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); | 301 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); |
299 return bitmap; | 302 return bitmap; |
300 } | 303 } |
301 | 304 |
302 void EmbedderTest::UnloadPage(FPDF_PAGE page, FPDF_FORMHANDLE form) { | 305 void EmbedderTest::UnloadPage(FPDF_PAGE page, FPDF_FORMHANDLE form) { |
303 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); | 306 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); |
304 FORM_OnBeforeClosePage(page, form); | 307 FORM_OnBeforeClosePage(page, form); |
305 FPDF_ClosePage(page); | 308 FPDF_ClosePage(page); |
306 } | 309 } |
| 310 |
| 311 // Can't use gtest-provided main since we need to stash the path to the |
| 312 // executable in order to find the external V8 binary data files. |
| 313 int main(int argc, char** argv) { |
| 314 EmbedderTest::SetExePath(argv[0]); |
| 315 testing::InitGoogleTest(&argc, argv); |
| 316 return RUN_ALL_TESTS(); |
| 317 } |
OLD | NEW |