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 | |
Dan Sinclair | 81f02f4 | 2017-09-26 12:02:16 -0400 | [diff] [blame] | 29 | font_mgr_ = pdfium::MakeUnique<CFGAS_FontMgr>(); |
| 30 | if (!font_mgr_->EnumFonts()) |
| 31 | font_mgr_ = nullptr; |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void TearDown() override { |
| 35 | font_mgr_.reset(); |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 36 | } |
| 37 | CFGAS_FontMgr* FontManager() const { return font_mgr_.get(); } |
| 38 | |
| 39 | private: |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 40 | std::unique_ptr<CFGAS_FontMgr> font_mgr_; |
| 41 | }; |
| 42 | |
| 43 | Environment* env_ = nullptr; |
| 44 | |
| 45 | } // namespace |
| 46 | |
| 47 | CFGAS_FontMgr* GetGlobalFontManager() { |
| 48 | return env_->FontManager(); |
| 49 | } |
| 50 | #endif // PDF_ENABLE_XFA |
| 51 | |
Tom Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 52 | // Can't use gtest-provided main since we need to initialize partition |
| 53 | // alloc before invoking any test. |
| 54 | int main(int argc, char** argv) { |
Dan Sinclair | dbc3d3e | 2017-05-11 13:41:38 -0400 | [diff] [blame] | 55 | FXMEM_InitializePartitionAlloc(); |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 56 | |
| 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 Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 63 | testing::InitGoogleTest(&argc, argv); |
| 64 | testing::InitGoogleMock(&argc, argv); |
| 65 | return RUN_ALL_TESTS(); |
| 66 | } |