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> |
Tom Sepez | 3f8ee5e | 2018-02-09 18:26:09 +0000 | [diff] [blame] | 6 | #include <string> |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 7 | |
Tom Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 8 | #include "core/fxcrt/fx_memory.h" |
| 9 | #include "testing/gmock/include/gmock/gmock.h" |
| 10 | #include "testing/gtest/include/gtest/gtest.h" |
Tom Sepez | 3f8ee5e | 2018-02-09 18:26:09 +0000 | [diff] [blame] | 11 | #include "testing/test_support.h" |
| 12 | |
Ryan Harrison | 4f21d77 | 2018-06-01 15:19:04 +0000 | [diff] [blame] | 13 | #ifdef PDF_ENABLE_V8 |
Tom Sepez | 3f8ee5e | 2018-02-09 18:26:09 +0000 | [diff] [blame] | 14 | #include "v8/include/v8-platform.h" |
| 15 | #include "v8/include/v8.h" |
Ryan Harrison | 4f21d77 | 2018-06-01 15:19:04 +0000 | [diff] [blame] | 16 | #endif // PDF_ENABLE_V8 |
Tom Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 17 | |
Ryan Harrison | d60d7cb | 2018-06-01 15:28:54 +0000 | [diff] [blame^] | 18 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 96d6b4d | 2018-01-11 14:31:41 +0000 | [diff] [blame] | 19 | #include "core/fxge/cfx_fontmgr.h" |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 20 | #include "core/fxge/cfx_gemodule.h" |
| 21 | #include "xfa/fgas/font/cfgas_fontmgr.h" |
| 22 | #include "xfa/fgas/font/cfgas_gefont.h" |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | // The loading time of the CFGAS_FontMgr is linear in the number of times it is |
| 27 | // loaded. So, if a test suite has a lot of tests that need a font manager they |
| 28 | // can end up executing very, very slowly. |
| 29 | class Environment : public testing::Environment { |
| 30 | public: |
| 31 | void SetUp() override { |
| 32 | // TODO(dsinclair): This font loading is slow. We should make a test font |
| 33 | // loader which loads up a single font we use in all tests. |
| 34 | CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo( |
Dan Sinclair | f8af565 | 2018-03-06 18:56:33 +0000 | [diff] [blame] | 35 | SystemFontInfoIface::CreateDefault(nullptr)); |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 36 | |
Dan Sinclair | 81f02f4 | 2017-09-26 12:02:16 -0400 | [diff] [blame] | 37 | font_mgr_ = pdfium::MakeUnique<CFGAS_FontMgr>(); |
| 38 | if (!font_mgr_->EnumFonts()) |
| 39 | font_mgr_ = nullptr; |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void TearDown() override { |
| 43 | font_mgr_.reset(); |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 44 | } |
| 45 | CFGAS_FontMgr* FontManager() const { return font_mgr_.get(); } |
| 46 | |
| 47 | private: |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 48 | std::unique_ptr<CFGAS_FontMgr> font_mgr_; |
| 49 | }; |
| 50 | |
| 51 | Environment* env_ = nullptr; |
| 52 | |
| 53 | } // namespace |
| 54 | |
| 55 | CFGAS_FontMgr* GetGlobalFontManager() { |
| 56 | return env_->FontManager(); |
| 57 | } |
| 58 | #endif // PDF_ENABLE_XFA |
| 59 | |
Tom Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 60 | // Can't use gtest-provided main since we need to initialize partition |
| 61 | // alloc before invoking any test. |
| 62 | int main(int argc, char** argv) { |
Dan Sinclair | dbc3d3e | 2017-05-11 13:41:38 -0400 | [diff] [blame] | 63 | FXMEM_InitializePartitionAlloc(); |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 64 | |
Tom Sepez | 3f8ee5e | 2018-02-09 18:26:09 +0000 | [diff] [blame] | 65 | #ifdef PDF_ENABLE_V8 |
| 66 | std::unique_ptr<v8::Platform> platform; |
Nico Weber | 611431d | 2018-02-26 20:36:16 +0000 | [diff] [blame] | 67 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
Tom Sepez | 3f8ee5e | 2018-02-09 18:26:09 +0000 | [diff] [blame] | 68 | static v8::StartupData* natives = new v8::StartupData; |
| 69 | static v8::StartupData* snapshot = new v8::StartupData; |
Tom Sepez | 3f8ee5e | 2018-02-09 18:26:09 +0000 | [diff] [blame] | 70 | platform = InitializeV8ForPDFiumWithStartupData(argv[0], std::string(), |
| 71 | natives, snapshot); |
| 72 | #else // V8_USE_EXTERNAL_STARTUP_DATA |
| 73 | platform = InitializeV8ForPDFium(argv[0]); |
| 74 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 75 | #endif // PDF_ENABLE_V8 |
| 76 | |
Ryan Harrison | d60d7cb | 2018-06-01 15:28:54 +0000 | [diff] [blame^] | 77 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 78 | env_ = new Environment(); |
| 79 | // The env will be deleted by gtest. |
| 80 | AddGlobalTestEnvironment(env_); |
| 81 | #endif // PDF_ENABLE_XFA |
| 82 | |
Tom Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 83 | testing::InitGoogleTest(&argc, argv); |
| 84 | testing::InitGoogleMock(&argc, argv); |
Tom Sepez | 3f8ee5e | 2018-02-09 18:26:09 +0000 | [diff] [blame] | 85 | |
| 86 | int ret_val = RUN_ALL_TESTS(); |
| 87 | |
| 88 | #ifdef PDF_ENABLE_V8 |
| 89 | v8::V8::ShutdownPlatform(); |
| 90 | #endif // PDF_ENABLE_V8 |
| 91 | |
| 92 | return ret_val; |
Tom Sepez | 64ee2c3 | 2017-04-24 15:04:25 -0700 | [diff] [blame] | 93 | } |