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 "default_symbol_config.h"
17 #include "gtest/gtest.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Rosen {
24 namespace Symbol {
25 class DefaultSymbolConfigTest : public testing::Test {
26 public:
27 void SetUp() override;
28 void TearDown() override;
29 };
30
SetUp()31 void DefaultSymbolConfigTest::SetUp()
32 {
33 DefaultSymbolConfig::GetInstance()->ParseConfigOfHmSymbol("/system/fonts/hm_symbol_config_next.json");
34 auto groups = DefaultSymbolConfig::GetInstance()->GetSymbolLayersGroups(3); // 3 is an existing GlyphID
35 ASSERT_TRUE(groups.symbolGlyphId != 0);
36 }
TearDown()37 void DefaultSymbolConfigTest::TearDown()
38 {
39 DefaultSymbolConfig::GetInstance()->Clear();
40 }
41
42 /**
43 * @tc.name: GetSymbolLayersGroups001
44 * @tc.desc: Test GetSymbolLayersGroups
45 * @tc.type: FUNC
46 */
47 HWTEST_F(DefaultSymbolConfigTest, GetSymbolLayersGroups001, TestSize.Level0)
48 {
49 DefaultSymbolConfig::GetInstance()->Clear();
50 int result =
51 DefaultSymbolConfig::GetInstance()->ParseConfigOfHmSymbol("/system/fonts/hm_symbol_config_next_undefined.json");
52 EXPECT_EQ(result, 1); // 1 means ERROR_CONFIG_NOT_FOUND
53 auto groups = DefaultSymbolConfig::GetInstance()->GetSymbolLayersGroups(3); // 3 is an existing GlyphID
54 ASSERT_TRUE(groups.symbolGlyphId == 0);
55 }
56
57 /**
58 * @tc.name: GetSymbolLayersGroups002
59 * @tc.desc: Test GetSymbolLayersGroups
60 * @tc.type: FUNC
61 */
62 HWTEST_F(DefaultSymbolConfigTest, GetSymbolLayersGroups002, TestSize.Level0)
63 {
64 DefaultSymbolConfig::GetInstance()->Clear();
65 int result = DefaultSymbolConfig::GetInstance()->ParseConfigOfHmSymbol("/system/fonts/hm_symbol_config_next.json");
66 EXPECT_EQ(result, 0); // 0 meas NO_ERROR
67 auto groups = DefaultSymbolConfig::GetInstance()->GetSymbolLayersGroups(3); // 3 is an existing GlyphID
68 ASSERT_TRUE(groups.symbolGlyphId != 0);
69 }
70
71 /**
72 * @tc.name: GetGroupParameters001
73 * @tc.desc: Test GetGroupParameters by scale effect with wholeSymbol or bylayer
74 * @tc.type: FUNC
75 */
76 HWTEST_F(DefaultSymbolConfigTest, GetGroupParameters001, TestSize.Level0)
77 {
78 auto parameters = DefaultSymbolConfig::GetInstance()->GetGroupParameters(
79 OHOS::Rosen::Drawing::DrawingAnimationType::SCALE_TYPE, 1, 1);
80 if (!parameters.empty()) {
81 EXPECT_EQ(parameters.size(), 1);
82 } else {
83 EXPECT_EQ(parameters.empty(), true);
84 }
85
86 uint16_t groups = 3; // the 3 is layers of effect
87 auto parameters1 = DefaultSymbolConfig::GetInstance()->GetGroupParameters(
88 OHOS::Rosen::Drawing::DrawingAnimationType::SCALE_TYPE, groups, 0);
89 if (!parameters1.empty()) {
90 EXPECT_EQ(parameters1.size(), groups);
91 }
92
93 groups = 2; // the 2 is layers of effect
94 auto parameters2 = DefaultSymbolConfig::GetInstance()->GetGroupParameters(
95 OHOS::Rosen::Drawing::DrawingAnimationType::SCALE_TYPE, groups, 0);
96 if (!parameters2.empty()) {
97 EXPECT_EQ(parameters2.size(), groups);
98 }
99 }
100
101 /**
102 * @tc.name: GetGroupParameters002
103 * @tc.desc: Test GetGroupParameters by scale effect with UP or DOWN
104 * @tc.type: FUNC
105 */
106 HWTEST_F(DefaultSymbolConfigTest, GetGroupParameters002, TestSize.Level0)
107 {
108 uint16_t groups = 1; // the 1 is layers of effect
109 auto parameters1 =
110 DefaultSymbolConfig::GetInstance()->GetGroupParameters(OHOS::Rosen::Drawing::DrawingAnimationType::SCALE_TYPE,
111 groups, 1, OHOS::Rosen::Drawing::DrawingCommonSubType::UP);
112 if (!parameters1.empty()) {
113 EXPECT_EQ(parameters1.size(), groups);
114 }
115
116 auto parameters2 =
117 DefaultSymbolConfig::GetInstance()->GetGroupParameters(OHOS::Rosen::Drawing::DrawingAnimationType::SCALE_TYPE,
118 groups, 1, OHOS::Rosen::Drawing::DrawingCommonSubType::DOWN);
119 if (!parameters2.empty()) {
120 EXPECT_EQ(parameters2.size(), groups);
121 }
122 }
123
124 /**
125 * @tc.name: GetGroupParameters003
126 * @tc.desc: Test GetGroupParameters by scale effect with number of error layers
127 * @tc.type: FUNC
128 */
129 HWTEST_F(DefaultSymbolConfigTest, GetGroupParameters003, TestSize.Level0)
130 {
131 uint16_t groups = 300; // the 300 is Out of layers Scope
132 auto parameters = DefaultSymbolConfig::GetInstance()->GetGroupParameters(
133 OHOS::Rosen::Drawing::DrawingAnimationType::SCALE_TYPE, groups, 0);
134 EXPECT_EQ(parameters.empty(), true);
135 }
136
137 /**
138 * @tc.name: GetGroupParameters004
139 * @tc.desc: Test GetGroupParameters by variable_color effext by cumulative or iteratuve
140 * @tc.type: FUNC
141 */
142 HWTEST_F(DefaultSymbolConfigTest, GetGroupParameters004, TestSize.Level0)
143 {
144 uint16_t groups = 3; // the 1 is layers of effect
145 auto parameters1 = DefaultSymbolConfig::GetInstance()->GetGroupParameters(
146 OHOS::Rosen::Drawing::DrawingAnimationType::VARIABLE_COLOR_TYPE, groups, 1,
147 OHOS::Rosen::Drawing::DrawingCommonSubType::UP);
148 if (!parameters1.empty()) {
149 EXPECT_EQ(parameters1.size(), groups);
150 }
151
152 auto parameters2 = DefaultSymbolConfig::GetInstance()->GetGroupParameters(
153 OHOS::Rosen::Drawing::DrawingAnimationType::VARIABLE_COLOR_TYPE, groups, 0,
154 OHOS::Rosen::Drawing::DrawingCommonSubType::DOWN);
155 if (!parameters2.empty()) {
156 EXPECT_EQ(parameters2.size(), groups);
157 }
158 }
159 } // namespace Symbol
160 } // namespace Rosen
161 } // namespace OHOS