Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Unified Diff: tests/TypefaceTest.cpp

Issue 1879423002: Remove requestedStyle from SkTypefaceCache. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More interesting coverage. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ports/SkFontMgr_win_dw.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/TypefaceTest.cpp
diff --git a/tests/TypefaceTest.cpp b/tests/TypefaceTest.cpp
index b3bc157eba81ed09fd1aadf98ffb63af49e172d8..130cabf37a72562c96da12a545b47e02503800d6 100644
--- a/tests/TypefaceTest.cpp
+++ b/tests/TypefaceTest.cpp
@@ -5,7 +5,9 @@
* found in the LICENSE file.
*/
+#include "SkRefCnt.h"
#include "SkTypeface.h"
+#include "SkTypefaceCache.h"
#include "Test.h"
DEF_TEST(Typeface, reporter) {
@@ -24,3 +26,68 @@ DEF_TEST(Typeface, reporter) {
REPORTER_ASSERT(reporter, nullptr == t3.get());
#endif
}
+
+class SkEmptyTypeface : public SkTypeface {
+public:
+ static sk_sp<SkTypeface> Create(SkFontID id) { return sk_sp<SkTypeface>(new SkEmptyTypeface(id)); }
+protected:
+ SkEmptyTypeface(SkFontID id) : SkTypeface(SkFontStyle(), id, true) { }
+
+ SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
+ SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+ const SkDescriptor*) const override {
+ return nullptr;
+ }
+ void onFilterRec(SkScalerContextRec*) const override { }
+ virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo,
+ const uint32_t*, uint32_t) const override { return nullptr; }
+ void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
+ virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
+ uint16_t glyphs[], int glyphCount) const override {
+ SK_ABORT("unimplemented");
+ return 0;
+ }
+ int onCountGlyphs() const override { return 0; };
+ int onGetUPEM() const override { return 0; };
+ void onGetFamilyName(SkString* familyName) const override { familyName->reset(); }
+ SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
+ SK_ABORT("unimplemented");
+ return nullptr;
+ };
+ int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
+ size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override { return 0; }
+};
+
+static bool count_proc(SkTypeface* face, void* ctx) {
+ int* count = static_cast<int*>(ctx);
+ *count = *count + 1;
+ return false;
+}
+static int count(skiatest::Reporter* reporter, const SkTypefaceCache& cache) {
+ int count = 0;
+ SkTypeface* none = cache.findByProcAndRef(count_proc, &count);
+ REPORTER_ASSERT(reporter, none == nullptr);
+ return count;
+}
+
+DEF_TEST(TypefaceCache, reporter) {
+ sk_sp<SkTypeface> t1(SkEmptyTypeface::Create(1));
+ {
+ SkTypefaceCache cache;
+ REPORTER_ASSERT(reporter, count(reporter, cache) == 0);
+ {
+ sk_sp<SkTypeface> t0(SkEmptyTypeface::Create(0));
+ cache.add(t0.get());
+ REPORTER_ASSERT(reporter, count(reporter, cache) == 1);
+ cache.add(t1.get());
+ REPORTER_ASSERT(reporter, count(reporter, cache) == 2);
+ cache.purgeAll();
+ REPORTER_ASSERT(reporter, count(reporter, cache) == 2);
+ }
+ REPORTER_ASSERT(reporter, count(reporter, cache) == 2);
+ cache.purgeAll();
+ REPORTER_ASSERT(reporter, count(reporter, cache) == 1);
+ }
+ REPORTER_ASSERT(reporter, t1->unique());
+}
« no previous file with comments | « src/ports/SkFontMgr_win_dw.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698