blob: 1b1dcb0e32c60cd9a4192dae1b8fd702aec1198e [file] [log] [blame]
Tom Sepez64ee2c32017-04-24 15:04:25 -07001// Copyright 2017 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
Dan Sinclair574d4402017-08-28 10:11:24 -04005#include <memory>
6
Tom Sepez64ee2c32017-04-24 15:04:25 -07007#include "core/fxcrt/fx_memory.h"
8#include "testing/gmock/include/gmock/gmock.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
Dan Sinclair574d4402017-08-28 10:11:24 -040011#if PDF_ENABLE_XFA
12#include "core/fxge/cfx_gemodule.h"
13#include "xfa/fgas/font/cfgas_fontmgr.h"
14#include "xfa/fgas/font/cfgas_gefont.h"
15
16namespace {
17
18// The loading time of the CFGAS_FontMgr is linear in the number of times it is
19// loaded. So, if a test suite has a lot of tests that need a font manager they
20// can end up executing very, very slowly.
21class Environment : public testing::Environment {
22 public:
23 void SetUp() override {
24 // TODO(dsinclair): This font loading is slow. We should make a test font
25 // loader which loads up a single font we use in all tests.
26 CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo(
27 IFX_SystemFontInfo::CreateDefault(nullptr));
28
29#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
30 font_mgr_ = CFGAS_FontMgr::Create(FX_GetDefFontEnumerator());
31#else
32 font_source_ = pdfium::MakeUnique<CFX_FontSourceEnum_File>();
33 font_mgr_ = CFGAS_FontMgr::Create(font_source_.get());
34#endif
35 }
36
37 void TearDown() override {
38 font_mgr_.reset();
39#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
40 font_source_.reset();
41#endif
42 }
43 CFGAS_FontMgr* FontManager() const { return font_mgr_.get(); }
44
45 private:
46#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
47 std::unique_ptr<CFX_FontSourceEnum_File> font_source_;
48#endif
49 std::unique_ptr<CFGAS_FontMgr> font_mgr_;
50};
51
52Environment* env_ = nullptr;
53
54} // namespace
55
56CFGAS_FontMgr* GetGlobalFontManager() {
57 return env_->FontManager();
58}
59#endif // PDF_ENABLE_XFA
60
Tom Sepez64ee2c32017-04-24 15:04:25 -070061// Can't use gtest-provided main since we need to initialize partition
62// alloc before invoking any test.
63int main(int argc, char** argv) {
Dan Sinclairdbc3d3e2017-05-11 13:41:38 -040064 FXMEM_InitializePartitionAlloc();
Dan Sinclair574d4402017-08-28 10:11:24 -040065
66#if PDF_ENABLE_XFA
67 env_ = new Environment();
68 // The env will be deleted by gtest.
69 AddGlobalTestEnvironment(env_);
70#endif // PDF_ENABLE_XFA
71
Tom Sepez64ee2c32017-04-24 15:04:25 -070072 testing::InitGoogleTest(&argc, argv);
73 testing::InitGoogleMock(&argc, argv);
74 return RUN_ALL_TESTS();
75}