Avoid unnecessarily initializing fontconfig in tests
Some tests like base_unittests don't actually need fontconfig initialized, so it saves a bit of time to omit the call to FcInit(). Luckily, in all cases, FcInit() is already called everywhere FontConfig is needed. BUG=None R=thakis,derat Change-Id: I5ccad01e252499b2137d67004482f3a3652484b5 Reviewed-on: https://chromium-review.googlesource.com/c/1487186 Commit-Queue: Thomas Anderson <thomasanderson@chromium.org> Reviewed-by: Dan Erat <derat@chromium.org> Reviewed-by: Nico Weber <thakis@chromium.org> Cr-Commit-Position: refs/heads/master@{#635357}
This commit is contained in:
@ -24,12 +24,6 @@ void SetUpFontconfig() {
|
|||||||
// TODO(thomasanderson): This still stat()'s the real /etc/fonts/fonts.conf.
|
// TODO(thomasanderson): This still stat()'s the real /etc/fonts/fonts.conf.
|
||||||
// Prevent fontconfig from doing this.
|
// Prevent fontconfig from doing this.
|
||||||
CHECK(env->SetVar("FONTCONFIG_SYSROOT", dir_module.value().c_str()));
|
CHECK(env->SetVar("FONTCONFIG_SYSROOT", dir_module.value().c_str()));
|
||||||
|
|
||||||
CHECK(FcInit());
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDownFontconfig() {
|
|
||||||
FcFini();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
@ -7,12 +7,10 @@
|
|||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
|
|
||||||
// Initializes Fontconfig with a custom configuration suitable for tests.
|
// Prepares Fontconfig with a custom configuration suitable for tests. FcInit()
|
||||||
|
// must still be called.
|
||||||
void SetUpFontconfig();
|
void SetUpFontconfig();
|
||||||
|
|
||||||
// Deinitializes Fontconfig.
|
|
||||||
void TearDownFontconfig();
|
|
||||||
|
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
|
||||||
#endif // BASE_TEST_FONTCONFIG_UTIL_LINUX_H_
|
#endif // BASE_TEST_FONTCONFIG_UTIL_LINUX_H_
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include <fontconfig/fontconfig.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
@ -54,7 +55,8 @@ int main() {
|
|||||||
CHECK(base::DeleteFile(fontconfig_caches, /*recursive=*/true));
|
CHECK(base::DeleteFile(fontconfig_caches, /*recursive=*/true));
|
||||||
|
|
||||||
base::SetUpFontconfig();
|
base::SetUpFontconfig();
|
||||||
base::TearDownFontconfig();
|
FcInit();
|
||||||
|
FcFini();
|
||||||
|
|
||||||
// Check existence of intended fontconfig cache file.
|
// Check existence of intended fontconfig cache file.
|
||||||
CHECK(base::PathExists(
|
CHECK(base::PathExists(
|
||||||
|
@ -487,8 +487,6 @@ void TestSuite::Initialize() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(OS_LINUX)
|
#if defined(OS_LINUX)
|
||||||
// TODO(thomasanderson): Call TearDownFontconfig() in Shutdown(). It would
|
|
||||||
// currently crash because of leaked FcFontSet's in font_fallback_linux.cc.
|
|
||||||
SetUpFontconfig();
|
SetUpFontconfig();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -108,24 +108,15 @@ class FontRenderParamsTest : public testing::Test {
|
|||||||
original_font_delegate_ = SkiaFontDelegate::instance();
|
original_font_delegate_ = SkiaFontDelegate::instance();
|
||||||
SkiaFontDelegate::SetInstance(&test_font_delegate_);
|
SkiaFontDelegate::SetInstance(&test_font_delegate_);
|
||||||
ClearFontRenderParamsCacheForTest();
|
ClearFontRenderParamsCacheForTest();
|
||||||
|
FcInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
~FontRenderParamsTest() override {
|
~FontRenderParamsTest() override {
|
||||||
|
FcFini();
|
||||||
SkiaFontDelegate::SetInstance(
|
SkiaFontDelegate::SetInstance(
|
||||||
const_cast<SkiaFontDelegate*>(original_font_delegate_));
|
const_cast<SkiaFontDelegate*>(original_font_delegate_));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetUp() override {
|
|
||||||
// Fontconfig should already be set up by the test runner.
|
|
||||||
DCHECK(FcConfigGetCurrent());
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown() override {
|
|
||||||
// We might have made a mess introducing new fontconfig settings. Reset the
|
|
||||||
// state of fontconfig for the next test.
|
|
||||||
base::SetUpFontconfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const SkiaFontDelegate* original_font_delegate_;
|
const SkiaFontDelegate* original_font_delegate_;
|
||||||
TestFontDelegate test_font_delegate_;
|
TestFontDelegate test_font_delegate_;
|
||||||
|
Reference in New Issue
Block a user