• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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_manager_test.h"
17 
18 #include "resource_manager_test_common.h"
19 #include "theme_pack_manager.h"
20 using namespace OHOS::Global::Resource;
21 using namespace testing::ext;
22 namespace {
23 class ThemeManagerTest : 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 
ThemeManagerTest()33     ThemeManagerTest()
34     {}
35 
~ThemeManagerTest()36     ~ThemeManagerTest()
37     {}
38 
39 public:
40     std::shared_ptr<ResourceManager> rm;
41     std::shared_ptr<ResourceManagerTestCommon> rmc;
42     std::shared_ptr<ThemePackManager> tm;
43 };
44 
SetUpTestCase(void)45 void ThemeManagerTest::SetUpTestCase(void)
46 {
47     // step 1: input testsuit setup step
48     g_logLevel = LOG_DEBUG;
49 }
50 
TearDownTestCase(void)51 void ThemeManagerTest::TearDownTestCase(void)
52 {
53     // step 2: input testsuit teardown step
54 }
55 
SetUp(void)56 void ThemeManagerTest::SetUp(void)
57 {
58     this->tm = ThemePackManager::GetThemePackManager();
59     std::string hapPath;
60     std::vector<std::string> overlayPath;
61     ResConfigImpl *rc = new ResConfigImpl;
62     int32_t appType = 0;
63     int32_t userId = 100; // userId is 100
64     this->rm = CreateResourceManager("ohos.global.test.all", "entry", hapPath, overlayPath, *rc, appType, userId);
65     this->rmc = std::make_shared<ResourceManagerTestCommon>(rm);
66 }
67 
TearDown(void)68 void ThemeManagerTest::TearDown(void)
69 {
70     RESMGR_HILOGD(RESMGR_TAG, "ThemeManagerTest teardown");
71 }
72 
73 /*
74  * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest001
75  * @tc.desc: Test LoadThemeSkinResource function, file case.
76  * @tc.type: FUNC
77  */
78 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest001, TestSize.Level1)
79 {
80    // success cases
81     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
82     ASSERT_TRUE(ret);
83     int id = rmc->GetResId("base_only", ResType::COLOR);
84     uint32_t outValue;
85     std::vector<std::string> rootDirs;
86     std::string rootDir = "/data/test/theme/skin/ohos.global.test.all";
87     rootDirs.emplace_back(rootDir);
88     int32_t userId = 100; // userId is 100
89     // the bundlename is invalid
90     tm->LoadThemeSkinResource("ohos.global.test", "entry", rootDirs, userId);
91     rm->GetColorById(id, outValue);
92     ASSERT_EQ(0, outValue); // base_only APP value is #000000
93 }
94 
95 /*
96  * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest002
97  * @tc.desc: Test AddResource function, file case.
98  * @tc.type: FUNC
99  */
100 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest002, TestSize.Level1)
101 {
102    // success cases
103     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
104     ASSERT_TRUE(ret);
105     int id = rmc->GetResId("base_only", ResType::COLOR);
106     uint32_t outValue;
107     rm->GetColorById(id, outValue);
108     ASSERT_EQ(0, outValue); // base_only APP value is #000000
109 
110     std::vector<std::string> rootDirs;
111     std::string rootDir = "/data/test/theme/skin/ohos.global.test.all";
112     rootDirs.emplace_back(rootDir);
113     int32_t userId = 100; // userId is 100
114     tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId);
115     rm->GetColorById(id, outValue);
116     ASSERT_EQ(4294967295, outValue); // base_only theme value is #ffffff(4294967295)
117 }
118 
119 /*
120  * @tc.name: ThemeManagerTestChangeSkinResourceStatusTest001
121  * @tc.desc: Test ChangeSkinResourceStatus function, file case.
122  * @tc.type: FUNC
123  */
124 HWTEST_F(ThemeManagerTest, ThemeManagerTestChangeSkinResourceStatusTest001, TestSize.Level1)
125 {
126    // success cases
127     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
128     ASSERT_TRUE(ret);
129 
130     std::vector<std::string> rootDirs;
131     std::string rootDir = "/data/test/theme/skin/ohos.global.test.all";
132     rootDirs.emplace_back(rootDir);
133     int32_t userId = 100; // userId is 100
134     tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId);
135     uint32_t outValue;
136     int id = rmc->GetResId("base_only", ResType::COLOR);
137     rm->GetColorById(id, outValue);
138     ASSERT_EQ(4294967295, outValue); // base_only theme value is #ffffff(4294967295)
139 
140     tm->ChangeSkinResourceStatus(userId);
141     tm->ClearSkinResource();
142 
143     rm->GetColorById(id, outValue);
144     ASSERT_EQ(0, outValue); // base_only APP value is #000000
145 }
146 
147 /*
148  * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest003
149  * @tc.desc: Test GetThemeDataById function, file case.
150  * @tc.type: FUNC
151  */
152 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest003, TestSize.Level1)
153 {
154    // success cases
155     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
156     ASSERT_TRUE(ret);
157     std::vector<std::string> rootDirs;
158     int32_t userId = 100; // userId is 100
159     tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId);
160     int id = rmc->GetResId("ohos_device_theme", ResType::THEME);
161     std::map<std::string, ResourceManager::ResData> outValue;
162     rm->GetThemeDataById(id, outValue);
163     ASSERT_EQ(ResType::FLOAT, outValue["width1"].resType);
164     ASSERT_EQ(ResType::STRING, outValue["width2"].resType);
165     ASSERT_EQ(ResType::FLOAT, outValue["height1"].resType);
166     ASSERT_EQ(ResType::STRING, outValue["height2"].resType);
167     ASSERT_EQ(ResType::COLOR, outValue["textColor1"].resType);
168     ASSERT_EQ(ResType::STRING, outValue["textColor2"].resType);
169     ASSERT_EQ(ResType::PATTERN, outValue["button_pattern"].resType);
170     ASSERT_EQ(ResType::THEME, outValue["ohosTheme"].resType);
171     ASSERT_EQ(ResType::PATTERN, outValue["text_pattern"].resType);
172     ASSERT_EQ(ResType::PATTERN, outValue["list_pattern"].resType);
173     ASSERT_EQ("100fp", outValue["width1"].value);
174     ASSERT_EQ("100fp", outValue["width2"].value);
175     ASSERT_EQ("100vp", outValue["height1"].value);
176     ASSERT_EQ("100vp", outValue["height2"].value);
177     ASSERT_EQ("#000000FF", outValue["textColor1"].value);
178     ASSERT_EQ("#000000FF", outValue["textColor2"].value);
179     ASSERT_EQ("16777333", outValue["button_pattern"].value);
180     ASSERT_EQ("16777328", outValue["ohosTheme"].value);
181     ASSERT_EQ("16777332", outValue["text_pattern"].value);
182     ASSERT_EQ("16777331", outValue["list_pattern"].value);
183 
184     std::string rootDir = "/data/test/theme/skin/ohos.global.test.all";
185     rootDirs.emplace_back(rootDir);
186     tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId);
187     rm->GetThemeDataById(id, outValue);
188     ASSERT_EQ(ResType::FLOAT, outValue["width1"].resType);
189     ASSERT_EQ(ResType::STRING, outValue["width2"].resType);
190     ASSERT_EQ(ResType::FLOAT, outValue["height1"].resType);
191     ASSERT_EQ(ResType::STRING, outValue["height2"].resType);
192     ASSERT_EQ(ResType::COLOR, outValue["textColor1"].resType);
193     ASSERT_EQ(ResType::STRING, outValue["textColor2"].resType);
194     ASSERT_EQ("1000fp", outValue["width1"].value);
195     ASSERT_EQ("100fp", outValue["width2"].value);
196     ASSERT_EQ("1000vp", outValue["height1"].value);
197     ASSERT_EQ("100vp", outValue["height2"].value);
198     ASSERT_EQ("#000000AA", outValue["textColor1"].value);
199     ASSERT_EQ("#000000FF", outValue["textColor2"].value);
200     ASSERT_EQ("16777333", outValue["button_pattern"].value);
201     ASSERT_EQ("16777328", outValue["ohosTheme"].value);
202     ASSERT_EQ("16777332", outValue["text_pattern"].value);
203     ASSERT_EQ("16777331", outValue["list_pattern"].value);
204 }
205 
206 /*
207  * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest004
208  * @tc.desc: Test GetThemeDataByName function, file case.
209  * @tc.type: FUNC
210  */
211 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest004, TestSize.Level1)
212 {
213    // success cases
214     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
215     ASSERT_TRUE(ret);
216     std::vector<std::string> rootDirs;
217     int32_t userId = 100; // userId is 100
218     tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId);
219     std::map<std::string, ResourceManager::ResData> outValue;
220     rm->GetThemeDataByName("ohos_device_theme", outValue);
221     ASSERT_EQ(ResType::FLOAT, outValue["width1"].resType);
222     ASSERT_EQ(ResType::STRING, outValue["width2"].resType);
223     ASSERT_EQ(ResType::FLOAT, outValue["height1"].resType);
224     ASSERT_EQ(ResType::STRING, outValue["height2"].resType);
225     ASSERT_EQ(ResType::COLOR, outValue["textColor1"].resType);
226     ASSERT_EQ(ResType::STRING, outValue["textColor2"].resType);
227     ASSERT_EQ(ResType::PATTERN, outValue["button_pattern"].resType);
228     ASSERT_EQ(ResType::THEME, outValue["ohosTheme"].resType);
229     ASSERT_EQ(ResType::PATTERN, outValue["text_pattern"].resType);
230     ASSERT_EQ(ResType::PATTERN, outValue["list_pattern"].resType);
231     ASSERT_EQ("100fp", outValue["width1"].value);
232     ASSERT_EQ("100fp", outValue["width2"].value);
233     ASSERT_EQ("100vp", outValue["height1"].value);
234     ASSERT_EQ("100vp", outValue["height2"].value);
235     ASSERT_EQ("#000000FF", outValue["textColor1"].value);
236     ASSERT_EQ("#000000FF", outValue["textColor2"].value);
237     ASSERT_EQ("16777333", outValue["button_pattern"].value);
238     ASSERT_EQ("16777328", outValue["ohosTheme"].value);
239     ASSERT_EQ("16777332", outValue["text_pattern"].value);
240     ASSERT_EQ("16777331", outValue["list_pattern"].value);
241 
242     std::string rootDir = "/data/test/theme/skin/ohos.global.test.all";
243     rootDirs.emplace_back(rootDir);
244     tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId);
245     rm->GetThemeDataByName("ohos_device_theme", outValue);
246     ASSERT_EQ(ResType::FLOAT, outValue["width1"].resType);
247     ASSERT_EQ(ResType::STRING, outValue["width2"].resType);
248     ASSERT_EQ(ResType::FLOAT, outValue["height1"].resType);
249     ASSERT_EQ(ResType::STRING, outValue["height2"].resType);
250     ASSERT_EQ(ResType::COLOR, outValue["textColor1"].resType);
251     ASSERT_EQ(ResType::STRING, outValue["textColor2"].resType);
252     ASSERT_EQ("1000fp", outValue["width1"].value);
253     ASSERT_EQ("100fp", outValue["width2"].value);
254     ASSERT_EQ("1000vp", outValue["height1"].value);
255     ASSERT_EQ("100vp", outValue["height2"].value);
256     ASSERT_EQ("#000000AA", outValue["textColor1"].value);
257     ASSERT_EQ("#000000FF", outValue["textColor2"].value);
258     ASSERT_EQ("16777333", outValue["button_pattern"].value);
259     ASSERT_EQ("16777328", outValue["ohosTheme"].value);
260     ASSERT_EQ("16777332", outValue["text_pattern"].value);
261     ASSERT_EQ("16777331", outValue["list_pattern"].value);
262 }
263 
264 /*
265  * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest005
266  * @tc.desc: Test GetPatternDataByName function, file case.
267  * @tc.type: FUNC
268  */
269 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest005, TestSize.Level1)
270 {
271    // success cases
272     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
273     ASSERT_TRUE(ret);
274     std::vector<std::string> rootDirs;
275     int32_t userId = 100; // userId is 100
276     tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId);
277     std::map<std::string, ResourceManager::ResData> outValue;
278     rm->GetPatternDataByName("ohos_test_button_pattern", outValue);
279     ASSERT_EQ(ResType::STRING, outValue["width"].resType);
280     ASSERT_EQ(ResType::FLOAT, outValue["height"].resType);
281     ASSERT_EQ(ResType::STRING, outValue["bgColor"].resType);
282     ASSERT_EQ(ResType::STRING, outValue["fgColor"].resType);
283     ASSERT_EQ(ResType::PATTERN, outValue["fontPattern"].resType);
284     ASSERT_EQ(ResType::STRING, outValue["marginColor"].resType);
285     ASSERT_EQ(ResType::PATTERN, outValue["baseFontPattern"].resType);
286     ASSERT_EQ("10vp", outValue["width"].value);
287     ASSERT_EQ("66vp", outValue["height"].value);
288     ASSERT_EQ("#FF0000BB", outValue["bgColor"].value);
289     ASSERT_EQ("#FF0000CC", outValue["fgColor"].value);
290     ASSERT_EQ("16777334", outValue["fontPattern"].value);
291     ASSERT_EQ("#FF00AA00", outValue["marginColor"].value);
292     ASSERT_EQ("16777335", outValue["baseFontPattern"].value);
293 
294     std::string rootDir = "/data/test/theme/skin/ohos.global.test.all";
295     rootDirs.emplace_back(rootDir);
296     tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId);
297     rm->GetPatternDataByName("ohos_test_button_pattern", outValue);
298     ASSERT_EQ(ResType::STRING, outValue["width"].resType);
299     ASSERT_EQ(ResType::FLOAT, outValue["height"].resType);
300     ASSERT_EQ(ResType::STRING, outValue["bgColor"].resType);
301     ASSERT_EQ(ResType::STRING, outValue["fgColor"].resType);
302     ASSERT_EQ(ResType::PATTERN, outValue["fontPattern"].resType);
303     ASSERT_EQ(ResType::STRING, outValue["marginColor"].resType);
304     ASSERT_EQ(ResType::PATTERN, outValue["baseFontPattern"].resType);
305     ASSERT_EQ("10vp", outValue["width"].value);
306     ASSERT_EQ("666vp", outValue["height"].value);
307     ASSERT_EQ("#FF0000BB", outValue["bgColor"].value);
308     ASSERT_EQ("#FF0000CC", outValue["fgColor"].value);
309     ASSERT_EQ("16777334", outValue["fontPattern"].value);
310     ASSERT_EQ("#FF00AA00", outValue["marginColor"].value);
311     ASSERT_EQ("16777335", outValue["baseFontPattern"].value);
312 }
313 
314 /*
315  * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest006
316  * @tc.desc: Test GetPatternDataById function, file case.
317  * @tc.type: FUNC
318  */
319 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest006, TestSize.Level1)
320 {
321    // success cases
322     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
323     ASSERT_TRUE(ret);
324     std::vector<std::string> rootDirs;
325     int32_t userId = 100; // userId is 100
326     tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId);
327     int id = rmc->GetResId("ohos_test_button_pattern", ResType::PATTERN);
328     std::map<std::string, ResourceManager::ResData> outValue;
329     rm->GetPatternDataById(id, outValue);
330     ASSERT_EQ(ResType::STRING, outValue["width"].resType);
331     ASSERT_EQ(ResType::FLOAT, outValue["height"].resType);
332     ASSERT_EQ(ResType::STRING, outValue["bgColor"].resType);
333     ASSERT_EQ(ResType::STRING, outValue["fgColor"].resType);
334     ASSERT_EQ(ResType::PATTERN, outValue["fontPattern"].resType);
335     ASSERT_EQ(ResType::STRING, outValue["marginColor"].resType);
336     ASSERT_EQ(ResType::PATTERN, outValue["baseFontPattern"].resType);
337     ASSERT_EQ("10vp", outValue["width"].value);
338     ASSERT_EQ("66vp", outValue["height"].value);
339     ASSERT_EQ("#FF0000BB", outValue["bgColor"].value);
340     ASSERT_EQ("#FF0000CC", outValue["fgColor"].value);
341     ASSERT_EQ("16777334", outValue["fontPattern"].value);
342     ASSERT_EQ("#FF00AA00", outValue["marginColor"].value);
343     ASSERT_EQ("16777335", outValue["baseFontPattern"].value);
344 
345     std::string rootDir = "/data/test/theme/skin/ohos.global.test.all";
346     rootDirs.emplace_back(rootDir);
347     tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId);
348     rm->GetPatternDataById(id, outValue);
349     ASSERT_EQ(ResType::STRING, outValue["width"].resType);
350     ASSERT_EQ(ResType::FLOAT, outValue["height"].resType);
351     ASSERT_EQ(ResType::STRING, outValue["bgColor"].resType);
352     ASSERT_EQ(ResType::STRING, outValue["fgColor"].resType);
353     ASSERT_EQ(ResType::PATTERN, outValue["fontPattern"].resType);
354     ASSERT_EQ(ResType::STRING, outValue["marginColor"].resType);
355     ASSERT_EQ(ResType::PATTERN, outValue["baseFontPattern"].resType);
356     ASSERT_EQ("10vp", outValue["width"].value);
357     ASSERT_EQ("666vp", outValue["height"].value);
358     ASSERT_EQ("#FF0000BB", outValue["bgColor"].value);
359     ASSERT_EQ("#FF0000CC", outValue["fgColor"].value);
360     ASSERT_EQ("16777334", outValue["fontPattern"].value);
361     ASSERT_EQ("#FF00AA00", outValue["marginColor"].value);
362     ASSERT_EQ("16777335", outValue["baseFontPattern"].value);
363 }
364 
365 /*
366  * @tc.name: ThemeManagerTestLoadThemeIconsResourceTest001
367  * @tc.desc: Test GetThemeIcons function, file case.
368  * @tc.type: FUNC
369  */
370 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeIconsResourceTest001, TestSize.Level1)
371 {
372     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
373     ASSERT_TRUE(ret);
374     std::vector<std::string> rootDirs;
375     std::string rootDir = "/data/test/theme/icons/ohos.global.test.all";
376     uint32_t resId = 16777306;
377     std::pair<std::unique_ptr<uint8_t[]>, size_t> foregroundInfo;
378     std::pair<std::unique_ptr<uint8_t[]>, size_t> backgroundInfo;
379     RState state = rm->GetThemeIcons(resId, foregroundInfo, backgroundInfo);
380     EXPECT_TRUE(state == ERROR_CODE_RES_ID_NOT_FOUND);
381 
382     rootDirs.emplace_back(rootDir);
383     int32_t userId = 100; // userId is 100
384     tm->LoadThemeIconsResource("ohos.global.test.all", "entry", rootDirs, userId);
385     state = rm->GetThemeIcons(resId, foregroundInfo, backgroundInfo);
386     EXPECT_TRUE(state == SUCCESS);
387     tm->LoadThemeIconsResource("ohos.global.test.all", "entry", {}, userId);
388 }
389 
390 /*
391  * @tc.name: ThemeManagerTestLoadThemeIconsResourceTest002
392  * @tc.desc: Test GetThemeIcons function, file case.
393  * @tc.type: FUNC
394  */
395 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeIconsResourceTest002, TestSize.Level1)
396 {
397     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
398     ASSERT_TRUE(ret);
399     uint32_t resId = 16777306;
400     std::pair<std::unique_ptr<uint8_t[]>, size_t> foregroundInfo;
401     std::pair<std::unique_ptr<uint8_t[]>, size_t> backgroundInfo;
402     RState state = rm->GetThemeIcons(resId, foregroundInfo, backgroundInfo);
403     EXPECT_EQ(state, ERROR_CODE_RES_ID_NOT_FOUND);
404 
405     std::vector<std::string> rootDirs;
406     rootDirs.emplace_back("/data/test/theme/icons/dynamic_icons");
407     int32_t userId = 100; // userId is 100
408     tm->LoadThemeIconsResource("ohos.global.test.all", "entry", rootDirs, userId);
409     state = rm->GetThemeIcons(resId, foregroundInfo, backgroundInfo);
410     EXPECT_EQ(state, SUCCESS);
411     tm->LoadThemeIconsResource("ohos.global.test.all", "entry", {}, userId);
412 }
413 
414 /*
415  * @tc.name: ThemeManagerTestLoadThemeIconsResourceTest003
416  * @tc.desc: Test GetThemeIcons function, file case.
417  * @tc.type: FUNC
418  */
419 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeIconsResourceTest003, TestSize.Level1)
420 {
421     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
422     ASSERT_TRUE(ret);
423     std::vector<std::string> rootDirs;
424     std::string rootDir = "/data/test/theme/icons/ohos.global.test.all";
425     uint32_t resId = 16777306;
426     std::pair<std::unique_ptr<uint8_t[]>, size_t> foregroundInfo;
427     std::pair<std::unique_ptr<uint8_t[]>, size_t> backgroundInfo;
428     RState state = rm->GetThemeIcons(resId, foregroundInfo, backgroundInfo, 0, "ohos.global.test.all.EntryAbility");
429     EXPECT_EQ(state, ERROR_CODE_RES_ID_NOT_FOUND);
430 
431     rootDirs.emplace_back(rootDir);
432     int32_t userId = 100; // userId is 100
433     tm->LoadThemeIconsResource("ohos.global.test.all", "entry", rootDirs, userId);
434     state = rm->GetThemeIcons(resId, foregroundInfo, backgroundInfo, 0, "ohos.global.test.all.EntryAbility");
435     EXPECT_EQ(state, SUCCESS);
436     tm->LoadThemeIconsResource("ohos.global.test.all", "entry", {}, userId);
437 }
438 
439 /*
440  * @tc.name: ThemeManagerTestLoadThemeIconsResourceTest004
441  * @tc.desc: Test FindThemeIconResource function, file case.
442  * @tc.type: FUNC
443  */
444 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeIconsResourceTest004, TestSize.Level1)
445 {
446     std::vector<std::string> rootDirs;
447     std::string rootDir = "/data/test/theme/theme1/icons/ohos.global.test1";
448     rootDirs.emplace_back(rootDir);
449     int32_t userId = 100; // userId is 100
450     tm->LoadThemeIconsResource("ohos.global.test1", "entry", rootDirs, userId);
451     std::pair<std::string, std::string> bundleInfo;
452     bundleInfo.first = "ohos.global.test1";
453     std::string iconName("foreground");
454     std::string iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
455     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/foreground.png");
456     iconName = "background";
457     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
458     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/background.png");
459 }
460 
461 /*
462  * @tc.name: ThemeManagerTestLoadThemeIconsResourceTest005
463  * @tc.desc: Test FindThemeIconResource function, file case.
464  * @tc.type: FUNC
465  */
466 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeIconsResourceTest005, TestSize.Level1)
467 {
468     std::vector<std::string> rootDirs;
469     std::string rootDir = "/data/test/theme/theme1/icons/ohos.global.test1";
470     rootDirs.emplace_back(rootDir);
471     int32_t userId = 100; // userId is 100
472     tm->LoadThemeIconsResource("ohos.global.test1", "entry", rootDirs, userId);
473     std::pair<std::string, std::string> bundleInfo;
474     bundleInfo.first = "ohos.global.test1";
475     std::string iconName("foreground");
476     std::string iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
477     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/foreground.png");
478     iconName = "background";
479     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
480     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/background.png");
481 
482     rootDirs.clear();
483     rootDirs.emplace_back("/data/test/theme/theme2/icons/ohos.global.test2");
484     tm->LoadThemeIconsResource("ohos.global.test2", "entry", rootDirs, userId);
485     bundleInfo.first = "ohos.global.test2";
486     iconName = "foreground";
487     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
488     EXPECT_EQ(iconPath, "/data/test/theme/theme2/icons/ohos.global.test2/entry/foreground.png");
489     iconName = "background";
490     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
491     EXPECT_EQ(iconPath, "/data/test/theme/theme2/icons/ohos.global.test2/entry/background.png");
492 }
493 
494 /*
495  * @tc.name: ThemeManagerTestLoadThemeIconsResourceTest006
496  * @tc.desc: Test FindThemeIconResource function, file case.
497  * @tc.type: FUNC
498  */
499 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeIconsResourceTest006, TestSize.Level1)
500 {
501     std::vector<std::string> rootDirs;
502     std::string rootDir = "/data/test/theme/theme1/icons/ohos.global.test1";
503     rootDirs.emplace_back(rootDir);
504     int32_t userId = 100; // userId is 100
505     tm->LoadThemeIconsResource("ohos.global.test1", "entry", rootDirs, userId);
506     std::pair<std::string, std::string> bundleInfo;
507     bundleInfo.first = "ohos.global.test1";
508     std::string iconName("foreground");
509     std::string iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
510     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/foreground.png");
511     iconName = "background";
512     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
513     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/background.png");
514 
515     rootDirs.clear();
516     rootDirs.emplace_back("/data/test/theme/theme2/icons/ohos.global.test2");
517     tm->LoadThemeIconsResource("ohos.global.test2", "entry", rootDirs, userId);
518     iconName = "foreground";
519     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
520     EXPECT_EQ(iconPath, "");
521     iconName = "background";
522     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
523     EXPECT_EQ(iconPath, "");
524 }
525 
526 /*
527  * @tc.name: ThemeManagerTestLoadThemeIconsResourceTest007
528  * @tc.desc: Test FindThemeIconResource function, file case.
529  * @tc.type: FUNC
530  */
531 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeIconsResourceTest007, TestSize.Level1)
532 {
533     std::vector<std::string> rootDirs;
534     std::string rootDir = "/data/test/theme/theme1/icons";
535     rootDirs = tm->GetRootDir(rootDir);
536     int32_t userId = 100; // userId is 100
537     tm->LoadThemeIconsResource("ohos.global.test1", "entry", rootDirs, userId);
538     std::pair<std::string, std::string> bundleInfo;
539     bundleInfo.first = "ohos.global.test1";
540     std::string iconName("foreground");
541     std::string iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
542     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/foreground.png");
543     iconName = "background";
544     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
545     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/background.png");
546 
547     tm->LoadThemeIconRes("ohos.global.test1", "entry", userId);
548     iconName = "foreground";
549     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
550     EXPECT_EQ(iconPath, "");
551     iconName = "background";
552     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
553     EXPECT_EQ(iconPath, "");
554 }
555 
556 /*
557  * @tc.name: ThemeManagerTestLoadThemeIconsResourceTest008
558  * @tc.desc: Test FindThemeIconResource function, file case.
559  * @tc.type: FUNC
560  */
561 HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeIconsResourceTest008, TestSize.Level1)
562 {
563     std::vector<std::string> rootDirs;
564     std::string rootDir = "/data/test/theme/theme1/icons";
565     rootDirs = tm->GetRootDir(rootDir);
566     int32_t userId = 100; // userId is 100
567     tm->LoadThemeIconsResource("ohos.global.test1", "entry", rootDirs, userId);
568     std::pair<std::string, std::string> bundleInfo;
569     bundleInfo.first = "ohos.global.test1";
570     std::string iconName("foreground");
571     std::string iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
572     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/foreground.png");
573     iconName = "background";
574     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
575     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/background.png");
576 
577     tm->LoadThemeIconRes("ohos.global.test1", "entry", userId);
578     iconName = "foreground";
579     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
580     EXPECT_EQ(iconPath, "");
581     iconName = "background";
582     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
583     EXPECT_EQ(iconPath, "");
584 
585     rootDirs.clear();
586     rootDirs = tm->GetRootDir("/data/test/theme/theme2/icons");
587     tm->LoadThemeIconsResource("ohos.global.test2", "entry", rootDirs, userId);
588     bundleInfo.first = "ohos.global.test2";
589     iconName = "foreground";
590     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
591     EXPECT_EQ(iconPath, "/data/test/theme/theme2/icons/ohos.global.test2/entry/foreground.png");
592     iconName = "background";
593     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
594     EXPECT_EQ(iconPath, "/data/test/theme/theme2/icons/ohos.global.test2/entry/background.png");
595 }
596 
597 /*
598  * @tc.name: ThemeManagerTestChangeIconResourceStatusTest001
599  * @tc.desc: Test ChangeIconResourceStatus function, file case.
600  * @tc.type: FUNC
601  */
602 HWTEST_F(ThemeManagerTest, ThemeManagerTestChangeIconResourceStatusTest001, TestSize.Level1)
603 {
604     std::vector<std::string> rootDirs;
605     std::string rootDir = "/data/test/theme/theme1/icons";
606     rootDirs = tm->GetRootDir(rootDir);
607     int32_t userId = 100; // userId is 100
608     tm->LoadThemeIconsResource("ohos.global.test1", "entry", rootDirs, userId);
609     std::pair<std::string, std::string> bundleInfo;
610     bundleInfo.first = "ohos.global.test1";
611     std::string iconName("foreground");
612     std::string iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
613     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/foreground.png");
614     iconName = "background";
615     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
616     EXPECT_EQ(iconPath, "/data/test/theme/theme1/icons/ohos.global.test1/entry/background.png");
617 
618     tm->ChangeIconResourceStatus(userId);
619     tm->ClearIconResource();
620 
621     iconName = "foreground";
622     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
623     EXPECT_EQ(iconPath, "");
624     iconName = "background";
625     iconPath = tm->FindThemeIconResource(bundleInfo, iconName, userId);
626     EXPECT_EQ(iconPath, "");
627 }
628 
629 /*
630  * @tc.name: ThemeManagerTestHasIconInThemeTest001
631  * @tc.desc: Test HasIconInTheme function, file case.
632  * @tc.type: FUNC
633  */
634 HWTEST_F(ThemeManagerTest, ThemeManagerTestHasIconInThemeTest001, TestSize.Level1)
635 {
636     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
637     ASSERT_TRUE(ret);
638     std::vector<std::string> rootDirs;
639     std::string rootDir = "/data/test/theme/icons/ohos.global.test.all";
640     rootDirs.emplace_back(rootDir);
641     int32_t userId = 100; // userId is 100
642     tm->LoadThemeIconsResource("ohos.global.test.all", "entry", rootDirs, userId);
643     bool result = rm->HasIconInTheme("ohos.global.test");
644     EXPECT_TRUE(result == false);
645 
646     result = rm->HasIconInTheme("ohos.global.test.all");
647     EXPECT_TRUE(result == true);
648 }
649 
650 /*
651  * @tc.name: ThemeManagerTestGetOtherIconsInfoTest001
652  * @tc.desc: Test GetOtherIconsInfo function, file case.
653  * @tc.type: FUNC
654  */
655 HWTEST_F(ThemeManagerTest, ThemeManagerTestGetOtherIconsInfoTest001, TestSize.Level1)
656 {
657     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
658     ASSERT_TRUE(ret);
659     std::vector<std::string> rootDirs;
660     std::string rootDir = "/data/test/theme/icons/other_icons";
661     rootDirs.emplace_back(rootDir);
662     int32_t userId = 100; // userId is 100
663     tm->LoadThemeIconsResource("other_icons", "", rootDirs, userId);
664     std::unique_ptr<uint8_t[]> outValue;
665     size_t len;
666     RState state = rm->GetOtherIconsInfo("other_icons", outValue, len, true);
667     EXPECT_EQ(state, ERROR_CODE_RES_NOT_FOUND_BY_NAME);
668 
669     state = rm->GetOtherIconsInfo("foreground", outValue, len, false);
670     EXPECT_EQ(state, SUCCESS);
671 }
672 
673 /*
674  * @tc.name: ThemeManagerTestGetOtherIconsInfoTest002
675  * @tc.desc: Test GetOtherIconsInfo function, file case.
676  * @tc.type: FUNC
677  */
678 HWTEST_F(ThemeManagerTest, ThemeManagerTestGetOtherIconsInfoTest002, TestSize.Level1)
679 {
680     std::vector<std::string> rootDirs;
681     std::string rootDir = "/data/test/theme/icons/";
682     rootDirs = tm->GetRootDir(rootDir);
683     int32_t userId = 100; // userId is 100
684     tm->LoadThemeIconsResource("other_icons", "", rootDirs, userId);
685     std::unique_ptr<uint8_t[]> outValue;
686     size_t len;
687     RState state = rm->GetOtherIconsInfo("icon_mask", outValue, len, true);
688     EXPECT_EQ(state, SUCCESS);
689 
690     state = rm->GetOtherIconsInfo("icon_mask", outValue, len, false);
691     EXPECT_EQ(state, ERROR_CODE_RES_NOT_FOUND_BY_NAME);
692 }
693 
694 /*
695  * @tc.name: ThemeManagerTestGetOtherIconsInfoTest003
696  * @tc.desc: Test GetOtherIconsInfo function, file case.
697  * @tc.type: FUNC
698  */
699 HWTEST_F(ThemeManagerTest, ThemeManagerTestGetOtherIconsInfoTest003, TestSize.Level1)
700 {
701     std::vector<std::string> rootDirs;
702     std::string rootDir = "/data/test/theme/icons/";
703     rootDirs = tm->GetRootDir(rootDir);
704     int32_t userId = 100; // userId is 100
705     tm->LoadThemeIconsResource("other_icons", "", rootDirs, userId);
706     std::unique_ptr<uint8_t[]> outValue;
707     size_t len;
708     RState state = rm->GetOtherIconsInfo("icon_mask", outValue, len, true);
709     EXPECT_EQ(state, SUCCESS);
710 
711     RState state1 = tm->GetThemeIconFromCache("global_icon_mask", outValue, len);
712     EXPECT_EQ(state1, SUCCESS);
713 
714     RState state2 = rm->GetOtherIconsInfo("icon_mask", outValue, len, true);
715     EXPECT_EQ(state2, SUCCESS);
716 }
717 
718 /*
719  * @tc.name: ThemeManagerTestGetThemeIconFromCacheTest001
720  * @tc.desc: Test GetThemeIconFromCache function, file case.
721  * @tc.type: FUNC
722  */
723 HWTEST_F(ThemeManagerTest, ThemeManagerTestGetThemeIconFromCacheTest001, TestSize.Level1)
724 {
725     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
726     ASSERT_TRUE(ret);
727     std::vector<std::string> rootDirs;
728     std::string rootDir = "/data/test/theme/icons/other_icons";
729     rootDirs.emplace_back(rootDir);
730     int32_t userId = 100; // userId is 100
731     tm->LoadThemeIconsResource("other_icons", "", rootDirs, userId);
732     std::unique_ptr<uint8_t[]> outValue;
733     size_t len;
734     RState state = tm->GetThemeIconFromCache("other_icons_background", outValue, len);
735     EXPECT_EQ(state, NOT_FOUND);
736     state = tm->GetOtherIconsInfo("background", outValue, len, false, userId);
737     EXPECT_EQ(state, SUCCESS);
738     state = tm->GetThemeIconFromCache("other_icons_background", outValue, len);
739     EXPECT_EQ(state, SUCCESS);
740 }
741 
742 /*
743  * @tc.name: ThemeManagerTestGetThemeIconFromCacheTest002
744  * @tc.desc: Test GetThemeIconFromCache function, file case.
745  * @tc.type: FUNC
746  */
747 HWTEST_F(ThemeManagerTest, ThemeManagerTestGetThemeIconFromCacheTest002, TestSize.Level1)
748 {
749     std::vector<std::string> rootDirs;
750     std::string rootDir = "/data/test/theme/icons/other_icons";
751     rootDirs.emplace_back(rootDir);
752     int32_t userId = 100; // userId is 100
753     tm->LoadThemeIconsResource("other_icons", "", rootDirs, userId);
754     std::unique_ptr<uint8_t[]> outValue;
755     size_t len;
756     RState state = tm->GetOtherIconsInfo("background", outValue, len, false, userId);
757     EXPECT_EQ(state, SUCCESS);
758     state = tm->GetThemeIconFromCache("global_icon_mask", outValue, len);
759     EXPECT_EQ(state, NOT_FOUND);
760     state = tm->GetOtherIconsInfo("icon_mask", outValue, len, true, userId);
761     EXPECT_EQ(state, SUCCESS);
762     state = tm->GetThemeIconFromCache("global_icon_mask", outValue, len);
763     EXPECT_EQ(state, SUCCESS);
764 }
765 
766 /*
767  * @tc.name: ThemeManagerTestIsUpdateByUserIdTest001
768  * @tc.desc: Test IsUpdateByUserId function, file case.
769  * @tc.type: FUNC
770  */
771 HWTEST_F(ThemeManagerTest, ThemeManagerTestIsUpdateByUserIdTest001, TestSize.Level1)
772 {
773     int32_t userId = 100;
774     tm->UpdateUserId(userId);
775     bool result = tm->IsUpdateByUserId(userId);
776     ASSERT_FALSE(result);
777 
778     userId = 101;
779     result = tm->IsUpdateByUserId(userId);
780     ASSERT_TRUE(result);
781 }
782 
783 /*
784  * @tc.name: ThemeManagerTestIsSameResourceByUserIdTest001
785  * @tc.desc: Test IsSameResourceByUserId function, file case.
786  * @tc.type: FUNC
787  */
788 HWTEST_F(ThemeManagerTest, ThemeManagerTestIsSameResourceByUserIdTest001, TestSize.Level1)
789 {
790     std::string path("/data/service/el1/public/themes/100/a/app/icons/ohos.global.test2/entry/foreground.png");
791     int32_t userId = 100;
792     bool result = tm->IsSameResourceByUserId(path, userId);
793     EXPECT_TRUE(result == true);
794 
795     userId = 101;
796     result = tm->IsSameResourceByUserId(path, userId);
797     EXPECT_TRUE(result == false);
798 }
799 
800 /*
801  * @tc.name: ThemeManagerTestIsSameResourceByUserIdTest002
802  * @tc.desc: Test IsSameResourceByUserId function, file case.
803  * @tc.type: FUNC
804  */
805 HWTEST_F(ThemeManagerTest, ThemeManagerTestIsSameResourceByUserIdTest002, TestSize.Level1)
806 {
807     std::string path("/data/service/el1/public/themes/100");
808     int32_t userId = 100;
809     bool result = tm->IsSameResourceByUserId(path, userId);
810     EXPECT_TRUE(result);
811 }
812 
813 /*
814  * @tc.name: ThemeManagerTestIsSameResourceByUserIdTest003
815  * @tc.desc: Test IsSameResourceByUserId function, file case.
816  * @tc.type: FUNC
817  */
818 HWTEST_F(ThemeManagerTest, ThemeManagerTestIsSameResourceByUserIdTest003, TestSize.Level1)
819 {
820     std::string path("/data/service/el1/public/themes/abc/");
821     int32_t userId = 100;
822     bool result = tm->IsSameResourceByUserId(path, userId);
823     EXPECT_TRUE(result);
824 }
825 
826 /*
827  * @tc.name: ThemeManagerTestGetMaskStringTest001
828  * @tc.desc: Test GetMaskString function, file case.
829  * @tc.type: FUNC
830  */
831 HWTEST_F(ThemeManagerTest, ThemeManagerTestGetMaskStringTest001, TestSize.Level1)
832 {
833     std::string path("/data/service/el1/public/themes/100/a/app/icons/ohos.global.test2/entry/foreground.png");
834     std::string maskPath = tm->GetMaskString(path);
835     EXPECT_EQ(maskPath, "100/a/app/icons/ohos.global.test2/entry/foreground.png");
836 
837     path = "/data/test/theme/theme2/icons/ohos.global.test2/entry/foreground.png";
838     maskPath = tm->GetMaskString(path);
839     EXPECT_EQ(maskPath, path);
840 }
841 }
842