Home | History | Annotate | Download | only in tests
      1 /*
      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 "SkCommandLineFlags.h"
      9 #include "SkFontMgr.h"
     10 #include "SkTypeface.h"
     11 #include "Test.h"
     12 
     13 #include "SkFont.h"
     14 #include "SkPaint.h"
     15 
     16 #include <initializer_list>
     17 #include <limits>
     18 #include <vector>
     19 
     20 static void test_font(skiatest::Reporter* reporter) {
     21     uint32_t flags = 0;
     22     SkAutoTUnref<SkFont> font(SkFont::Create(nullptr, 24, SkFont::kA8_MaskType, flags));
     23 
     24     REPORTER_ASSERT(reporter, font->getTypeface());
     25     REPORTER_ASSERT(reporter, 24 == font->getSize());
     26     REPORTER_ASSERT(reporter, 1 == font->getScaleX());
     27     REPORTER_ASSERT(reporter, 0 == font->getSkewX());
     28     REPORTER_ASSERT(reporter, SkFont::kA8_MaskType == font->getMaskType());
     29 
     30     uint16_t glyphs[5];
     31     sk_bzero(glyphs, sizeof(glyphs));
     32 
     33     int count = font->textToGlyphs("Hello", 5, kUTF8_SkTextEncoding, glyphs, SK_ARRAY_COUNT(glyphs));
     34 
     35     REPORTER_ASSERT(reporter, 5 == count);
     36     for (int i = 0; i < count; ++i) {
     37         REPORTER_ASSERT(reporter, 0 != glyphs[i]);
     38     }
     39     REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e'
     40     REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l'
     41 
     42     SkAutoTUnref<SkFont> newFont(font->cloneWithSize(36));
     43     REPORTER_ASSERT(reporter, newFont.get());
     44     REPORTER_ASSERT(reporter, font->getTypeface() == newFont->getTypeface());
     45     REPORTER_ASSERT(reporter, 36 == newFont->getSize());   // double check we haven't changed
     46     REPORTER_ASSERT(reporter, 24 == font->getSize());   // double check we haven't changed
     47 
     48     SkPaint paint;
     49     paint.setTextSize(18);
     50     font.reset(SkFont::Testing_CreateFromPaint(paint));
     51     REPORTER_ASSERT(reporter, font.get());
     52     REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize());
     53     REPORTER_ASSERT(reporter, SkFont::kBW_MaskType == font->getMaskType());
     54 }
     55 
     56 /*
     57  *  If the font backend is going to "alias" some font names to other fonts
     58  *  (e.g. sans -> Arial) then we want to at least get the same typeface back
     59  *  if we request the alias name multiple times.
     60  */
     61 static void test_alias_names(skiatest::Reporter* reporter) {
     62     const char* inNames[] = {
     63         "sans", "sans-serif", "serif", "monospace", "times", "helvetica"
     64     };
     65 
     66     for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) {
     67         SkAutoTUnref<SkTypeface> first(SkTypeface::CreateFromName(inNames[i],
     68                                                           SkTypeface::kNormal));
     69         if (nullptr == first.get()) {
     70             continue;
     71         }
     72         for (int j = 0; j < 10; ++j) {
     73             SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(inNames[i],
     74                                                          SkTypeface::kNormal));
     75     #if 0
     76             SkString name;
     77             face->getFamilyName(&name);
     78             printf("request %s, received %s, first id %x received %x\n",
     79                    inNames[i], name.c_str(), first->uniqueID(), face->uniqueID());
     80     #endif
     81             REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID());
     82         }
     83     }
     84 }
     85 
     86 static void test_fontiter(skiatest::Reporter* reporter, bool verbose) {
     87     SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
     88     int count = fm->countFamilies();
     89 
     90     for (int i = 0; i < count; ++i) {
     91         SkString fname;
     92         fm->getFamilyName(i, &fname);
     93 
     94         SkAutoTUnref<SkFontStyleSet> fnset(fm->matchFamily(fname.c_str()));
     95         SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
     96         REPORTER_ASSERT(reporter, fnset->count() == set->count());
     97 
     98         if (verbose) {
     99             SkDebugf("[%2d] %s\n", i, fname.c_str());
    100         }
    101 
    102         for (int j = 0; j < set->count(); ++j) {
    103             SkString sname;
    104             SkFontStyle fs;
    105             set->getStyle(j, &fs, &sname);
    106 //            REPORTER_ASSERT(reporter, sname.size() > 0);
    107 
    108             SkAutoTUnref<SkTypeface> face(set->createTypeface(j));
    109 //            REPORTER_ASSERT(reporter, face.get());
    110 
    111             if (verbose) {
    112                 SkDebugf("\t[%d] %s [%3d %d %d]\n", j, sname.c_str(),
    113                          fs.weight(), fs.width(), fs.isItalic());
    114             }
    115         }
    116     }
    117 }
    118 
    119 static void test_matchStyleCSS3(skiatest::Reporter* reporter) {
    120     static const SkFontID invalidFontID = std::numeric_limits<SkFontID>::max();
    121     static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
    122 
    123     class TestTypeface : public SkTypeface {
    124     public:
    125         TestTypeface(const SkFontStyle& fontStyle, SkFontID id) : SkTypeface(fontStyle, id, false){}
    126     protected:
    127         SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
    128         SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override {
    129             return nullptr;
    130         }
    131         void onFilterRec(SkScalerContextRec*) const override { }
    132         virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
    133             PerGlyphInfo,
    134             const uint32_t*, uint32_t) const override { return nullptr; }
    135         void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
    136         virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
    137             uint16_t glyphs[], int glyphCount) const override {
    138             if (glyphs && glyphCount > 0) {
    139                 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0]));
    140             }
    141             return 0;
    142         }
    143         int onCountGlyphs() const override { return 0; };
    144         int onGetUPEM() const override { return 0; };
    145         class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings {
    146         public:
    147             bool next(SkTypeface::LocalizedString*) override { return false; }
    148         };
    149         void onGetFamilyName(SkString* familyName) const override {
    150             familyName->reset();
    151         }
    152         SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
    153             return new EmptyLocalizedStrings;
    154         };
    155         int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
    156         size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override {
    157             return 0;
    158         }
    159     };
    160 
    161     class TestFontStyleSet : public SkFontStyleSet {
    162     public:
    163         TestFontStyleSet(std::initializer_list<SkFontStyle> styles) : fStyles(styles) {}
    164         int count() override { return static_cast<int>(fStyles.size()); }
    165         void getStyle(int index, SkFontStyle* style, SkString*) override {
    166             if (style) {
    167                 *style = fStyles[index];
    168             }
    169         }
    170         SkTypeface* createTypeface(int index) override {
    171             if (index < 0 || this->count() <= index) {
    172                 return new TestTypeface(invalidFontStyle, invalidFontID);
    173             }
    174             return new TestTypeface(fStyles[index], index);
    175         }
    176         SkTypeface* matchStyle(const SkFontStyle& pattern) override {
    177             return this->matchStyleCSS3(pattern);
    178         }
    179     private:
    180         std::vector<SkFontStyle> fStyles;
    181     };
    182 
    183     SkFontStyle condensed_normal_100(SkFontStyle::kThin_Weight,  SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
    184     SkFontStyle condensed_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
    185     SkFontStyle condensed_italic_100(SkFontStyle::kThin_Weight,  SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
    186     SkFontStyle condensed_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
    187     SkFontStyle  expanded_normal_100(SkFontStyle::kThin_Weight,  SkFontStyle::kExpanded_Width,  SkFontStyle::kUpright_Slant);
    188     SkFontStyle  expanded_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width,  SkFontStyle::kUpright_Slant);
    189     SkFontStyle  expanded_italic_100(SkFontStyle::kThin_Weight,  SkFontStyle::kExpanded_Width,  SkFontStyle::kItalic_Slant);
    190     SkFontStyle  expanded_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width,  SkFontStyle::kItalic_Slant);
    191 
    192     SkFontStyle normal_normal_100(SkFontStyle::kThin_Weight,       SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
    193     SkFontStyle normal_normal_200(SkFontStyle::kExtraLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
    194     SkFontStyle normal_normal_300(SkFontStyle::kLight_Weight,      SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
    195     SkFontStyle normal_normal_400(SkFontStyle::kNormal_Weight,     SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
    196     SkFontStyle normal_normal_500(SkFontStyle::kMedium_Weight,     SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
    197     SkFontStyle normal_normal_600(SkFontStyle::kSemiBold_Weight,   SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
    198     SkFontStyle normal_normal_700(SkFontStyle::kBold_Weight,       SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
    199     SkFontStyle normal_normal_800(SkFontStyle::kExtraBold_Weight,  SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
    200     SkFontStyle normal_normal_900(SkFontStyle::kBlack_Weight,      SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
    201 
    202     struct StyleSetTest {
    203         TestFontStyleSet styleSet;
    204         struct Case {
    205             SkFontStyle pattern;
    206             SkFontStyle expectedResult;
    207         };
    208         std::vector<Case> cases;
    209     } tests[] = {
    210         {
    211             { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900,
    212                expanded_normal_100, expanded_normal_900, expanded_italic_100, expanded_italic_900 },
    213             {
    214                 { condensed_normal_100, condensed_normal_100 },
    215                 { condensed_normal_900, condensed_normal_900 },
    216                 { condensed_italic_100, condensed_italic_100 },
    217                 { condensed_italic_900, condensed_italic_900 },
    218                 { expanded_normal_100, expanded_normal_100 },
    219                 { expanded_normal_900, expanded_normal_900 },
    220                 { expanded_italic_100, expanded_italic_100 },
    221                 { expanded_italic_900, expanded_italic_900 },
    222             },
    223         },
    224 
    225         {
    226             { condensed_normal_100,condensed_italic_100,expanded_normal_100,expanded_italic_100 },
    227             {
    228                 { condensed_normal_100, condensed_normal_100 },
    229                 { condensed_normal_900, condensed_normal_100 },
    230                 { condensed_italic_100, condensed_italic_100 },
    231                 { condensed_italic_900, condensed_italic_100 },
    232                 { expanded_normal_100, expanded_normal_100 },
    233                 { expanded_normal_900, expanded_normal_100 },
    234                 { expanded_italic_100, expanded_italic_100 },
    235                 { expanded_italic_900, expanded_italic_100 },
    236             },
    237         },
    238 
    239         {
    240             { condensed_normal_900,condensed_italic_900,expanded_normal_900,expanded_italic_900 },
    241             {
    242                 { condensed_normal_100, condensed_normal_900 },
    243                 { condensed_normal_900, condensed_normal_900 },
    244                 { condensed_italic_100, condensed_italic_900 },
    245                 { condensed_italic_900, condensed_italic_900 },
    246                 { expanded_normal_100, expanded_normal_900 },
    247                 { expanded_normal_900, expanded_normal_900 },
    248                 { expanded_italic_100, expanded_italic_900 },
    249                 { expanded_italic_900, expanded_italic_900 },
    250             },
    251         },
    252 
    253         {
    254             { condensed_normal_100,condensed_normal_900,expanded_normal_100,expanded_normal_900 },
    255             {
    256                 { condensed_normal_100, condensed_normal_100 },
    257                 { condensed_normal_900, condensed_normal_900 },
    258                 { condensed_italic_100, condensed_normal_100 },
    259                 { condensed_italic_900, condensed_normal_900 },
    260                 { expanded_normal_100, expanded_normal_100 },
    261                 { expanded_normal_900, expanded_normal_900 },
    262                 { expanded_italic_100, expanded_normal_100 },
    263                 { expanded_italic_900, expanded_normal_900 },
    264             },
    265         },
    266 
    267         {
    268             { condensed_normal_100,expanded_normal_100 },
    269             {
    270                 { condensed_normal_100, condensed_normal_100 },
    271                 { condensed_normal_900, condensed_normal_100 },
    272                 { condensed_italic_100, condensed_normal_100 },
    273                 { condensed_italic_900, condensed_normal_100 },
    274                 { expanded_normal_100, expanded_normal_100 },
    275                 { expanded_normal_900, expanded_normal_100 },
    276                 { expanded_italic_100, expanded_normal_100 },
    277                 { expanded_italic_900, expanded_normal_100 },
    278             },
    279         },
    280 
    281         {
    282             { condensed_normal_900,expanded_normal_900 },
    283             {
    284                 { condensed_normal_100, condensed_normal_900 },
    285                 { condensed_normal_900, condensed_normal_900 },
    286                 { condensed_italic_100, condensed_normal_900 },
    287                 { condensed_italic_900, condensed_normal_900 },
    288                 { expanded_normal_100, expanded_normal_900 },
    289                 { expanded_normal_900, expanded_normal_900 },
    290                 { expanded_italic_100, expanded_normal_900 },
    291                 { expanded_italic_900, expanded_normal_900 },
    292             },
    293         },
    294 
    295         {
    296             { condensed_italic_100,condensed_italic_900,expanded_italic_100,expanded_italic_900 },
    297             {
    298                 { condensed_normal_100, condensed_italic_100 },
    299                 { condensed_normal_900, condensed_italic_900 },
    300                 { condensed_italic_100, condensed_italic_100 },
    301                 { condensed_italic_900, condensed_italic_900 },
    302                 { expanded_normal_100, expanded_italic_100 },
    303                 { expanded_normal_900, expanded_italic_900 },
    304                 { expanded_italic_100, expanded_italic_100 },
    305                 { expanded_italic_900, expanded_italic_900 },
    306             },
    307         },
    308 
    309         {
    310             { condensed_italic_100,expanded_italic_100 },
    311             {
    312                 { condensed_normal_100, condensed_italic_100 },
    313                 { condensed_normal_900, condensed_italic_100 },
    314                 { condensed_italic_100, condensed_italic_100 },
    315                 { condensed_italic_900, condensed_italic_100 },
    316                 { expanded_normal_100, expanded_italic_100 },
    317                 { expanded_normal_900, expanded_italic_100 },
    318                 { expanded_italic_100, expanded_italic_100 },
    319                 { expanded_italic_900, expanded_italic_100 },
    320             },
    321         },
    322 
    323         {
    324             { condensed_italic_900,expanded_italic_900 },
    325             {
    326                 { condensed_normal_100, condensed_italic_900 },
    327                 { condensed_normal_900, condensed_italic_900 },
    328                 { condensed_italic_100, condensed_italic_900 },
    329                 { condensed_italic_900, condensed_italic_900 },
    330                 { expanded_normal_100, expanded_italic_900 },
    331                 { expanded_normal_900, expanded_italic_900 },
    332                 { expanded_italic_100, expanded_italic_900 },
    333                 { expanded_italic_900, expanded_italic_900 },
    334             },
    335         },
    336 
    337         {
    338             { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900 },
    339             {
    340                 { condensed_normal_100, condensed_normal_100 },
    341                 { condensed_normal_900, condensed_normal_900 },
    342                 { condensed_italic_100, condensed_italic_100 },
    343                 { condensed_italic_900, condensed_italic_900 },
    344                 { expanded_normal_100, condensed_normal_100 },
    345                 { expanded_normal_900, condensed_normal_900 },
    346                 { expanded_italic_100, condensed_italic_100 },
    347                 { expanded_italic_900, condensed_italic_900 },
    348             },
    349         },
    350 
    351         {
    352             { condensed_normal_100,condensed_italic_100 },
    353             {
    354                 { condensed_normal_100, condensed_normal_100 },
    355                 { condensed_normal_900, condensed_normal_100 },
    356                 { condensed_italic_100, condensed_italic_100 },
    357                 { condensed_italic_900, condensed_italic_100 },
    358                 { expanded_normal_100, condensed_normal_100 },
    359                 { expanded_normal_900, condensed_normal_100 },
    360                 { expanded_italic_100, condensed_italic_100 },
    361                 { expanded_italic_900, condensed_italic_100 },
    362             },
    363         },
    364 
    365         {
    366             { condensed_normal_900,condensed_italic_900 },
    367             {
    368                 { condensed_normal_100, condensed_normal_900 },
    369                 { condensed_normal_900, condensed_normal_900 },
    370                 { condensed_italic_100, condensed_italic_900 },
    371                 { condensed_italic_900, condensed_italic_900 },
    372                 { expanded_normal_100, condensed_normal_900 },
    373                 { expanded_normal_900, condensed_normal_900 },
    374                 { expanded_italic_100, condensed_italic_900 },
    375                 { expanded_italic_900, condensed_italic_900 },
    376             },
    377         },
    378 
    379         {
    380             { condensed_normal_100,condensed_normal_900 },
    381             {
    382                 { condensed_normal_100, condensed_normal_100 },
    383                 { condensed_normal_900, condensed_normal_900 },
    384                 { condensed_italic_100, condensed_normal_100 },
    385                 { condensed_italic_900, condensed_normal_900 },
    386                 { expanded_normal_100, condensed_normal_100 },
    387                 { expanded_normal_900, condensed_normal_900 },
    388                 { expanded_italic_100, condensed_normal_100 },
    389                 { expanded_italic_900, condensed_normal_900 },
    390             },
    391         },
    392 
    393         {
    394             { condensed_normal_100 },
    395             {
    396                 { condensed_normal_100, condensed_normal_100 },
    397                 { condensed_normal_900, condensed_normal_100 },
    398                 { condensed_italic_100, condensed_normal_100 },
    399                 { condensed_italic_900, condensed_normal_100 },
    400                 { expanded_normal_100, condensed_normal_100 },
    401                 { expanded_normal_900, condensed_normal_100 },
    402                 { expanded_italic_100, condensed_normal_100 },
    403                 { expanded_italic_900, condensed_normal_100 },
    404             },
    405         },
    406 
    407         {
    408             { condensed_normal_900 },
    409             {
    410                 { condensed_normal_100, condensed_normal_900 },
    411                 { condensed_normal_900, condensed_normal_900 },
    412                 { condensed_italic_100, condensed_normal_900 },
    413                 { condensed_italic_900, condensed_normal_900 },
    414                 { expanded_normal_100, condensed_normal_900 },
    415                 { expanded_normal_900, condensed_normal_900 },
    416                 { expanded_italic_100, condensed_normal_900 },
    417                 { expanded_italic_900, condensed_normal_900 },
    418             },
    419         },
    420 
    421         {
    422             { condensed_italic_100,condensed_italic_900 },
    423             {
    424                 { condensed_normal_100, condensed_italic_100 },
    425                 { condensed_normal_900, condensed_italic_900 },
    426                 { condensed_italic_100, condensed_italic_100 },
    427                 { condensed_italic_900, condensed_italic_900 },
    428                 { expanded_normal_100, condensed_italic_100 },
    429                 { expanded_normal_900, condensed_italic_900 },
    430                 { expanded_italic_100, condensed_italic_100 },
    431                 { expanded_italic_900, condensed_italic_900 },
    432             },
    433         },
    434 
    435         {
    436             { condensed_italic_100 },
    437             {
    438                 { condensed_normal_100, condensed_italic_100 },
    439                 { condensed_normal_900, condensed_italic_100 },
    440                 { condensed_italic_100, condensed_italic_100 },
    441                 { condensed_italic_900, condensed_italic_100 },
    442                 { expanded_normal_100, condensed_italic_100 },
    443                 { expanded_normal_900, condensed_italic_100 },
    444                 { expanded_italic_100, condensed_italic_100 },
    445                 { expanded_italic_900, condensed_italic_100 },
    446             },
    447         },
    448 
    449         {
    450             { condensed_italic_900 },
    451             {
    452                 { condensed_normal_100, condensed_italic_900 },
    453                 { condensed_normal_900, condensed_italic_900 },
    454                 { condensed_italic_100, condensed_italic_900 },
    455                 { condensed_italic_900, condensed_italic_900 },
    456                 { expanded_normal_100, condensed_italic_900 },
    457                 { expanded_normal_900, condensed_italic_900 },
    458                 { expanded_italic_100, condensed_italic_900 },
    459                 { expanded_italic_900, condensed_italic_900 },
    460             },
    461         },
    462 
    463         {
    464             { expanded_normal_100,expanded_normal_900,expanded_italic_100,expanded_italic_900 },
    465             {
    466                 { condensed_normal_100, expanded_normal_100 },
    467                 { condensed_normal_900, expanded_normal_900 },
    468                 { condensed_italic_100, expanded_italic_100 },
    469                 { condensed_italic_900, expanded_italic_900 },
    470                 { expanded_normal_100, expanded_normal_100 },
    471                 { expanded_normal_900, expanded_normal_900 },
    472                 { expanded_italic_100, expanded_italic_100 },
    473                 { expanded_italic_900, expanded_italic_900 },
    474             },
    475         },
    476 
    477         {
    478             { expanded_normal_100,expanded_italic_100 },
    479             {
    480                 { condensed_normal_100, expanded_normal_100 },
    481                 { condensed_normal_900, expanded_normal_100 },
    482                 { condensed_italic_100, expanded_italic_100 },
    483                 { condensed_italic_900, expanded_italic_100 },
    484                 { expanded_normal_100, expanded_normal_100 },
    485                 { expanded_normal_900, expanded_normal_100 },
    486                 { expanded_italic_100, expanded_italic_100 },
    487                 { expanded_italic_900, expanded_italic_100 },
    488             },
    489         },
    490 
    491         {
    492             { expanded_normal_900,expanded_italic_900 },
    493             {
    494                 { condensed_normal_100, expanded_normal_900 },
    495                 { condensed_normal_900, expanded_normal_900 },
    496                 { condensed_italic_100, expanded_italic_900 },
    497                 { condensed_italic_900, expanded_italic_900 },
    498                 { expanded_normal_100, expanded_normal_900 },
    499                 { expanded_normal_900, expanded_normal_900 },
    500                 { expanded_italic_100, expanded_italic_900 },
    501                 { expanded_italic_900, expanded_italic_900 },
    502             },
    503         },
    504 
    505         {
    506             { expanded_normal_100,expanded_normal_900 },
    507             {
    508                 { condensed_normal_100, expanded_normal_100 },
    509                 { condensed_normal_900, expanded_normal_900 },
    510                 { condensed_italic_100, expanded_normal_100 },
    511                 { condensed_italic_900, expanded_normal_900 },
    512                 { expanded_normal_100, expanded_normal_100 },
    513                 { expanded_normal_900, expanded_normal_900 },
    514                 { expanded_italic_100, expanded_normal_100 },
    515                 { expanded_italic_900, expanded_normal_900 },
    516             },
    517         },
    518 
    519         {
    520             { expanded_normal_100 },
    521             {
    522                 { condensed_normal_100, expanded_normal_100 },
    523                 { condensed_normal_900, expanded_normal_100 },
    524                 { condensed_italic_100, expanded_normal_100 },
    525                 { condensed_italic_900, expanded_normal_100 },
    526                 { expanded_normal_100, expanded_normal_100 },
    527                 { expanded_normal_900, expanded_normal_100 },
    528                 { expanded_italic_100, expanded_normal_100 },
    529                 { expanded_italic_900, expanded_normal_100 },
    530             },
    531         },
    532 
    533         {
    534             { expanded_normal_900 },
    535             {
    536                 { condensed_normal_100, expanded_normal_900 },
    537                 { condensed_normal_900, expanded_normal_900 },
    538                 { condensed_italic_100, expanded_normal_900 },
    539                 { condensed_italic_900, expanded_normal_900 },
    540                 { expanded_normal_100, expanded_normal_900 },
    541                 { expanded_normal_900, expanded_normal_900 },
    542                 { expanded_italic_100, expanded_normal_900 },
    543                 { expanded_italic_900, expanded_normal_900 },
    544             },
    545         },
    546 
    547         {
    548             { expanded_italic_100,expanded_italic_900 },
    549             {
    550                 { condensed_normal_100, expanded_italic_100 },
    551                 { condensed_normal_900, expanded_italic_900 },
    552                 { condensed_italic_100, expanded_italic_100 },
    553                 { condensed_italic_900, expanded_italic_900 },
    554                 { expanded_normal_100, expanded_italic_100 },
    555                 { expanded_normal_900, expanded_italic_900 },
    556                 { expanded_italic_100, expanded_italic_100 },
    557                 { expanded_italic_900, expanded_italic_900 },
    558             },
    559         },
    560 
    561         {
    562             { expanded_italic_100 },
    563             {
    564                 { condensed_normal_100, expanded_italic_100 },
    565                 { condensed_normal_900, expanded_italic_100 },
    566                 { condensed_italic_100, expanded_italic_100 },
    567                 { condensed_italic_900, expanded_italic_100 },
    568                 { expanded_normal_100, expanded_italic_100 },
    569                 { expanded_normal_900, expanded_italic_100 },
    570                 { expanded_italic_100, expanded_italic_100 },
    571                 { expanded_italic_900, expanded_italic_100 },
    572             },
    573         },
    574 
    575         {
    576             { expanded_italic_900 },
    577             {
    578                 { condensed_normal_100, expanded_italic_900 },
    579                 { condensed_normal_900, expanded_italic_900 },
    580                 { condensed_italic_100, expanded_italic_900 },
    581                 { condensed_italic_900, expanded_italic_900 },
    582                 { expanded_normal_100, expanded_italic_900 },
    583                 { expanded_normal_900, expanded_italic_900 },
    584                 { expanded_italic_100, expanded_italic_900 },
    585                 { expanded_italic_900, expanded_italic_900 },
    586             },
    587         },
    588 
    589         {
    590             { normal_normal_100, normal_normal_900 },
    591             {
    592                 { normal_normal_300, normal_normal_100 },
    593                 { normal_normal_400, normal_normal_100 },
    594                 { normal_normal_500, normal_normal_100 },
    595                 { normal_normal_600, normal_normal_900 },
    596             },
    597         },
    598 
    599         {
    600             { normal_normal_100, normal_normal_400, normal_normal_900 },
    601             {
    602                 { normal_normal_300, normal_normal_100 },
    603                 { normal_normal_400, normal_normal_400 },
    604                 { normal_normal_500, normal_normal_400 },
    605                 { normal_normal_600, normal_normal_900 },
    606             },
    607         },
    608 
    609         {
    610             { normal_normal_100, normal_normal_500, normal_normal_900 },
    611             {
    612                 { normal_normal_300, normal_normal_100 },
    613                 { normal_normal_400, normal_normal_500 },
    614                 { normal_normal_500, normal_normal_500 },
    615                 { normal_normal_600, normal_normal_900 },
    616             },
    617         },
    618 
    619         {
    620             { },
    621             {
    622                 { normal_normal_300, invalidFontStyle },
    623                 { normal_normal_400, invalidFontStyle },
    624                 { normal_normal_500, invalidFontStyle },
    625                 { normal_normal_600, invalidFontStyle },
    626             },
    627         },
    628     };
    629 
    630     for (StyleSetTest& test : tests) {
    631         for (const StyleSetTest::Case testCase : test.cases) {
    632             SkAutoTUnref<SkTypeface> typeface(test.styleSet.matchStyle(testCase.pattern));
    633             if (typeface) {
    634                 REPORTER_ASSERT(reporter, typeface->fontStyle() == testCase.expectedResult);
    635             } else {
    636                 REPORTER_ASSERT(reporter, invalidFontStyle == testCase.expectedResult);
    637             }
    638         }
    639     }
    640 }
    641 
    642 DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests.");
    643 
    644 DEF_TEST(FontMgr, reporter) {
    645     test_matchStyleCSS3(reporter);
    646     test_fontiter(reporter, FLAGS_verboseFontMgr);
    647     test_alias_names(reporter);
    648     test_font(reporter);
    649 }
    650