blob: 64b12993a9f6e5414c4ee516aaf2f2a33a1db4e1 [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
Lei Zhang96d6b4d2018-01-11 14:31:41 +000012#include "core/fxge/cfx_fontmgr.h"
Dan Sinclair574d4402017-08-28 10:11:24 -040013#include "core/fxge/cfx_gemodule.h"
14#include "xfa/fgas/font/cfgas_fontmgr.h"
15#include "xfa/fgas/font/cfgas_gefont.h"
16
17namespace {
18
19// The loading time of the CFGAS_FontMgr is linear in the number of times it is
20// loaded. So, if a test suite has a lot of tests that need a font manager they
21// can end up executing very, very slowly.
22class Environment : public testing::Environment {
23 public:
24 void SetUp() override {
25 // TODO(dsinclair): This font loading is slow. We should make a test font
26 // loader which loads up a single font we use in all tests.
27 CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo(
28 IFX_SystemFontInfo::CreateDefault(nullptr));
29
Dan Sinclair81f02f42017-09-26 12:02:16 -040030 font_mgr_ = pdfium::MakeUnique<CFGAS_FontMgr>();
31 if (!font_mgr_->EnumFonts())
32 font_mgr_ = nullptr;
Dan Sinclair574d4402017-08-28 10:11:24 -040033 }
34
35 void TearDown() override {
36 font_mgr_.reset();
Dan Sinclair574d4402017-08-28 10:11:24 -040037 }
38 CFGAS_FontMgr* FontManager() const { return font_mgr_.get(); }
39
40 private:
Dan Sinclair574d4402017-08-28 10:11:24 -040041 std::unique_ptr<CFGAS_FontMgr> font_mgr_;
42};
43
44Environment* env_ = nullptr;
45
46} // namespace
47
48CFGAS_FontMgr* GetGlobalFontManager() {
49 return env_->FontManager();
50}
51#endif // PDF_ENABLE_XFA
52
Tom Sepez64ee2c32017-04-24 15:04:25 -070053// Can't use gtest-provided main since we need to initialize partition
54// alloc before invoking any test.
55int main(int argc, char** argv) {
Dan Sinclairdbc3d3e2017-05-11 13:41:38 -040056 FXMEM_InitializePartitionAlloc();
Dan Sinclair574d4402017-08-28 10:11:24 -040057
58#if PDF_ENABLE_XFA
59 env_ = new Environment();
60 // The env will be deleted by gtest.
61 AddGlobalTestEnvironment(env_);
62#endif // PDF_ENABLE_XFA
63
Tom Sepez64ee2c32017-04-24 15:04:25 -070064 testing::InitGoogleTest(&argc, argv);
65 testing::InitGoogleMock(&argc, argv);
66 return RUN_ALL_TESTS();
67}