blob: ffc95216ccada7ea134c7e136cf7dccae6273415 [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
Dan Sinclair81f02f42017-09-26 12:02:16 -040029 font_mgr_ = pdfium::MakeUnique<CFGAS_FontMgr>();
30 if (!font_mgr_->EnumFonts())
31 font_mgr_ = nullptr;
Dan Sinclair574d4402017-08-28 10:11:24 -040032 }
33
34 void TearDown() override {
35 font_mgr_.reset();
Dan Sinclair574d4402017-08-28 10:11:24 -040036 }
37 CFGAS_FontMgr* FontManager() const { return font_mgr_.get(); }
38
39 private:
Dan Sinclair574d4402017-08-28 10:11:24 -040040 std::unique_ptr<CFGAS_FontMgr> font_mgr_;
41};
42
43Environment* env_ = nullptr;
44
45} // namespace
46
47CFGAS_FontMgr* GetGlobalFontManager() {
48 return env_->FontManager();
49}
50#endif // PDF_ENABLE_XFA
51
Tom Sepez64ee2c32017-04-24 15:04:25 -070052// Can't use gtest-provided main since we need to initialize partition
53// alloc before invoking any test.
54int main(int argc, char** argv) {
Dan Sinclairdbc3d3e2017-05-11 13:41:38 -040055 FXMEM_InitializePartitionAlloc();
Dan Sinclair574d4402017-08-28 10:11:24 -040056
57#if PDF_ENABLE_XFA
58 env_ = new Environment();
59 // The env will be deleted by gtest.
60 AddGlobalTestEnvironment(env_);
61#endif // PDF_ENABLE_XFA
62
Tom Sepez64ee2c32017-04-24 15:04:25 -070063 testing::InitGoogleTest(&argc, argv);
64 testing::InitGoogleMock(&argc, argv);
65 return RUN_ALL_TESTS();
66}