blob: 1c32704938d69ab723b204d28673537108cb9dff [file] [log] [blame]
tomhudsonf79673b2014-08-05 06:36:11 -07001/*
2 * Copyright 2014 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 "Resources.h"
9#include "SkFontConfigParser_android.h"
10#include "Test.h"
11
12void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies,
13 skiatest::Reporter* reporter) {
14 REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5);
15 REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans-serif"));
16 REPORTER_ASSERT(reporter,
17 !strcmp(fontFamilies[0]->fFontFiles[0].fFileName.c_str(),
18 "Roboto-Regular.ttf"));
19 REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont);
20
21}
22
23void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) {
24#if SK_DEBUG_FONTS
25 for (int i = 0; i < fontFamilies.count(); ++i) {
26 SkDebugf("Family %d:\n", i);
tomhudson07544752014-08-05 13:35:00 -070027 switch(fontFamilies[i]->fVariant) {
28 case SkPaintOptionsAndroid::kElegant_Variant: SkDebugf(" elegant"); break;
29 case SkPaintOptionsAndroid::kCompact_Variant: SkDebugf(" compact"); break;
30 default: break;
31 }
32 if (!fontFamilies[i]->fLanguage.getTag().isEmpty()) {
33 SkDebugf(" language: %s", fontFamilies[i]->fLanguage.getTag().c_str());
34 }
tomhudsonf79673b2014-08-05 06:36:11 -070035 for (int j = 0; j < fontFamilies[i]->fNames.count(); ++j) {
36 SkDebugf(" name %s\n", fontFamilies[i]->fNames[j].c_str());
37 }
tomhudson07544752014-08-05 13:35:00 -070038 for (int j = 0; j < fontFamilies[i]->fFontFiles.count(); ++j) {
39 const FontFileInfo& ffi = fontFamilies[i]->fFontFiles[j];
40 SkDebugf(" file (%d %s %d) %s\n",
41 ffi.fWeight,
42 ffi.fPaintOptions.getLanguage().getTag().isEmpty() ? "" :
43 ffi.fPaintOptions.getLanguage().getTag().c_str(),
44 ffi.fPaintOptions.getFontVariant(),
45 ffi.fFileName.c_str());
46 }
tomhudsonf79673b2014-08-05 06:36:11 -070047 }
48#endif // SK_DEBUG_FONTS
49}
50
51DEF_TEST(FontConfigParserAndroid, reporter) {
52
tomhudson8aed3c12014-08-07 10:20:51 -070053 bool resourcesMissing = false;
54
tomhudsonf79673b2014-08-05 06:36:11 -070055 SkTDArray<FontFamily*> preV17FontFamilies;
56 SkFontConfigParser::GetTestFontFamilies(preV17FontFamilies,
57 GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(),
58 GetResourcePath("android_fonts/pre_v17/fallback_fonts.xml").c_str());
59
tomhudson8aed3c12014-08-07 10:20:51 -070060 if (preV17FontFamilies.count() > 0) {
61 REPORTER_ASSERT(reporter, preV17FontFamilies.count() == 14);
tomhudsonf79673b2014-08-05 06:36:11 -070062
tomhudson8aed3c12014-08-07 10:20:51 -070063 DumpLoadedFonts(preV17FontFamilies);
64 ValidateLoadedFonts(preV17FontFamilies, reporter);
65 } else {
66 resourcesMissing = true;
67 }
tomhudsonf79673b2014-08-05 06:36:11 -070068
tomhudson07544752014-08-05 13:35:00 -070069
tomhudsonf79673b2014-08-05 06:36:11 -070070 SkTDArray<FontFamily*> v17FontFamilies;
71 SkFontConfigParser::GetTestFontFamilies(v17FontFamilies,
72 GetResourcePath("android_fonts/v17/system_fonts.xml").c_str(),
73 GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str());
74
tomhudson8aed3c12014-08-07 10:20:51 -070075 if (v17FontFamilies.count() > 0) {
76 REPORTER_ASSERT(reporter, v17FontFamilies.count() == 41);
tomhudsonf79673b2014-08-05 06:36:11 -070077
tomhudson8aed3c12014-08-07 10:20:51 -070078 DumpLoadedFonts(v17FontFamilies);
79 ValidateLoadedFonts(v17FontFamilies, reporter);
80 } else {
81 resourcesMissing = true;
82 }
tomhudsonf79673b2014-08-05 06:36:11 -070083
tomhudson07544752014-08-05 13:35:00 -070084
tomhudsonf79673b2014-08-05 06:36:11 -070085 SkTDArray<FontFamily*> v22FontFamilies;
86 SkFontConfigParser::GetTestFontFamilies(v22FontFamilies,
87 GetResourcePath("android_fonts/v22/fonts.xml").c_str(),
88 NULL);
89
tomhudson8aed3c12014-08-07 10:20:51 -070090 if (v22FontFamilies.count() > 0) {
91 REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53);
tomhudsonf79673b2014-08-05 06:36:11 -070092
tomhudson8aed3c12014-08-07 10:20:51 -070093 DumpLoadedFonts(v22FontFamilies);
94 ValidateLoadedFonts(v22FontFamilies, reporter);
95 } else {
96 resourcesMissing = true;
97 }
98
99 if (resourcesMissing) {
100 SkDebugf("---- Resource files missing for FontConfigParser test\n");
101 }
tomhudsonf79673b2014-08-05 06:36:11 -0700102}
103