Verify all parsed test font files start with cap.

All of the Android test font configuration files have file names which
start with a capital latin letter. Verify this is true of the parsed file
names. This would have caught previous issues with slicing, and will
hopefully prevent such issues going unnoticed in the future.

Review URL: https://codereview.chromium.org/925933003
This commit is contained in:
bungeman 2015-02-13 08:55:16 -08:00 committed by Commit bot
parent f16c00e41b
commit 9a0808fd8e
2 changed files with 21 additions and 8 deletions

View File

@ -449,7 +449,8 @@ static int parse_config_file(const char* filename, SkTDArray<FontFamily*>& famil
// One would assume it would be faster to have a buffer on the stack and call XML_Parse.
// But XML_Parse will call XML_GetBuffer anyway and memmove the passed buffer into it.
// (Unless XML_CONTEXT_BYTES is undefined, but all users define it.)
static const int bufferSize = 512;
// In debug, buffer a small odd number of bytes to detect slicing in XML_CharacterDataHandler.
static const int bufferSize = 512 SkDEBUGCODE( - 507);
bool done = false;
while (!done) {
void* buffer = XML_GetBuffer(parser, bufferSize);
@ -508,10 +509,12 @@ static void append_fallback_font_families_for_locale(SkTDArray<FontFamily*>& fal
}
for (struct dirent* dirEntry; (dirEntry = readdir(fontDirectory));) {
// The size of both the prefix, suffix, and a minimum valid language code
static const size_t minSize = sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1
+ sizeof(LOCALE_FALLBACK_FONTS_SUFFIX) - 1
+ 2;
// The size of the prefix and suffix.
static const size_t fixedLen = sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1
+ sizeof(LOCALE_FALLBACK_FONTS_SUFFIX) - 1;
// The size of the prefix, suffix, and a minimum valid language code
static const size_t minSize = fixedLen + 2;
SkString fileName(dirEntry->d_name);
if (fileName.size() < minSize ||
@ -521,9 +524,6 @@ static void append_fallback_font_families_for_locale(SkTDArray<FontFamily*>& fal
continue;
}
static const size_t fixedLen = sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1
+ sizeof(LOCALE_FALLBACK_FONTS_SUFFIX) - 1;
SkString locale(fileName.c_str() + sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1,
fileName.size() - fixedLen);

View File

@ -48,6 +48,19 @@ void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* firstE
REPORTER_ASSERT(reporter, isALPHA(c) || isDIGIT(c) || '-' == c);
}
}
// All file names in the test configuration files start with a capital letter.
// This is not a general requirement, but it is true of all the test configuration data.
// Verifying ensures the filenames have been read sanely and have not been 'sliced'.
for (int i = 0; i < fontFamilies.count(); ++i) {
FontFamily& family = *fontFamilies[i];
for (int j = 0; j < family.fFonts.count(); ++j) {
FontFileInfo& file = family.fFonts[j];
REPORTER_ASSERT(reporter, !file.fFileName.isEmpty() &&
file.fFileName[0] >= 'A' &&
file.fFileName[0] <= 'Z');
}
}
}
void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) {