blob: 0fdab8d652edc39aae4c63aca39e834d3032a06e [file] [log] [blame]
Tom Sepez22818532020-07-22 20:40:56 +00001// Copyright 2019 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/xfa_test_environment.h"
6
7#include <memory>
8#include <utility>
9
10#include "core/fxge/cfx_fontmgr.h"
11#include "core/fxge/cfx_gemodule.h"
12#include "core/fxge/systemfontinfo_iface.h"
13#include "testing/gtest/include/gtest/gtest.h"
14#include "xfa/fgas/font/cfgas_fontmgr.h"
15
16namespace {
17
18XFATestEnvironment* g_env = nullptr;
19
20} // namespace
21
22XFATestEnvironment::XFATestEnvironment() {
23 ASSERT(!g_env);
24 g_env = this;
25}
26
27XFATestEnvironment::~XFATestEnvironment() {
28 ASSERT(g_env);
29 g_env = nullptr;
30}
31
32void XFATestEnvironment::SetUp() {
Tom Sepez9873bf32020-08-24 17:16:36 +000033 // This font loading is slow, but we do it only once per binary
34 // execution, not once per test.
Tom Sepez22818532020-07-22 20:40:56 +000035 CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo(
Tom Sepez9873bf32020-08-24 17:16:36 +000036 CFX_GEModule::Get()->GetPlatform()->CreateDefaultSystemFontInfo());
Tom Sepez22818532020-07-22 20:40:56 +000037
38 auto font_mgr = std::make_unique<CFGAS_FontMgr>();
39 if (font_mgr->EnumFonts())
40 font_mgr_ = std::move(font_mgr);
41}
42
43void XFATestEnvironment::TearDown() {
44 font_mgr_.reset();
45}
46
47// static
48CFGAS_FontMgr* XFATestEnvironment::GetGlobalFontManager() {
49 return g_env->font_mgr_.get();
50}