blob: d96bfcb8f319864f0b944c77602fe7d429b2461a [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"
Tom Sepez25f33d02021-01-29 01:58:51 +00009#include "third_party/base/check.h"
Tom Sepez72f520c2020-08-24 23:43:46 +000010
11#ifdef PDF_ENABLE_V8
12#include "testing/v8_test_environment.h"
13#endif // PDF_ENABLE_V8
14
15namespace {
16
17EmbedderTestEnvironment* g_environment = nullptr;
18
19} // namespace
20
21EmbedderTestEnvironment::EmbedderTestEnvironment() {
Tom Sepez25f33d02021-01-29 01:58:51 +000022 DCHECK(!g_environment);
Tom Sepez72f520c2020-08-24 23:43:46 +000023 g_environment = this;
24}
25
26EmbedderTestEnvironment::~EmbedderTestEnvironment() {
Tom Sepez25f33d02021-01-29 01:58:51 +000027 DCHECK(g_environment);
Tom Sepez72f520c2020-08-24 23:43:46 +000028 g_environment = nullptr;
29}
30
31// static
32EmbedderTestEnvironment* EmbedderTestEnvironment::GetInstance() {
33 return g_environment;
34}
35
36void EmbedderTestEnvironment::SetUp() {
37 FPDF_LIBRARY_CONFIG config;
38 config.version = 3;
39 config.m_pUserFontPaths = nullptr;
40 config.m_v8EmbedderSlot = 0;
41 config.m_pPlatform = nullptr;
42#ifdef PDF_ENABLE_V8
43 config.m_pIsolate = V8TestEnvironment::GetInstance()->isolate();
44 config.m_pPlatform = V8TestEnvironment::GetInstance()->platform();
45#else // PDF_ENABLE_V8
46 config.m_pIsolate = nullptr;
47 config.m_pPlatform = nullptr;
48#endif // PDF_ENABLE_V8
49
50 FPDF_InitLibraryWithConfig(&config);
51}
52
53void EmbedderTestEnvironment::TearDown() {
54 FPDF_DestroyLibrary();
55}