Home | History | Annotate | Download | only in stresstest
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "minikin/FontFamily.h"
     18 
     19 #include <gtest/gtest.h>
     20 #include <hb.h>
     21 
     22 #include "minikin/FontCollection.h"
     23 
     24 #include "FontTestUtils.h"
     25 #include "FreeTypeMinikinFontForTest.h"
     26 #include "MinikinInternal.h"
     27 
     28 namespace minikin {
     29 
     30 typedef std::pair<std::string, int> TestParam;
     31 
     32 class FontFamilyHarfBuzzCompatibilityTest : public ::testing::TestWithParam<TestParam> {};
     33 
     34 TEST_P(FontFamilyHarfBuzzCompatibilityTest, CoverageTest) {
     35     const std::string& fontPath = GetParam().first;
     36     int ttcIndex = GetParam().second;
     37 
     38     auto font = std::make_shared<FreeTypeMinikinFontForTest>(fontPath);
     39     std::vector<Font> fonts;
     40     fonts.push_back(Font::Builder(font).build());
     41     std::shared_ptr<FontFamily> family = std::make_shared<FontFamily>(std::move(fonts));
     42 
     43     hb_font_t* hbFont = family->getFont(0)->baseFont().get();
     44 
     45     for (uint32_t codePoint = 0; codePoint < MAX_UNICODE_CODE_POINT; ++codePoint) {
     46         uint32_t unusedGlyph;
     47         EXPECT_EQ(family->hasGlyph(codePoint, 0 /* variation selector */),
     48                   static_cast<bool>(hb_font_get_glyph(hbFont, codePoint, 0 /* variation selector */,
     49                                                       &unusedGlyph)));
     50     }
     51 
     52     for (uint32_t vs = VS1; vs < VS256; ++vs) {
     53         // Move to variation selectors supplements after variation selectors.
     54         if (vs == VS16 + 1) {
     55             vs = VS17;
     56         }
     57         for (uint32_t codePoint = 0; codePoint < MAX_UNICODE_CODE_POINT; ++codePoint) {
     58             uint32_t unusedGlyph;
     59             ASSERT_EQ(family->hasGlyph(codePoint, vs),
     60                       static_cast<bool>(hb_font_get_glyph(hbFont, codePoint, vs, &unusedGlyph)))
     61                     << "Inconsistent Result: " << fontPath << "#" << ttcIndex << ": U+" << std::hex
     62                     << codePoint << " U+" << std::hex << vs
     63                     << " Minikin: " << family->hasGlyph(codePoint, vs) << " HarfBuzz: "
     64                     << static_cast<bool>(hb_font_get_glyph(hbFont, codePoint, vs, &unusedGlyph));
     65         }
     66     }
     67     hb_font_destroy(hbFont);
     68 }
     69 
     70 INSTANTIATE_TEST_CASE_P(FontFamilyTest, FontFamilyHarfBuzzCompatibilityTest,
     71                         ::testing::Values(TestParam("/system/fonts/NotoSansCJK-Regular.ttc", 0),
     72                                           TestParam("/system/fonts/NotoColorEmoji.ttf", 0)));
     73 }  // namespace minikin
     74