blob: 6b6ee9a73f9899bed76985ca7fe2fe85055e3af7 [file] [log] [blame]
reed@google.com83165a52013-04-11 18:31:25 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "Test.h"
9
10#include "SkCommandLineFlags.h"
11#include "SkFontMgr.h"
12#include "SkTypeface.h"
13
14static void test_fontiter(skiatest::Reporter* reporter, bool verbose) {
15 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
16 int count = fm->countFamilies();
17
18 for (int i = 0; i < count; ++i) {
19 SkString fname;
20 fm->getFamilyName(i, &fname);
21 REPORTER_ASSERT(reporter, fname.size() > 0);
22
bungeman@google.com71033442013-05-01 14:21:20 +000023 SkAutoTUnref<SkFontStyleSet> fnset(fm->matchFamily(fname.c_str()));
reed@google.com83165a52013-04-11 18:31:25 +000024 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
bungeman@google.com71033442013-05-01 14:21:20 +000025 REPORTER_ASSERT(reporter, fnset->count() == set->count());
reed@google.com83165a52013-04-11 18:31:25 +000026
27 if (verbose) {
28 SkDebugf("[%2d] %s\n", i, fname.c_str());
29 }
30
31 for (int j = 0; j < set->count(); ++j) {
32 SkString sname;
33 SkFontStyle fs;
34 set->getStyle(j, &fs, &sname);
reed@google.comeb029572013-04-25 14:59:32 +000035// REPORTER_ASSERT(reporter, sname.size() > 0);
reed@google.com83165a52013-04-11 18:31:25 +000036
37 SkAutoTUnref<SkTypeface> face(set->createTypeface(j));
reed@google.comc1ccda32013-04-19 14:28:54 +000038// REPORTER_ASSERT(reporter, face.get());
reed@google.com83165a52013-04-11 18:31:25 +000039
40 if (verbose) {
41 SkDebugf("\t[%d] %s [%3d %d %d]\n", j, sname.c_str(),
42 fs.weight(), fs.width(), fs.isItalic());
43 }
44 }
45 }
46}
47
reed@google.com66c9f992013-04-11 19:04:34 +000048DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests.");
reed@google.com83165a52013-04-11 18:31:25 +000049
50static void TestFontMgr(skiatest::Reporter* reporter) {
51 test_fontiter(reporter, FLAGS_verboseFontMgr);
52}
53
54#include "TestClassDef.h"
55DEFINE_TESTCLASS("FontMgr", FontMgrClass, TestFontMgr)