Tom Sepez | 2281853 | 2020-07-22 20:40:56 +0000 | [diff] [blame] | 1 | // 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" |
Tom Sepez | c99362a | 2020-09-02 23:49:25 +0000 | [diff] [blame] | 14 | #include "third_party/base/logging.h" |
Tom Sepez | 2281853 | 2020-07-22 20:40:56 +0000 | [diff] [blame] | 15 | #include "xfa/fgas/font/cfgas_fontmgr.h" |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | XFATestEnvironment* g_env = nullptr; |
| 20 | |
| 21 | } // namespace |
| 22 | |
| 23 | XFATestEnvironment::XFATestEnvironment() { |
| 24 | ASSERT(!g_env); |
| 25 | g_env = this; |
| 26 | } |
| 27 | |
| 28 | XFATestEnvironment::~XFATestEnvironment() { |
| 29 | ASSERT(g_env); |
| 30 | g_env = nullptr; |
| 31 | } |
| 32 | |
| 33 | void XFATestEnvironment::SetUp() { |
Tom Sepez | 9873bf3 | 2020-08-24 17:16:36 +0000 | [diff] [blame] | 34 | // This font loading is slow, but we do it only once per binary |
| 35 | // execution, not once per test. |
Tom Sepez | 2281853 | 2020-07-22 20:40:56 +0000 | [diff] [blame] | 36 | CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo( |
Tom Sepez | 9873bf3 | 2020-08-24 17:16:36 +0000 | [diff] [blame] | 37 | CFX_GEModule::Get()->GetPlatform()->CreateDefaultSystemFontInfo()); |
Tom Sepez | 2281853 | 2020-07-22 20:40:56 +0000 | [diff] [blame] | 38 | |
Tom Sepez | c99362a | 2020-09-02 23:49:25 +0000 | [diff] [blame] | 39 | font_mgr_ = std::make_unique<CFGAS_FontMgr>(); |
| 40 | CHECK(font_mgr_->EnumFonts()); |
Tom Sepez | 2281853 | 2020-07-22 20:40:56 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void XFATestEnvironment::TearDown() { |
| 44 | font_mgr_.reset(); |
| 45 | } |
| 46 | |
| 47 | // static |
| 48 | CFGAS_FontMgr* XFATestEnvironment::GetGlobalFontManager() { |
| 49 | return g_env->font_mgr_.get(); |
| 50 | } |