1 /*
2 * Copyright (C) 2018 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/SystemFonts.h"
18
19 #include <gtest/gtest.h>
20
21 #include "minikin/FontCollection.h"
22
23 #include "FontTestUtils.h"
24
25 namespace minikin {
26 namespace {
27
28 class TestableSystemFonts : public SystemFonts {
29 public:
TestableSystemFonts()30 TestableSystemFonts() : SystemFonts() {}
~TestableSystemFonts()31 virtual ~TestableSystemFonts() {}
32
findFontCollection(const std::string & familyName) const33 std::shared_ptr<FontCollection> findFontCollection(const std::string& familyName) const {
34 return findFontCollectionInternal(familyName);
35 }
36
registerFallback(const std::string & familyName,const std::shared_ptr<FontCollection> & fc)37 void registerFallback(const std::string& familyName,
38 const std::shared_ptr<FontCollection>& fc) {
39 registerFallbackInternal(familyName, fc);
40 }
41
registerDefault(const std::shared_ptr<FontCollection> & fc)42 void registerDefault(const std::shared_ptr<FontCollection>& fc) { registerDefaultInternal(fc); }
43 };
44
TEST(SystemFontsTest,registerAndLookup)45 TEST(SystemFontsTest, registerAndLookup) {
46 TestableSystemFonts systemFonts;
47 auto fc = buildFontCollection("Ascii.ttf");
48 systemFonts.registerFallback("sans", fc);
49 EXPECT_EQ(fc, systemFonts.findFontCollection("sans"));
50 }
51
TEST(SystemFontsTest,registerDefaultAndLookup)52 TEST(SystemFontsTest, registerDefaultAndLookup) {
53 TestableSystemFonts systemFonts;
54 auto fc = buildFontCollection("Ascii.ttf");
55 systemFonts.registerDefault(fc);
56 EXPECT_EQ(fc, systemFonts.findFontCollection("unknown-name"));
57 }
58
TEST(SystemFontsTest,registerDefaultAndFallback)59 TEST(SystemFontsTest, registerDefaultAndFallback) {
60 TestableSystemFonts systemFonts;
61 auto fc1 = buildFontCollection("Ascii.ttf");
62 auto fc2 = buildFontCollection("Bold.ttf");
63 systemFonts.registerDefault(fc1);
64 systemFonts.registerFallback("sans", fc2);
65 EXPECT_EQ(fc1, systemFonts.findFontCollection("unknown-name"));
66 EXPECT_EQ(fc2, systemFonts.findFontCollection("sans"));
67 }
68
69 } // namespace
70 } // namespace minikin
71