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

Side by Side Diff: tests/TypefaceTest.cpp

Issue 1887093002: Put SkEmptyTypeface in anonymous namespace. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « src/core/SkTypeface.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkRefCnt.h" 8 #include "SkRefCnt.h"
9 #include "SkTypeface.h" 9 #include "SkTypeface.h"
10 #include "SkTypefaceCache.h" 10 #include "SkTypefaceCache.h"
11 #include "Test.h" 11 #include "Test.h"
12 12
13 DEF_TEST(Typeface, reporter) { 13 DEF_TEST(Typeface, reporter) {
14 14
15 SkAutoTUnref<SkTypeface> t1(SkTypeface::CreateFromName(nullptr, SkTypeface:: kNormal)); 15 SkAutoTUnref<SkTypeface> t1(SkTypeface::CreateFromName(nullptr, SkTypeface:: kNormal));
16 SkAutoTUnref<SkTypeface> t2(SkTypeface::RefDefault(SkTypeface::kNormal)); 16 SkAutoTUnref<SkTypeface> t2(SkTypeface::RefDefault(SkTypeface::kNormal));
17 17
18 REPORTER_ASSERT(reporter, SkTypeface::Equal(t1.get(), t2.get())); 18 REPORTER_ASSERT(reporter, SkTypeface::Equal(t1.get(), t2.get()));
19 REPORTER_ASSERT(reporter, SkTypeface::Equal(0, t1.get())); 19 REPORTER_ASSERT(reporter, SkTypeface::Equal(0, t1.get()));
20 REPORTER_ASSERT(reporter, SkTypeface::Equal(0, t2.get())); 20 REPORTER_ASSERT(reporter, SkTypeface::Equal(0, t2.get()));
21 REPORTER_ASSERT(reporter, SkTypeface::Equal(t1.get(), 0)); 21 REPORTER_ASSERT(reporter, SkTypeface::Equal(t1.get(), 0));
22 REPORTER_ASSERT(reporter, SkTypeface::Equal(t2.get(), 0)); 22 REPORTER_ASSERT(reporter, SkTypeface::Equal(t2.get(), 0));
23 23
24 #ifdef SK_BUILD_FOR_ANDROID 24 #ifdef SK_BUILD_FOR_ANDROID
25 SkAutoTUnref<SkTypeface> t3(SkTypeface::CreateFromName("non-existent-font", SkTypeface::kNormal)); 25 SkAutoTUnref<SkTypeface> t3(SkTypeface::CreateFromName("non-existent-font", SkTypeface::kNormal));
26 REPORTER_ASSERT(reporter, nullptr == t3.get()); 26 REPORTER_ASSERT(reporter, nullptr == t3.get());
27 #endif 27 #endif
28 } 28 }
29 29
30 namespace {
31
30 class SkEmptyTypeface : public SkTypeface { 32 class SkEmptyTypeface : public SkTypeface {
31 public: 33 public:
32 static sk_sp<SkTypeface> Create(SkFontID id) { return sk_sp<SkTypeface>(new SkEmptyTypeface(id)); } 34 static sk_sp<SkTypeface> Create(SkFontID id) { return sk_sp<SkTypeface>(new SkEmptyTypeface(id)); }
33 protected: 35 protected:
34 SkEmptyTypeface(SkFontID id) : SkTypeface(SkFontStyle(), id, true) { } 36 SkEmptyTypeface(SkFontID id) : SkTypeface(SkFontStyle(), id, true) { }
35 37
36 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; } 38 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
37 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, 39 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
38 const SkDescriptor*) const override { 40 const SkDescriptor*) const override {
39 return nullptr; 41 return nullptr;
(...skipping 12 matching lines...) Expand all
52 int onGetUPEM() const override { return 0; }; 54 int onGetUPEM() const override { return 0; };
53 void onGetFamilyName(SkString* familyName) const override { familyName->rese t(); } 55 void onGetFamilyName(SkString* familyName) const override { familyName->rese t(); }
54 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override { 56 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
55 SK_ABORT("unimplemented"); 57 SK_ABORT("unimplemented");
56 return nullptr; 58 return nullptr;
57 }; 59 };
58 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; } 60 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
59 size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override { return 0; } 61 size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override { return 0; }
60 }; 62 };
61 63
64 }
65
62 static bool count_proc(SkTypeface* face, void* ctx) { 66 static bool count_proc(SkTypeface* face, void* ctx) {
63 int* count = static_cast<int*>(ctx); 67 int* count = static_cast<int*>(ctx);
64 *count = *count + 1; 68 *count = *count + 1;
65 return false; 69 return false;
66 } 70 }
67 static int count(skiatest::Reporter* reporter, const SkTypefaceCache& cache) { 71 static int count(skiatest::Reporter* reporter, const SkTypefaceCache& cache) {
68 int count = 0; 72 int count = 0;
69 SkTypeface* none = cache.findByProcAndRef(count_proc, &count); 73 SkTypeface* none = cache.findByProcAndRef(count_proc, &count);
70 REPORTER_ASSERT(reporter, none == nullptr); 74 REPORTER_ASSERT(reporter, none == nullptr);
71 return count; 75 return count;
(...skipping 12 matching lines...) Expand all
84 REPORTER_ASSERT(reporter, count(reporter, cache) == 2); 88 REPORTER_ASSERT(reporter, count(reporter, cache) == 2);
85 cache.purgeAll(); 89 cache.purgeAll();
86 REPORTER_ASSERT(reporter, count(reporter, cache) == 2); 90 REPORTER_ASSERT(reporter, count(reporter, cache) == 2);
87 } 91 }
88 REPORTER_ASSERT(reporter, count(reporter, cache) == 2); 92 REPORTER_ASSERT(reporter, count(reporter, cache) == 2);
89 cache.purgeAll(); 93 cache.purgeAll();
90 REPORTER_ASSERT(reporter, count(reporter, cache) == 1); 94 REPORTER_ASSERT(reporter, count(reporter, cache) == 1);
91 } 95 }
92 REPORTER_ASSERT(reporter, t1->unique()); 96 REPORTER_ASSERT(reporter, t1->unique());
93 } 97 }
OLDNEW
« no previous file with comments | « src/core/SkTypeface.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698