Tom Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 1 | // 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 Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 5 | #include <memory> |
| 6 | |
Tom Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 7 | #include "core/fxcrt/fx_memory.h" |
| 8 | #include "testing/gmock/include/gmock/gmock.h" |
| 9 | #include "testing/gtest/include/gtest/gtest.h" |
| 10 | |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 11 | #if PDF_ENABLE_XFA |
Lei Zhang | 96d6b4d | 2018-01-11 14:31:41 +0000 | [diff] [blame^] | 12 | #include "core/fxge/cfx_fontmgr.h" |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 13 | #include "core/fxge/cfx_gemodule.h" |
| 14 | #include "xfa/fgas/font/cfgas_fontmgr.h" |
| 15 | #include "xfa/fgas/font/cfgas_gefont.h" |
| 16 | |
| 17 | namespace { |
| 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. |
| 22 | class 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 Sinclair | 81f02f4 | 2017-09-26 12:02:16 -0400 | [diff] [blame] | 30 | font_mgr_ = pdfium::MakeUnique<CFGAS_FontMgr>(); |
| 31 | if (!font_mgr_->EnumFonts()) |
| 32 | font_mgr_ = nullptr; |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void TearDown() override { |
| 36 | font_mgr_.reset(); |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 37 | } |
| 38 | CFGAS_FontMgr* FontManager() const { return font_mgr_.get(); } |
| 39 | |
| 40 | private: |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 41 | std::unique_ptr<CFGAS_FontMgr> font_mgr_; |
| 42 | }; |
| 43 | |
| 44 | Environment* env_ = nullptr; |
| 45 | |
| 46 | } // namespace |
| 47 | |
| 48 | CFGAS_FontMgr* GetGlobalFontManager() { |
| 49 | return env_->FontManager(); |
| 50 | } |
| 51 | #endif // PDF_ENABLE_XFA |
| 52 | |
Tom Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 53 | // Can't use gtest-provided main since we need to initialize partition |
| 54 | // alloc before invoking any test. |
| 55 | int main(int argc, char** argv) { |
Dan Sinclair | dbc3d3e | 2017-05-11 13:41:38 -0400 | [diff] [blame] | 56 | FXMEM_InitializePartitionAlloc(); |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 57 | |
| 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 Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 64 | testing::InitGoogleTest(&argc, argv); |
| 65 | testing::InitGoogleMock(&argc, argv); |
| 66 | return RUN_ALL_TESTS(); |
| 67 | } |