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 DispatchResource 001
307 * @tc.desc: Verify if can DispatchResource
308 * @tc.type: FUNC
309 * @tc.require: issueI8VZVN
310 * @tc.author:z30053169
311 */
312 HWTEST_F(PluginMgrTest, DispatchResource001, TestSize.Level1)
313 {
314 pluginMgr_->Init();
315 #ifndef RESOURCE_SCHEDULE_SERVICE_WITH_FFRT_ENABLE
316 if (pluginMgr_->dispatcher_ == nullptr) {
317 pluginMgr_->dispatcher_ = std::make_shared<AppExecFwk::EventHandler>(
318 AppExecFwk::EventRunner::Create("rssDispatcher"));
319 }
320 #endif
321 nlohmann::json payload;
322 auto data = std::make_shared<ResData>(ResType::RES_TYPE_APP_ABILITY_START,
323 ResType::AppStartType::APP_COLD_START, payload);
324 pluginMgr_->DispatchResource(data);
325 EXPECT_TRUE(true);
326 pluginMgr_->DispatchResource(nullptr);
327 SUCCEED();
328 }
329
330 /**
331 * @tc.name: Plugin mgr test DispatchResource 002
332 * @tc.desc: Verify if can DispatchResource
333 * @tc.type: FUNC
334 * @tc.require: issueI8VZVN
335 * @tc.author:z30053169
336 */
337 HWTEST_F(PluginMgrTest, DispatchResource002, TestSize.Level1)
338 {
339 #ifndef RESOURCE_SCHEDULE_SERVICE_WITH_FFRT_ENABLE
340 if (PluginMgr::GetInstance().dispatcher_ == nullptr) {
341 PluginMgr::GetInstance().dispatcher_ = std::make_shared<AppExecFwk::EventHandler>(
342 AppExecFwk::EventRunner::Create("rssDispatcher"));
343 }
344 #endif
345 nlohmann::json payload;
346 auto data = std::make_shared<ResData>(ResType::RES_TYPE_APP_ABILITY_START,
347 ResType::AppStartType::APP_COLD_START, payload);
348 PluginMgr::GetInstance().SubscribeResource("", 0);
349 SUCCEED();
350 PluginMgr::GetInstance().SubscribeResource("test", ResType::RES_TYPE_APP_ABILITY_START);
351 SUCCEED();
352 PluginMgr::GetInstance().DispatchResource(data);
353 EXPECT_TRUE(true);
354 PluginMgr::GetInstance().UnSubscribeResource("", 0);
355 SUCCEED();
356 }
357
358 /**
359 * @tc.name: Plugin mgr test SubscribeResource 001
360 * @tc.desc: Verify if can stop success.
361 * @tc.type: FUNC
362 * @tc.require: issueI798UT
363 * @tc.author:xukuan
364 */
365 HWTEST_F(PluginMgrTest, SubscribeResource001, TestSize.Level1)
366 {
367 pluginMgr_->Init();
368 pluginMgr_->SubscribeResource(LIB_NAME, ResType::RES_TYPE_SCREEN_STATUS);
369 auto iter = pluginMgr_->resTypeLibMap_.find(ResType::RES_TYPE_SCREEN_STATUS);
370 string libName = iter->second.back();
371 EXPECT_EQ(libName.compare(LIB_NAME), 0);
372 }
373
374 /**
375 * @tc.name: Plugin mgr test Dump 001
376 * @tc.desc: Verify if dump commands is success.
377 * @tc.type: FUNC
378 * @tc.require: issueI5WWV3
379 * @tc.author:lice
380 */
381 HWTEST_F(PluginMgrTest, Dump001, TestSize.Level1)
382 {
383 std::string res;
384 pluginMgr_->Init();
385 pluginMgr_->DumpAllPlugin(res);
386 EXPECT_TRUE(!res.empty());
387 res = "";
388
389 pluginMgr_->LoadPlugin();
390 pluginMgr_->DumpHelpFromPlugin(res);
391 EXPECT_TRUE(res.empty());
392 res = "";
393
394 std::vector<std::string> args;
395 pluginMgr_->DumpOnePlugin(res, LIB_NAME, args);
396 EXPECT_TRUE(!res.empty());
397 res = "";
398
399 args.emplace_back("-h");
400 pluginMgr_->DumpOnePlugin(res, LIB_NAME, args);
401 EXPECT_TRUE(!res.empty());
402 res = "";
403 pluginMgr_->DumpAllPluginConfig(res);
404 EXPECT_TRUE(!res.empty());
405 }
406
407 /**
408 * @tc.name: Plugin mgr test RepairPlugin 001
409 * @tc.desc: Verify if RepairPlugin is success.
410 * @tc.type: FUNC
411 * @tc.require: issueI5WWV3
412 * @tc.author:lice
413 */
414 HWTEST_F(PluginMgrTest, RepairPlugin001, TestSize.Level1)
415 {
416 PluginLib libInfo = pluginMgr_->pluginLibMap_.find(LIB_NAME)->second;
417 pluginMgr_->RepairPlugin(Clock::now(), LIB_NAME, libInfo);
418 EXPECT_TRUE(true);
419 }
420
421 /**
422 * @tc.name: Plugin mgr test UnSubscribeResource 001
423 * @tc.desc: Verify if can stop success.
424 * @tc.type: FUNC
425 * @tc.require: issueI798UT
426 * @tc.author:xukuan
427 */
428 HWTEST_F(PluginMgrTest, UnSubscribeResource001, TestSize.Level1)
429 {
430 pluginMgr_->UnSubscribeResource(LIB_NAME, ResType::RES_TYPE_SCREEN_STATUS);
431 auto iter = pluginMgr_->resTypeLibMap_.find(ResType::RES_TYPE_SCREEN_STATUS);
432 EXPECT_TRUE(iter == pluginMgr_->resTypeLibMap_.end());
433 }
434
435 /*
436 * @tc.name: SocPerfSubTest_DispatchResource_001
437 * @tc.desc: DispatchResource Plugin
438 * @tc.type FUNC
439 * @tc.author:zoujie
440 * @tc.require: issueI5VWUI
441 */
442 HWTEST_F(PluginMgrTest, PluginMgrTest_DispatchResource_001, TestSize.Level1)
443 {
444 nlohmann::json payload;
445 auto data = std::make_shared<ResData>(ResType::RES_TYPE_APP_ABILITY_START,
446 ResType::AppStartType::APP_COLD_START, payload);
447 /* Init */
448 SocPerfPlugin::GetInstance().Init();
449 /* HandleAppAbilityStart */
450 SocPerfPlugin::GetInstance().DispatchResource(data);
451
452 data->value = ResType::AppStartType::APP_WARM_START;
453 SocPerfPlugin::GetInstance().DispatchResource(data);
454
455 /* HandleWindowFocus */
456 data->resType = ResType::RES_TYPE_WINDOW_FOCUS;
457 data->value = ResType::WindowFocusStatus::WINDOW_FOCUS;
458 SocPerfPlugin::GetInstance().DispatchResource(data);
459
460 /* HandleEventClick */
461 data->resType = ResType::RES_TYPE_CLICK_RECOGNIZE;
462 data->value = ResType::ClickEventType::TOUCH_EVENT_DOWN;
463 SocPerfPlugin::GetInstance().DispatchResource(data);
464 data->value = ResType::ClickEventType::TOUCH_EVENT_UP;
465 SocPerfPlugin::GetInstance().DispatchResource(data);
466 data->value = ResType::ClickEventType::CLICK_EVENT;
467 SocPerfPlugin::GetInstance().DispatchResource(data);
468
469 /* HandlePushPage */
470 data->resType = ResType::RES_TYPE_PUSH_PAGE;
471 data->value = ResType::PushPageType::PUSH_PAGE_START;
472 SocPerfPlugin::GetInstance().DispatchResource(data);
473 data->value = ResType::PushPageType::PUSH_PAGE_COMPLETE;
474 SocPerfPlugin::GetInstance().DispatchResource(data);
475
476 /* HandlePopPage */
477 data->resType = ResType::RES_TYPE_POP_PAGE;
478 data->value = 0;
479 SocPerfPlugin::GetInstance().DispatchResource(data);
480
481 /* HandleEventSlide */
482 data->resType = ResType::RES_TYPE_SLIDE_RECOGNIZE;
483 data->value = ResType::SlideEventStatus::SLIDE_EVENT_ON;
484 SocPerfPlugin::GetInstance().DispatchResource(data);
485 data->value = ResType::SlideEventStatus::SLIDE_EVENT_OFF;
486 SocPerfPlugin::GetInstance().DispatchResource(data);
487
488 /* HandleEventWebGesture */
489 data->resType = ResType::RES_TYPE_WEB_GESTURE;
490 data->value = 0;
491 SocPerfPlugin::GetInstance().DispatchResource(data);
492
493 /* HandleResizeWindow */
494 data->resType = ResType::RES_TYPE_RESIZE_WINDOW;
495 data->value = ResType::WindowResizeType::WINDOW_RESIZING;
496 SocPerfPlugin::GetInstance().DispatchResource(data);
497 data->value = ResType::WindowResizeType::WINDOW_RESIZE_STOP;
498 SocPerfPlugin::GetInstance().DispatchResource(data);
499
500 /* HandleMoveWindow */
501 data->resType = ResType::RES_TYPE_MOVE_WINDOW;
502 data->value = ResType::WindowMoveType::WINDOW_MOVING;
503 SocPerfPlugin::GetInstance().DispatchResource(data);
504 data->value = ResType::WindowMoveType::WINDOW_MOVE_STOP;
505 SocPerfPlugin::GetInstance().DispatchResource(data);
506
507 /* DeInit */
508 SocPerfPlugin::GetInstance().Disable();
509 EXPECT_TRUE(SocPerfPlugin::GetInstance().handle_ == nullptr);
510 }
511
512 /*
513 * @tc.name: SocPerfSubTest_DispatchResource_002
514 * @tc.desc: DispatchResource Plugin
515 * @tc.type FUNC
516 * @tc.author:qiunaiguang
517 * @tc.require: issueI6I9QS
518 */
519 HWTEST_F(PluginMgrTest, PluginMgrTest_DispatchResource_002, Function | MediumTest | Level0)
520 {
521 /* Init */
522 SocPerfPlugin::GetInstance().Init();
523
524 nlohmann::json payload;
525 std::shared_ptr<ResData> resData =
526 std::make_shared<ResData>(ResType::RES_TYPE_LOAD_PAGE, ResType::LoadPageType::LOAD_PAGE_START, payload);
527 SocPerfPlugin::GetInstance().HandleLoadPage(resData);
528 resData->value = ResType::LoadPageType::LOAD_PAGE_COMPLETE;
529 SocPerfPlugin::GetInstance().HandleLoadPage(resData);
530 /* DeInit */
531 SocPerfPlugin::GetInstance().Disable();
532 EXPECT_TRUE(SocPerfPlugin::GetInstance().handle_ == nullptr);
533 }
534
535 /*
536 * @tc.name: SocPerfSubTest_DispatchResource_003
537 * @tc.desc: DispatchResource Plugin
538 * @tc.type FUNC
539 * @tc.author:qiunaiguang
540 * @tc.require: issueI6I9QS
541 */
542 HWTEST_F(PluginMgrTest, PluginMgrTest_DispatchResource_003, Function | MediumTest | Level0)
543 {
544 /* Init */
545 SocPerfPlugin::GetInstance().Init();
546 nlohmann::json payload;
547 std::shared_ptr<ResData> resData =
548 std::make_shared<ResData>(ResType::RES_TYPE_SHOW_REMOTE_ANIMATION,
549 ResType::ShowRemoteAnimationStatus::ANIMATION_BEGIN, payload);
550 SocPerfPlugin::GetInstance().HandleRemoteAnimation(resData);
551
552 resData->value = ResType::ShowRemoteAnimationStatus::ANIMATION_END;
553 SocPerfPlugin::GetInstance().HandleRemoteAnimation(resData);
554 /* DeInit */
555 SocPerfPlugin::GetInstance().Disable();
556 EXPECT_TRUE(SocPerfPlugin::GetInstance().handle_ == nullptr);
557 }
558
559 /*
560 * @tc.name: SocPerfSubTest_DispatchResource_004
561 * @tc.desc: DispatchResource Plugin
562 * @tc.type FUNC
563 * @tc.author:qiunaiguang
564 * @tc.require: issueI6I9QS
565 */
566 HWTEST_F(PluginMgrTest, PluginMgrTest_DispatchResource_004, Function | MediumTest | Level0)
567 {
568 /* Init */
569 SocPerfPlugin::GetInstance().Init();
570 SocPerfPlugin::GetInstance().InitFeatureSwitch("socperf_on_demand");
571 SocPerfPlugin::GetInstance().InitFeatureSwitch("test");
572 /* DeInit */
573 SocPerfPlugin::GetInstance().Disable();
574 EXPECT_TRUE(SocPerfPlugin::GetInstance().handle_ == nullptr);
575 }
576
577 /*
578 * @tc.name: SocPerfSubTest_DispatchResource_005
579 * @tc.desc: DispatchResource Plugin
580 * @tc.type FUNC
581 * @tc.author:fangdinggeng
582 * @tc.require: issueI5VWUI
583 */
584 HWTEST_F(PluginMgrTest, PluginMgrTest_DispatchResource_005, TestSize.Level1)
585 {
586 nlohmann::json payload;
587 auto data = std::make_shared<ResData>(ResType::RES_TYPE_DEVICE_MODE_STATUS,
588 ResType::DeviceModeStatus::MODE_ENTER, payload);
589 /* Init */
590 SocPerfPlugin::GetInstance().Init();
591
592 /* HandleDeviceModeStatusChange */
593 data->payload["deviceMode"] = "test";
594 SocPerfPlugin::GetInstance().DispatchResource(data);
595 data->value = ResType::DeviceModeStatus::MODE_QUIT;
596 SocPerfPlugin::GetInstance().DispatchResource(data);
597
598 /* DeInit */
599 SocPerfPlugin::GetInstance().Disable();
600 EXPECT_TRUE(SocPerfPlugin::GetInstance().handle_ == nullptr);
601 }
602
603 /**
604 * @tc.name: Plugin mgr test DumPluginInfoAppend_001
605 * @tc.desc: test the interface DumpluginInfoAppend
606 * @tc.type: FUNC
607 * @tc.require: issueI8VZVN
608 * @tc.author:z30053169
609 */
610 HWTEST_F(PluginMgrTest, DumPluginInfoAppend_001, TestSize.Level1)
611 {
612 string result;
613 PluginInfo info;
614 info.switchOn = false;
615 PluginMgr::GetInstance().DumpPluginInfoAppend(result, info);
616 EXPECT_FALSE(result.empty());
617 }
618
619 /**
620 * @tc.name: Plugin mgr test DispatchResource 003
621 * @tc.desc: test the interface DispatchResource
622 * @tc.type: FUNC
623 * @tc.require: issueI8VZVN
624 * @tc.author:z30053169
625 */
626 HWTEST_F(PluginMgrTest, DispatchResource003, TestSize.Level1)
627 {
628 nlohmann::json payload;
629 #ifndef RESOURCE_SCHEDULE_SERVICE_WITH_FFRT_ENABLE
630 PluginMgr::GetInstance().dispatcher_ = nullptr;
631 #endif
632 auto data = std::make_shared<ResData>(ResType::RES_TYPE_APP_ABILITY_START,
633 ResType::AppStartType::APP_COLD_START, payload);
634 PluginMgr::GetInstance().UnSubscribeResource("test", ResType::RES_TYPE_APP_ABILITY_START);
635 PluginMgr::GetInstance().DispatchResource(data);
636 EXPECT_TRUE(true);
637 }
638
639 /**
640 * @tc.name: Plugin mgr test DispatchResource 004
641 * @tc.desc: Verify if can DispatchResource
642 * @tc.type: FUNC
643 * @tc.require: issueI91HSR
644 * @tc.author:baiheng
645 */
646 HWTEST_F(PluginMgrTest, DispatchResource004, TestSize.Level1)
647 {
648 nlohmann::json payload;
649 auto dataNoExtType = std::make_shared<ResData>(ResType::RES_TYPE_KEY_PERF_SCENE,
650 ResType::KeyPerfStatus::ENTER_SCENE, payload);
651 PluginMgr::GetInstance().SubscribeResource("test", 10000);
652 SUCCEED();
653 PluginMgr::GetInstance().DispatchResource(dataNoExtType);
654 EXPECT_TRUE(PluginMgr::GetInstance().resTypeLibMap_.size() == 1);
655 }
656
657 /**
658 * @tc.name: Plugin mgr test DispatchResource 005
659 * @tc.desc: Verify if can DispatchResource
660 * @tc.type: FUNC
661 * @tc.require: issueI91HSR
662 * @tc.author:baiheng
663 */
664 HWTEST_F(PluginMgrTest, DispatchResource005, TestSize.Level1)
665 {
666 nlohmann::json payload;
667 payload["extType"] = "10000";
668 auto dataWithExtType = std::make_shared<ResData>(ResType::RES_TYPE_KEY_PERF_SCENE,
669 ResType::KeyPerfStatus::ENTER_SCENE, payload);
670 PluginMgr::GetInstance().SubscribeResource("test", 10000);
671 SUCCEED();
672 PluginMgr::GetInstance().DispatchResource(dataWithExtType);
673 EXPECT_TRUE(PluginMgr::GetInstance().resTypeLibMap_.size() == 1);
674 }
675
676 /**
677 * @tc.name: Plugin mgr test GetPluginLib 001
678 * @tc.desc: Verify if can get pluginlib with wrong env.
679 * @tc.type: FUNC
680 * @tc.require: issueI9C9JN
681 * @tc.author:xiaoshun
682 */
683 HWTEST_F(PluginMgrTest, GetPluginLib001, TestSize.Level0)
684 {
685 std::shared_ptr<PluginLib> libInfoPtr = pluginMgr_->GetPluginLib("test");
686 EXPECT_TRUE(libInfoPtr == nullptr);
687 }
688
689 /**
690 * @tc.name: Plugin mgr test GetPluginLib 002
691 * @tc.desc: Verify if can get pluginlib
692 * @tc.type: FUNC
693 * @tc.require: issueI9C9JN
694 * @tc.author:xiaoshun
695 */
696 HWTEST_F(PluginMgrTest, GetPluginLib002, TestSize.Level0)
697 {
698 std::shared_ptr<PluginLib> libInfoPtr = pluginMgr_->GetPluginLib("libapp_preload_plugin.z.so");
699 EXPECT_TRUE(pluginMgr_->pluginLibMap_.find("libapp_preload_plugin.z.so") == pluginMgr_->pluginLibMap_.end() ?
700 libInfoPtr == nullptr : libInfoPtr != nullptr);
701 }
702
703 /**
704 * @tc.name: Plugin mgr test InnerTimeUtil 001
705 * @tc.desc: InnerTimeUtil
706 * @tc.type: FUNC
707 * @tc.require: issueI9C9JN
708 * @tc.author:luolu
709 */
710 HWTEST_F(PluginMgrTest, InnerTimeUtil001, TestSize.Level0)
711 {
712 PluginMgr::InnerTimeUtil innerTimeUtil("test1", "test2");
713 EXPECT_EQ(innerTimeUtil.functionName_, "test1");
714 EXPECT_EQ(innerTimeUtil.pluginName_, "test2");
715 }
716
717 /**
718 * @tc.name: Plugin mgr test LoadPlugin 001
719 * @tc.desc: LoadPlugin
720 * @tc.type: FUNC
721 * @tc.require: issueI9C9JN
722 * @tc.author:luolu
723 */
724 HWTEST_F(PluginMgrTest, LoadPlugin001, TestSize.Level0)
725 {
726 PluginMgr::GetInstance().LoadPlugin();
727 EXPECT_EQ(PluginMgr::GetInstance().pluginLibMap_.size(), 0);
728 }
729
730 /**
731 * @tc.name: Plugin mgr test SubscribeSyncResource 002
732 * @tc.desc: SubscribeSyncResource
733 * @tc.type: FUNC
734 * @tc.require: issueI9C9JN
735 * @tc.author:luolu
736 */
737 HWTEST_F(PluginMgrTest, SubscribeSyncResource002, TestSize.Level0)
738 {
739 std::string pluginLib;
740 uint32_t resType = 0;
741 PluginMgr::GetInstance().SubscribeSyncResource(pluginLib, resType);
742 EXPECT_EQ(PluginMgr::GetInstance().resTypeLibSyncMap_.size(), 0);
743 PluginMgr::GetInstance().UnSubscribeSyncResource(pluginLib, resType);
744 }
745
746 /**
747 * @tc.name: Plugin mgr test GetConfigReaderStr 001
748 * @tc.desc: Verify if can get ConfigReaderStr.
749 * @tc.type: FUNC
750 */
751 HWTEST_F(PluginMgrTest, GetConfigReaderStr001, TestSize.Level0)
752 {
753 auto configStr = pluginMgr_->GetConfigReaderStr();
754 EXPECT_TRUE(!configStr.empty());
755 }
756
757 /**
758 * @tc.name: Plugin mgr test GetPluginSwitchStr 001
759 * @tc.desc: Verify if can get PluginSwitchStr.
760 * @tc.type: FUNC
761 */
762 HWTEST_F(PluginMgrTest, GetPluginSwitchStr001, TestSize.Level0)
763 {
764 auto switchStr = pluginMgr_->GetPluginSwitchStr();
765 EXPECT_TRUE(!switchStr.empty());
766 }
767
768 /**
769 * @tc.name: Plugin mgr test ParseConfigReader 001
770 * @tc.desc: Verify if can Parse ConfigReader.
771 * @tc.type: FUNC
772 */
773 HWTEST_F(PluginMgrTest, ParseConfigReader001, TestSize.Level0)
774 {
775 pluginMgr_->Init();
776 auto configStrs = pluginMgr_->GetConfigReaderStr();
777 pluginMgr_->ParseConfigReader(configStrs);
778 EXPECT_TRUE(pluginMgr_->configReader_ != nullptr);
779 }
780
781 /**
782 * @tc.name: Plugin mgr test ParsePluginSwitch 001
783 * @tc.desc: Verify if can Parse PluginSwitch.
784 * @tc.type: FUNC
785 */
786 HWTEST_F(PluginMgrTest, ParsePluginSwitchr001, TestSize.Level0)
787 {
788 pluginMgr_->Init();
789 auto switchStrs = pluginMgr_->GetPluginSwitchStr();
790 pluginMgr_->ParsePluginSwitch(switchStrs);
791 EXPECT_TRUE(pluginMgr_->configReader_ != nullptr);
792 }
793 } // namespace ResourceSchedule
794 } // namespace OHOS
795