Tom Sepez | 72f520c | 2020-08-24 23:43:46 +0000 | [diff] [blame] | 1 | // Copyright 2020 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "testing/embedder_test_environment.h" |
| 6 | |
| 7 | #include "core/fxcrt/fx_system.h" |
| 8 | #include "public/fpdfview.h" |
| 9 | |
| 10 | #ifdef PDF_ENABLE_V8 |
| 11 | #include "testing/v8_test_environment.h" |
| 12 | #endif // PDF_ENABLE_V8 |
| 13 | |
| 14 | namespace { |
| 15 | |
| 16 | EmbedderTestEnvironment* g_environment = nullptr; |
| 17 | |
| 18 | } // namespace |
| 19 | |
| 20 | EmbedderTestEnvironment::EmbedderTestEnvironment() { |
| 21 | ASSERT(!g_environment); |
| 22 | g_environment = this; |
| 23 | } |
| 24 | |
| 25 | EmbedderTestEnvironment::~EmbedderTestEnvironment() { |
| 26 | ASSERT(g_environment); |
| 27 | g_environment = nullptr; |
| 28 | } |
| 29 | |
| 30 | // static |
| 31 | EmbedderTestEnvironment* EmbedderTestEnvironment::GetInstance() { |
| 32 | return g_environment; |
| 33 | } |
| 34 | |
| 35 | void EmbedderTestEnvironment::SetUp() { |
| 36 | FPDF_LIBRARY_CONFIG config; |
| 37 | config.version = 3; |
| 38 | config.m_pUserFontPaths = nullptr; |
| 39 | config.m_v8EmbedderSlot = 0; |
| 40 | config.m_pPlatform = nullptr; |
| 41 | #ifdef PDF_ENABLE_V8 |
| 42 | config.m_pIsolate = V8TestEnvironment::GetInstance()->isolate(); |
| 43 | config.m_pPlatform = V8TestEnvironment::GetInstance()->platform(); |
| 44 | #else // PDF_ENABLE_V8 |
| 45 | config.m_pIsolate = nullptr; |
| 46 | config.m_pPlatform = nullptr; |
| 47 | #endif // PDF_ENABLE_V8 |
| 48 | |
| 49 | FPDF_InitLibraryWithConfig(&config); |
| 50 | } |
| 51 | |
| 52 | void EmbedderTestEnvironment::TearDown() { |
| 53 | FPDF_DestroyLibrary(); |
| 54 | } |