tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TestFontOverlapPrevention.cpp (2471B)


      1 /* vim:set ts=2 sw=2 sts=2 et: */
      2 /* Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 #include "gtest/gtest.h"
      7 #include <vector>
      8 #include <string>
      9 
     10 #define StandardFonts
     11 #ifdef XP_WIN
     12 #  include "../thebes/StandardFonts-win10.inc"
     13 #elif defined(XP_MACOSX)
     14 #  include "../thebes/StandardFonts-macos.inc"
     15 #elif defined(XP_LINUX)
     16 #  include "../thebes/StandardFonts-linux.inc"
     17 #elif defined(XP_ANDROID)
     18 #  include "../thebes/StandardFonts-android.inc"
     19 #endif
     20 #undef StandardFonts
     21 
     22 // Helper to collect FONT_RULE font names
     23 std::vector<std::string> GetFontRuleNames() {
     24  std::vector<std::string> fontRuleNames;
     25 #undef FONT_RULE
     26 #define FONT_RULE(fontName, ...) fontRuleNames.push_back(fontName);
     27 #define FontInclusionByLocaleRules
     28 
     29 #ifdef XP_WIN
     30 #  include "../thebes/StandardFonts-win10.inc"
     31 #elif defined(XP_MACOSX)
     32 #  include "../thebes/StandardFonts-macos.inc"
     33 #elif defined(XP_LINUX)
     34 #  include "../thebes/StandardFonts-linux.inc"
     35 #elif defined(XP_ANDROID)
     36 #  include "../thebes/StandardFonts-android.inc"
     37 #endif
     38 
     39 #undef FontInclusionByLocaleRules
     40 #undef FONT_RULE
     41  return fontRuleNames;
     42 }
     43 
     44 /*
     45 * This test verifies that the font names defined in the language pack
     46 * (kLangPackFonts) do not overlap with the font names defined by FONT_RULE
     47 * macros in the platform-specific standard font inclusion files.
     48 *
     49 * The code in gfxDWriteFontList::GetVisibilityForFamily assumes that a font is
     50 * not in both lists.
     51 */
     52 
     53 TEST(StandardFontsTest, LangPackAndFontRuleNoOverlap)
     54 {
     55  // Get LangPack font names
     56  std::set<std::string> langPackFonts;
     57  for (const char* font : kLangPackFonts) {
     58    langPackFonts.insert(font);
     59  }
     60 
     61  // Get FONT_RULE font names
     62  std::vector<std::string> fontRuleNames = GetFontRuleNames();
     63 
     64  // Check for overlap
     65  for (const auto& font : fontRuleNames) {
     66    auto it = std::find_if(langPackFonts.begin(), langPackFonts.end(),
     67                           [&font](const std::string& langPackFont) {
     68                             return std::equal(
     69                                 font.begin(), font.end(), langPackFont.begin(),
     70                                 langPackFont.end(), [](char a, char b) {
     71                                   return tolower(a) == tolower(b);
     72                                 });
     73                           });
     74    ASSERT_EQ(it, langPackFonts.end())
     75        << "Font '" << font
     76        << "' is in both kLangPackFonts and FONT_RULE (case insensitive)";
     77  }
     78 }