blob: 0b10a934db1e92c46b73d086566ba83b4e1bafa4 [file] [log] [blame]
Tom Sepez72f520c2020-08-24 23:43:46 +00001// 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
14namespace {
15
16EmbedderTestEnvironment* g_environment = nullptr;
17
18} // namespace
19
20EmbedderTestEnvironment::EmbedderTestEnvironment() {
21 ASSERT(!g_environment);
22 g_environment = this;
23}
24
25EmbedderTestEnvironment::~EmbedderTestEnvironment() {
26 ASSERT(g_environment);
27 g_environment = nullptr;
28}
29
30// static
31EmbedderTestEnvironment* EmbedderTestEnvironment::GetInstance() {
32 return g_environment;
33}
34
35void 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
52void EmbedderTestEnvironment::TearDown() {
53 FPDF_DestroyLibrary();
54}