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

Side by Side Diff: testing/embedder_test.cpp

Issue 1393833006: Merge to XFA: Allow compiling PDFium without V8. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Rebase, fix build, stray include. 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') | xfa.gyp » ('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 #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 185
180 // Note: The shut down order here is the reverse of the non-XFA branch 186 // Note: The shut down order here is the reverse of the non-XFA branch
181 // order. Need to work out if this is required, and if it is, the lifetimes 187 // order. Need to work out if this is required, and if it is, the lifetimes
182 // of objects owned by |doc| that |form| reference. 188 // of objects owned by |doc| that |form| reference.
183 FPDF_CloseDocument(document_); 189 FPDF_CloseDocument(document_);
184 FPDFDOC_ExitFormFillEnvironment(form_handle_); 190 FPDFDOC_ExitFormFillEnvironment(form_handle_);
185 } 191 }
186 FPDFAvail_Destroy(avail_); 192 FPDFAvail_Destroy(avail_);
187 FPDF_DestroyLibrary(); 193 FPDF_DestroyLibrary();
194
195 #ifdef PDF_ENABLE_V8
188 v8::V8::ShutdownPlatform(); 196 v8::V8::ShutdownPlatform();
189 delete platform_; 197 delete platform_;
198 #endif // PDF_ENABLE_V8
199
190 delete loader_; 200 delete loader_;
191 free(file_contents_); 201 free(file_contents_);
192 } 202 }
193 203
194 bool EmbedderTest::OpenDocument(const std::string& filename) { 204 bool EmbedderTest::OpenDocument(const std::string& filename) {
195 file_contents_ = GetFileContents(filename.c_str(), &file_length_); 205 file_contents_ = GetFileContents(filename.c_str(), &file_length_);
196 if (!file_contents_) { 206 if (!file_contents_) {
197 return false; 207 return false;
198 } 208 }
199 209
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 367 }
358 368
359 // Can't use gtest-provided main since we need to stash the path to the 369 // Can't use gtest-provided main since we need to stash the path to the
360 // executable in order to find the external V8 binary data files. 370 // executable in order to find the external V8 binary data files.
361 int main(int argc, char** argv) { 371 int main(int argc, char** argv) {
362 g_exe_path_ = argv[0]; 372 g_exe_path_ = argv[0];
363 testing::InitGoogleTest(&argc, argv); 373 testing::InitGoogleTest(&argc, argv);
364 testing::InitGoogleMock(&argc, argv); 374 testing::InitGoogleMock(&argc, argv);
365 return RUN_ALL_TESTS(); 375 return RUN_ALL_TESTS();
366 } 376 }
OLDNEW
« no previous file with comments | « testing/embedder_test.h ('k') | xfa.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698