fontmgr_fuchsia_unittest.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2018 The Chromium 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. #include <fuchsia/fonts/cpp/fidl.h>
  5. #include "skia/ext/test_fonts_fuchsia.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. #include "third_party/skia/include/core/SkFontMgr.h"
  8. #include "third_party/skia/include/core/SkTypeface.h"
  9. #include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"
  10. namespace skia {
  11. // Tests for SkFontMgr_Fuchsia in Skia.
  12. class FuchsiaFontManagerTest : public testing::Test {
  13. public:
  14. FuchsiaFontManagerTest()
  15. : font_manager_(
  16. SkFontMgr_New_Fuchsia(GetTestFontsProvider().BindSync())) {}
  17. protected:
  18. sk_sp<SkFontMgr> font_manager_;
  19. };
  20. // Verify that SkTypeface objects are cached.
  21. TEST_F(FuchsiaFontManagerTest, Caching) {
  22. sk_sp<SkTypeface> sans(
  23. font_manager_->matchFamilyStyle("sans", SkFontStyle()));
  24. EXPECT_TRUE(sans);
  25. sk_sp<SkTypeface> sans2(
  26. font_manager_->matchFamilyStyle("sans", SkFontStyle()));
  27. // Expect that the same SkTypeface is returned for both requests.
  28. EXPECT_EQ(sans.get(), sans2.get());
  29. // Request serif and verify that a different SkTypeface is returned.
  30. sk_sp<SkTypeface> serif(
  31. font_manager_->matchFamilyStyle("serif", SkFontStyle()));
  32. EXPECT_NE(sans.get(), serif.get());
  33. }
  34. // Verify that SkTypeface can outlive the manager.
  35. TEST_F(FuchsiaFontManagerTest, TypefaceOutlivesManager) {
  36. sk_sp<SkTypeface> sans(
  37. font_manager_->matchFamilyStyle("sans", SkFontStyle()));
  38. font_manager_.reset();
  39. }
  40. // Verify that we can query a font after releasing a previous instance.
  41. TEST_F(FuchsiaFontManagerTest, ReleaseThenCreateAgain) {
  42. sk_sp<SkTypeface> serif(
  43. font_manager_->matchFamilyStyle("serif", SkFontStyle()));
  44. EXPECT_TRUE(serif);
  45. serif.reset();
  46. sk_sp<SkTypeface> serif2(
  47. font_manager_->matchFamilyStyle("serif", SkFontStyle()));
  48. EXPECT_TRUE(serif2);
  49. }
  50. } // namespace skia