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