blob: dec8de0844952871f42e83742298b6f1b48f5551 [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
Tom Sepez37999602022-05-20 16:44:20 +00007#include <ostream>
8
Tom Sepez72f520c2020-08-24 23:43:46 +00009#include "core/fxcrt/fx_system.h"
10#include "public/fpdfview.h"
Tom Sepez25f33d02021-01-29 01:58:51 +000011#include "third_party/base/check.h"
Tom Sepez72f520c2020-08-24 23:43:46 +000012
13#ifdef PDF_ENABLE_V8
14#include "testing/v8_test_environment.h"
15#endif // PDF_ENABLE_V8
16
17namespace {
18
19EmbedderTestEnvironment* g_environment = nullptr;
20
21} // namespace
22
23EmbedderTestEnvironment::EmbedderTestEnvironment() {
Tom Sepez25f33d02021-01-29 01:58:51 +000024 DCHECK(!g_environment);
Tom Sepez72f520c2020-08-24 23:43:46 +000025 g_environment = this;
26}
27
28EmbedderTestEnvironment::~EmbedderTestEnvironment() {
Tom Sepez25f33d02021-01-29 01:58:51 +000029 DCHECK(g_environment);
Tom Sepez72f520c2020-08-24 23:43:46 +000030 g_environment = nullptr;
31}
32
33// static
34EmbedderTestEnvironment* EmbedderTestEnvironment::GetInstance() {
35 return g_environment;
36}
37
38void EmbedderTestEnvironment::SetUp() {
39 FPDF_LIBRARY_CONFIG config;
40 config.version = 3;
41 config.m_pUserFontPaths = nullptr;
42 config.m_v8EmbedderSlot = 0;
43 config.m_pPlatform = nullptr;
Tom Andersond4fe5f72021-12-03 20:52:52 +000044
45 config.m_pUserFontPaths = test_fonts_.font_paths();
46
Tom Sepez72f520c2020-08-24 23:43:46 +000047#ifdef PDF_ENABLE_V8
48 config.m_pIsolate = V8TestEnvironment::GetInstance()->isolate();
49 config.m_pPlatform = V8TestEnvironment::GetInstance()->platform();
50#else // PDF_ENABLE_V8
51 config.m_pIsolate = nullptr;
52 config.m_pPlatform = nullptr;
53#endif // PDF_ENABLE_V8
54
55 FPDF_InitLibraryWithConfig(&config);
Tom Andersond4fe5f72021-12-03 20:52:52 +000056
57 test_fonts_.InstallFontMapper();
Tom Sepez72f520c2020-08-24 23:43:46 +000058}
59
60void EmbedderTestEnvironment::TearDown() {
61 FPDF_DestroyLibrary();
62}
Tom Sepez37999602022-05-20 16:44:20 +000063
64void EmbedderTestEnvironment::AddFlags(int argc, char** argv) {
65 for (int i = 1; i < argc; ++i)
66 AddFlag(argv[i]);
67}
68
69void EmbedderTestEnvironment::AddFlag(const std::string& flag) {
70 if (flag == "--write-pngs")
71 write_pngs_ = true;
72 else
73 std::cerr << "Unknown flag: " << flag << "\n";
74}