Home | History | Annotate | Download | only in testing
      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 
      5 #include <memory>
      6 
      7 #include "core/fxcrt/fx_memory.h"
      8 #include "testing/gmock/include/gmock/gmock.h"
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 
     11 #if PDF_ENABLE_XFA
     12 #include "core/fxge/cfx_fontmgr.h"
     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 
     30     font_mgr_ = pdfium::MakeUnique<CFGAS_FontMgr>();
     31     if (!font_mgr_->EnumFonts())
     32       font_mgr_ = nullptr;
     33   }
     34 
     35   void TearDown() override {
     36     font_mgr_.reset();
     37   }
     38   CFGAS_FontMgr* FontManager() const { return font_mgr_.get(); }
     39 
     40  private:
     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 
     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) {
     56   FXMEM_InitializePartitionAlloc();
     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 
     64   testing::InitGoogleTest(&argc, argv);
     65   testing::InitGoogleMock(&argc, argv);
     66   return RUN_ALL_TESTS();
     67 }
     68