OLD | NEW |
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 "Test.h" | 8 #include "Test.h" |
9 | 9 |
10 #include "SkCommandLineFlags.h" | 10 #include "SkCommandLineFlags.h" |
11 #include "SkFontMgr.h" | 11 #include "SkFontMgr.h" |
12 #include "SkTypeface.h" | 12 #include "SkTypeface.h" |
13 | 13 |
14 #if !defined(SK_BUILD_FOR_ANDROID) | |
15 /* | 14 /* |
16 * If the font backend is going to "alias" some font names to other fonts | 15 * If the font backend is going to "alias" some font names to other fonts |
17 * (e.g. sans -> Arial) then we want to at least get the same typeface back | 16 * (e.g. sans -> Arial) then we want to at least get the same typeface back |
18 * if we request the alias name multiple times. | 17 * if we request the alias name multiple times. |
19 */ | 18 */ |
20 static void test_badnames(skiatest::Reporter* reporter) { | 19 static void test_alias_names(skiatest::Reporter* reporter) { |
21 const char* inName = "sans"; | 20 const char* inNames[] = { |
22 SkAutoTUnref<SkTypeface> first(SkTypeface::CreateFromName(inName, SkTypeface
::kNormal)); | 21 "sans", "sans-serif", "serif", "monospace", "times", "helvetica" |
23 | 22 }; |
24 SkString name; | 23 |
25 for (int i = 0; i < 10; ++i) { | 24 for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) { |
26 SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(inName, SkTypef
ace::kNormal)); | 25 SkAutoTUnref<SkTypeface> first(SkTypeface::CreateFromName(inNames[i], |
27 #if 0 | 26 SkTypeface::kNormal)); |
28 face->getFamilyName(&name); | 27 if (NULL == first.get()) { |
29 printf("request %s, received %s, first id %x received %x\n", | 28 continue; |
30 inName, name.c_str(), first->uniqueID(), face->uniqueID()); | 29 } |
31 #endif | 30 for (int j = 0; j < 10; ++j) { |
32 REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID()); | 31 SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(inNames[i], |
| 32 SkTypeface::kNormal)); |
| 33 #if 0 |
| 34 SkString name; |
| 35 face->getFamilyName(&name); |
| 36 printf("request %s, received %s, first id %x received %x\n", |
| 37 inNames[i], name.c_str(), first->uniqueID(), face->uniqueID()
); |
| 38 #endif |
| 39 REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID()); |
| 40 } |
33 } | 41 } |
34 } | 42 } |
35 #endif | |
36 | 43 |
37 static void test_fontiter(skiatest::Reporter* reporter, bool verbose) { | 44 static void test_fontiter(skiatest::Reporter* reporter, bool verbose) { |
38 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 45 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
39 int count = fm->countFamilies(); | 46 int count = fm->countFamilies(); |
40 | 47 |
41 for (int i = 0; i < count; ++i) { | 48 for (int i = 0; i < count; ++i) { |
42 SkString fname; | 49 SkString fname; |
43 fm->getFamilyName(i, &fname); | 50 fm->getFamilyName(i, &fname); |
44 REPORTER_ASSERT(reporter, fname.size() > 0); | 51 REPORTER_ASSERT(reporter, fname.size() > 0); |
45 | 52 |
(...skipping 19 matching lines...) Expand all Loading... |
65 fs.weight(), fs.width(), fs.isItalic()); | 72 fs.weight(), fs.width(), fs.isItalic()); |
66 } | 73 } |
67 } | 74 } |
68 } | 75 } |
69 } | 76 } |
70 | 77 |
71 DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); | 78 DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); |
72 | 79 |
73 static void TestFontMgr(skiatest::Reporter* reporter) { | 80 static void TestFontMgr(skiatest::Reporter* reporter) { |
74 test_fontiter(reporter, FLAGS_verboseFontMgr); | 81 test_fontiter(reporter, FLAGS_verboseFontMgr); |
75 // The badnames test fails on Android because "sans" is not a valid alias | 82 test_alias_names(reporter); |
76 #if !defined(SK_BUILD_FOR_ANDROID) | |
77 test_badnames(reporter); | |
78 #endif | |
79 } | 83 } |
80 | 84 |
81 #include "TestClassDef.h" | 85 #include "TestClassDef.h" |
82 DEFINE_TESTCLASS("FontMgr", FontMgrClass, TestFontMgr) | 86 DEFINE_TESTCLASS("FontMgr", FontMgrClass, TestFontMgr) |
OLD | NEW |