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