blob: 168ad69ae19a4253288b87852fa5877e0cea511d [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;
Tom Andersond4fe5f72021-12-03 20:52:52 +000042
43 config.m_pUserFontPaths = test_fonts_.font_paths();
44
Tom Sepez72f520c2020-08-24 23:43:46 +000045#ifdef PDF_ENABLE_V8
46 config.m_pIsolate = V8TestEnvironment::GetInstance()->isolate();
47 config.m_pPlatform = V8TestEnvironment::GetInstance()->platform();
48#else // PDF_ENABLE_V8
49 config.m_pIsolate = nullptr;
50 config.m_pPlatform = nullptr;
51#endif // PDF_ENABLE_V8
52
53 FPDF_InitLibraryWithConfig(&config);
Tom Andersond4fe5f72021-12-03 20:52:52 +000054
55 test_fonts_.InstallFontMapper();
Tom Sepez72f520c2020-08-24 23:43:46 +000056}
57
58void EmbedderTestEnvironment::TearDown() {
59 FPDF_DestroyLibrary();
60}