• 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 <fstream>
17 #include <gtest/gtest.h>
18 
19 #include "font_config.h"
20 #include "font_parser.h"
21 #include "texgine/utils/exlog.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace TextEngine {
29 static const std::string FILE_NAME = "/system/fonts/visibility_list.json";
30 
31 class FontParserTest : public testing::Test {
32 };
33 
GetFontSet(const char * fname)34 std::vector<std::string> GetFontSet(const char* fname)
35 {
36     FontConfig fontConfig(fname);
37     return fontConfig.GetFontSet();
38 }
39 
ShowVisibilityFonts(std::vector<FontParser::FontDescriptor> & visibilityFonts)40 void ShowVisibilityFonts(std::vector<FontParser::FontDescriptor>& visibilityFonts)
41 {
42     for (auto &it : visibilityFonts) {
43         LOGSO_FUNC_LINE(INFO) << "\n fontFamily: " << it.fontFamily
44                               << "\n fontSubfamily: " << it.fontSubfamily
45                               << "\n fullName: " << it.fullName
46                               << "\n italic: " << it.italic
47                               << "\n monoSpace: " << it.monoSpace
48                               << "\n path: " << it.path
49                               << "\n postScriptName: " << it.postScriptName
50                               << "\n symbolic: " << it.symbolic
51                               << "\n weight: " << it.weight
52                               << "\n width: " << it.width;
53     }
54 }
55 
56 /**
57  * @tc.name: FontParserTest1
58  * @tc.desc: test get fontSet file parser
59  * @tc.type:FUNC
60  */
61 HWTEST_F(FontParserTest, FontParserTest1, TestSize.Level1)
62 {
63     auto fontSet1 = GetFontSet(nullptr);
64     EXPECT_EQ(fontSet1.size(), 0);
65 
66     std::ifstream fileStream(FILE_NAME.c_str());
67     if (fileStream.is_open()) {
68         auto fontSet2 = GetFontSet(FILE_NAME.c_str());
69         EXPECT_NE(fontSet2.size(), 0);
70         fileStream.close();
71     } else {
72         auto fontSet2 = GetFontSet(FILE_NAME.c_str());
73         EXPECT_EQ(fontSet2.size(), 0);
74     }
75 }
76 
77 /**
78  * @tc.name: FontParserTest2
79  * @tc.desc: test font file parser
80  * @tc.type:FUNC
81  */
82 HWTEST_F(FontParserTest, FontParserTest2, TestSize.Level1)
83 {
84     FontParser fontParser;
85     auto visibilityFonts = fontParser.GetVisibilityFonts();
86     std::ifstream fileStream(FILE_NAME.c_str());
87     if (fileStream.is_open()) {
88         EXPECT_NE(visibilityFonts.size(), 0);
89         ShowVisibilityFonts(visibilityFonts);
90         fileStream.close();
91     } else {
92         EXPECT_EQ(visibilityFonts.size(), 0);
93     }
94 }
95 
96 /**
97  * @tc.name: FontConfigTest1
98  * @tc.desc: test font file parser
99  * @tc.type:FUNC
100  */
101 HWTEST_F(FontParserTest, FontConfigTest1, TestSize.Level1)
102 {
103     FontConfigJson fontConfigJson;
104     EXPECT_EQ(fontConfigJson.ParseFile(), 0);
105     fontConfigJson.Dump();
106 }
107 } // namespace TextEngine
108 } // namespace Rosen
109 } // namespace OHOS
110