• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 
19 #include "param_test_macros.h"
20 #include "texgine_data.h"
21 #include "texgine_font_manager.h"
22 #include "texgine_stream.h"
23 #include "texgine/system_font_provider.h"
24 #include "texgine_typeface.h"
25 #include "variant_font_style_set.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Rosen {
32 namespace TextEngine {
33 struct MockVars {
34     std::shared_ptr<TexgineFontStyleSet> fontStyleSet = TexgineFontStyleSet::CreateEmpty();
35     std::shared_ptr<TexgineFontManager> fontMgr = std::make_shared<TexgineFontManager>();
36 } g_sfpMockvars;
37 
InitSfpMockVars(MockVars vars)38 void InitSfpMockVars(MockVars vars)
39 {
40     g_sfpMockvars = std::move(vars);
41 }
42 
RefDefault()43 std::shared_ptr<TexgineFontManager> TexgineFontManager::RefDefault()
44 {
45     return g_sfpMockvars.fontMgr;
46 }
47 
MatchFamily(const std::string & familyName)48 std::shared_ptr<TexgineFontStyleSet> TexgineFontManager::MatchFamily(const std::string &familyName)
49 {
50     return g_sfpMockvars.fontStyleSet;
51 }
52 
53 class SystemFontProviderTest : public testing::Test {
54 public:
55     std::shared_ptr<SystemFontProvider> systemFontProvider = SystemFontProvider::GetInstance();
56 };
57 
58 /**
59  * @tc.name: GetInstance
60  * @tc.desc: Verify the GetInstance
61  * @tc.type:FUNC
62  * @tc.require: issueI6V6JD
63  */
64 HWTEST_F(SystemFontProviderTest, GetInstance, TestSize.Level1)
65 {
66     EXPECT_NE(SystemFontProvider::GetInstance(), nullptr);
67 }
68 
69 /**
70  * @tc.name: MatchFamily1
71  * @tc.desc: Verify the MatchFamily
72  * @tc.type:FUNC
73  * @tc.require: issueI6V6JD
74  */
75 HWTEST_F(SystemFontProviderTest, MatchFamily1, TestSize.Level1)
76 {
77     InitSfpMockVars({.fontMgr = nullptr});
78     auto fss = systemFontProvider->MatchFamily("");
79     EXPECT_EQ(fss, nullptr);
80 }
81 
82 /**
83  * @tc.name: MatchFamily2
84  * @tc.desc: Verify the MatchFamily
85  * @tc.type:FUNC
86  * @tc.require: issueI6V6JD
87  */
88 HWTEST_F(SystemFontProviderTest, MatchFamily2, TestSize.Level1)
89 {
90     InitSfpMockVars({.fontStyleSet = nullptr});
91     auto fss = systemFontProvider->MatchFamily("");
92     EXPECT_EQ(fss->TryToTexgineFontStyleSet(), nullptr);
93 }
94 
95 /**
96  * @tc.name: MatchFamily3
97  * @tc.desc: Verify the MatchFamily
98  * @tc.type:FUNC
99  * @tc.require: issueI6V6JD
100  */
101 HWTEST_F(SystemFontProviderTest, MatchFamily3, TestSize.Level1)
102 {
103     InitSfpMockVars({});
104     auto fss = systemFontProvider->MatchFamily("");
105     EXPECT_NE(fss, nullptr);
106     EXPECT_NE(fss->TryToTexgineFontStyleSet()->GetFontStyleSet(), nullptr);
107 }
108 } // namespace TextEngine
109 } // namespace Rosen
110 } // namespace OHOS
111