1 /*
2  * Copyright (c) 2022-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 <dlfcn.h>
17 #include "plugin_mgr.h"
18 #include "res_type.h"
19 #include "plugin_mgr_test.h"
20 #include "socperf_plugin.h"
21 #include "mock_plugin_mgr.h"
22 #include "res_data.h"
23 #include "res_type.h"
24 
25 using namespace std;
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace ResourceSchedule {
30 namespace {
31     const string LIB_NAME = "libunittest_plugin.z.so";
32 }
33 
SetUpTestCase()34 void PluginMgrTest::SetUpTestCase() {}
35 
TearDownTestCase()36 void PluginMgrTest::TearDownTestCase() {}
37 
SetUp()38 void PluginMgrTest::SetUp()
39 {
40     /**
41      * @tc.setup: initialize the member variable pluginMgr_
42      */
43     pluginMgr_ = make_shared<MockPluginMgr>();
44 }
45 
TearDown()46 void PluginMgrTest::TearDown()
47 {
48     /**
49      * @tc.teardown: clear pluginMgr_
50      */
51     pluginMgr_ = nullptr;
52 }
53 
GetSubItemValue(std::string PluginName,std::string configName)54 std::string PluginMgrTest::GetSubItemValue(std::string PluginName, std::string configName)
55 {
56     std::string subItemValue;
57     PluginConfig config = pluginMgr_->GetConfig(PluginName, configName);
58     if (config.itemList.size() <= 0) {
59         return "";
60     }
61     for (auto item : config.itemList) {
62         for (auto subItem : item.subItemList) {
63             if (subItem.name == "tag") {
64                 subItemValue = subItem.value;
65             }
66         }
67     }
68     return subItemValue;
69 }
70 
71 /**
72  * @tc.name: Plugin mgr test Init 001
73  * @tc.desc: Verify if can init success.
74  * @tc.type: FUNC
75  * @tc.require: issueI798UT
76  * @tc.author:xukuan
77  */
78 HWTEST_F(PluginMgrTest, Init001, TestSize.Level1)
79 {
80     pluginMgr_->Init();
81     EXPECT_TRUE(pluginMgr_->initStatus == pluginMgr_->INIT_SUCCESS);
82     EXPECT_EQ(pluginMgr_->pluginLibMap_.size(), 0);
83 }
84 
85 /**
86  * @tc.name: Plugin mgr test Init 002
87  * @tc.desc: Verify if can init fault.
88  * @tc.type: FUNC
89  * @tc.require: issueI8VZVN
90  * @tc.author:z30053169
91  */
92 HWTEST_F(PluginMgrTest, Init002, TestSize.Level1)
93 {
94     PluginMgr::GetInstance().pluginSwitch_ = nullptr;
95     pluginMgr_->Init();
96     EXPECT_TRUE(pluginMgr_->pluginSwitch_ != nullptr);
97 }
98 
99 /**
100  * @tc.name: Plugin mgr test GetPluginSwitch 001
101  * @tc.desc: Verify if can get pluginSwitch
102  * @tc.type: FUNC
103  * @tc.require: issuesIA7P80
104  * @tc.author:xiaoshun
105  */
106 HWTEST_F(PluginMgrTest, GetPluginSwitch001, TestSize.Level0)
107 {
108     pluginMgr_->Init();
109     auto pluginInfoList = pluginMgr_->pluginSwitch_->GetPluginSwitch();
110     bool result;
111     for (auto pluginInfo : pluginInfoList) {
112         if (pluginInfo.libPath == "libapp_preload_plugin.z.so") {
113             EXPECT_TRUE(pluginInfo.switchOn);
114         } else if (pluginInfo.libPath == "libapp_preload_plugin2.z.so" ||
115             pluginInfo.libPath == "libapp_preload_plugin3.z.so" ||
116             pluginInfo.libPath == "libapp_preload_plugin4.z.so") {
117             EXPECT_TRUE(!pluginInfo.switchOn);
118         }
119     }
120 }
121 
122 /**
123  * @tc.name: Plugin mgr test Stop 001
124  * @tc.desc: Verify if can stop success.
125  * @tc.type: FUNC
126  * @tc.require: issueI798UT
127  * @tc.author:xukuan
128  */
129 HWTEST_F(PluginMgrTest, Stop001, TestSize.Level1)
130 {
131     pluginMgr_->Stop();
132     EXPECT_EQ(pluginMgr_->pluginLibMap_.size(), 0);
133     EXPECT_EQ(pluginMgr_->resTypeLibMap_.size(), 0);
134     EXPECT_TRUE(pluginMgr_->configReader_ == nullptr);
135 }
136 
137 /**
138  * @tc.name: Plugin mgr test GetConfig 001
139  * @tc.desc: Verify if can get config with wrong env.
140  * @tc.type: FUNC
141  * @tc.require: issueI5WWV3
142  * @tc.author:lice
143  */
144 HWTEST_F(PluginMgrTest, GetConfig001, TestSize.Level1)
145 {
146     PluginConfig config = pluginMgr_->GetConfig("", "");
147     EXPECT_TRUE(config.itemList.empty());
148 }
149 
150 /**
151  * @tc.name: Plugin mgr test GetConfig 002
152  * @tc.desc: Verify if can get config with wrong env.
153  * @tc.type: FUNC
154  * @tc.require: issuesIA7P80
155  * @tc.author:lice
156  */
157 HWTEST_F(PluginMgrTest, GetConfig002, TestSize.Level1)
158 {
159     pluginMgr_->Init();
160     std::string subItemValue = GetSubItemValue("demo2", "sample");
161     bool ret = !subItemValue.empty() && subItemValue == "test_sys_prod";
162     EXPECT_TRUE(ret);
163     subItemValue = GetSubItemValue("demo3", "sample");
164     ret = !subItemValue.empty() && subItemValue == "test_sys_prod";
165     EXPECT_TRUE(ret);
166     subItemValue = GetSubItemValue("demo4", "sample");
167     ret = !subItemValue.empty() && subItemValue == "test_system";
168     EXPECT_TRUE(ret);
169 }
170 
171 /**
172  * @tc.name: Plugin mgr test GetConfig 003
173  * @tc.desc: Verify if can get config with wrong env.
174  * @tc.type: FUNC
175  * @tc.require: issueI8VZVN
176  * @tc.author:z30053169
177  */
178 HWTEST_F(PluginMgrTest, GetConfig003, TestSize.Level1)
179 {
180     PluginMgr::GetInstance().configReader_ = nullptr;
181     PluginConfig config = pluginMgr_->GetConfig("", "");
182     EXPECT_EQ(config.itemList.size(), 0);
183 }
184 
185 /**
186  * @tc.name: Plugin mgr test SubscribeResource 002
187  * @tc.desc: Verify if can SubscribeResource
188  * @tc.type: FUNC
189  * @tc.require: issueI8VZVN
190  * @tc.author:z30053169
191  */
192 HWTEST_F(PluginMgrTest, SubscribeResource002, TestSize.Level1)
193 {
194     PluginMgr::GetInstance().SubscribeResource("", 0);
195     SUCCEED();
196     PluginMgr::GetInstance().SubscribeResource("test", 1);
197     SUCCEED();
198     PluginMgr::GetInstance().UnSubscribeResource("test", 1);
199     EXPECT_EQ(PluginMgr::GetInstance().resTypeLibMap_.size(), 0);
200 }
201 
202 /**
203  * @tc.name: Plugin mgr test UnSubscribeResource 003
204  * @tc.desc: Verify if can SubscribeResource
205  * @tc.type: FUNC
206  * @tc.require: issueI8VZVN
207  * @tc.author:z30053169
208  */
209 HWTEST_F(PluginMgrTest, UnSubscribeResource003, TestSize.Level1)
210 {
211     PluginMgr::GetInstance().UnSubscribeResource("", 0);
212     SUCCEED();
213     PluginMgr::GetInstance().UnSubscribeResource("test", 0);
214     SUCCEED();
215     PluginMgr::GetInstance().SubscribeResource("test1", 1);
216     PluginMgr::GetInstance().SubscribeResource("test2", 1);
217     PluginMgr::GetInstance().UnSubscribeResource("test1", 1);
218     SUCCEED();
219     PluginMgr::GetInstance().UnSubscribeResource("test2", 1);
220     EXPECT_EQ(PluginMgr::GetInstance().resTypeLibMap_.size(), 0);
221 }
222 
223 /**
224  * @tc.name: Plugin mgr test DispatchResource 001
225  * @tc.desc: Verify if can DispatchResource
226  * @tc.type: FUNC
227  * @tc.require: issueI8VZVN
228  * @tc.author:z30053169
229  */
230 HWTEST_F(PluginMgrTest, DispatchResource001, TestSize.Level1)
231 {
232     pluginMgr_->Init();
233     if (pluginMgr_->dispatcher_ == nullptr) {
234         pluginMgr_->dispatcher_ = std::make_shared<AppExecFwk::EventHandler>(
235             AppExecFwk::EventRunner::Create("rssDispatcher"));
236     }
237     nlohmann::json payload;
238     auto data = std::make_shared<ResData>(ResType::RES_TYPE_APP_ABILITY_START,
239         ResType::AppStartType::APP_COLD_START, payload);
240     pluginMgr_->DispatchResource(data);
241     EXPECT_TRUE(pluginMgr_->dispatcher_ != nullptr);
242     pluginMgr_->DispatchResource(nullptr);
243     SUCCEED();
244 }
245 
246 /**
247  * @tc.name: Plugin mgr test DispatchResource 002
248  * @tc.desc: Verify if can DispatchResource
249  * @tc.type: FUNC
250  * @tc.require: issueI8VZVN
251  * @tc.author:z30053169
252  */
253 HWTEST_F(PluginMgrTest, DispatchResource002, TestSize.Level1)
254 {
255     if (PluginMgr::GetInstance().dispatcher_ == nullptr) {
256         PluginMgr::GetInstance().dispatcher_ = std::make_shared<AppExecFwk::EventHandler>(
257             AppExecFwk::EventRunner::Create("rssDispatcher"));
258     }
259     nlohmann::json payload;
260     auto data = std::make_shared<ResData>(ResType::RES_TYPE_APP_ABILITY_START,
261         ResType::AppStartType::APP_COLD_START, payload);
262     PluginMgr::GetInstance().SubscribeResource("", 0);
263     SUCCEED();
264     PluginMgr::GetInstance().SubscribeResource("test", ResType::RES_TYPE_APP_ABILITY_START);
265     SUCCEED();
266     PluginMgr::GetInstance().DispatchResource(data);
267     EXPECT_TRUE(PluginMgr::GetInstance().dispatcher_ != nullptr);
268     PluginMgr::GetInstance().UnSubscribeResource("", 0);
269     SUCCEED();
270 }
271 
272 /**
273  * @tc.name: Plugin mgr test SubscribeResource 001
274  * @tc.desc: Verify if can stop success.
275  * @tc.type: FUNC
276  * @tc.require: issueI798UT
277  * @tc.author:xukuan
278  */
279 HWTEST_F(PluginMgrTest, SubscribeResource001, TestSize.Level1)
280 {
281     pluginMgr_->Init();
282     pluginMgr_->SubscribeResource(LIB_NAME, ResType::RES_TYPE_SCREEN_STATUS);
283     auto iter = pluginMgr_->resTypeLibMap_.find(ResType::RES_TYPE_SCREEN_STATUS);
284     string libName = iter->second.back();
285     EXPECT_EQ(libName.compare(LIB_NAME), 0);
286 }
287 
288 /**
289  * @tc.name: Plugin mgr test Dump 001
290  * @tc.desc: Verify if dump commands is success.
291  * @tc.type: FUNC
292  * @tc.require: issueI5WWV3
293  * @tc.author:lice
294  */
295 HWTEST_F(PluginMgrTest, Dump001, TestSize.Level1)
296 {
297     std::string res;
298     pluginMgr_->Init();
299     pluginMgr_->DumpAllPlugin(res);
300     EXPECT_TRUE(!res.empty());
301     res = "";
302 
303     pluginMgr_->LoadPlugin();
304     pluginMgr_->DumpHelpFromPlugin(res);
305     EXPECT_TRUE(res.empty());
306     res = "";
307 
308     std::vector<std::string> args;
309     pluginMgr_->DumpOnePlugin(res, LIB_NAME, args);
310     EXPECT_TRUE(!res.empty());
311     res = "";
312 
313     args.emplace_back("-h");
314     pluginMgr_->DumpOnePlugin(res, LIB_NAME, args);
315     EXPECT_TRUE(!res.empty());
316     res = "";
317     pluginMgr_->DumpAllPluginConfig(res);
318     EXPECT_TRUE(!res.empty());
319 }
320 
321 /**
322  * @tc.name: Plugin mgr test RepairPlugin 001
323  * @tc.desc: Verify if RepairPlugin is success.
324  * @tc.type: FUNC
325  * @tc.require: issueI5WWV3
326  * @tc.author:lice
327  */
328 HWTEST_F(PluginMgrTest, RepairPlugin001, TestSize.Level1)
329 {
330     PluginLib libInfo = pluginMgr_->pluginLibMap_.find(LIB_NAME)->second;
331     pluginMgr_->RepairPlugin(Clock::now(), LIB_NAME, libInfo);
332     EXPECT_TRUE(true);
333 }
334 
335 /**
336  * @tc.name: Plugin mgr test UnSubscribeResource 001
337  * @tc.desc: Verify if can stop success.
338  * @tc.type: FUNC
339  * @tc.require: issueI798UT
340  * @tc.author:xukuan
341  */
342 HWTEST_F(PluginMgrTest, UnSubscribeResource001, TestSize.Level1)
343 {
344     pluginMgr_->UnSubscribeResource(LIB_NAME, ResType::RES_TYPE_SCREEN_STATUS);
345     auto iter = pluginMgr_->resTypeLibMap_.find(ResType::RES_TYPE_SCREEN_STATUS);
346     EXPECT_TRUE(iter == pluginMgr_->resTypeLibMap_.end());
347 }
348 
349 /*
350  * @tc.name: SocPerfSubTest_DispatchResource_001
351  * @tc.desc: DispatchResource Plugin
352  * @tc.type FUNC
353  * @tc.author:zoujie
354  * @tc.require: issueI5VWUI
355  */
356 HWTEST_F(PluginMgrTest, PluginMgrTest_DispatchResource_001, TestSize.Level1)
357 {
358     nlohmann::json payload;
359     auto data = std::make_shared<ResData>(ResType::RES_TYPE_APP_ABILITY_START,
360         ResType::AppStartType::APP_COLD_START, payload);
361     /* Init */
362     SocPerfPlugin::GetInstance().Init();
363     /* HandleAppAbilityStart */
364     SocPerfPlugin::GetInstance().DispatchResource(data);
365 
366     data->value = ResType::AppStartType::APP_WARM_START;
367     SocPerfPlugin::GetInstance().DispatchResource(data);
368 
369     /* HandleWindowFocus */
370     data->resType = ResType::RES_TYPE_WINDOW_FOCUS;
371     data->value = ResType::WindowFocusStatus::WINDOW_FOCUS;
372     SocPerfPlugin::GetInstance().DispatchResource(data);
373 
374     /* HandleEventClick */
375     data->resType = ResType::RES_TYPE_CLICK_RECOGNIZE;
376     data->value = ResType::ClickEventType::TOUCH_EVENT_DOWN;
377     SocPerfPlugin::GetInstance().DispatchResource(data);
378     data->value = ResType::ClickEventType::TOUCH_EVENT_UP;
379     SocPerfPlugin::GetInstance().DispatchResource(data);
380     data->value = ResType::ClickEventType::CLICK_EVENT;
381     SocPerfPlugin::GetInstance().DispatchResource(data);
382 
383     /* HandlePushPage */
384     data->resType = ResType::RES_TYPE_PUSH_PAGE;
385     data->value = ResType::PushPageType::PUSH_PAGE_START;
386     SocPerfPlugin::GetInstance().DispatchResource(data);
387     data->value = ResType::PushPageType::PUSH_PAGE_COMPLETE;
388     SocPerfPlugin::GetInstance().DispatchResource(data);
389 
390     /* HandlePopPage */
391     data->resType = ResType::RES_TYPE_POP_PAGE;
392     data->value = 0;
393     SocPerfPlugin::GetInstance().DispatchResource(data);
394 
395     /* HandleEventSlide */
396     data->resType = ResType::RES_TYPE_SLIDE_RECOGNIZE;
397     data->value = ResType::SlideEventStatus::SLIDE_EVENT_ON;
398     SocPerfPlugin::GetInstance().DispatchResource(data);
399     data->value = ResType::SlideEventStatus::SLIDE_EVENT_OFF;
400     SocPerfPlugin::GetInstance().DispatchResource(data);
401 
402     /* HandleEventWebGesture */
403     data->resType = ResType::RES_TYPE_WEB_GESTURE;
404     data->value = 0;
405     SocPerfPlugin::GetInstance().DispatchResource(data);
406 
407     /* HandleResizeWindow */
408     data->resType = ResType::RES_TYPE_RESIZE_WINDOW;
409     data->value = ResType::WindowResizeType::WINDOW_RESIZING;
410     SocPerfPlugin::GetInstance().DispatchResource(data);
411     data->value = ResType::WindowResizeType::WINDOW_RESIZE_STOP;
412     SocPerfPlugin::GetInstance().DispatchResource(data);
413 
414     /* HandleMoveWindow */
415     data->resType = ResType::RES_TYPE_MOVE_WINDOW;
416     data->value = ResType::WindowMoveType::WINDOW_MOVING;
417     SocPerfPlugin::GetInstance().DispatchResource(data);
418     data->value = ResType::WindowMoveType::WINDOW_MOVE_STOP;
419     SocPerfPlugin::GetInstance().DispatchResource(data);
420 
421     /* DeInit */
422     SocPerfPlugin::GetInstance().Disable();
423     EXPECT_TRUE(SocPerfPlugin::GetInstance().handle_ == nullptr);
424 }
425 
426 /*
427  * @tc.name: SocPerfSubTest_DispatchResource_002
428  * @tc.desc: DispatchResource Plugin
429  * @tc.type FUNC
430  * @tc.author:qiunaiguang
431  * @tc.require: issueI6I9QS
432  */
433 HWTEST_F(PluginMgrTest, PluginMgrTest_DispatchResource_002, Function | MediumTest | Level0)
434 {
435     /* Init */
436     SocPerfPlugin::GetInstance().Init();
437 
438     nlohmann::json payload;
439     std::shared_ptr<ResData> resData =
440         std::make_shared<ResData>(ResType::RES_TYPE_LOAD_PAGE, ResType::LoadPageType::LOAD_PAGE_START, payload);
441     SocPerfPlugin::GetInstance().HandleLoadPage(resData);
442     resData->value = ResType::LoadPageType::LOAD_PAGE_COMPLETE;
443     SocPerfPlugin::GetInstance().HandleLoadPage(resData);
444     /* DeInit */
445     SocPerfPlugin::GetInstance().Disable();
446     EXPECT_TRUE(SocPerfPlugin::GetInstance().handle_ == nullptr);
447 }
448 
449 /*
450  * @tc.name: SocPerfSubTest_DispatchResource_003
451  * @tc.desc: DispatchResource Plugin
452  * @tc.type FUNC
453  * @tc.author:qiunaiguang
454  * @tc.require: issueI6I9QS
455  */
456 HWTEST_F(PluginMgrTest, PluginMgrTest_DispatchResource_003, Function | MediumTest | Level0)
457 {
458     /* Init */
459     SocPerfPlugin::GetInstance().Init();
460     nlohmann::json payload;
461     std::shared_ptr<ResData> resData =
462         std::make_shared<ResData>(ResType::RES_TYPE_SHOW_REMOTE_ANIMATION,
463         ResType::ShowRemoteAnimationStatus::ANIMATION_BEGIN, payload);
464     SocPerfPlugin::GetInstance().HandleRemoteAnimation(resData);
465 
466     resData->value = ResType::ShowRemoteAnimationStatus::ANIMATION_END;
467     SocPerfPlugin::GetInstance().HandleRemoteAnimation(resData);
468     /* DeInit */
469     SocPerfPlugin::GetInstance().Disable();
470     EXPECT_TRUE(SocPerfPlugin::GetInstance().handle_ == nullptr);
471 }
472 
473 /*
474  * @tc.name: SocPerfSubTest_DispatchResource_004
475  * @tc.desc: DispatchResource Plugin
476  * @tc.type FUNC
477  * @tc.author:qiunaiguang
478  * @tc.require: issueI6I9QS
479  */
480 HWTEST_F(PluginMgrTest, PluginMgrTest_DispatchResource_004, Function | MediumTest | Level0)
481 {
482     /* Init */
483     SocPerfPlugin::GetInstance().Init();
484     SocPerfPlugin::GetInstance().InitFeatureSwitch("socperf_on_demand");
485     SocPerfPlugin::GetInstance().InitFeatureSwitch("test");
486     /* DeInit */
487     SocPerfPlugin::GetInstance().Disable();
488     EXPECT_TRUE(SocPerfPlugin::GetInstance().handle_ == nullptr);
489 }
490 
491 /*
492  * @tc.name: SocPerfSubTest_DispatchResource_005
493  * @tc.desc: DispatchResource Plugin
494  * @tc.type FUNC
495  * @tc.author:fangdinggeng
496  * @tc.require: issueI5VWUI
497  */
498 HWTEST_F(PluginMgrTest, PluginMgrTest_DispatchResource_005, TestSize.Level1)
499 {
500     nlohmann::json payload;
501     auto data = std::make_shared<ResData>(ResType::RES_TYPE_DEVICE_MODE_STATUS,
502         ResType::DeviceModeStatus::MODE_ENTER, payload);
503     /* Init */
504     SocPerfPlugin::GetInstance().Init();
505 
506     /* HandleDeviceModeStatusChange */
507     data->payload["deviceMode"] = "test";
508     SocPerfPlugin::GetInstance().DispatchResource(data);
509     data->value = ResType::DeviceModeStatus::MODE_QUIT;
510     SocPerfPlugin::GetInstance().DispatchResource(data);
511 
512     /* DeInit */
513     SocPerfPlugin::GetInstance().Disable();
514     EXPECT_TRUE(SocPerfPlugin::GetInstance().handle_ == nullptr);
515 }
516 
517 /**
518  * @tc.name: Plugin mgr test DumPluginInfoAppend_001
519  * @tc.desc: test the interface DumpluginInfoAppend
520  * @tc.type: FUNC
521  * @tc.require: issueI8VZVN
522  * @tc.author:z30053169
523  */
524 HWTEST_F(PluginMgrTest, DumPluginInfoAppend_001, TestSize.Level1)
525 {
526     string result;
527     PluginInfo info;
528     info.switchOn = false;
529     PluginMgr::GetInstance().DumpPluginInfoAppend(result, info);
530     EXPECT_FALSE(result.empty());
531 }
532 
533 /**
534  * @tc.name: Plugin mgr test DispatchResource 003
535  * @tc.desc: test the interface DispatchResource
536  * @tc.type: FUNC
537  * @tc.require: issueI8VZVN
538  * @tc.author:z30053169
539  */
540 HWTEST_F(PluginMgrTest, DispatchResource003, TestSize.Level1)
541 {
542     nlohmann::json payload;
543     PluginMgr::GetInstance().dispatcher_ = nullptr;
544     auto data = std::make_shared<ResData>(ResType::RES_TYPE_APP_ABILITY_START,
545         ResType::AppStartType::APP_COLD_START, payload);
546     PluginMgr::GetInstance().UnSubscribeResource("test", ResType::RES_TYPE_APP_ABILITY_START);
547     PluginMgr::GetInstance().DispatchResource(data);
548     EXPECT_TRUE(PluginMgr::GetInstance().dispatcher_ == nullptr);
549 }
550 
551 /**
552  * @tc.name: Plugin mgr test DispatchResource 004
553  * @tc.desc: Verify if can DispatchResource
554  * @tc.type: FUNC
555  * @tc.require: issueI91HSR
556  * @tc.author:baiheng
557  */
558 HWTEST_F(PluginMgrTest, DispatchResource004, TestSize.Level1)
559 {
560     nlohmann::json payload;
561     auto dataNoExtType = std::make_shared<ResData>(ResType::RES_TYPE_KEY_PERF_SCENE,
562         ResType::KeyPerfStatus::ENTER_SCENE, payload);
563     PluginMgr::GetInstance().SubscribeResource("test", 10000);
564     SUCCEED();
565     PluginMgr::GetInstance().DispatchResource(dataNoExtType);
566     EXPECT_TRUE(PluginMgr::GetInstance().resTypeLibMap_.size() == 1);
567 }
568 
569 /**
570  * @tc.name: Plugin mgr test DispatchResource 005
571  * @tc.desc: Verify if can DispatchResource
572  * @tc.type: FUNC
573  * @tc.require: issueI91HSR
574  * @tc.author:baiheng
575  */
576 HWTEST_F(PluginMgrTest, DispatchResource005, TestSize.Level1)
577 {
578     nlohmann::json payload;
579     payload["extType"] = "10000";
580     auto dataWithExtType = std::make_shared<ResData>(ResType::RES_TYPE_KEY_PERF_SCENE,
581         ResType::KeyPerfStatus::ENTER_SCENE, payload);
582     PluginMgr::GetInstance().SubscribeResource("test", 10000);
583     SUCCEED();
584     PluginMgr::GetInstance().DispatchResource(dataWithExtType);
585     EXPECT_TRUE(PluginMgr::GetInstance().resTypeLibMap_.size() == 1);
586 }
587 
588 /**
589  * @tc.name: Plugin mgr test GetPluginLib 001
590  * @tc.desc: Verify if can get pluginlib with wrong env.
591  * @tc.type: FUNC
592  * @tc.require: issueI9C9JN
593  * @tc.author:xiaoshun
594  */
595 HWTEST_F(PluginMgrTest, GetPluginLib001, TestSize.Level0)
596 {
597     std::shared_ptr<PluginLib> libInfoPtr = pluginMgr_->GetPluginLib("test");
598     EXPECT_TRUE(libInfoPtr == nullptr);
599 }
600 
601 /**
602  * @tc.name: Plugin mgr test GetPluginLib 002
603  * @tc.desc: Verify if can get pluginlib
604  * @tc.type: FUNC
605  * @tc.require: issueI9C9JN
606  * @tc.author:xiaoshun
607  */
608 HWTEST_F(PluginMgrTest, GetPluginLib002, TestSize.Level0)
609 {
610     std::shared_ptr<PluginLib> libInfoPtr = pluginMgr_->GetPluginLib("libapp_preload_plugin.z.so");
611     EXPECT_TRUE(pluginMgr_->pluginLibMap_.find("libapp_preload_plugin.z.so") == pluginMgr_->pluginLibMap_.end() ?
612         libInfoPtr == nullptr : libInfoPtr != nullptr);
613 }
614 
615 /**
616  * @tc.name: Plugin mgr test InnerTimeUtil 001
617  * @tc.desc: InnerTimeUtil
618  * @tc.type: FUNC
619  * @tc.require: issueI9C9JN
620  * @tc.author:luolu
621  */
622 HWTEST_F(PluginMgrTest, InnerTimeUtil001, TestSize.Level0)
623 {
624     PluginMgr::InnerTimeUtil innerTimeUtil("test1", "test2");
625     EXPECT_EQ(innerTimeUtil.functionName_, "test1");
626     EXPECT_EQ(innerTimeUtil.pluginName_, "test2");
627 }
628 
629 /**
630  * @tc.name: Plugin mgr test LoadPlugin 001
631  * @tc.desc: LoadPlugin
632  * @tc.type: FUNC
633  * @tc.require: issueI9C9JN
634  * @tc.author:luolu
635  */
636 HWTEST_F(PluginMgrTest, LoadPlugin001, TestSize.Level0)
637 {
638     PluginMgr::GetInstance().LoadPlugin();
639     EXPECT_EQ(PluginMgr::GetInstance().pluginLibMap_.size(), 0);
640 }
641 
642 /**
643  * @tc.name: Plugin mgr test SubscribeSyncResource 002
644  * @tc.desc: SubscribeSyncResource
645  * @tc.type: FUNC
646  * @tc.require: issueI9C9JN
647  * @tc.author:luolu
648  */
649 HWTEST_F(PluginMgrTest, SubscribeSyncResource002, TestSize.Level0)
650 {
651     std::string pluginLib;
652     uint32_t resType = 0;
653     PluginMgr::GetInstance().SubscribeSyncResource(pluginLib, resType);
654     EXPECT_EQ(PluginMgr::GetInstance().resTypeLibSyncMap_.size(), 0);
655     PluginMgr::GetInstance().UnSubscribeSyncResource(pluginLib, resType);
656 }
657 
658 /**
659  * @tc.name: Plugin mgr test GetConfigReaderStr 001
660  * @tc.desc: Verify if can get ConfigReaderStr.
661  * @tc.type: FUNC
662  */
663 HWTEST_F(PluginMgrTest, GetConfigReaderStr001, TestSize.Level0)
664 {
665     auto configStr = pluginMgr_->GetConfigReaderStr();
666     EXPECT_TRUE(!configStr.empty());
667 }
668 
669 /**
670  * @tc.name: Plugin mgr test GetPluginSwitchStr 001
671  * @tc.desc: Verify if can get PluginSwitchStr.
672  * @tc.type: FUNC
673  */
674 HWTEST_F(PluginMgrTest, GetPluginSwitchStr001, TestSize.Level0)
675 {
676     auto switchStr = pluginMgr_->GetPluginSwitchStr();
677     EXPECT_TRUE(!switchStr.empty());
678 }
679 
680 /**
681  * @tc.name: Plugin mgr test ParseConfigReader 001
682  * @tc.desc: Verify if can Parse ConfigReader.
683  * @tc.type: FUNC
684  */
685 HWTEST_F(PluginMgrTest, ParseConfigReader001, TestSize.Level0)
686 {
687     pluginMgr_->Init();
688     auto configStrs = pluginMgr_->GetConfigReaderStr();
689     pluginMgr_->ParseConfigReader(configStrs);
690     EXPECT_TRUE(pluginMgr_->configReader_ != nullptr);
691 }
692 
693 /**
694  * @tc.name: Plugin mgr test ParsePluginSwitch 001
695  * @tc.desc: Verify if can Parse PluginSwitch.
696  * @tc.type: FUNC
697  */
698 HWTEST_F(PluginMgrTest, ParsePluginSwitchr001, TestSize.Level0)
699 {
700     pluginMgr_->Init();
701     auto switchStrs = pluginMgr_->GetPluginSwitchStr();
702     pluginMgr_->ParsePluginSwitch(switchStrs);
703     EXPECT_TRUE(pluginMgr_->configReader_ != nullptr);
704 }
705 } // namespace ResourceSchedule
706 } // namespace OHOS
707