summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-08-28 10:11:24 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-28 15:07:01 +0000
commit574d4408a5174bb410cf4ec3db24283671bcce79 (patch)
tree907e53814373e98780de4eabeb55ca48f8669a29
parent133617c2d2b941e239e9234b1a4e9dc7476a2fa5 (diff)
downloadpdfium-574d4408a5174bb410cf4ec3db24283671bcce79.tar.xz
Add a global font loader in XFA tests
This CL creates a global font loader for use in XFA tests. This is needed because the CFGAS_FontMangaer takes a linearly increasing amount of time to load fonts each time it's loaded. This can get excessively slow for test suites which run a lot of tests. Change-Id: Ie389844b56598ce414f4f761654fa4ed465955fd Reviewed-on: https://pdfium-review.googlesource.com/12090 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r--BUILD.gn1
-rw-r--r--fpdfsdk/fpdfview_unittest.cpp20
-rw-r--r--testing/test_support.h8
-rw-r--r--testing/unit_test_main.cpp59
-rw-r--r--xfa/fgas/layout/cfx_rtfbreak_unittest.cpp18
5 files changed, 69 insertions, 37 deletions
diff --git a/BUILD.gn b/BUILD.gn
index f7163ddf98..9eb7fb04af 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1932,7 +1932,6 @@ test("pdfium_unittests") {
"core/fxge/dib/cstretchengine_unittest.cpp",
"fpdfsdk/fpdfdoc_unittest.cpp",
"fpdfsdk/fpdfeditimg_unittest.cpp",
- "fpdfsdk/fpdfview_unittest.cpp",
"testing/unit_test_main.cpp",
]
deps = [
diff --git a/fpdfsdk/fpdfview_unittest.cpp b/fpdfsdk/fpdfview_unittest.cpp
deleted file mode 100644
index 27680b3d4e..0000000000
--- a/fpdfsdk/fpdfview_unittest.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "public/fpdfview.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/test_support.h"
-
-TEST(FPDFView, DoubleInit) {
- FPDF_InitLibrary();
- FPDF_InitLibrary();
- FPDF_DestroyLibrary();
-}
-
-TEST(FPDFView, DoubleDestroy) {
- FPDF_InitLibrary();
- FPDF_DestroyLibrary();
- FPDF_DestroyLibrary();
-}
diff --git a/testing/test_support.h b/testing/test_support.h
index feec4bbe0b..7525c10b36 100644
--- a/testing/test_support.h
+++ b/testing/test_support.h
@@ -13,6 +13,10 @@
#include "public/fpdfview.h"
+#if PDF_ENABLE_XFA
+#include "xfa/fgas/font/cfgas_fontmgr.h"
+#endif // PDF_ENABLE_XFA
+
namespace pdfium {
#define STR_IN_TEST_CASE(input_literal, ...) \
@@ -110,4 +114,8 @@ class TestLoader {
const size_t m_Len;
};
+#if PDF_ENABLE_XFA
+CFGAS_FontMgr* GetGlobalFontManager();
+#endif // PDF_ENABLE_XFA
+
#endif // TESTING_TEST_SUPPORT_H_
diff --git a/testing/unit_test_main.cpp b/testing/unit_test_main.cpp
index f57ec3c555..1b1dcb0e32 100644
--- a/testing/unit_test_main.cpp
+++ b/testing/unit_test_main.cpp
@@ -2,14 +2,73 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <memory>
+
#include "core/fxcrt/fx_memory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if PDF_ENABLE_XFA
+#include "core/fxge/cfx_gemodule.h"
+#include "xfa/fgas/font/cfgas_fontmgr.h"
+#include "xfa/fgas/font/cfgas_gefont.h"
+
+namespace {
+
+// The loading time of the CFGAS_FontMgr is linear in the number of times it is
+// loaded. So, if a test suite has a lot of tests that need a font manager they
+// can end up executing very, very slowly.
+class Environment : public testing::Environment {
+ public:
+ void SetUp() override {
+ // TODO(dsinclair): This font loading is slow. We should make a test font
+ // loader which loads up a single font we use in all tests.
+ CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo(
+ IFX_SystemFontInfo::CreateDefault(nullptr));
+
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+ font_mgr_ = CFGAS_FontMgr::Create(FX_GetDefFontEnumerator());
+#else
+ font_source_ = pdfium::MakeUnique<CFX_FontSourceEnum_File>();
+ font_mgr_ = CFGAS_FontMgr::Create(font_source_.get());
+#endif
+ }
+
+ void TearDown() override {
+ font_mgr_.reset();
+#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
+ font_source_.reset();
+#endif
+ }
+ CFGAS_FontMgr* FontManager() const { return font_mgr_.get(); }
+
+ private:
+#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
+ std::unique_ptr<CFX_FontSourceEnum_File> font_source_;
+#endif
+ std::unique_ptr<CFGAS_FontMgr> font_mgr_;
+};
+
+Environment* env_ = nullptr;
+
+} // namespace
+
+CFGAS_FontMgr* GetGlobalFontManager() {
+ return env_->FontManager();
+}
+#endif // PDF_ENABLE_XFA
+
// Can't use gtest-provided main since we need to initialize partition
// alloc before invoking any test.
int main(int argc, char** argv) {
FXMEM_InitializePartitionAlloc();
+
+#if PDF_ENABLE_XFA
+ env_ = new Environment();
+ // The env will be deleted by gtest.
+ AddGlobalTestEnvironment(env_);
+#endif // PDF_ENABLE_XFA
+
testing::InitGoogleTest(&argc, argv);
testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
diff --git a/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp b/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp
index cef215fe2a..8997edc083 100644
--- a/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp
+++ b/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp
@@ -18,17 +18,8 @@
class CFX_RTFBreakTest : public testing::Test {
public:
void SetUp() override {
- CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo(
- IFX_SystemFontInfo::CreateDefault(nullptr));
-
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
- font_mgr_ = CFGAS_FontMgr::Create(FX_GetDefFontEnumerator());
-#else
- font_source_ = pdfium::MakeUnique<CFX_FontSourceEnum_File>();
- font_mgr_ = CFGAS_FontMgr::Create(font_source_.get());
-#endif
-
- font_ = CFGAS_GEFont::LoadFont(L"Arial Black", 0, 0, font_mgr_.get());
+ font_ =
+ CFGAS_GEFont::LoadFont(L"Arial Black", 0, 0, GetGlobalFontManager());
ASSERT(font_.Get() != nullptr);
}
@@ -39,12 +30,7 @@ class CFX_RTFBreakTest : public testing::Test {
}
private:
- std::unique_ptr<CFGAS_FontMgr> font_mgr_;
CFX_RetainPtr<CFGAS_GEFont> font_;
-
-#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
- std::unique_ptr<CFX_FontSourceEnum_File> font_source_;
-#endif
};
// As soon as you get one of the control characters the break is complete