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

Side by Side Diff: testing/embedder_test.cpp

Issue 1395733006: Allow compiling PDFium without V8. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: PDFium Authors Created 5 years, 2 months 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') | no next file » | 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 #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_text.h" 17 #include "../public/fpdf_text.h"
18 #include "../public/fpdfview.h" 18 #include "../public/fpdfview.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20
21 #ifdef PDF_ENABLE_V8
20 #include "v8/include/libplatform/libplatform.h" 22 #include "v8/include/libplatform/libplatform.h"
21 #include "v8/include/v8.h" 23 #include "v8/include/v8.h"
24 #endif // PDF_ENABLE_V8
22 25
23 #ifdef _WIN32 26 #ifdef _WIN32
24 #define snprintf _snprintf 27 #define snprintf _snprintf
25 #define PATH_SEPARATOR '\\' 28 #define PATH_SEPARATOR '\\'
26 #else 29 #else
27 #define PATH_SEPARATOR '/' 30 #define PATH_SEPARATOR '/'
28 #endif 31 #endif
29 32
30 namespace { 33 namespace {
31 34
(...skipping 20 matching lines...) Expand all
52 (void)fclose(file); 55 (void)fclose(file);
53 if (bytes_read != file_length) { 56 if (bytes_read != file_length) {
54 fprintf(stderr, "Failed to read: %s\n", filename); 57 fprintf(stderr, "Failed to read: %s\n", filename);
55 free(buffer); 58 free(buffer);
56 return nullptr; 59 return nullptr;
57 } 60 }
58 *retlen = bytes_read; 61 *retlen = bytes_read;
59 return buffer; 62 return buffer;
60 } 63 }
61 64
65 #ifdef PDF_ENABLE_V8
62 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 66 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
63 // Returns the full path for an external V8 data file based on either 67 // Returns the full path for an external V8 data file based on either
64 // the currect exectuable path or an explicit override. 68 // the currect exectuable path or an explicit override.
65 static std::string GetFullPathForSnapshotFile(const std::string& exe_path, 69 static std::string GetFullPathForSnapshotFile(const std::string& exe_path,
66 const std::string& filename) { 70 const std::string& filename) {
67 std::string result; 71 std::string result;
68 if (!exe_path.empty()) { 72 if (!exe_path.empty()) {
69 size_t last_separator = exe_path.rfind(PATH_SEPARATOR); 73 size_t last_separator = exe_path.rfind(PATH_SEPARATOR);
70 if (last_separator != std::string::npos) { 74 if (last_separator != std::string::npos) {
71 result = exe_path.substr(0, last_separator + 1); 75 result = exe_path.substr(0, last_separator + 1);
(...skipping 12 matching lines...) Expand all
84 size_t data_length = 0; 88 size_t data_length = 0;
85 char* data_buffer = GetFileContents(full_path.c_str(), &data_length); 89 char* data_buffer = GetFileContents(full_path.c_str(), &data_length);
86 if (!data_buffer) { 90 if (!data_buffer) {
87 return false; 91 return false;
88 } 92 }
89 result_data->data = const_cast<const char*>(data_buffer); 93 result_data->data = const_cast<const char*>(data_buffer);
90 result_data->raw_size = data_length; 94 result_data->raw_size = data_length;
91 return true; 95 return true;
92 } 96 }
93 #endif // V8_USE_EXTERNAL_STARTUP_DATA 97 #endif // V8_USE_EXTERNAL_STARTUP_DATA
94 98 #endif // PDF_ENABLE_V8
95 } // namespace 99 } // namespace
96 100
97 class TestLoader { 101 class TestLoader {
98 public: 102 public:
99 TestLoader(const char* pBuf, size_t len); 103 TestLoader(const char* pBuf, size_t len);
100 104
101 const char* m_pBuf; 105 const char* m_pBuf;
102 size_t m_Len; 106 size_t m_Len;
103 }; 107 };
104 108
(...skipping 29 matching lines...) Expand all
134 memset(&hints_, 0, sizeof(hints_)); 138 memset(&hints_, 0, sizeof(hints_));
135 memset(&file_access_, 0, sizeof(file_access_)); 139 memset(&file_access_, 0, sizeof(file_access_));
136 memset(&file_avail_, 0, sizeof(file_avail_)); 140 memset(&file_avail_, 0, sizeof(file_avail_));
137 delegate_ = default_delegate_.get(); 141 delegate_ = default_delegate_.get();
138 } 142 }
139 143
140 EmbedderTest::~EmbedderTest() { 144 EmbedderTest::~EmbedderTest() {
141 } 145 }
142 146
143 void EmbedderTest::SetUp() { 147 void EmbedderTest::SetUp() {
148 #ifdef PDF_ENABLE_V8
144 v8::V8::InitializeICU(); 149 v8::V8::InitializeICU();
145 150
146 platform_ = v8::platform::CreateDefaultPlatform(); 151 platform_ = v8::platform::CreateDefaultPlatform();
147 v8::V8::InitializePlatform(platform_); 152 v8::V8::InitializePlatform(platform_);
148 v8::V8::Initialize(); 153 v8::V8::Initialize();
149 154
150 // By enabling predictable mode, V8 won't post any background tasks. 155 // By enabling predictable mode, V8 won't post any background tasks.
151 const char predictable_flag[] = "--predictable"; 156 const char predictable_flag[] = "--predictable";
152 v8::V8::SetFlagsFromString(predictable_flag, 157 v8::V8::SetFlagsFromString(predictable_flag,
153 static_cast<int>(strlen(predictable_flag))); 158 static_cast<int>(strlen(predictable_flag)));
154 159
155 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 160 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
156 ASSERT_TRUE(GetExternalData(g_exe_path_, "natives_blob.bin", &natives_)); 161 ASSERT_TRUE(GetExternalData(g_exe_path_, "natives_blob.bin", &natives_));
157 ASSERT_TRUE(GetExternalData(g_exe_path_, "snapshot_blob.bin", &snapshot_)); 162 ASSERT_TRUE(GetExternalData(g_exe_path_, "snapshot_blob.bin", &snapshot_));
158 v8::V8::SetNativesDataBlob(&natives_); 163 v8::V8::SetNativesDataBlob(&natives_);
159 v8::V8::SetSnapshotDataBlob(&snapshot_); 164 v8::V8::SetSnapshotDataBlob(&snapshot_);
160 #endif // V8_USE_EXTERNAL_STARTUP_DATA 165 #endif // V8_USE_EXTERNAL_STARTUP_DATA
166 #endif // FPDF_ENABLE_V8
161 167
162 FPDF_LIBRARY_CONFIG config; 168 FPDF_LIBRARY_CONFIG config;
163 config.version = 2; 169 config.version = 2;
164 config.m_pUserFontPaths = nullptr; 170 config.m_pUserFontPaths = nullptr;
171 config.m_v8EmbedderSlot = 0;
165 config.m_pIsolate = external_isolate_; 172 config.m_pIsolate = external_isolate_;
166 config.m_v8EmbedderSlot = 0;
167 FPDF_InitLibraryWithConfig(&config); 173 FPDF_InitLibraryWithConfig(&config);
168 174
169 UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(this); 175 UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(this);
170 memset(info, 0, sizeof(UNSUPPORT_INFO)); 176 memset(info, 0, sizeof(UNSUPPORT_INFO));
171 info->version = 1; 177 info->version = 1;
172 info->FSDK_UnSupport_Handler = UnsupportedHandlerTrampoline; 178 info->FSDK_UnSupport_Handler = UnsupportedHandlerTrampoline;
173 FSDK_SetUnSpObjProcessHandler(info); 179 FSDK_SetUnSpObjProcessHandler(info);
174 } 180 }
175 181
176 void EmbedderTest::TearDown() { 182 void EmbedderTest::TearDown() {
177 if (document_) { 183 if (document_) {
178 FORM_DoDocumentAAction(form_handle_, FPDFDOC_AACTION_WC); 184 FORM_DoDocumentAAction(form_handle_, FPDFDOC_AACTION_WC);
179 FPDFDOC_ExitFormFillEnvironment(form_handle_); 185 FPDFDOC_ExitFormFillEnvironment(form_handle_);
180 FPDF_CloseDocument(document_); 186 FPDF_CloseDocument(document_);
181 } 187 }
182 FPDFAvail_Destroy(avail_); 188 FPDFAvail_Destroy(avail_);
183 FPDF_DestroyLibrary(); 189 FPDF_DestroyLibrary();
190
191 #ifdef PDF_ENABLE_V8
184 v8::V8::ShutdownPlatform(); 192 v8::V8::ShutdownPlatform();
185 delete platform_; 193 delete platform_;
194 #endif // PDF_ENABLE_V8
195
186 delete loader_; 196 delete loader_;
187 free(file_contents_); 197 free(file_contents_);
188 } 198 }
189 199
190 bool EmbedderTest::OpenDocument(const std::string& filename) { 200 bool EmbedderTest::OpenDocument(const std::string& filename) {
191 file_contents_ = GetFileContents(filename.c_str(), &file_length_); 201 file_contents_ = GetFileContents(filename.c_str(), &file_length_);
192 if (!file_contents_) { 202 if (!file_contents_) {
193 return false; 203 return false;
194 } 204 }
195 205
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 356 }
347 357
348 // Can't use gtest-provided main since we need to stash the path to the 358 // Can't use gtest-provided main since we need to stash the path to the
349 // executable in order to find the external V8 binary data files. 359 // executable in order to find the external V8 binary data files.
350 int main(int argc, char** argv) { 360 int main(int argc, char** argv) {
351 g_exe_path_ = argv[0]; 361 g_exe_path_ = argv[0];
352 testing::InitGoogleTest(&argc, argv); 362 testing::InitGoogleTest(&argc, argv);
353 testing::InitGoogleMock(&argc, argv); 363 testing::InitGoogleMock(&argc, argv);
354 return RUN_ALL_TESTS(); 364 return RUN_ALL_TESTS();
355 } 365 }
OLDNEW
« no previous file with comments | « testing/embedder_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698