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 = nullptr;
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
43 #ifndef USE_ROSEN_DRAWING
RefDefault()44 std::shared_ptr<TexgineFontManager> TexgineFontManager::RefDefault()
45 {
46 return g_sfpMockvars.fontMgr;
47 }
48 #endif
49
50 #ifndef USE_ROSEN_DRAWING
MatchFamily(const std::string & familyName)51 std::shared_ptr<TexgineFontStyleSet> TexgineFontManager::MatchFamily(const std::string &familyName)
52 {
53 return g_sfpMockvars.fontStyleSet;
54 }
55 #endif
56
57 class SystemFontProviderTest : public testing::Test {
58 public:
59 std::shared_ptr<SystemFontProvider> systemFontProvider = SystemFontProvider::GetInstance();
60 };
61
62 /**
63 * @tc.name: GetInstance
64 * @tc.desc: Verify the GetInstance
65 * @tc.type:FUNC
66 * @tc.require: issueI6V6JD
67 */
68 HWTEST_F(SystemFontProviderTest, GetInstance, TestSize.Level1)
69 {
70 EXPECT_NE(SystemFontProvider::GetInstance(), nullptr);
71 }
72
73 /**
74 * @tc.name: MatchFamily1
75 * @tc.desc: Verify the MatchFamily
76 * @tc.type:FUNC
77 * @tc.require: issueI6V6JD
78 */
79 HWTEST_F(SystemFontProviderTest, MatchFamily1, TestSize.Level1)
80 {
81 InitSfpMockVars({.fontMgr = nullptr});
82 auto fss = systemFontProvider->MatchFamily("");
83 EXPECT_NE(fss, nullptr);
84 }
85
86 /**
87 * @tc.name: MatchFamily2
88 * @tc.desc: Verify the MatchFamily
89 * @tc.type:FUNC
90 * @tc.require: issueI6V6JD
91 */
92 HWTEST_F(SystemFontProviderTest, MatchFamily2, TestSize.Level1)
93 {
94 InitSfpMockVars({});
95 auto fss = systemFontProvider->MatchFamily("");
96 EXPECT_NE(fss, nullptr);
97 EXPECT_NE(fss->TryToTexgineFontStyleSet(), nullptr);
98 }
99 } // namespace TextEngine
100 } // namespace Rosen
101 } // namespace OHOS
102