1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cstddef>
17 #include <fstream>
18
19 #include "gtest/gtest.h"
20 #include "impl_factory.h"
21 #include "impl_interface/font_mgr_impl.h"
22
23 #include "text/font_mgr.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30 namespace Drawing {
31 class FontMgrTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp() override;
36 void TearDown() override;
37 };
38
SetUpTestCase()39 void FontMgrTest::SetUpTestCase() {}
TearDownTestCase()40 void FontMgrTest::TearDownTestCase() {}
SetUp()41 void FontMgrTest::SetUp() {}
TearDown()42 void FontMgrTest::TearDown() {}
43
44 /**
45 * @tc.name:LoadDynamicFont002
46 * @tc.desc: Test LoadDynamicFont
47 * @tc.type: FUNC
48 * @tc.require: I91F9L
49 */
50 HWTEST_F(FontMgrTest, LoadDynamicFont002, TestSize.Level1)
51 {
52 std::shared_ptr<FontMgr> FontMgr = FontMgr::CreateDynamicFontMgr();
53 std::vector<uint8_t> emptyFontData;
54 Typeface* typeface = FontMgr->LoadDynamicFont("EmptyFont", emptyFontData.data(), emptyFontData.size());
55 ASSERT_TRUE(typeface == nullptr);
56 }
57
58 /**
59 *
60 * @tc.name:MatchFamilyStyleCharacter001
61 * @tc.desc: Test MatchFamilyStyleCharacter
62 * @tc.type: FUNC
63 * @tc.require: I91F9L
64 */
65 HWTEST_F(FontMgrTest, MatchFamilyStyleCharacter001, TestSize.Level1)
66 {
67 std::shared_ptr<FontMgr> FontMgr = FontMgr::CreateDefaultFontMgr();
68 FontStyle fontStyle;
69 const char* bcp47[] = { "en-US" };
70 int bcp47Count = 1;
71 int32_t character = 'A';
72 Typeface* typeface = FontMgr->MatchFamilyStyleCharacter("serif", fontStyle, bcp47, bcp47Count, character);
73 ASSERT_TRUE(typeface != nullptr);
74 }
75
76 /**
77 * @tc.name:MatchFamily002
78 * @tc.desc: Test MatchFamily
79 * @tc.type: FUNC
80 * @tc.require: I91F9L
81 */
82 HWTEST_F(FontMgrTest, MatchFamily002, TestSize.Level1)
83 {
84 std::shared_ptr<FontMgr> FontMgr = FontMgr::CreateDefaultFontMgr();
85 const char* familyName = "serif";
86 FontStyleSet* fontStyleSet = FontMgr->MatchFamily(familyName);
87 ASSERT_TRUE(fontStyleSet != nullptr);
88 }
89
90 /**
91 * @tc.name:CountFamilies001
92 * @tc.desc: Test CountFamilies
93 * @tc.type: FUNC
94 * @tc.require: I91F9L
95 */
96 HWTEST_F(FontMgrTest, CountFamilies001, TestSize.Level1)
97 {
98 std::shared_ptr<FontMgr> FontMgr = FontMgr::CreateDefaultFontMgr();
99 int familyCount = FontMgr->CountFamilies();
100 ASSERT_GE(familyCount, 0);
101 }
102
103 /**
104 * @tc.name:GetFamilyName001
105 * @tc.desc: Test GetFamilyName
106 * @tc.type: FUNC
107 * @tc.require: I91F9L
108 */
109 HWTEST_F(FontMgrTest, GetFamilyName001, TestSize.Level1)
110 {
111 std::shared_ptr<FontMgr> FontMgr = FontMgr::CreateDefaultFontMgr();
112 std::string familyName;
113 FontMgr->GetFamilyName(0, familyName);
114 ASSERT_TRUE(familyName.length() > 0);
115 }
116
117 /**
118 * @tc.name:CreateStyleSet001
119 * @tc.desc: Test CreateStyleSet
120 * @tc.type: FUNC
121 * @tc.require: I91F9L
122 */
123 HWTEST_F(FontMgrTest, CreateStyleSet001, TestSize.Level1)
124 {
125 std::shared_ptr<FontMgr> FontMgr = FontMgr::CreateDefaultFontMgr();
126 ASSERT_TRUE(FontMgr != nullptr);
127 FontStyleSet* fontStyleSet = FontMgr->CreateStyleSet(0);
128 ASSERT_TRUE(fontStyleSet != nullptr);
129 }
130 } // namespace Drawing
131 } // namespace Rosen
132 } // namespace OHOS
133