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 "theme_config_test.h"
17
18 #include "resource_manager_test_common.h"
19 #include "theme_pack_config.h"
20 using namespace OHOS::Global::Resource;
21 using namespace testing::ext;
22 namespace {
23 class ThemeConfigTest : public testing::Test {
24 public:
25 static void SetUpTestCase(void);
26
27 static void TearDownTestCase(void);
28
29 void SetUp();
30
31 void TearDown();
32
ThemeConfigTest()33 ThemeConfigTest()
34 {}
35
~ThemeConfigTest()36 ~ThemeConfigTest()
37 {}
38
39 public:
40 std::shared_ptr<ThemeConfig> themeConfig;
41 std::shared_ptr<ResConfigImpl> resConfig;
42 };
43
SetUpTestCase(void)44 void ThemeConfigTest::SetUpTestCase(void)
45 {
46 // step 1: input testsuit setup step
47 g_logLevel = LOG_DEBUG;
48 }
49
TearDownTestCase(void)50 void ThemeConfigTest::TearDownTestCase(void)
51 {
52 // step 2: input testsuit teardown step
53 }
54
SetUp(void)55 void ThemeConfigTest::SetUp(void)
56 {
57 this->themeConfig = std::make_shared<ThemeConfig>();
58 this->resConfig = std::make_shared<ResConfigImpl>();
59 }
60
TearDown(void)61 void ThemeConfigTest::TearDown(void)
62 {
63 RESMGR_HILOGD(RESMGR_TAG, "ThemeConfigTest teardown");
64 }
65
66 /*
67 * @tc.name: ThemeConfigSetThemeDirectionTest001
68 * @tc.desc: Test SetThemeDirection function, file case.
69 * @tc.type: FUNC
70 */
71 HWTEST_F(ThemeConfigTest, ThemeConfigSetThemeDirectionTest001, TestSize.Level1)
72 {
73 this->themeConfig->SetThemeDirection(DIRECTION_VERTICAL);
74 EXPECT_EQ(this->themeConfig->GetThemeDirection(), DIRECTION_VERTICAL);
75 }
76
77 /*
78 * @tc.name: ThemeConfigSetColorModeTest001
79 * @tc.desc: Test LoadThemeSkinResource function, file case.
80 * @tc.type: FUNC
81 */
82 HWTEST_F(ThemeConfigTest, ThemeConfigSetColorModeTest001, TestSize.Level1)
83 {
84 this->themeConfig->SetThemeColorMode(DARK);
85 EXPECT_EQ(this->themeConfig->GetThemeColorMode(), DARK);
86 }
87
88 /*
89 * @tc.name: ThemeConfigMatchTest001
90 * @tc.desc: Test Match function, file case.
91 * @tc.type: FUNC
92 */
93 HWTEST_F(ThemeConfigTest, ThemeConfigMatchTest001, TestSize.Level1)
94 {
95 this->themeConfig->SetThemeDirection(DIRECTION_NOT_SET);
96 this->resConfig->SetDirection(DIRECTION_NOT_SET);
97 bool ret = this->themeConfig->Match(themeConfig, *this->resConfig);
98 EXPECT_TRUE(ret);
99
100 this->resConfig->SetDirection(DIRECTION_VERTICAL);
101 ret = this->themeConfig->Match(themeConfig, *this->resConfig);
102 EXPECT_TRUE(ret);
103
104 this->resConfig->SetDirection(DIRECTION_NOT_SET);
105 this->themeConfig->SetThemeDirection(DIRECTION_VERTICAL);
106 ret = this->themeConfig->Match(themeConfig, *this->resConfig);
107 EXPECT_TRUE(ret);
108 }
109
110 /*
111 * @tc.name: ThemeConfigMatchTest002
112 * @tc.desc: Test Match function, file case.
113 * @tc.type: FUNC
114 */
115 HWTEST_F(ThemeConfigTest, ThemeConfigMatchTest002, TestSize.Level1)
116 {
117 this->themeConfig->SetThemeDirection(DIRECTION_HORIZONTAL);
118 this->resConfig->SetDirection(DIRECTION_VERTICAL);
119 bool ret = this->themeConfig->Match(themeConfig, *this->resConfig);
120 EXPECT_FALSE(ret);
121
122 this->resConfig->SetDirection(DIRECTION_HORIZONTAL);
123 ret = this->themeConfig->Match(themeConfig, *this->resConfig);
124 EXPECT_TRUE(ret);
125 }
126
127 /*
128 * @tc.name: ThemeConfigMatchTest003
129 * @tc.desc: Test Match function, file case.
130 * @tc.type: FUNC
131 */
132 HWTEST_F(ThemeConfigTest, ThemeConfigMatchTest003, TestSize.Level1)
133 {
134 this->themeConfig->SetThemeDirection(DIRECTION_VERTICAL);
135 this->themeConfig->SetThemeColorMode(DARK);
136
137 this->resConfig->SetDirection(DIRECTION_VERTICAL);
138 this->resConfig->SetColorMode(DARK);
139 this->resConfig->SetAppColorMode(false);
140 this->resConfig->SetAppDarkRes(false);
141
142 bool ret = this->themeConfig->Match(themeConfig, *this->resConfig);
143 EXPECT_FALSE(ret);
144
145 this->themeConfig->SetThemeColorMode(COLOR_MODE_NOT_SET);
146 ret = this->themeConfig->Match(themeConfig, *this->resConfig);
147 EXPECT_TRUE(ret);
148
149 this->themeConfig->SetThemeColorMode(LIGHT);
150 this->resConfig->SetAppDarkRes(true);
151 ret = this->themeConfig->Match(themeConfig, *this->resConfig);
152 EXPECT_FALSE(ret);
153 }
154
155 /*
156 * @tc.name: ThemeConfigMatchTest004
157 * @tc.desc: Test Match function, file case.
158 * @tc.type: FUNC
159 */
160 HWTEST_F(ThemeConfigTest, ThemeConfigMatchTest004, TestSize.Level1)
161 {
162 this->themeConfig->SetThemeDirection(DIRECTION_VERTICAL);
163 this->resConfig->SetDirection(DIRECTION_VERTICAL);
164
165 this->themeConfig->SetThemeColorMode(DARK);
166 this->resConfig->SetColorMode(LIGHT);
167 this->resConfig->SetAppColorMode(false);
168 this->resConfig->SetAppDarkRes(false);
169
170 bool ret = this->themeConfig->Match(themeConfig, *this->resConfig);
171 EXPECT_FALSE(ret);
172 }
173
174 /*
175 * @tc.name: ThemeConfigMatchTest005
176 * @tc.desc: Test Match function, file case.
177 * @tc.type: FUNC
178 */
179 HWTEST_F(ThemeConfigTest, ThemeConfigMatchTest005, TestSize.Level1)
180 {
181 this->themeConfig->SetThemeDirection(DIRECTION_VERTICAL);
182 this->resConfig->SetDirection(DIRECTION_VERTICAL);
183
184 this->themeConfig->SetThemeColorMode(DARK);
185 this->resConfig->SetColorMode(DARK);
186 this->resConfig->SetAppColorMode(true);
187 this->resConfig->SetAppDarkRes(false);
188
189 bool ret = this->themeConfig->Match(themeConfig, *this->resConfig);
190 EXPECT_TRUE(ret);
191 }
192
193 /*
194 * @tc.name: ThemeConfigMatchTest006
195 * @tc.desc: Test Match function, file case.
196 * @tc.type: FUNC
197 */
198 HWTEST_F(ThemeConfigTest, ThemeConfigMatchTest006, TestSize.Level1)
199 {
200 this->themeConfig->SetThemeDirection(DIRECTION_VERTICAL);
201 this->resConfig->SetDirection(DIRECTION_VERTICAL);
202
203 this->themeConfig->SetThemeColorMode(DARK);
204 this->resConfig->SetColorMode(DARK);
205 this->resConfig->SetAppColorMode(false);
206 this->resConfig->SetAppDarkRes(true);
207
208 bool ret = this->themeConfig->Match(themeConfig, *this->resConfig);
209 EXPECT_TRUE(ret);
210 }
211
212 /*
213 * @tc.name: ThemeConfigBestMatchTest001
214 * @tc.desc: Test BestMatch function, file case.
215 * @tc.type: FUNC
216 */
217 HWTEST_F(ThemeConfigTest, ThemeConfigBestMatchTest001, TestSize.Level1)
218 {
219 this->themeConfig->SetThemeDirection(DIRECTION_VERTICAL);
220 this->resConfig->SetDirection(DIRECTION_VERTICAL);
221
222 std::shared_ptr<ThemeConfig> otherThemeConfig = std::make_shared<ThemeConfig>();
223 otherThemeConfig->SetThemeDirection(DIRECTION_HORIZONTAL);
224
225 bool ret = this->themeConfig->BestMatch(otherThemeConfig, *this->resConfig);
226 EXPECT_TRUE(ret);
227
228 this->themeConfig->SetThemeDirection(DIRECTION_NOT_SET);
229 ret = this->themeConfig->BestMatch(otherThemeConfig, *this->resConfig);
230 EXPECT_FALSE(ret);
231 }
232
233 /*
234 * @tc.name: ThemeConfigBestMatchTest002
235 * @tc.desc: Test BestMatch function, file case.
236 * @tc.type: FUNC
237 */
238 HWTEST_F(ThemeConfigTest, ThemeConfigBestMatchTest002, TestSize.Level1)
239 {
240 this->themeConfig->SetThemeDirection(DIRECTION_VERTICAL);
241 this->themeConfig->SetThemeColorMode(DARK);
242 this->resConfig->SetDirection(DIRECTION_VERTICAL);
243 this->resConfig->SetColorMode(DARK);
244
245 std::shared_ptr<ThemeConfig> otherThemeConfig = std::make_shared<ThemeConfig>();
246 otherThemeConfig->SetThemeDirection(DIRECTION_VERTICAL);
247 otherThemeConfig->SetThemeColorMode(LIGHT);
248
249 bool ret = this->themeConfig->BestMatch(otherThemeConfig, *this->resConfig);
250 EXPECT_TRUE(ret);
251
252 this->themeConfig->SetThemeColorMode(COLOR_MODE_NOT_SET);
253 ret = this->themeConfig->BestMatch(otherThemeConfig, *this->resConfig);
254 EXPECT_FALSE(ret);
255 }
256
257 /*
258 * @tc.name: ThemeConfigBestMatchTest003
259 * @tc.desc: Test BestMatch function, file case.
260 * @tc.type: FUNC
261 */
262 HWTEST_F(ThemeConfigTest, ThemeConfigBestMatchTest003, TestSize.Level1)
263 {
264 this->themeConfig->SetThemeDirection(DIRECTION_VERTICAL);
265 this->themeConfig->SetThemeColorMode(DARK);
266 this->resConfig->SetDirection(DIRECTION_VERTICAL);
267 this->resConfig->SetColorMode(DARK);
268
269 std::shared_ptr<ThemeConfig> otherThemeConfig = std::make_shared<ThemeConfig>();
270 otherThemeConfig->SetThemeDirection(DIRECTION_VERTICAL);
271 otherThemeConfig->SetThemeColorMode(DARK);
272
273 bool ret = this->themeConfig->BestMatch(otherThemeConfig, *this->resConfig);
274 EXPECT_TRUE(ret);
275 }
276
277 /*
278 * @tc.name: ThemeConfigBestMatchTest004
279 * @tc.desc: Test BestMatch function, file case.
280 * @tc.type: FUNC
281 */
282 HWTEST_F(ThemeConfigTest, ThemeConfigBestMatchTest004, TestSize.Level1)
283 {
284 this->themeConfig->SetThemeDirection(DIRECTION_HORIZONTAL);
285 this->resConfig->SetDirection(DIRECTION_NOT_SET);
286 this->resConfig->SetColorMode(COLOR_MODE_NOT_SET);
287
288 std::shared_ptr<ThemeConfig> otherThemeConfig = std::make_shared<ThemeConfig>();
289 otherThemeConfig->SetThemeDirection(DIRECTION_VERTICAL);
290
291 bool ret = this->themeConfig->BestMatch(otherThemeConfig, *this->resConfig);
292 EXPECT_TRUE(ret);
293
294 this->themeConfig->SetThemeDirection(DIRECTION_NOT_SET);
295 ret = this->themeConfig->BestMatch(otherThemeConfig, *this->resConfig);
296 EXPECT_FALSE(ret);
297 }
298
299 /*
300 * @tc.name: ThemeConfigBestMatchTest005
301 * @tc.desc: Test BestMatch function, file case.
302 * @tc.type: FUNC
303 */
304 HWTEST_F(ThemeConfigTest, ThemeConfigBestMatchTest005, TestSize.Level1)
305 {
306 this->themeConfig->SetThemeDirection(DIRECTION_VERTICAL);
307 this->themeConfig->SetThemeColorMode(LIGHT);
308 this->resConfig->SetDirection(DIRECTION_NOT_SET);
309 this->resConfig->SetColorMode(COLOR_MODE_NOT_SET);
310
311 std::shared_ptr<ThemeConfig> otherThemeConfig = std::make_shared<ThemeConfig>();
312 otherThemeConfig->SetThemeDirection(DIRECTION_VERTICAL);
313 otherThemeConfig->SetThemeColorMode(DARK);
314
315 bool ret = this->themeConfig->BestMatch(otherThemeConfig, *this->resConfig);
316 EXPECT_TRUE(ret);
317
318 this->themeConfig->SetThemeColorMode(COLOR_MODE_NOT_SET);
319 ret = this->themeConfig->BestMatch(otherThemeConfig, *this->resConfig);
320 EXPECT_FALSE(ret);
321 }
322 } // namespace
323