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

Side by Side Diff: testing/embedder_test.cpp

Issue 1138143003: Fix leaks in the embedder tests themselves. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 7 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 | « fpdfsdk/src/fpdfview_embeddertest.cpp ('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>
(...skipping 18 matching lines...) Expand all
29 29
30 namespace { 30 namespace {
31 31
32 const char* g_exe_path_ = nullptr; 32 const char* g_exe_path_ = nullptr;
33 33
34 // Reads the entire contents of a file into a newly malloc'd buffer. 34 // Reads the entire contents of a file into a newly malloc'd buffer.
35 static char* GetFileContents(const char* filename, size_t* retlen) { 35 static char* GetFileContents(const char* filename, size_t* retlen) {
36 FILE* file = fopen(filename, "rb"); 36 FILE* file = fopen(filename, "rb");
37 if (!file) { 37 if (!file) {
38 fprintf(stderr, "Failed to open: %s\n", filename); 38 fprintf(stderr, "Failed to open: %s\n", filename);
39 return NULL; 39 return nullptr;
40 } 40 }
41 (void) fseek(file, 0, SEEK_END); 41 (void) fseek(file, 0, SEEK_END);
42 size_t file_length = ftell(file); 42 size_t file_length = ftell(file);
43 if (!file_length) { 43 if (!file_length) {
44 return NULL; 44 return nullptr;
45 } 45 }
46 (void) fseek(file, 0, SEEK_SET); 46 (void) fseek(file, 0, SEEK_SET);
47 char* buffer = (char*) malloc(file_length); 47 char* buffer = (char*) malloc(file_length);
48 if (!buffer) { 48 if (!buffer) {
49 return NULL; 49 return nullptr;
50 } 50 }
51 size_t bytes_read = fread(buffer, 1, file_length, file); 51 size_t bytes_read = fread(buffer, 1, file_length, file);
52 (void) fclose(file); 52 (void) fclose(file);
53 if (bytes_read != file_length) { 53 if (bytes_read != file_length) {
54 fprintf(stderr, "Failed to read: %s\n", filename); 54 fprintf(stderr, "Failed to read: %s\n", filename);
55 free(buffer); 55 free(buffer);
56 return NULL; 56 return nullptr;
57 } 57 }
58 *retlen = bytes_read; 58 *retlen = bytes_read;
59 return buffer; 59 return buffer;
60 } 60 }
61 61
62 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 62 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
63 // Returns the full path for an external V8 data file based on either 63 // Returns the full path for an external V8 data file based on either
64 // the currect exectuable path or an explicit override. 64 // the currect exectuable path or an explicit override.
65 static std::string GetFullPathForSnapshotFile(const std::string& exe_path, 65 static std::string GetFullPathForSnapshotFile(const std::string& exe_path,
66 const std::string& filename) { 66 const std::string& filename) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 FPDF_InitLibrary(); 204 FPDF_InitLibrary();
205 205
206 UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(this); 206 UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(this);
207 memset(info, 0, sizeof(UNSUPPORT_INFO)); 207 memset(info, 0, sizeof(UNSUPPORT_INFO));
208 info->version = 1; 208 info->version = 1;
209 info->FSDK_UnSupport_Handler = UnsupportedHandlerTrampoline; 209 info->FSDK_UnSupport_Handler = UnsupportedHandlerTrampoline;
210 FSDK_SetUnSpObjProcessHandler(info); 210 FSDK_SetUnSpObjProcessHandler(info);
211 } 211 }
212 212
213 void EmbedderTest::TearDown() { 213 void EmbedderTest::TearDown() {
214 if (form_handle_) { 214 if (document_) {
215 FORM_DoDocumentAAction(form_handle_, FPDFDOC_AACTION_WC); 215 FORM_DoDocumentAAction(form_handle_, FPDFDOC_AACTION_WC);
Lei Zhang 2015/05/15 06:48:57 See PDFiumEngine::~PDFiumEngine().
Tom Sepez 2015/05/15 15:12:39 See comment I left there -- why doesn't document_
216 FPDF_CloseDocument(document_);
216 FPDFDOC_ExitFormFillEnvironment(form_handle_); 217 FPDFDOC_ExitFormFillEnvironment(form_handle_);
217 } 218 }
218 if (document_) {
219 FPDF_CloseDocument(document_);
220 }
221 FPDFAvail_Destroy(avail_); 219 FPDFAvail_Destroy(avail_);
222 FPDF_DestroyLibrary(); 220 FPDF_DestroyLibrary();
223 if (loader_) { 221 delete loader_;
224 delete loader_; 222 free(file_contents_);
225 }
226 if (file_contents_) {
227 free(file_contents_);
228 }
229 } 223 }
230 224
231 bool EmbedderTest::OpenDocument(const std::string& filename) { 225 bool EmbedderTest::OpenDocument(const std::string& filename) {
232 file_contents_ = GetFileContents(filename.c_str(), &file_length_); 226 file_contents_ = GetFileContents(filename.c_str(), &file_length_);
233 if (!file_contents_) { 227 if (!file_contents_) {
234 return false; 228 return false;
235 } 229 }
236 230
237 loader_ = new TestLoader(file_contents_, file_length_); 231 loader_ = new TestLoader(file_contents_, file_length_);
238 file_access_.m_FileLen = static_cast<unsigned long>(file_length_); 232 file_access_.m_FileLen = static_cast<unsigned long>(file_length_);
239 file_access_.m_GetBlock = Get_Block; 233 file_access_.m_GetBlock = Get_Block;
240 file_access_.m_Param = loader_; 234 file_access_.m_Param = loader_;
241 235
242 file_avail_.version = 1; 236 file_avail_.version = 1;
243 file_avail_.IsDataAvail = Is_Data_Avail; 237 file_avail_.IsDataAvail = Is_Data_Avail;
244 238
245 hints_.version = 1; 239 hints_.version = 1;
246 hints_.AddSegment = Add_Segment; 240 hints_.AddSegment = Add_Segment;
247 241
248 avail_ = FPDFAvail_Create(&file_avail_, &file_access_); 242 avail_ = FPDFAvail_Create(&file_avail_, &file_access_);
249 (void) FPDFAvail_IsDocAvail(avail_, &hints_); 243 (void) FPDFAvail_IsDocAvail(avail_, &hints_);
250 244
251 if (!FPDFAvail_IsLinearized(avail_)) { 245 if (!FPDFAvail_IsLinearized(avail_)) {
252 document_ = FPDF_LoadCustomDocument(&file_access_, NULL); 246 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr);
253 } else { 247 } else {
254 document_ = FPDFAvail_GetDocument(avail_, NULL); 248 document_ = FPDFAvail_GetDocument(avail_, nullptr);
255 } 249 }
256 250
257 (void) FPDF_GetDocPermissions(document_); 251 (void) FPDF_GetDocPermissions(document_);
258 (void) FPDFAvail_IsFormAvail(avail_, &hints_); 252 (void) FPDFAvail_IsFormAvail(avail_, &hints_);
259 253
260 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); 254 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
261 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); 255 memset(platform, 0, sizeof(IPDF_JSPLATFORM));
262 platform->version = 1; 256 platform->version = 1;
263 platform->app_alert = AlertTrampoline; 257 platform->app_alert = AlertTrampoline;
264 258
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 } 331 }
338 332
339 // Can't use gtest-provided main since we need to stash the path to the 333 // Can't use gtest-provided main since we need to stash the path to the
340 // executable in order to find the external V8 binary data files. 334 // executable in order to find the external V8 binary data files.
341 int main(int argc, char** argv) { 335 int main(int argc, char** argv) {
342 g_exe_path_ = argv[0]; 336 g_exe_path_ = argv[0];
343 testing::InitGoogleTest(&argc, argv); 337 testing::InitGoogleTest(&argc, argv);
344 testing::InitGoogleMock(&argc, argv); 338 testing::InitGoogleMock(&argc, argv);
345 return RUN_ALL_TESTS(); 339 return RUN_ALL_TESTS();
346 } 340 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdfview_embeddertest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698