aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2015-02-11 07:18:51 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-11 07:18:51 -0800
commitc3c694342ad393b88cee5885395f182082aa2ebb (patch)
treef1c6cd5128c1596ac15b4b9eb8c2e524706236c8 /tests
parent02b05015b55d1900a9e34039942101da189053ce (diff)
Fix append_fallback_font_families_for_locale.
The language was being set to garbage, now set to part of the file name. Add a test to ensure we continue to parse fallback directories correctly. BUG=chromium:422180 Review URL: https://codereview.chromium.org/912053003
Diffstat (limited to 'tests')
-rw-r--r--tests/FontConfigParser.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/tests/FontConfigParser.cpp b/tests/FontConfigParser.cpp
index dfc8093f2a..dc1fac0547 100644
--- a/tests/FontConfigParser.cpp
+++ b/tests/FontConfigParser.cpp
@@ -22,6 +22,16 @@ int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) {
return countOfFallbackFonts;
}
+//https://tools.ietf.org/html/rfc5234#appendix-B.1
+static bool isALPHA(int c) {
+ return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
+}
+
+//https://tools.ietf.org/html/rfc5234#appendix-B.1
+static bool isDIGIT(int c) {
+ return ('0' <= c && c <= '9');
+}
+
void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* firstExpectedFile,
skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5);
@@ -29,6 +39,15 @@ void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* firstE
REPORTER_ASSERT(reporter,
!strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(), firstExpectedFile));
REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont);
+
+ // Check that the languages are all sane.
+ for (int i = 0; i < fontFamilies.count(); ++i) {
+ const SkString& lang = fontFamilies[i]->fLanguage.getTag();
+ for (size_t j = 0; j < lang.size(); ++j) {
+ int c = lang[j];
+ REPORTER_ASSERT(reporter, isALPHA(c) || isDIGIT(c) || '-' == c);
+ }
+ }
}
void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) {
@@ -55,6 +74,7 @@ void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) {
SkDebugf(" file (%d) %s#%d\n", ffi.fWeight, ffi.fFileName.c_str(), ffi.fIndex);
}
}
+ SkDebugf("\n\n");
}
DEF_TEST(FontConfigParserAndroid, reporter) {
@@ -82,11 +102,12 @@ DEF_TEST(FontConfigParserAndroid, reporter) {
SkFontConfigParser::GetCustomFontFamilies(v17FontFamilies,
SkString("/custom/font/path/"),
GetResourcePath("android_fonts/v17/system_fonts.xml").c_str(),
- GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str());
+ GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str(),
+ GetResourcePath("android_fonts/v17").c_str());
if (v17FontFamilies.count() > 0) {
- REPORTER_ASSERT(reporter, v17FontFamilies.count() == 41);
- REPORTER_ASSERT(reporter, CountFallbacks(v17FontFamilies) == 31);
+ REPORTER_ASSERT(reporter, v17FontFamilies.count() == 56);
+ REPORTER_ASSERT(reporter, CountFallbacks(v17FontFamilies) == 46);
DumpLoadedFonts(v17FontFamilies);
ValidateLoadedFonts(v17FontFamilies, "Roboto-Regular.ttf", reporter);