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 |
| 12 | #include "core/fxge/cfx_gemodule.h" |
| 13 | #include "xfa/fgas/font/cfgas_fontmgr.h" |
| 14 | #include "xfa/fgas/font/cfgas_gefont.h" |
| 15 | |
| 16 | namespace { |
| 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. |
| 21 | class 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 | |
| 52 | Environment* env_ = nullptr; |
| 53 | |
| 54 | } // namespace |
| 55 | |
| 56 | CFGAS_FontMgr* GetGlobalFontManager() { |
| 57 | return env_->FontManager(); |
| 58 | } |
| 59 | #endif // PDF_ENABLE_XFA |
| 60 | |
Tom Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 61 | // Can't use gtest-provided main since we need to initialize partition |
| 62 | // alloc before invoking any test. |
| 63 | int main(int argc, char** argv) { |
Dan Sinclair | dbc3d3e | 2017-05-11 13:41:38 -0400 | [diff] [blame] | 64 | FXMEM_InitializePartitionAlloc(); |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame^] | 65 | |
| 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 Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 72 | testing::InitGoogleTest(&argc, argv); |
| 73 | testing::InitGoogleMock(&argc, argv); |
| 74 | return RUN_ALL_TESTS(); |
| 75 | } |