• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 <functional>
17 #include <gtest/gtest.h>
18 #define private public
19 #include "work_scheduler_service.h"
20 #include "work_status.h"
21 #include "work_bundle_group_change_callback.h"
22 #include "work_scheduler_connection.h"
23 #include "work_queue_event_handler.h"
24 #include "work_event_handler.h"
25 #include "conditions/battery_level_listener.h"
26 #include "common_event_manager.h"
27 #include "common_event_support.h"
28 #include "battery_info.h"
29 #include "conditions/battery_status_listener.h"
30 #include "conditions/charger_listener.h"
31 #include "event_publisher.h"
32 #include "accesstoken_kit.h"
33 #include "token_setproc.h"
34 
35 #ifdef DEVICE_USAGE_STATISTICS_ENABLE
36 #include "bundle_active_client.h"
37 #endif
38 #ifdef DEVICE_STANDBY_ENABLE
39 #include "standby_service_client.h"
40 #include "allow_type.h"
41 #endif
42 #ifdef RESOURCESCHEDULE_BGTASKMGR_ENABLE
43 #include "scheduler_bg_task_subscriber.h"
44 #include "background_task_mgr_helper.h"
45 #include "resource_type.h"
46 #endif
47 #include "work_sched_errors.h"
48 #include "work_sched_hilog.h"
49 
50 #ifdef DEVICE_STANDBY_ENABLE
51 namespace OHOS {
52 namespace DevStandbyMgr {
SubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber> & subscriber)53 ErrCode StandbyServiceClient::SubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber)
54 {
55     return ERR_OK;
56 }
57 }
58 }
59 #endif
60 
61 #ifdef RESOURCESCHEDULE_BGTASKMGR_ENABLE
62 namespace OHOS {
63 namespace BackgroundTaskMgr {
SubscribeBackgroundTask(const BackgroundTaskSubscriber & subscriber)64 ErrCode BackgroundTaskMgrHelper::SubscribeBackgroundTask(const BackgroundTaskSubscriber &subscriber)
65 {
66     return ERR_OK;
67 }
68 }
69 }
70 #endif
71 
72 #ifdef DEVICE_USAGE_STATISTICS_ENABLE
73 namespace OHOS {
74 namespace DeviceUsageStats {
RegisterAppGroupCallBack(const sptr<IAppGroupCallback> & observer)75 ErrCode BundleActiveClient::RegisterAppGroupCallBack(const sptr<IAppGroupCallback> &observer)
76 {
77     return ERR_OK;
78 }
79 }
80 }
81 #endif
82 
83 namespace OHOS {
84 namespace WorkScheduler {
IsBaseAbilityReady()85 bool WorkSchedulerService::IsBaseAbilityReady()
86 {
87     return true;
88 }
89 }
90 }
91 
DecStrongRef(void const * obj)92 void OHOS::RefBase::DecStrongRef(void const* obj) {}
93 
94 using namespace testing::ext;
95 namespace OHOS {
96 namespace WorkScheduler {
97 namespace {
98     static const std::string PUSH_SERVICE_NAME = "push_manager_service";
99     static const std::string BGTASK_SERVICE_NAME = "bgtaskmgr_service";
100 }
101 class WorkSchedulerServiceTest : public testing::Test {
102 public:
SetUpTestCase()103     static void SetUpTestCase() {}
TearDownTestCase()104     static void TearDownTestCase() {}
SetUp()105     void SetUp() {}
TearDown()106     void TearDown() {}
107     static std::shared_ptr<WorkSchedulerService> workSchedulerService_;
108 };
109 
GetNativeToken(const std::string & name)110 void GetNativeToken(const std::string &name)
111 {
112     auto tokenId = Security::AccessToken::AccessTokenKit::GetNativeTokenId(name);
113     SetSelfTokenID(tokenId);
114 }
115 
116 std::shared_ptr<WorkSchedulerService> WorkSchedulerServiceTest::workSchedulerService_ =
117     DelayedSingleton<WorkSchedulerService>::GetInstance();
118 
119 class MyWorkSchedulerService : public WorkSchedServiceStub {
StartWork(const WorkInfo & workInfo)120     int32_t StartWork(const WorkInfo& workInfo) { return 0; }
StopWork(const WorkInfo & workInfo)121     int32_t StopWork(const WorkInfo& workInfo) { return 0; }
StopAndCancelWork(const WorkInfo & workInfo)122     int32_t StopAndCancelWork(const WorkInfo& workInfo)  { return 0; }
StopAndClearWorks()123     int32_t StopAndClearWorks() { return 0; }
IsLastWorkTimeout(int32_t workId,bool & result)124     int32_t IsLastWorkTimeout(int32_t workId, bool &result) { return 0; }
ObtainAllWorks(std::vector<WorkInfo> & workInfos)125     int32_t ObtainAllWorks(std::vector<WorkInfo>& workInfos) { return 0; }
ObtainWorksByUidAndWorkIdForInner(int32_t uid,std::vector<WorkInfo> & workInfos,int32_t workId)126     int32_t ObtainWorksByUidAndWorkIdForInner(int32_t uid, std::vector<WorkInfo>& workInfos,
127         int32_t workId) { return 0; }
GetWorkStatus(int32_t workId,WorkInfo & workInfo)128     int32_t GetWorkStatus(int32_t workId, WorkInfo& workInfo) { return 0; }
GetAllRunningWorks(std::vector<WorkInfo> & workInfos)129     int32_t GetAllRunningWorks(std::vector<WorkInfo>& workInfos) { return 0; }
PauseRunningWorks(int32_t uid)130     int32_t PauseRunningWorks(int32_t uid) {return 0; }
ResumePausedWorks(int32_t uid)131     int32_t ResumePausedWorks(int32_t uid) {return 0; }
SetWorkSchedulerConfig(const std::string & configData,int32_t sourceType)132     int32_t SetWorkSchedulerConfig(const std::string &configData, int32_t sourceType) { return 0; }
StopWorkForSA(int32_t saId)133     int32_t StopWorkForSA(int32_t saId) { return 0; }
StartWorkForInner(const WorkInfo & workInfo)134     int32_t StartWorkForInner(const WorkInfo& workInfo) { return 0; }
StopWorkForInner(const WorkInfo & workInfo,bool needCancel)135     int32_t StopWorkForInner(const WorkInfo& workInfo, bool needCancel) { return 0; }
136 };
137 /**
138  * @tc.name: onStart_001
139  * @tc.desc: Test WorkSchedulerService OnStart.
140  * @tc.type: FUNC
141  * @tc.require: I8ZDJI
142  */
143 HWTEST_F(WorkSchedulerServiceTest, onStart_001, TestSize.Level0)
144 {
145     workSchedulerService_->OnStart();
146     EXPECT_NE(workSchedulerService_, nullptr);
147 }
148 
149 /**
150  * @tc.name: startWork_001
151  * @tc.desc: Test WorkSchedulerService startWork.
152  * @tc.type: FUNC
153  * @tc.require: I8F08T
154  */
155 HWTEST_F(WorkSchedulerServiceTest, startWork_001, TestSize.Level0)
156 {
157     int32_t ret;
158 
159     workSchedulerService_->ready_ = false;
160     WorkInfo workinfo = WorkInfo();
161     ret = workSchedulerService_->StartWork(workinfo);
162     EXPECT_EQ(ret, E_SERVICE_NOT_READY);
163 
164     workSchedulerService_->ready_ = true;
165     ret = workSchedulerService_->StartWork(workinfo);
166     EXPECT_EQ(ret, E_CHECK_WORKINFO_FAILED);
167 
168     workSchedulerService_->checkBundle_ = false;
169     ret = workSchedulerService_->StartWork(workinfo);
170     EXPECT_EQ(ret, E_REPEAT_CYCLE_TIME_ERR);
171 
172     workinfo.RequestStorageLevel(WorkCondition::Storage::STORAGE_LEVEL_LOW_OR_OKAY);
173     ret = workSchedulerService_->StartWork(workinfo);
174     EXPECT_EQ(ret, 0);
175     ret = workSchedulerService_->StartWork(workinfo);
176     EXPECT_EQ(ret, E_ADD_REPEAT_WORK_ERR);
177 }
178 
179 /**
180  * @tc.name: stopWork_001
181  * @tc.desc: Test WorkSchedulerService stopWork.
182  * @tc.type: FUNC
183  * @tc.require: I8F08T
184  */
185 HWTEST_F(WorkSchedulerServiceTest, stopWork_001, TestSize.Level0)
186 {
187     int32_t ret;
188 
189     WS_HILOGI("WorkSchedulerServiceTest.stopWork_001 begin");
190     workSchedulerService_->ready_ = false;
191     workSchedulerService_->checkBundle_ = true;
192     WorkInfo workinfo = WorkInfo();
193     ret = workSchedulerService_->StopWork(workinfo);
194     EXPECT_EQ(ret, E_SERVICE_NOT_READY);
195 
196     workSchedulerService_->ready_ = true;
197     ret = workSchedulerService_->StopWork(workinfo);
198     EXPECT_EQ(ret, E_CHECK_WORKINFO_FAILED);
199 
200     workSchedulerService_->checkBundle_ = false;
201     ret = workSchedulerService_->StopWork(workinfo);
202     EXPECT_EQ(ret, 0);
203     WS_HILOGI("WorkSchedulerServiceTest.stopWork_001 end");
204 }
205 
206 /**
207  * @tc.name: StopAndCancelWork_001
208  * @tc.desc: Test WorkSchedulerService StopAndCancelWork.
209  * @tc.type: FUNC
210  * @tc.require: I8F08T
211  */
212 HWTEST_F(WorkSchedulerServiceTest, StopAndCancelWork_001, TestSize.Level0)
213 {
214     int32_t ret;
215 
216     WS_HILOGI("WorkSchedulerServiceTest.StopAndCancelWork_001 begin");
217     workSchedulerService_->ready_ = false;
218     workSchedulerService_->checkBundle_ = true;
219     WorkInfo workinfo = WorkInfo();
220     ret = workSchedulerService_->StopAndCancelWork(workinfo);
221     EXPECT_EQ(ret, E_SERVICE_NOT_READY);
222 
223     workSchedulerService_->ready_ = true;
224     ret = workSchedulerService_->StopAndCancelWork(workinfo);
225     EXPECT_EQ(ret, E_CHECK_WORKINFO_FAILED);
226 
227     workSchedulerService_->checkBundle_ = false;
228     ret = workSchedulerService_->StopAndCancelWork(workinfo);
229     EXPECT_EQ(ret, 0);
230     WS_HILOGI("WorkSchedulerServiceTest.StopAndCancelWork_001 end");
231 }
232 
233 /**
234  * @tc.name: StopAndClearWorks_001
235  * @tc.desc: Test WorkSchedulerService StopAndClearWorks.
236  * @tc.type: FUNC
237  * @tc.require: I8F08T
238  */
239 HWTEST_F(WorkSchedulerServiceTest, StopAndClearWorks_001, TestSize.Level0)
240 {
241     int32_t ret;
242 
243     WS_HILOGI("WorkSchedulerServiceTest.StopAndClearWorks_001 begin");
244     workSchedulerService_->ready_ = false;
245     workSchedulerService_->checkBundle_ = true;
246     ret = workSchedulerService_->StopAndClearWorks();
247     EXPECT_EQ(ret, E_SERVICE_NOT_READY);
248 
249     workSchedulerService_->ready_ = true;
250     ret = workSchedulerService_->StopAndClearWorks();
251     EXPECT_EQ(ret, 0);
252     WS_HILOGI("WorkSchedulerServiceTest.StopAndClearWorks_001 end");
253 }
254 
255 /**
256  * @tc.name: IsLastWorkTimeout_001
257  * @tc.desc: Test WorkSchedulerService IsLastWorkTimeout.
258  * @tc.type: FUNC
259  * @tc.require: I8F08T
260  */
261 HWTEST_F(WorkSchedulerServiceTest, IsLastWorkTimeout_001, TestSize.Level0)
262 {
263     bool result;
264     auto ret = workSchedulerService_->IsLastWorkTimeout(1, result);
265     EXPECT_EQ(ret, E_WORK_NOT_EXIST_FAILED);
266 }
267 
268 /**
269  * @tc.name: ObtainAllWorks_001
270  * @tc.desc: Test WorkSchedulerService ObtainAllWorks.
271  * @tc.type: FUNC
272  * @tc.require: IA4HTC
273  */
274 HWTEST_F(WorkSchedulerServiceTest, ObtainAllWorks_001, TestSize.Level0)
275 {
276     std::vector<WorkInfo> workInfos;
277     auto ret = workSchedulerService_->ObtainAllWorks(workInfos);
278     EXPECT_EQ(ret, 0);
279 }
280 
281 /**
282  * @tc.name: GetWorkStatus_001
283  * @tc.desc: Test WorkSchedulerService GetWorkStatus.
284  * @tc.type: FUNC
285  * @tc.require: IA4HTC
286  */
287 HWTEST_F(WorkSchedulerServiceTest, GetWorkStatus_001, TestSize.Level0)
288 {
289     WorkInfo workInfo;
290     int32_t workId = 0;
291     auto ret = workSchedulerService_->GetWorkStatus(workId, workInfo);
292     EXPECT_EQ(ret, E_WORK_NOT_EXIST_FAILED);
293 }
294 
295 /**
296  * @tc.name: ObtainWorksByUidAndWorkIdForInner_001
297  * @tc.desc: Test WorkSchedulerService ObtainWorksByUidAndWorkIdForInner.
298  * @tc.type: FUNC
299  * @tc.require: IA4HTC
300  */
301 HWTEST_F(WorkSchedulerServiceTest, ObtainWorksByUidAndWorkIdForInner_001, TestSize.Level0)
302 {
303     std::vector<WorkInfo> workInfos;
304     int32_t uid = 1;
305     int32_t workId = 1;
306     workSchedulerService_->ready_ = false;
307     int32_t ret = -1;
308     ret = workSchedulerService_->ObtainWorksByUidAndWorkIdForInner(uid, workInfos, workId);
309     EXPECT_EQ(ret, E_SERVICE_NOT_READY);
310 
311     workSchedulerService_->ready_ = true;
312     ret = workSchedulerService_->ObtainWorksByUidAndWorkIdForInner(uid, workInfos, workId);
313     EXPECT_EQ(ret, E_WORK_NOT_EXIST_FAILED);
314 
315     workId = -1;
316     ret = workSchedulerService_->ObtainWorksByUidAndWorkIdForInner(uid, workInfos, workId);
317     EXPECT_EQ(ret, ERR_OK);
318 }
319 
320 /**
321  * @tc.name: GetAllRunningWorks_001
322  * @tc.desc: Test WorkSchedulerService GetAllRunningWorks.
323  * @tc.type: FUNC
324  * @tc.require: I8F08T
325  */
326 HWTEST_F(WorkSchedulerServiceTest, GetAllRunningWorks_001, TestSize.Level0)
327 {
328     std::vector<WorkInfo> workInfos;
329 
330     auto ret = workSchedulerService_->GetAllRunningWorks(workInfos);
331     EXPECT_EQ(ret, E_INVALID_PROCESS_NAME);
332 }
333 
334 /**
335  * @tc.name: Datashare_001
336  * @tc.desc: Test Datashare
337  * @tc.type: FUNC
338  * @tc.require: I8ZDJI
339  */
340 HWTEST_F(WorkSchedulerServiceTest, Datashare_001, TestSize.Level1)
341 {
342     WS_HILOGI("====== test begin ====== ");
343     std::vector<std::string> argsInStr;
344     argsInStr.push_back("-k");
345     argsInStr.push_back("settings.power.suspend_sources");
346     std::string result;
347     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
348     WS_HILOGI("%{public}s", result.c_str());
349     EXPECT_EQ(result.empty(), 0);
350     WS_HILOGI("====== test end ====== ");
351 }
352 
353 HWTEST_F(WorkSchedulerServiceTest, ListenerStart_001, TestSize.Level1)
354 {
355     WS_HILOGI("====== ListenerStart_001 begin====== ");
356     for (auto pair : workSchedulerService_->workQueueManager_->listenerMap_)
357     {
358         pair.second->Start();
359     }
360     std::vector<std::pair<string, string>> infos = {
361         {"event", "info"},
362         {"network", "wifi"},
363         {"network", "disconnect"},
364         {"network", "invalid"},
365         {"charging", "usb"},
366         {"charging", "ac"},
367         {"charging", "wireless"},
368         {"charging", "none"},
369         {"charging", "invalid"},
370         {"storage", "low"},
371         {"storage", "ok"},
372         {"storage", "invalid"},
373         {"batteryStatus", "low"},
374         {"batteryStatus", "ok"},
375         {"batteryStatus", "invalid"},
376     };
377     EventPublisher eventPublisher;
378     for (auto it : infos) {
379         std::string result;
380         std::string eventType = it.first;
381         std::string eventValue = it.second;
382         eventPublisher.Dump(result, eventType, eventValue);
383         WS_HILOGI("%{public}s", result.c_str());
384         EXPECT_EQ(!result.empty(), true);
385     }
386     WS_HILOGI("====== ListenerStart_001 end ====== ");
387 }
388 
389 HWTEST_F(WorkSchedulerServiceTest, Dump_001, TestSize.Level1)
390 {
391     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_001 begin ====== ");
392     std::vector<std::string> argsInStr;
393     std::string result;
394     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
395     WS_HILOGI("%{public}s", result.c_str());
396 
397     argsInStr.clear();
398     result.clear();
399     argsInStr.push_back("-h");
400     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
401     WS_HILOGI("%{public}s", result.c_str());
402 
403     result.clear();
404     argsInStr.clear();
405     argsInStr.push_back("-a");
406     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
407     WS_HILOGI("%{public}s", result.c_str());
408 
409     result.clear();
410     argsInStr.clear();
411     argsInStr.push_back("-x");
412     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
413     WS_HILOGI("%{public}s", result.c_str());
414 
415     result.clear();
416     argsInStr.clear();
417     argsInStr.push_back("-memory");
418     argsInStr.push_back("100");
419     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
420     WS_HILOGI("%{public}s", result.c_str());
421 
422     result.clear();
423     argsInStr.clear();
424     argsInStr.push_back("-watchdog_time");
425     argsInStr.push_back("100");
426     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
427     EXPECT_FALSE(result.empty());
428     WS_HILOGI("%{public}s", result.c_str());
429     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_001 end ====== ");
430 }
431 
432 HWTEST_F(WorkSchedulerServiceTest, Dump_002, TestSize.Level1)
433 {
434     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_002 begin ====== ");
435     std::vector<std::string> argsInStr;
436     std::string result;
437     argsInStr.push_back("-repeat_time_min");
438     argsInStr.push_back("100");
439     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
440     WS_HILOGI("%{public}s", result.c_str());
441 
442     result.clear();
443     argsInStr.clear();
444     argsInStr.push_back("-min_interval");
445     argsInStr.push_back("100");
446     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
447     WS_HILOGI("%{public}s", result.c_str());
448 
449     result.clear();
450     argsInStr.clear();
451     argsInStr.push_back("-test");
452     argsInStr.push_back("100");
453     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
454     WS_HILOGI("%{public}s", result.c_str());
455     EXPECT_EQ(result.empty(), false);
456     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_002 end ====== ");
457 }
458 
459 HWTEST_F(WorkSchedulerServiceTest, Dump_003, TestSize.Level1)
460 {
461     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_003 begin ====== ");
462     std::vector<std::string> argsInStr;
463     std::string result;
464 
465     argsInStr.clear();
466     result.clear();
467     argsInStr.push_back("-d");
468     argsInStr.push_back("storage");
469     argsInStr.push_back("ok");
470     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
471     WS_HILOGI("%{public}s", result.c_str());
472 
473     argsInStr.clear();
474     result.clear();
475     argsInStr.push_back("-t");
476     argsInStr.push_back("bundlename");
477     argsInStr.push_back("abilityname");
478     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
479     WS_HILOGI("%{public}s", result.c_str());
480 
481     WorkInfo workinfo = WorkInfo();
482     result.clear();
483     workinfo.RequestStorageLevel(WorkCondition::Storage::STORAGE_LEVEL_LOW_OR_OKAY);
484     workinfo.RefreshUid(2);
485     workinfo.SetElement("bundlename", "abilityname");
486     workSchedulerService_->AddWorkInner(workinfo);
487     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
488     EXPECT_TRUE(result.empty());
489     WS_HILOGI("%{public}s", result.c_str());
490     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_003 end ====== ");
491 }
492 
493 HWTEST_F(WorkSchedulerServiceTest, Dump_004, TestSize.Level1)
494 {
495     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_004 begin ====== ");
496     std::vector<std::string> argsInStr;
497     std::string result;
498     argsInStr.push_back("-d");
499     argsInStr.push_back("storage");
500     argsInStr.push_back("ok");
501     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
502     WS_HILOGI("%{public}s", result.c_str());
503 
504     argsInStr.clear();
505     argsInStr.push_back("arg0");
506     argsInStr.push_back("arg1");
507     argsInStr.push_back("arg2");
508     argsInStr.push_back("arg3");
509     argsInStr.push_back("arg4");
510     result.clear();
511     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
512     WS_HILOGI("%{public}s", result.c_str());
513     EXPECT_EQ(result.empty(), false);
514     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_004 end ====== ");
515 }
516 
517 /**
518  * @tc.name: Dump_005
519  * @tc.desc: Test WorkSchedulerService Dump.
520  * @tc.type: FUNC
521  * @tc.require: I9RYLE
522  */
523 HWTEST_F(WorkSchedulerServiceTest, Dump_005, TestSize.Level1)
524 {
525     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_005 begin ====== ");
526     std::vector<std::string> argsInStr;
527     std::string result;
528     argsInStr.push_back("-count");
529     argsInStr.push_back("1");
530     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
531     WS_HILOGI("%{public}s", result.c_str());
532     EXPECT_EQ(result.empty(), false);
533     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_005 end ====== ");
534 }
535 
536 /**
537  * @tc.name: Dump_006
538  * @tc.desc: Test WorkSchedulerService Dump.
539  * @tc.type: FUNC
540  * @tc.require: IAHY0B
541  */
542 HWTEST_F(WorkSchedulerServiceTest, Dump_006, TestSize.Level1)
543 {
544     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_006 begin ====== ");
545     std::vector<std::string> argsInStr;
546     std::string result;
547     argsInStr.push_back("-s");
548     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
549     WS_HILOGI("%{public}s", result.c_str());
550     EXPECT_FALSE(result.empty());
551 
552     argsInStr.clear();
553     result.clear();
554     argsInStr.push_back("-s");
555     argsInStr.push_back("-1");
556     argsInStr.push_back("-1");
557     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
558     WS_HILOGI("%{public}s", result.c_str());
559     EXPECT_FALSE(result.empty());
560 
561     argsInStr.clear();
562     result.clear();
563     argsInStr.push_back("-s");
564     argsInStr.push_back("1");
565     argsInStr.push_back("200000");
566     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
567     WS_HILOGI("%{public}s", result.c_str());
568     EXPECT_FALSE(result.empty());
569 
570     argsInStr.clear();
571     result.clear();
572     WorkInfo workinfo = WorkInfo();
573     workinfo.uid_ = 202000;
574     workinfo.workId_ = 1;
575     workinfo.saId_ = 1000;
576     workinfo.residentSa_ = true;
577     workSchedulerService_->AddWorkInner(workinfo);
578     argsInStr.push_back("-s");
579     argsInStr.push_back("1000");
580     argsInStr.push_back("202000");
581     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
582     WS_HILOGI("%{public}s", result.c_str());
583     EXPECT_FALSE(result.empty());
584     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_006 end ====== ");
585 }
586 
587 /**
588  * @tc.name: Dump_007
589  * @tc.desc: Test WorkSchedulerService Dump.
590  * @tc.type: FUNC
591  * @tc.require: IAJSVG
592  */
593 HWTEST_F(WorkSchedulerServiceTest, Dump_007, TestSize.Level1)
594 {
595     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_007 begin ====== ");
596     std::vector<std::string> argsInStr;
597     std::string result;
598     argsInStr.push_back("-x");
599     argsInStr.push_back("1");
600     argsInStr.push_back("1");
601     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
602     WS_HILOGI("%{public}s", result.c_str());
603     EXPECT_EQ(result.empty(), false);
604 
605     argsInStr.clear();
606     result.clear();
607     argsInStr.push_back("-x");
608     argsInStr.push_back("1");
609     argsInStr.push_back("p");
610     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
611     WS_HILOGI("%{public}s", result.c_str());
612     EXPECT_EQ(result.empty(), false);
613 
614     argsInStr.clear();
615     result.clear();
616     argsInStr.push_back("-x");
617     argsInStr.push_back("1");
618     argsInStr.push_back("r");
619     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
620     WS_HILOGI("%{public}s", result.c_str());
621     EXPECT_EQ(result.empty(), false);
622 
623     argsInStr.clear();
624     result.clear();
625     argsInStr.push_back("-cpu");
626     argsInStr.push_back("1");
627     workSchedulerService_->DumpProcessForEngMode(argsInStr, result);
628     WS_HILOGI("%{public}s", result.c_str());
629     EXPECT_EQ(result.empty(), false);
630     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_007 end ====== ");
631 }
632 
633 /**
634  * @tc.name: Dump_008
635  * @tc.desc: Test WorkSchedulerService Dump.
636  * @tc.type: FUNC
637  * @tc.require: IAJSVG
638  */
639 HWTEST_F(WorkSchedulerServiceTest, Dump_008, TestSize.Level1)
640 {
641     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_008 begin ====== ");
642     std::vector<std::string> argsInStr;
643     std::string result;
644     argsInStr.push_back("-t");
645     argsInStr.push_back("bundlename");
646     argsInStr.push_back("abilityname");
647     workSchedulerService_->DumpProcessForUserMode(argsInStr, result);
648     EXPECT_EQ(result.empty(), true);
649     WS_HILOGI("====== WorkSchedulerServiceTest.Dump_008 end ====== ");
650 }
651 
652 HWTEST_F(WorkSchedulerServiceTest, WorkStandbyStateChangeCallbackTest_001, TestSize.Level1)
653 {
654     WS_HILOGI("====== WorkSchedulerServiceTest.WorkStandbyStateChangeCallbackTest_001 begin ====== ");
655     workSchedulerService_->standbyStateObserver_->OnDeviceIdleMode(true, false);
656     workSchedulerService_->standbyStateObserver_->OnDeviceIdleMode(true, true);
657     workSchedulerService_->standbyStateObserver_->OnDeviceIdleMode(false, true);
658     workSchedulerService_->standbyStateObserver_->OnAllowListChanged(0, "bundlename", 0, true);
659     EXPECT_NE(workSchedulerService_, nullptr);
660     WS_HILOGI("====== WorkSchedulerServiceTest.WorkStandbyStateChangeCallbackTest_001 end ====== ");
661 }
662 
663 HWTEST_F(WorkSchedulerServiceTest, WorkBundleGroupChangeCallback_001, TestSize.Level1)
664 {
665     WS_HILOGI("====== WorkSchedulerServiceTest.WorkBundleGroupChangeCallback_001 begin ====== ");
666     OHOS::DeviceUsageStats::AppGroupCallbackInfo appGroupCallbackInfo1(0, 1, 2, 0, "bundlename");
667     workSchedulerService_->groupObserver_->OnAppGroupChanged(appGroupCallbackInfo1);
668     OHOS::DeviceUsageStats::AppGroupCallbackInfo appGroupCallbackInfo2(0, 2, 1, 0, "bundlename");
669     workSchedulerService_->groupObserver_->OnAppGroupChanged(appGroupCallbackInfo2);
670     EXPECT_NE(workSchedulerService_, nullptr);
671     WS_HILOGI("====== WorkSchedulerServiceTest.WorkBundleGroupChangeCallback_001 end ====== ");
672 }
673 
674 HWTEST_F(WorkSchedulerServiceTest, WorkSchedulerConnection_001, TestSize.Level1)
675 {
676     WS_HILOGI("====== WorkSchedulerServiceTest.WorkSchedulerConnection_001 begin ====== ");
677     auto workinfo = std::make_shared<WorkInfo>();
678     WorkSchedulerConnection conection(workinfo);
679     AppExecFwk::ElementName element;
680     conection.StopWork();
681     conection.OnAbilityDisconnectDone(element, 0);
682     EXPECT_EQ(conection.proxy_, nullptr);
683     WS_HILOGI("====== WorkSchedulerServiceTest.WorkSchedulerConnection_001 end ====== ");
684 }
685 
686 HWTEST_F(WorkSchedulerServiceTest, SchedulerBgTaskSubscriber_001, TestSize.Level1)
687 {
688     WS_HILOGI("====== WorkSchedulerServiceTest.SchedulerBgTaskSubscriber_001 begin ====== ");
689     SchedulerBgTaskSubscriber subscriber;
690     subscriber.OnProcEfficiencyResourcesApply(nullptr);
691     subscriber.OnProcEfficiencyResourcesReset(nullptr);
692     subscriber.OnAppEfficiencyResourcesApply(nullptr);
693     subscriber.OnAppEfficiencyResourcesReset(nullptr);
694 
695     auto resourceInfo = std::make_shared<BackgroundTaskMgr::ResourceCallbackInfo>(0, 0, 0xFFFF, "name");
696     subscriber.OnProcEfficiencyResourcesApply(resourceInfo);
697     subscriber.OnProcEfficiencyResourcesReset(resourceInfo);
698     subscriber.OnAppEfficiencyResourcesApply(resourceInfo);
699     subscriber.OnAppEfficiencyResourcesReset(resourceInfo);
700     EXPECT_EQ(resourceInfo->GetBundleName(), "name");
701     WS_HILOGI("====== WorkSchedulerServiceTest.SchedulerBgTaskSubscriber_001 end ====== ");
702 }
703 
704 HWTEST_F(WorkSchedulerServiceTest, WorkQueueEventHandler_001, TestSize.Level1)
705 {
706     WS_HILOGI("====== WorkSchedulerServiceTest.WorkQueueEventHandler_001 begin ====== ");
707     WorkQueueEventHandler handler(nullptr, nullptr);
708     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(0);
709     handler.ProcessEvent(event);
710     event = AppExecFwk::InnerEvent::Get(1);
711     handler.ProcessEvent(event);
712     event = AppExecFwk::InnerEvent::Get(2);
713     handler.ProcessEvent(event);
714     EXPECT_TRUE(handler.manager_ == nullptr);
715     WS_HILOGI("====== WorkSchedulerServiceTest.WorkQueueEventHandler_001 end ====== ");
716 }
717 
718 HWTEST_F(WorkSchedulerServiceTest, WorkEventHandler_001, TestSize.Level1)
719 {
720     WS_HILOGI("====== WorkSchedulerServiceTest.WorkEventHandler_001 begin ====== ");
721     WorkEventHandler handler(workSchedulerService_->eventRunner_, workSchedulerService_);
722     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(0);
723     handler.ProcessEvent(event);
724     event = AppExecFwk::InnerEvent::Get(1);
725     handler.ProcessEvent(event);
726     event = AppExecFwk::InnerEvent::Get(2);
727     handler.ProcessEvent(event);
728     event = AppExecFwk::InnerEvent::Get(3);
729     handler.ProcessEvent(event);
730     event = AppExecFwk::InnerEvent::Get(4);
731     handler.ProcessEvent(event);
732     event = AppExecFwk::InnerEvent::Get(5);
733     handler.ProcessEvent(event);
734     EXPECT_TRUE(workSchedulerService_->eventRunner_ != nullptr);
735     WS_HILOGI("====== WorkSchedulerServiceTest.WorkEventHandler_001 end ====== ");
736 }
737 
738 HWTEST_F(WorkSchedulerServiceTest, BatteryLevelListener_001, TestSize.Level1)
739 {
740     WS_HILOGI("====== WorkSchedulerServiceTest.BatteryLevelListener_001 begin ====== ");
741 
742     BatteryLevelListener batteryLevelListener(workSchedulerService_->workQueueManager_, workSchedulerService_);
743 
744     batteryLevelListener.Start();
745     EXPECT_NE(batteryLevelListener.commonEventSubscriber, nullptr);
746 
747     EventFwk::CommonEventData data;
748     batteryLevelListener.commonEventSubscriber->OnReceiveEvent(data);
749 
750     EventFwk::Want want;
751     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_BATTERY_CHANGED);
752     data.SetWant(want);
753     batteryLevelListener.commonEventSubscriber->OnReceiveEvent(data);
754 
755     want.SetParam(PowerMgr::BatteryInfo::COMMON_EVENT_KEY_CAPACITY, 20);
756     data.SetWant(want);
757     batteryLevelListener.commonEventSubscriber->OnReceiveEvent(data);
758     batteryLevelListener.Stop();
759 
760     WS_HILOGI("====== WorkSchedulerServiceTest.BatteryLevelListener_001 end ====== ");
761 }
762 
763 HWTEST_F(WorkSchedulerServiceTest, BatteryStatusListener_001, TestSize.Level1)
764 {
765     WS_HILOGI("====== WorkSchedulerServiceTest.BatteryStatusListener_001 begin ====== ");
766     BatteryStatusListener batteryStatusListener(workSchedulerService_->workQueueManager_);
767 
768     batteryStatusListener.Start();
769     EXPECT_NE(batteryStatusListener.commonEventSubscriber, nullptr);
770 
771     EventFwk::CommonEventData data;
772     batteryStatusListener.commonEventSubscriber->OnReceiveEvent(data);
773 
774     EventFwk::Want want;
775     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_BATTERY_LOW);
776     data.SetWant(want);
777     batteryStatusListener.commonEventSubscriber->OnReceiveEvent(data);
778 
779     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_BATTERY_OKAY);
780     data.SetWant(want);
781     batteryStatusListener.commonEventSubscriber->OnReceiveEvent(data);
782     batteryStatusListener.Stop();
783 
784     WS_HILOGI("====== WorkSchedulerServiceTest.BatteryStatusListener_001 end ====== ");
785 }
786 
787 HWTEST_F(WorkSchedulerServiceTest, ChargerListener_001, TestSize.Level1)
788 {
789     WS_HILOGI("====== WorkSchedulerServiceTest.ChargerListener_001 begin ====== ");
790     ChargerListener chargerListener(workSchedulerService_->workQueueManager_);
791 
792     chargerListener.Start();
793     EXPECT_NE(chargerListener.commonEventSubscriber, nullptr);
794 
795     EventFwk::CommonEventData data;
796     chargerListener.commonEventSubscriber->OnReceiveEvent(data);
797 
798     EventFwk::Want want;
799     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_POWER_CONNECTED);
800     data.SetWant(want);
801     data.SetCode(static_cast<uint32_t>(PowerMgr::BatteryPluggedType::PLUGGED_TYPE_AC));
802     chargerListener.commonEventSubscriber->OnReceiveEvent(data);
803 
804     data.SetCode(static_cast<uint32_t>(PowerMgr::BatteryPluggedType::PLUGGED_TYPE_USB));
805     chargerListener.commonEventSubscriber->OnReceiveEvent(data);
806 
807 
808     data.SetCode(static_cast<uint32_t>(PowerMgr::BatteryPluggedType::PLUGGED_TYPE_WIRELESS));
809     chargerListener.commonEventSubscriber->OnReceiveEvent(data);
810 
811     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_POWER_DISCONNECTED);
812     data.SetWant(want);
813     data.SetCode(static_cast<uint32_t>(PowerMgr::BatteryPluggedType::PLUGGED_TYPE_NONE));
814     chargerListener.commonEventSubscriber->OnReceiveEvent(data);
815     chargerListener.Stop();
816 
817     WS_HILOGI("====== WorkSchedulerServiceTest.ChargerListener_001 end ====== ");
818 }
819 
820 HWTEST_F(WorkSchedulerServiceTest, ListenerStop_001, TestSize.Level1)
821 {
822     WS_HILOGI("====== ListenerStop_001 begin====== ");
823     for (auto pair : workSchedulerService_->workQueueManager_->listenerMap_)
824     {
825         pair.second->Stop();
826     }
827     workSchedulerService_->workQueueManager_->listenerMap_.clear();
828     EXPECT_TRUE(workSchedulerService_->workQueueManager_->listenerMap_.size() == 0);
829     WS_HILOGI("====== ListenerStop_001 end ====== ");
830 }
831 
832 HWTEST_F(WorkSchedulerServiceTest, WorkSchedServiceStub_001, TestSize.Level1)
833 {
834     MyWorkSchedulerService s;
835     MessageParcel data, reply;
836     MessageOption option;
837     const int size = 11;
838     for (int i = 0; i < size; i++) {
839         s.OnRemoteRequest(i, data, reply, option);
840         WorkInfo info;
841         info.Marshalling(data);
842         s.OnRemoteRequest(i, data, reply, option);
843     }
844     int32_t ret = s.OnRemoteRequest(0, data, reply, option);
845     EXPECT_TRUE(ret != ERR_OK);
846 }
847 
848 /**
849  * @tc.name: SendEvent_001
850  * @tc.desc: Test WorkSchedulerService SendEvent.
851  * @tc.type: FUNC
852  * @tc.require: I9J0A7
853  */
854 HWTEST_F(WorkSchedulerServiceTest, SendEvent_001, TestSize.Level1)
855 {
856     int32_t initDelay = 2 * 1000;
857     workSchedulerService_->GetHandler()->
858         SendEvent(AppExecFwk::InnerEvent::Get(WorkEventHandler::SERVICE_INIT_MSG, 0), initDelay);
859     EXPECT_TRUE(workSchedulerService_->ready_);
860 }
861 
862 /**
863  * @tc.name: GetJsonFromFile_001
864  * @tc.desc: Test WorkSchedulerService GetJsonFromFile.
865  * @tc.type: FUNC
866  * @tc.require: I9J0A7
867  */
868 HWTEST_F(WorkSchedulerServiceTest, GetJsonFromFile_001, TestSize.Level1)
869 {
870     nlohmann::json root;
871     const char* path = "/a/b/c";
872     bool ret = workSchedulerService_->GetJsonFromFile(path, root);
873     EXPECT_FALSE(ret);
874 }
875 
876 /**
877  * @tc.name: GetAppIndexAndBundleNameByUid_001
878  * @tc.desc: Test WorkSchedulerService GetAppIndexAndBundleNameByUid.
879  * @tc.type: FUNC
880  * @tc.require: I9TL53
881  */
882 HWTEST_F(WorkSchedulerServiceTest, GetAppIndexAndBundleNameByUid_001, TestSize.Level1)
883 {
884     int32_t appIndex;
885     std::string bundleName;
886     int32_t uid = 1;
887     bool ret = workSchedulerService_->GetAppIndexAndBundleNameByUid(uid, appIndex, bundleName);
888     EXPECT_FALSE(ret);
889 }
890 
891 /**
892  * @tc.name: LoadSa_001
893  * @tc.desc: Test WorkSchedulerService LoadSa.
894  * @tc.type: FUNC
895  * @tc.require: IAHY0B
896  */
897 HWTEST_F(WorkSchedulerServiceTest, LoadSa_001, TestSize.Level1)
898 {
899     std::shared_ptr<WorkInfo> workInfo_ = std::make_shared<WorkInfo>();
900     workInfo_->SetWorkId(-1);
901     std::string bundleName = "com.example.workStatus";
902     std::string abilityName = "workStatusAbility";
903     workInfo_->SetElement(bundleName, abilityName);
904     workInfo_->RequestPersisted(false);
905     time_t baseTime;
906     (void)time(&baseTime);
907     workInfo_->RequestBaseTime(baseTime);
908     std::shared_ptr<WorkStatus> workStatus_ = std::make_shared<WorkStatus>(*(workInfo_.get()), -1);
909 
910     workSchedulerService_->ready_ = false;
911     workSchedulerService_->LoadSa(workStatus_, "");
912 
913     workSchedulerService_->ready_ = true;
914     workSchedulerService_->LoadSa(workStatus_, "");
915 
916     workInfo_->saId_ = 401;
917     workSchedulerService_->LoadSa(workStatus_, "");
918 
919     workInfo_->residentSa_ = true;
920     workSchedulerService_->LoadSa(workStatus_, "");
921 
922     workInfo_->saId_ = 5300;
923     workSchedulerService_->LoadSa(workStatus_, "");
924 
925     workInfo_->residentSa_ = false;
926     bool ret = workSchedulerService_->LoadSa(workStatus_, "");
927     EXPECT_FALSE(ret);
928 }
929 
930 /**
931  * @tc.name: CheckExtensionInfos_001
932  * @tc.desc: Test WorkSchedulerService CheckExtensionInfos.
933  * @tc.type: FUNC
934  * @tc.require: IAJSVG
935  */
936 HWTEST_F(WorkSchedulerServiceTest, CheckExtensionInfos_001, TestSize.Level1)
937 {
938     int32_t uid = 1;
939     WorkInfo workInfo = WorkInfo();
940     workInfo.SetWorkId(1);
941     workInfo.SetElement("bundleName", "abilityName");
942     bool ret = workSchedulerService_->CheckExtensionInfos(workInfo, uid);
943     EXPECT_TRUE(ret);
944 }
945 
946 /**
947  * @tc.name: InitBgTaskSubscriber_001
948  * @tc.desc: Test WorkSchedulerService InitBgTaskSubscriber.
949  * @tc.type: FUNC
950  * @tc.require: IAJSVG
951  */
952 HWTEST_F(WorkSchedulerServiceTest, InitBgTaskSubscriber_001, TestSize.Level1)
953 {
954     bool ret = workSchedulerService_->InitBgTaskSubscriber();
955     EXPECT_TRUE(ret);
956 }
957 
958 /**
959  * @tc.name: AllowDump_001
960  * @tc.desc: Test WorkSchedulerService AllowDump.
961  * @tc.type: FUNC
962  * @tc.require: IAJSVG
963  */
964 HWTEST_F(WorkSchedulerServiceTest, AllowDump_001, TestSize.Level1)
965 {
966     bool ret = workSchedulerService_->AllowDump();
967     EXPECT_FALSE(ret);
968 }
969 
970 /**
971  * @tc.name: UpdateWorkBeforeRealStart_001
972  * @tc.desc: Test WorkSchedulerService UpdateWorkBeforeRealStart.
973  * @tc.type: FUNC
974  * @tc.require: IAJSVG
975  */
976 HWTEST_F(WorkSchedulerServiceTest, UpdateWorkBeforeRealStart_001, TestSize.Level1)
977 {
978     std::shared_ptr<WorkStatus> workStatus = nullptr;
979     workSchedulerService_->UpdateWorkBeforeRealStart(workStatus);
980 
981     WorkInfo workInfo = WorkInfo();
982     workStatus = std::make_shared<WorkStatus>(workInfo, 1);
983     workStatus->conditionMap_.clear();
984     workSchedulerService_->UpdateWorkBeforeRealStart(workStatus);
985 
986     std::shared_ptr<Condition> repeatCycle = std::make_shared<Condition>();
987     repeatCycle->boolVal = true;
988     workStatus->conditionMap_.emplace(WorkCondition::Type::TIMER, repeatCycle);
989     workSchedulerService_->UpdateWorkBeforeRealStart(workStatus);
990     EXPECT_TRUE(repeatCycle->intVal == 0);
991 }
992 
993 /**
994  * @tc.name: CheckEffiResApplyInfo_001
995  * @tc.desc: Test WorkSchedulerService CheckEffiResApplyInfo.
996  * @tc.type: FUNC
997  * @tc.require: IAJSVG
998  */
999 HWTEST_F(WorkSchedulerServiceTest, CheckEffiResApplyInfo_001, TestSize.Level1)
1000 {
1001     bool ret = workSchedulerService_->CheckEffiResApplyInfo(1);
1002     EXPECT_FALSE(ret);
1003 }
1004 
1005 /**
1006  * @tc.name: PauseRunningWorks_001
1007  * @tc.desc: Test WorkSchedulerService PauseRunningWorks.
1008  * @tc.type: FUNC
1009  * @tc.require: IAJSVG
1010  */
1011 HWTEST_F(WorkSchedulerServiceTest, PauseRunningWorks_001, TestSize.Level1)
1012 {
1013     workSchedulerService_->TriggerWorkIfConditionReady();
1014     int32_t ret = workSchedulerService_->PauseRunningWorks(1);
1015     EXPECT_TRUE(ret == E_INVALID_PROCESS_NAME);
1016     ret = workSchedulerService_->ResumePausedWorks(1);
1017     EXPECT_TRUE(ret == E_INVALID_PROCESS_NAME);
1018 }
1019 
1020 /**
1021  * @tc.name: OnAddSystemAbility_001
1022  * @tc.desc: Test WorkSchedulerService OnAddSystemAbility.
1023  * @tc.type: FUNC
1024  * @tc.require: IAJSVG
1025  */
1026 HWTEST_F(WorkSchedulerServiceTest, OnAddSystemAbility_001, TestSize.Level1)
1027 {
1028     std::string deviceId;
1029     int32_t DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID = 1914;
1030     int32_t DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID = 1907;
1031     workSchedulerService_->groupObserver_ = nullptr;
1032     workSchedulerService_->OnAddSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID, deviceId);
1033     EXPECT_TRUE(workSchedulerService_->groupObserver_ != nullptr);
1034     workSchedulerService_->OnRemoveSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID, deviceId);
1035     EXPECT_TRUE(workSchedulerService_->groupObserver_ == nullptr);
1036 
1037     workSchedulerService_->standbyStateObserver_ = nullptr;
1038     workSchedulerService_->OnAddSystemAbility(DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID, deviceId);
1039     EXPECT_TRUE(workSchedulerService_->standbyStateObserver_ != nullptr);
1040     workSchedulerService_->OnRemoveSystemAbility(DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID, deviceId);
1041     EXPECT_TRUE(workSchedulerService_->standbyStateObserver_ == nullptr);
1042 }
1043 
1044 /**
1045  * @tc.name: IsDebugApp_001
1046  * @tc.desc: Test WorkSchedulerService IsDebugApp.
1047  * @tc.type: FUNC
1048  * @tc.require: IAJSVG
1049  */
1050 HWTEST_F(WorkSchedulerServiceTest, IsDebugApp_001, TestSize.Level1)
1051 {
1052     bool ret = workSchedulerService_->IsDebugApp("bundleName");
1053     EXPECT_FALSE(ret);
1054 }
1055 
1056 /**
1057  * @tc.name: IsExemptionBundle_001
1058  * @tc.desc: Test WorkSchedulerService IsExemptionBundle.
1059  * @tc.type: FUNC
1060  * @tc.require: IAJSVG
1061  */
1062 HWTEST_F(WorkSchedulerServiceTest, IsExemptionBundle_001, TestSize.Level1)
1063 {
1064     workSchedulerService_->exemptionBundles_.clear();
1065     std::string bundleName = "com.demo.bundle";
1066     bool ret = workSchedulerService_->IsExemptionBundle(bundleName);
1067     EXPECT_FALSE(ret);
1068 }
1069 
1070 /**
1071  * @tc.name: IsExemptionBundle_002
1072  * @tc.desc: Test WorkSchedulerService IsExemptionBundle.
1073  * @tc.type: FUNC
1074  * @tc.require: IAJSVG
1075  */
1076 HWTEST_F(WorkSchedulerServiceTest, IsExemptionBundle_002, TestSize.Level1)
1077 {
1078     std::string bundleName = "com.demo.bundle";
1079     workSchedulerService_->exemptionBundles_.clear();
1080     workSchedulerService_->exemptionBundles_.insert(bundleName);
1081     bool ret = workSchedulerService_->IsExemptionBundle(bundleName);
1082     EXPECT_TRUE(ret);
1083 }
1084 
1085 /**
1086  * @tc.name: IsExemptionBundle_003
1087  * @tc.desc: Test WorkSchedulerService IsExemptionBundle.
1088  * @tc.type: FUNC
1089  * @tc.require: IAJSVG
1090  */
1091 HWTEST_F(WorkSchedulerServiceTest, IsExemptionBundle_003, TestSize.Level1)
1092 {
1093     std::string bundleName = "com.demo.bundle";
1094     workSchedulerService_->exemptionBundles_.clear();
1095     workSchedulerService_->exemptionBundles_.insert("com.demo.bundle1");
1096     bool ret = workSchedulerService_->IsExemptionBundle(bundleName);
1097     EXPECT_FALSE(ret);
1098 }
1099 
1100 /**
1101  * @tc.name: DumpExemptionBundles_001
1102  * @tc.desc: Test WorkSchedulerService DumpExemptionBundles.
1103  * @tc.type: FUNC
1104  * @tc.require: IAJSVG
1105  */
1106 HWTEST_F(WorkSchedulerServiceTest, DumpExemptionBundles_001, TestSize.Level1)
1107 {
1108     workSchedulerService_->exemptionBundles_.clear();
1109     std::string ret = workSchedulerService_->DumpExemptionBundles();
1110     EXPECT_TRUE(ret == "[]");
1111 }
1112 
1113 /**
1114  * @tc.name: DumpExemptionBundles_002
1115  * @tc.desc: Test WorkSchedulerService DumpExemptionBundles.
1116  * @tc.type: FUNC
1117  * @tc.require: IAJSVG
1118  */
1119 HWTEST_F(WorkSchedulerServiceTest, DumpExemptionBundles_002, TestSize.Level1)
1120 {
1121     workSchedulerService_->exemptionBundles_.insert("com.demo.bundle1");
1122     std::string ret = workSchedulerService_->DumpExemptionBundles();
1123     EXPECT_FALSE(ret.empty());
1124 }
1125 
1126 /**
1127  * @tc.name: LoadExemptionBundlesFromFile_001
1128  * @tc.desc: Test WorkSchedulerService LoadExemptionBundlesFromFile.
1129  * @tc.type: FUNC
1130  * @tc.require: IAJSVG
1131  */
1132 HWTEST_F(WorkSchedulerServiceTest, LoadExemptionBundlesFromFile_001, TestSize.Level1)
1133 {
1134     workSchedulerService_->exemptionBundles_.clear();
1135     const char* path = nullptr;
1136     workSchedulerService_->LoadExemptionBundlesFromFile(path);
1137     EXPECT_TRUE(workSchedulerService_->exemptionBundles_.empty());
1138 }
1139 
1140 /**
1141  * @tc.name: LoadExemptionBundlesFromFile_002
1142  * @tc.desc: Test WorkSchedulerService LoadExemptionBundlesFromFile.
1143  * @tc.type: FUNC
1144  * @tc.require: IAJSVG
1145  */
1146 HWTEST_F(WorkSchedulerServiceTest, LoadExemptionBundlesFromFile_002, TestSize.Level1)
1147 {
1148     workSchedulerService_->exemptionBundles_.clear();
1149     const char *path = "/a/b/c";
1150     workSchedulerService_->LoadExemptionBundlesFromFile(path);
1151     EXPECT_TRUE(workSchedulerService_->exemptionBundles_.empty());
1152 }
1153 
1154 /**
1155  * @tc.name: IsPreinstalledBundle_001
1156  * @tc.desc: Test WorkSchedulerService IsPreinstalledBundle.
1157  * @tc.type: FUNC
1158  * @tc.require: IAJSVG
1159  */
1160 HWTEST_F(WorkSchedulerServiceTest, IsPreinstalledBundle_001, TestSize.Level1)
1161 {
1162     workSchedulerService_->preinstalledBundles_.clear();
1163     std::string bundleName = "com.demo.bundle";
1164     bool ret = workSchedulerService_->IsPreinstalledBundle(bundleName);
1165     EXPECT_FALSE(ret);
1166 }
1167 
1168 /**
1169  * @tc.name: IsPreinstalledBundle_002
1170  * @tc.desc: Test WorkSchedulerService IsPreinstalledBundle.
1171  * @tc.type: FUNC
1172  * @tc.require: IAJSVG
1173  */
1174 HWTEST_F(WorkSchedulerServiceTest, IsPreinstalledBundle_002, TestSize.Level1)
1175 {
1176     workSchedulerService_->preinstalledBundles_.clear();
1177     std::string bundleName = "com.demo.bundle";
1178     workSchedulerService_->preinstalledBundles_.insert(bundleName);
1179     bool ret = workSchedulerService_->IsPreinstalledBundle(bundleName);
1180     EXPECT_TRUE(ret);
1181 }
1182 
1183 /**
1184  * @tc.name: IsPreinstalledBundle_003
1185  * @tc.desc: Test WorkSchedulerService IsPreinstalledBundle.
1186  * @tc.type: FUNC
1187  * @tc.require: IAJSVG
1188  */
1189 HWTEST_F(WorkSchedulerServiceTest, IsPreinstalledBundle_003, TestSize.Level1)
1190 {
1191     workSchedulerService_->preinstalledBundles_.clear();
1192     std::string bundleName = "com.demo.bundle";
1193     workSchedulerService_->preinstalledBundles_.insert("com.demo.bundle1");
1194     bool ret = workSchedulerService_->IsPreinstalledBundle(bundleName);
1195     EXPECT_FALSE(ret);
1196 }
1197 
1198 /**
1199  * @tc.name: LoadMinRepeatTimeFromFile_001
1200  * @tc.desc: Test WorkSchedulerService LoadMinRepeatTimeFromFile.
1201  * @tc.type: FUNC
1202  * @tc.require: IBB60P
1203  */
1204 HWTEST_F(WorkSchedulerServiceTest, LoadMinRepeatTimeFromFile_001, TestSize.Level1)
1205 {
1206     workSchedulerService_->specialMap_.clear();
1207     const char* path = nullptr;
1208     workSchedulerService_->LoadMinRepeatTimeFromFile(path);
1209     EXPECT_TRUE(workSchedulerService_->specialMap_.empty());
1210 }
1211 
1212 /**
1213  * @tc.name: LoadMinRepeatTimeFromFile_002
1214  * @tc.desc: Test WorkSchedulerService LoadMinRepeatTimeFromFile.
1215  * @tc.type: FUNC
1216  * @tc.require: IBB60P
1217  */
1218 HWTEST_F(WorkSchedulerServiceTest, LoadMinRepeatTimeFromFile_002, TestSize.Level1)
1219 {
1220     workSchedulerService_->specialMap_.clear();
1221     const char *path = "/a/b/c";
1222     workSchedulerService_->LoadMinRepeatTimeFromFile(path);
1223     EXPECT_TRUE(workSchedulerService_->specialMap_.empty());
1224 }
1225 
1226 /**
1227  * @tc.name: DumpTriggerWork_001
1228  * @tc.desc: Test WorkSchedulerService DumpTriggerWork.
1229  * @tc.type: FUNC
1230  * @tc.require: IC5H77
1231  */
1232 HWTEST_F(WorkSchedulerServiceTest, DumpTriggerWork_001, TestSize.Level1)
1233 {
1234     std::string uIdStr = "";
1235     std::string workIdStr = "123";
1236     std::string result;
1237     workSchedulerService_->DumpTriggerWork(uIdStr, workIdStr, result);
1238     EXPECT_EQ(result, "param invalid\n");
1239 }
1240 
1241 /**
1242  * @tc.name: DumpTriggerWork_002
1243  * @tc.desc: Test WorkSchedulerService DumpTriggerWork.
1244  * @tc.type: FUNC
1245  * @tc.require: IC5H77
1246  */
1247 HWTEST_F(WorkSchedulerServiceTest, DumpTriggerWork_002, TestSize.Level1)
1248 {
1249     std::string uIdStr = "0";
1250     std::string workIdStr = "123";
1251     std::string result;
1252     workSchedulerService_->DumpTriggerWork(uIdStr, workIdStr, result);
1253     EXPECT_EQ(result, "uIdStr param invalid, uIdStr:0\n");
1254 }
1255 
1256 /**
1257  * @tc.name: DumpTriggerWork_003
1258  * @tc.desc: Test WorkSchedulerService DumpTriggerWork.
1259  * @tc.type: FUNC
1260  * @tc.require: IC5H77
1261  */
1262 HWTEST_F(WorkSchedulerServiceTest, DumpTriggerWork_003, TestSize.Level1)
1263 {
1264     std::string uIdStr = "123";
1265     std::string workIdStr = "0";
1266     std::string result;
1267     workSchedulerService_->DumpTriggerWork(uIdStr, workIdStr, result);
1268     EXPECT_EQ(result, "workIdStr param invalid, workIdStr:0\n");
1269 }
1270 
1271 /**
1272  * @tc.name: DumpTriggerWork_004
1273  * @tc.desc: Test WorkSchedulerService DumpTriggerWork.
1274  * @tc.type: FUNC
1275  * @tc.require: IC5H77
1276  */
1277 HWTEST_F(WorkSchedulerServiceTest, DumpTriggerWork_004, TestSize.Level1)
1278 {
1279     std::string uIdStr = "123";
1280     std::string workIdStr = "456";
1281     std::string result;
1282     workSchedulerService_->DumpTriggerWork(uIdStr, workIdStr, result);
1283     EXPECT_EQ(result, "the work is not exist\n");
1284 }
1285 }
1286 }