• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #define private public
16 #define protected public
17 
18 #include <functional>
19 #include <chrono>
20 #include <thread>
21 #include <message_parcel.h>
22 
23 #include "gtest/gtest.h"
24 #include "gtest/hwext/gtest-multithread.h"
25 #include "singleton.h"
26 
27 #include "common_event_support.h"
28 #include "common_event_observer.h"
29 #include "allow_type.h"
30 #include "standby_service_client.h"
31 #include "standby_service.h"
32 #include "standby_service_impl.h"
33 #include "standby_state_subscriber.h"
34 #include "standby_state_subscriber.h"
35 #include "standby_service_subscriber_stub.h"
36 #include "device_standby_switch.h"
37 
38 #include "state_manager_adapter.h"
39 #include "constraint_manager_adapter.h"
40 #include "listener_manager_adapter.h"
41 #include "strategy_manager_adapter.h"
42 #include "standby_config_manager.h"
43 #include "common_event_listener.h"
44 #include "charge_state_monitor.h"
45 #include "motion_sensor_monitor.h"
46 #include "input_manager.h"
47 #include "background_task_listener.h"
48 #include "input_manager_listener.h"
49 #include "common_constant.h"
50 #include "dark_state.h"
51 
52 using namespace testing::ext;
53 using namespace testing::mt;
54 
55 namespace OHOS {
56 namespace DevStandbyMgr {
57 namespace {
58     const vector<std::string> COMMON_EVENT_LIST = {
59         EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON,
60         EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF,
61         EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING,
62         EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_ATTACHED,
63         EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING,
64         EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED,
65         EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON,
66         EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED,
67     };
68     constexpr int32_t SLEEP_TIMEOUT = 500;
69 }
70 
71 class StandbyPluginUnitTest : public testing::Test {
72 public:
73     static void SetUpTestCase();
74     static void TearDownTestCase();
SetUp()75     void SetUp() override {}
TearDown()76     void TearDown() override {}
77 
SleepForFC()78     inline static void SleepForFC()
79     {
80         std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMEOUT));
81     }
82 private:
83     static std::shared_ptr<ConstraintManagerAdapter> constraintManager_;
84     static std::shared_ptr<ListenerManagerAdapter> listenerManager_;
85     static std::shared_ptr<StrategyManagerAdapter> strategyManager_;
86     static std::shared_ptr<StateManagerAdapter> standbyStateManager_;
87 };
88 
TearDownTestCase()89 void StandbyPluginUnitTest::TearDownTestCase()
90 {
91     SleepForFC();
92     StandbyServiceImpl::GetInstance()->UnInit();
93     if (StandbyServiceImpl::GetInstance()->handler_) {
94         StandbyServiceImpl::GetInstance()->handler_->RemoveAllEvents();
95         auto runner = StandbyServiceImpl::GetInstance()->handler_->GetEventRunner();
96         if (runner) {
97             runner->Stop();
98             runner = nullptr;
99         }
100         StandbyServiceImpl::GetInstance()->handler_ = nullptr;
101     }
102 }
103 
104 std::shared_ptr<ConstraintManagerAdapter> StandbyPluginUnitTest::constraintManager_ {nullptr};
105 std::shared_ptr<ListenerManagerAdapter> StandbyPluginUnitTest::listenerManager_ {nullptr};
106 std::shared_ptr<StrategyManagerAdapter> StandbyPluginUnitTest::strategyManager_ {nullptr};
107 std::shared_ptr<StateManagerAdapter> StandbyPluginUnitTest::standbyStateManager_ {nullptr};
108 
SetUpTestCase()109 void StandbyPluginUnitTest::SetUpTestCase()
110 {
111     StandbyServiceImpl::GetInstance()->Init();
112     SleepForFC();
113 
114     constraintManager_ = std::make_shared<ConstraintManagerAdapter>();
115     listenerManager_ = std::make_shared<ListenerManagerAdapter>();
116     strategyManager_ = std::make_shared<StrategyManagerAdapter>();
117     standbyStateManager_ = std::make_shared<StateManagerAdapter>();
118 
119     StandbyServiceImpl::GetInstance()->constraintManager_ = constraintManager_;
120     StandbyServiceImpl::GetInstance()->listenerManager_ = listenerManager_;
121     StandbyServiceImpl::GetInstance()->strategyManager_ = strategyManager_;
122     StandbyServiceImpl::GetInstance()->standbyStateManager_ = standbyStateManager_;
123     StandbyServiceImpl::GetInstance()->InitReadyState();
124     SleepForFC();
125 }
126 
127 /**
128  * @tc.name: StandbyPluginUnitTest_001
129  * @tc.desc: test Init of StandbyPlugin.
130  * @tc.type: FUNC
131  * @tc.require:
132  */
133 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_001, TestSize.Level1)
134 {
135     listenerManager_->StopListener();
136     listenerManager_->UnInit();
137     constraintManager_->UnInit();
138     strategyManager_->strategyList_.clear();
139     standbyStateManager_->UnInit();
140     standbyStateManager_->Init();
141     strategyManager_->Init();
142     constraintManager_->Init();
143     listenerManager_->Init();
144     listenerManager_->StartListener();
145     EXPECT_NE(listenerManager_, nullptr);
146 }
147 
148 /**
149  * @tc.name: StandbyPluginUnitTest_002
150  * @tc.desc: test RegisterPolicy of StandbyPlugin.
151  * @tc.type: FUNC
152  * @tc.require:
153  */
154 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_002, TestSize.Level1)
155 {
156     strategyManager_->RegisterPolicy({"NETWORK", "TIMER", "RUNNING_LOCK", "WORK_SCHEDULER", ""});
157     EXPECT_FALSE(strategyManager_->strategyList_.empty());
158 }
159 
160 /**
161  * @tc.name: StandbyPluginUnitTest_003
162  * @tc.desc: test HandleEvent of StandbyPlugin.
163  * @tc.type: FUNC
164  * @tc.require:
165  */
166 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_003, TestSize.Level1)
167 {
168     StandbyMessage message(StandbyMessageType::PHASE_TRANSIT);
169     standbyStateManager_->HandleEvent(message);
170     strategyManager_->HandleEvent(message);
171     StandbyMessage commonEventMessage(StandbyMessageType::COMMON_EVENT);
172     standbyStateManager_->HandleEvent(commonEventMessage);
173     strategyManager_->HandleEvent(commonEventMessage);
174     StandbyMessage conditionChangeMessage(StandbyMessageType::RES_CTRL_CONDITION_CHANGED);
175     standbyStateManager_->HandleEvent(conditionChangeMessage);
176     strategyManager_->HandleEvent(conditionChangeMessage);
177     EXPECT_NE(listenerManager_, nullptr);
178 }
179 
180 /**
181  * @tc.name: StandbyPluginUnitTest_004
182  * @tc.desc: test CommonEventListener of StandbyPlugin.
183  * @tc.type: FUNC
184  * @tc.require:
185  */
186 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_004, TestSize.Level1)
187 {
188     EventFwk::CommonEventSubscribeInfo subscribeInfo {};
189     auto commonEventListener = std::make_shared<CommonEventListener>(subscribeInfo);
190 
191     EventFwk::CommonEventData eventData = EventFwk::CommonEventData();
192     commonEventListener->OnReceiveEvent(eventData);
193     for (const auto& eventName : COMMON_EVENT_LIST) {
194         AAFwk::Want want = AAFwk::Want();
195         want.SetAction(eventName);
196         eventData.SetWant(want);
197         commonEventListener->OnReceiveEvent(eventData);
198     }
199     SleepForFC();
200     SleepForFC();
201     for (const auto& eventName : COMMON_EVENT_LIST) {
202         StandbyMessage message;
203         message.action_ = eventName;
204         standbyStateManager_->HandleCommonEvent(message);
205     }
206     standbyStateManager_->TransitToState(StandbyState::WORKING);
207     SleepForFC();
208     EXPECT_NE(commonEventListener, nullptr);
209 }
210 
211 /**
212  * @tc.name: StandbyPluginUnitTest_005
213  * @tc.desc: test ChargeStateMonitor of StandbyPlugin.
214  * @tc.type: FUNC
215  * @tc.require:
216  */
217 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_005, TestSize.Level1)
218 {
219     auto chargeStateMonitor = std::make_shared<ChargeStateMonitor>();
220     chargeStateMonitor->Init();
221     chargeStateMonitor->StartMonitoring();
222     EXPECT_NE(chargeStateMonitor, nullptr);
223 }
224 
225 /**
226  * @tc.name: StandbyPluginUnitTest_006
227  * @tc.desc: test ChargeStateMonitor of StandbyPlugin.
228  * @tc.type: FUNC
229  * @tc.require:
230  */
231 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_006, TestSize.Level1)
232 {
233     StandbyConfigManager::GetInstance()->standbySwitchMap_[DETECT_MOTION_CONFIG] = false;
234     constraintManager_->UnInit();
235     constraintManager_->Init();
236     StandbyConfigManager::GetInstance()->standbySwitchMap_[DETECT_MOTION_CONFIG] = true;
237     constraintManager_->UnInit();
238     constraintManager_->Init();
239     constraintManager_->isEvaluation_ = true;
240     constraintManager_->StopEvalution();
241     constraintManager_->isEvaluation_ = false;
242     constraintManager_->curMonitor_ = nullptr;
243     constraintManager_->StopEvalution();
244     constraintManager_->isEvaluation_ = true;
245     ConstraintEvalParam params;
246     constraintManager_->StartEvalution(params);
247     constraintManager_->isEvaluation_ = false;
248     constraintManager_->StartEvalution(params);
249     std::shared_ptr<ChargeStateMonitor> monitor = nullptr;
250     constraintManager_->RegisterConstraintCallback(params, monitor);
251     constraintManager_->StartEvalution(params);
252     constraintManager_->constraintMap_.erase(params.GetHashValue());
253     ConstraintEvalParam repeatedMotionParams{StandbyState::SLEEP, SleepStatePhase::END, StandbyState::SLEEP,
254             SleepStatePhase::END};
255     repeatedMotionParams.isRepeatedDetection_ = true;
256     constraintManager_->StartEvalution(repeatedMotionParams);
257     SleepForFC();
258     ConstraintEvalParam motionDetectParams{StandbyState::NAP, NapStatePhase::END, StandbyState::SLEEP,
259             SleepStatePhase::SYS_RES_DEEP};
260     constraintManager_->StartEvalution(motionDetectParams);
261     constraintManager_->StopEvalution();
262     standbyStateManager_->ExitStandby(StandbyState::WORKING);
263     SleepForFC();
264     EXPECT_FALSE(constraintManager_->isEvaluation_);
265 }
266 
267 /**
268  * @tc.name: StandbyPluginUnitTest_007
269  * @tc.desc: test MotionSensorMonitor of StandbyPlugin.
270  * @tc.type: FUNC
271  * @tc.require:
272  */
273 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_007, TestSize.Level1)
274 {
275     ConstraintEvalParam repeatedMotionParams{};
276     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
277             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
278     repeatedMotionConstraint->StopMonitoring();
279     repeatedMotionConstraint->isMonitoring_ = true;
280     repeatedMotionConstraint->StopMonitoring();
281     repeatedMotionConstraint->isMonitoring_ = false;
282     repeatedMotionConstraint->StopMonitoring();
283     EXPECT_FALSE(repeatedMotionConstraint->isMonitoring_);
284 }
285 
286 /**
287  * @tc.name: StandbyPluginUnitTest_008
288  * @tc.desc: test CheckTransitionValid of StandbyPlugin.
289  * @tc.type: FUNC
290  * @tc.require:
291  */
292 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_008, TestSize.Level1)
293 {
294     for (auto &statePtr : standbyStateManager_->indexToState_) {
295         for (uint32_t nextState = StandbyState::WORKING; nextState <= StandbyState::SLEEP; ++nextState) {
296             statePtr->CheckTransitionValid(nextState);
297         }
298     }
299     EXPECT_TRUE(standbyStateManager_->CheckTransitionValid(StandbyState::WORKING, StandbyState::WORKING));
300 }
301 
302 /**
303  * @tc.name: StandbyPluginUnitTest_009
304  * @tc.desc: test TransitToState of StandbyPlugin.
305  * @tc.type: FUNC
306  * @tc.require:
307  */
308 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_009, TestSize.Level1)
309 {
310     standbyStateManager_->isEvalution_=true;
311     standbyStateManager_->ExitStandby(StandbyState::WORKING);
312     standbyStateManager_->isEvalution_=false;
313     standbyStateManager_->ExitStandby(StandbyState::WORKING);
314     standbyStateManager_->TransitToState(standbyStateManager_->curStatePtr_->GetCurState());
315     standbyStateManager_->TransitToState(StandbyState::MAINTENANCE);
316     standbyStateManager_->TransitToState(StandbyState::NAP);
317     SleepForFC();
318     standbyStateManager_->TransitToState(StandbyState::MAINTENANCE);
319     standbyStateManager_->TransitToState(StandbyState::NAP);
320     standbyStateManager_->TransitToState(StandbyState::WORKING);
321     standbyStateManager_->SendNotification(StandbyState::WORKING, true);
322     standbyStateManager_->SendNotification(StandbyState::WORKING, false);
323 
324     standbyStateManager_->isBlocked_ = true;
325     standbyStateManager_->EnterStandby(StandbyState::WORKING);
326     standbyStateManager_->isBlocked_ = false;
327     standbyStateManager_->EnterStandby(StandbyState::WORKING);
328     standbyStateManager_->TransitToState(StandbyState::WORKING);
329     EXPECT_NE(standbyStateManager_->GetCurState(), StandbyState::NAP);
330 }
331 
332 /**
333  * @tc.name: StandbyPluginUnitTest_010
334  * @tc.desc: test NapState of StandbyPlugin.
335  * @tc.type: FUNC
336  * @tc.require:
337  */
338 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_010, TestSize.Level1)
339 {
340     standbyStateManager_->darkStatePtr_->EndEvalCurrentState(false);
341     standbyStateManager_->darkStatePtr_->EndEvalCurrentState(true);
342 
343     standbyStateManager_->darkStatePtr_->curPhase_ = NapStatePhase::CONNECTION;
344     standbyStateManager_->napStatePtr_->EndEvalCurrentState(false);
345     standbyStateManager_->napStatePtr_->EndEvalCurrentState(true);
346     SleepForFC();
347     standbyStateManager_->darkStatePtr_->curPhase_ = NapStatePhase::SYS_RES_LIGHT;
348     standbyStateManager_->napStatePtr_->EndEvalCurrentState(false);
349     standbyStateManager_->napStatePtr_->EndEvalCurrentState(true);
350     SleepForFC();
351     standbyStateManager_->napStatePtr_->EndEvalCurrentState(false);
352     standbyStateManager_->napStatePtr_->EndEvalCurrentState(true);
353     SleepForFC();
354     EXPECT_NE(standbyStateManager_->curStatePtr_->GetCurState(), StandbyState::MAINTENANCE);
355 
356     standbyStateManager_->darkStatePtr_->stateManager_.reset();
357     standbyStateManager_->darkStatePtr_->EndEvalCurrentState(false);
358     standbyStateManager_->darkStatePtr_->stateManager_ = standbyStateManager_;
359 
360     standbyStateManager_->maintStatePtr_->stateManager_.reset();
361     standbyStateManager_->maintStatePtr_->BeginState();
362     standbyStateManager_->maintStatePtr_->stateManager_ = standbyStateManager_;
363 }
364 
365 /**
366  * @tc.name: StandbyPluginUnitTest_011
367  * @tc.desc: test SleepState of StandbyPlugin.
368  * @tc.type: FUNC
369  * @tc.require:
370  */
371 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_011, TestSize.Level1)
372 {
373     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
374     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(true);
375 
376     standbyStateManager_->sleepStatePtr_->curPhase_ = SleepStatePhase::SYS_RES_DEEP;
377     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
378     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(true);
379     SleepForFC();
380     standbyStateManager_->sleepStatePtr_->curPhase_ = SleepStatePhase::APP_RES_HARDWARE;
381     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
382     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(true);
383     SleepForFC();
384     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
385     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(true);
386     SleepForFC();
387     EXPECT_NE(standbyStateManager_->curStatePtr_->GetCurState(), StandbyState::WORKING);
388 }
389 
390 /**
391  * @tc.name: StandbyPluginUnitTest_012
392  * @tc.desc: test TransitToStateInner of StandbyPlugin.
393  * @tc.type: FUNC
394  * @tc.require:
395  */
396 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_012, TestSize.Level1)
397 {
398     standbyStateManager_->TransitToStateInner(StandbyState::WORKING);
399     standbyStateManager_->TransitToStateInner(StandbyState::DARK);
400     standbyStateManager_->TransitToStateInner(StandbyState::NAP);
401     SleepForFC();
402     standbyStateManager_->TransitToStateInner(StandbyState::MAINTENANCE);
403     standbyStateManager_->TransitToStateInner(StandbyState::NAP);
404     standbyStateManager_->TransitToStateInner(StandbyState::SLEEP);
405     SleepForFC();
406     standbyStateManager_->TransitToStateInner(StandbyState::MAINTENANCE);
407     standbyStateManager_->TransitToStateInner(StandbyState::SLEEP);
408     EXPECT_NE(standbyStateManager_->curStatePtr_->GetCurState(), StandbyState::WORKING);
409 }
410 
411 /**
412  * @tc.name: StandbyPluginUnitTest_013
413  * @tc.desc: test multithread OnReceiveEvent of StandbyService.
414  * @tc.type: FUNC
415  * @tc.require:
416  */
417 HWMTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_013, TestSize.Level1, 20)
418 {
419     EventFwk::CommonEventSubscribeInfo subscribeInfo {};
420     auto commonEventListener = std::make_shared<CommonEventListener>(subscribeInfo);
421 
422     EventFwk::CommonEventData eventData = EventFwk::CommonEventData();
423     commonEventListener->OnReceiveEvent(eventData);
424     for (const auto& event : COMMON_EVENT_LIST) {
425         AAFwk::Want want = AAFwk::Want();
426         want.SetAction(event);
427         eventData.SetWant(want);
428         commonEventListener->OnReceiveEvent(eventData);
429     }
430     EXPECT_TRUE(true);
431 }
432 
433 /**
434  * @tc.name: StandbyPluginUnitTest_014
435  * @tc.desc: test MotionSensorMonitor of AddEnergy.
436  * @tc.type: FUNC
437  * @tc.require:
438  */
439 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0014, TestSize.Level1)
440 {
441     ConstraintEvalParam repeatedMotionParams{};
442     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
443             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
444     AccelData* accelData = new AccelData();
445     repeatedMotionConstraint->AddEnergy(accelData);
446     repeatedMotionConstraint->hasPrevAccelData_ = true;
447     repeatedMotionConstraint->AddEnergy(accelData);
448     EXPECT_TRUE(repeatedMotionConstraint->hasPrevAccelData_ == true);
449 }
450 
451 /**
452  * @tc.name: StandbyPluginUnitTest_015
453  * @tc.desc: test MotionSensorMonitor of Init.
454  * @tc.type: FUNC
455  * @tc.require:
456  */
457 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0015, TestSize.Level1)
458 {
459     ConstraintEvalParam repeatedMotionParams{};
460     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
461             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
462     repeatedMotionConstraint->Init();
463     repeatedMotionConstraint->params_.isRepeatedDetection_ = true;
464     repeatedMotionConstraint->Init();
465     repeatedMotionConstraint->params_.isRepeatedDetection_ = false;
466     EXPECT_TRUE(repeatedMotionConstraint->Init() == true);
467 }
468 
469 /**
470  * @tc.name: StandbyPluginUnitTest_016
471  * @tc.desc: test MotionSensorMonitor of PeriodlyStartMotionDetection.
472  * @tc.type: FUNC
473  * @tc.require:
474  */
475 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0016, TestSize.Level1)
476 {
477     ConstraintEvalParam repeatedMotionParams{};
478     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
479             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
480     repeatedMotionConstraint->PeriodlyStartMotionDetection();
481     repeatedMotionConstraint->energy_ = 1;
482     repeatedMotionConstraint->PeriodlyStartMotionDetection();
483     EXPECT_TRUE(repeatedMotionConstraint->StartMonitoringInner() == ERR_OK);
484     repeatedMotionConstraint->isMonitoring_ = false;
485     repeatedMotionConstraint->StartMonitoringInner();
486 }
487 
488 /**
489  * @tc.name: StandbyPluginUnitTest_017
490  * @tc.desc: test MotionSensorMonitor of StartSensor.
491  * @tc.type: FUNC
492  * @tc.require:
493  */
494 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0017, TestSize.Level1)
495 {
496     ConstraintEvalParam repeatedMotionParams{};
497     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
498             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
499     int32_t sensorTypeId = 1;
500     SensorUser sensorUser;
501     repeatedMotionConstraint->isMonitoring_ = false;
502     repeatedMotionConstraint->StartSensor();
503     repeatedMotionConstraint->isMonitoring_ = true;
504     repeatedMotionConstraint->StartSensor();
505     sensorTypeId = repeatedMotionConstraint->detectionTimeOut_;
506     repeatedMotionConstraint->StartSensor();
507     EXPECT_TRUE(repeatedMotionConstraint->StartSensor() == ERR_OK);
508 }
509 
510 /**
511  * @tc.name: StandbyPluginUnitTest_018
512  * @tc.desc: test MotionSensorMonitor of StopSensor.
513  * @tc.type: FUNC
514  * @tc.require:
515  */
516 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0018, TestSize.Level1)
517 {
518     ConstraintEvalParam repeatedMotionParams{};
519     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
520             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
521     int32_t sensorTypeId = 1;
522     SensorUser sensorUser;
523     repeatedMotionConstraint->isMonitoring_ = false;
524     repeatedMotionConstraint->StopSensor();
525     repeatedMotionConstraint->isMonitoring_ = true;
526     repeatedMotionConstraint->StopSensor();
527     sensorTypeId = repeatedMotionConstraint->detectionTimeOut_;
528     repeatedMotionConstraint->StartSensor();
529     EXPECT_TRUE(repeatedMotionConstraint->isMonitoring_ == true);
530 }
531 
532 /**
533  * @tc.name: StandbyPluginUnitTest_019
534  * @tc.desc: test ConstraintManagerAdapter of Init.
535  * @tc.type: FUNC
536  * @tc.require:
537  */
538 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0019, TestSize.Level1)
539 {
540     auto repeatedMotionConstraint = std::make_shared<ConstraintManagerAdapter>();
541     repeatedMotionConstraint->Init();
542     EXPECT_TRUE(repeatedMotionConstraint->Init());
543     StandbyServiceImpl::GetInstance()->GetStateManager();
544     repeatedMotionConstraint->Init();
545 }
546 
547 /**
548  * @tc.name: StandbyPluginUnitTest_020
549  * @tc.desc: test ConstraintManagerAdapter of StartEvalution.
550  * @tc.type: FUNC
551  * @tc.require:
552  */
553 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0020, TestSize.Level1)
554 {
555     auto repeatedMotionConstraint = std::make_shared<ConstraintManagerAdapter>();
556     ConstraintEvalParam params;
557     repeatedMotionConstraint->StartEvalution(params);
558     repeatedMotionConstraint->isEvaluation_ = false;
559     repeatedMotionConstraint->StartEvalution(params);
560     repeatedMotionConstraint->isEvaluation_ = true;
561     repeatedMotionConstraint->UnInit();
562     EXPECT_TRUE(repeatedMotionConstraint->StartEvalution(params) != ERR_OK);
563 }
564 
565 /**
566  * @tc.name: StandbyPluginUnitTest_021
567  * @tc.desc: test ConstraintManagerAdapter of StopEvalution.
568  * @tc.type: FUNC
569  * @tc.require:
570  */
571 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0021, TestSize.Level1)
572 {
573     auto repeatedMotionConstraint = std::make_shared<ConstraintManagerAdapter>();
574     repeatedMotionConstraint->StopEvalution();
575     repeatedMotionConstraint->isEvaluation_ = false;
576     repeatedMotionConstraint->StopEvalution();
577     repeatedMotionConstraint->isEvaluation_ = true;
578     repeatedMotionConstraint->UnInit();
579     EXPECT_TRUE(repeatedMotionConstraint->StopEvalution() != ERR_OK);
580 }
581 
582 /**
583  * @tc.name: StandbyPluginUnitTest_022
584  * @tc.desc: test ChargeStateMonitor of StartMonitoring.
585  * @tc.type: FUNC
586  * @tc.require:
587  */
588 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0022, TestSize.Level1)
589 {
590     auto repeatedChargeStateMonitor = std::make_shared<ChargeStateMonitor>();
591     repeatedChargeStateMonitor->StartMonitoring();
592     standbyStateManager_->napStatePtr_->EndEvalCurrentState(false);
593     repeatedChargeStateMonitor->StartMonitoring();
594     EXPECT_TRUE(repeatedChargeStateMonitor->Init());
595 }
596 
597 /**
598  * @tc.name: StandbyPluginUnitTest_023
599  * @tc.desc: test StateManagerAdapter of UnInit.
600  * @tc.type: FUNC
601  * @tc.require:
602  */
603 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0023, TestSize.Level1)
604 {
605     EXPECT_TRUE(DelayedSingleton<StateManagerAdapter>::GetInstance()->Init());
606 }
607 
608 /**
609  * @tc.name: StandbyPluginUnitTest_024
610  * @tc.desc: test StateManagerAdapter of HandleEvent.
611  * @tc.type: FUNC
612  * @tc.require:
613  */
614 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0024, TestSize.Level1)
615 {
616     StandbyMessage message;
617     message.eventId_ = StandbyMessageType::COMMON_EVENT;
618     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleEvent(message);
619     message.eventId_ = StandbyMessageType::RES_CTRL_CONDITION_CHANGED;
620     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleEvent(message);
621     message.eventId_ = 1234;
622     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleEvent(message);
623     EXPECT_TRUE(message.eventId_ != StandbyMessageType::COMMON_EVENT);
624 }
625 
626 /**
627  * @tc.name: StandbyPluginUnitTest_025
628  * @tc.desc: test StateManagerAdapter of HandleCommonEvent.
629  * @tc.type: FUNC
630  * @tc.require:
631  */
632 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0025, TestSize.Level1)
633 {
634     StandbyMessage message;
635     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON;
636     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
637     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING;
638     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
639     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_ATTACHED;
640     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
641     DelayedSingleton<StateManagerAdapter>::GetInstance()->Init();
642     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
643     message.action_ = "1234";
644     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
645     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF;
646     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
647     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING;
648     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
649     EXPECT_TRUE(DelayedSingleton<StateManagerAdapter>::GetInstance()->indexToState_.size() != 0);
650 }
651 
652 /**
653  * @tc.name: StandbyPluginUnitTest_026
654  * @tc.desc: test StateManagerAdapter of HandleScrOffHalfHour.
655  * @tc.type: FUNC
656  * @tc.require:
657  */
658 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0026, TestSize.Level1)
659 {
660     StandbyMessage message;
661     DelayedSingleton<StateManagerAdapter>::GetInstance()->scrOffHalfHourTimerId_ = 0;
662     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleScrOffHalfHour(message);
663     DelayedSingleton<StateManagerAdapter>::GetInstance()->scrOffHalfHourTimerId_ = 1;
664     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleScrOffHalfHour(message);
665     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF;
666     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleScrOffHalfHour(message);
667     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON;
668     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleScrOffHalfHour(message);
669     EXPECT_TRUE(DelayedSingleton<StateManagerAdapter>::GetInstance()->isScreenOn_);
670     message.action_ = "1234";
671     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleScrOffHalfHour(message);
672 }
673 
674 /**
675  * @tc.name: StandbyPluginUnitTest_027
676  * @tc.desc: test StateManagerAdapter of HandleOpenCloseLid.
677  * @tc.type: FUNC
678  * @tc.require:
679  */
680 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0027, TestSize.Level1)
681 {
682     StandbyMessage message;
683     message.action_ = LID_OPEN;
684     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleOpenCloseLid(message);
685     message.action_ = LID_CLOSE;
686     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleOpenCloseLid(message);
687     message.action_ = "1234";
688     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleOpenCloseLid(message);
689     EXPECT_TRUE(DelayedSingleton<StateManagerAdapter>::GetInstance()->TransitToState(0) == ERR_OK);
690 }
691 
692 /**
693  * @tc.name: StandbyPluginUnitTest_028
694  * @tc.desc: test StateManagerAdapter of EndEvalCurrentState.
695  * @tc.type: FUNC
696  * @tc.require:
697  */
698 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0028, TestSize.Level1)
699 {
700     auto evalResult = true;
701     standbyStateManager_->isEvalution_ = false;
702     EXPECT_TRUE(standbyStateManager_->EndEvalCurrentState(evalResult) == ERR_STANDBY_STATE_TIMING_SEQ_ERROR);
703     standbyStateManager_->isEvalution_ = true;
704     standbyStateManager_->EndEvalCurrentState(evalResult);
705 }
706 
707 /**
708  * @tc.name: StandbyPluginUnitTest_029
709  * @tc.desc: test StateManagerAdapter of StopEvalution.
710  * @tc.type: FUNC
711  * @tc.require:
712  */
713 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0029, TestSize.Level1)
714 {
715     standbyStateManager_->isEvalution_ = false;
716     standbyStateManager_->StopEvalution();
717     standbyStateManager_->isEvalution_ = true;
718     standbyStateManager_->StopEvalution();
719     EXPECT_TRUE(standbyStateManager_->isEvalution_ == false);
720 }
721 
722 /**
723  * @tc.name: StandbyPluginUnitTest_030
724  * @tc.desc: test ListenerManagerAdapter of StartListener.
725  * @tc.type: FUNC
726  * @tc.require:
727  */
728 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0030, TestSize.Level1)
729 {
730     DelayedSingleton<ListenerManagerAdapter>::GetInstance()->StartListener();
731     DelayedSingleton<ListenerManagerAdapter>::GetInstance()->messageListenerList_.clear();
732     EXPECT_TRUE(DelayedSingleton<ListenerManagerAdapter>::GetInstance()->StartListener() == ERR_OK);
733 }
734 
735 /**
736  * @tc.name: StandbyPluginUnitTest_031
737  * @tc.desc: test ListenerManagerAdapter of StopListener.
738  * @tc.type: FUNC
739  * @tc.require:
740  */
741 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0031, TestSize.Level1)
742 {
743     DelayedSingleton<ListenerManagerAdapter>::GetInstance()->StopListener();
744     DelayedSingleton<ListenerManagerAdapter>::GetInstance()->messageListenerList_.clear();
745     EXPECT_TRUE(DelayedSingleton<ListenerManagerAdapter>::GetInstance()->StopListener() == ERR_OK);
746 }
747 
748 /**
749  * @tc.name: StandbyPluginUnitTest_032
750  * @tc.desc: test MotionSensorMonitor of AcceleromterCallback.
751  * @tc.type: FUNC
752  * @tc.require:
753  */
754 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0032, TestSize.Level1)
755 {
756     ConstraintEvalParam repeatedMotionParams{};
757     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
758             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
759     SensorEvent event;
760     repeatedMotionConstraint->Init();
761     GravityData data = {0, 0, 0};
762     event.sensorTypeId = SENSOR_TYPE_ID_NONE;
763     event.data = reinterpret_cast<uint8_t*>(&data);
764     repeatedMotionConstraint->AcceleromterCallback(&event);
765     EXPECT_TRUE(repeatedMotionConstraint->GetEnergy() == 0);
766     repeatedMotionConstraint->energy_ = 10000;
767     repeatedMotionConstraint->AcceleromterCallback(&event);
768     repeatedMotionConstraint->AcceleromterCallback(nullptr);
769 }
770 
771 /**
772  * @tc.name: StandbyPluginUnitTest_033
773  * @tc.desc: test MotionSensorMonitor of AcceleromterCallback.
774  * @tc.type: FUNC
775  * @tc.require:
776  */
777 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0033, TestSize.Level1)
778 {
779     ConstraintEvalParam repeatedMotionParams{};
780     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
781             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
782     SensorEvent event;
783     repeatedMotionConstraint->Init();
784     GravityData data = {0, 0, 0};
785     event.sensorTypeId = SENSOR_TYPE_ID_NONE;
786     event.data = reinterpret_cast<uint8_t*>(&data);
787     repeatedMotionConstraint->RepeatAcceleromterCallback(&event);
788     EXPECT_NE(repeatedMotionConstraint->GetEnergy(), 0);
789     repeatedMotionConstraint->energy_ = 10000;
790     repeatedMotionConstraint->RepeatAcceleromterCallback(&event);
791     repeatedMotionConstraint->RepeatAcceleromterCallback(nullptr);
792 }
793 
794 /**
795  * @tc.name: StandbyPluginUnitTest_034
796  * @tc.desc: test StateManagerAdapter of OnScreenOffHalfHourInner.
797  * @tc.type: FUNC
798  * @tc.require:
799  */
800 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0034, TestSize.Level1)
801 {
802     bool scrOffHalfHourCtrl = true;
803     bool repeated = true;
804     standbyStateManager_->OnScreenOffHalfHourInner(scrOffHalfHourCtrl, repeated);
805     repeated = false;
806     standbyStateManager_->OnScreenOffHalfHourInner(scrOffHalfHourCtrl, repeated);
807     scrOffHalfHourCtrl = false;
808     standbyStateManager_->OnScreenOffHalfHourInner(scrOffHalfHourCtrl, repeated);
809     repeated = true;
810     standbyStateManager_->OnScreenOffHalfHourInner(scrOffHalfHourCtrl, repeated);
811     EXPECT_TRUE(standbyStateManager_->scrOffHalfHourCtrl_ == false);
812 
813     standbyStateManager_->curStatePtr_ = standbyStateManager_->sleepStatePtr_;
814     standbyStateManager_->preStatePtr_ = standbyStateManager_->maintStatePtr_;
815     standbyStateManager_->OnScreenOffHalfHourInner(true, false);
816 
817     standbyStateManager_->curStatePtr_ = standbyStateManager_->maintStatePtr_;
818     standbyStateManager_->preStatePtr_ = standbyStateManager_->sleepStatePtr_;
819     standbyStateManager_->OnScreenOffHalfHourInner(true, false);
820 
821     standbyStateManager_->curStatePtr_ = standbyStateManager_->workingStatePtr_;
822     standbyStateManager_->preStatePtr_ = standbyStateManager_->sleepStatePtr_;
823     standbyStateManager_->OnScreenOffHalfHourInner(true, false);
824 }
825 
826 /**
827  * @tc.name: StandbyPluginUnitTest_035
828  * @tc.desc: test StateManagerAdapter of ShellDump.
829  * @tc.type: FUNC
830  * @tc.require:
831  */
832 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0035, TestSize.Level1)
833 {
834     std::vector<std::string> argsInStr {};
835     std::string result;
836     int32_t dumpFirstParam = 0;
837     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "0");
838     standbyStateManager_->ShellDump(argsInStr, result);
839     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "-D");
840     standbyStateManager_->ShellDump(argsInStr, result);
841     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "-E");
842     standbyStateManager_->ShellDump(argsInStr, result);
843     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "-S");
844     standbyStateManager_->ShellDump(argsInStr, result);
845     EXPECT_TRUE(argsInStr.size() != 0);
846 }
847 
848 /**
849  * @tc.name: StandbyPluginUnitTest_036
850  * @tc.desc: test StateManagerAdapter of DumpEnterSpecifiedState.
851  * @tc.type: FUNC
852  * @tc.require:
853  */
854 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0036, TestSize.Level1)
855 {
856     std::vector<std::string> argsInStr {};
857     std::string result;
858     int32_t dumpFirstParam = 0;
859     int32_t dumpThirdParam = 2;
860     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "0");
861     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "0");
862     argsInStr.insert(argsInStr.begin() + dumpThirdParam, "false");
863     standbyStateManager_->DumpEnterSpecifiedState(argsInStr, result);
864     argsInStr.insert(argsInStr.begin() + dumpThirdParam, "0");
865     standbyStateManager_->DumpEnterSpecifiedState(argsInStr, result);
866     EXPECT_TRUE(argsInStr.size() != 0);
867 }
868 
869 /**
870  * @tc.name: StandbyPluginUnitTest_037
871  * @tc.desc: test StateManagerAdapter of DumpActivateMotion.
872  * @tc.type: FUNC
873  * @tc.require:
874  */
875 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0037, TestSize.Level1)
876 {
877     std::vector<std::string> argsInStr {};
878     std::string result;
879     int32_t dumpFirstParam = 0;
880     int32_t dumpSecondParam = 1;
881     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "0");
882     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "0");
883     argsInStr.insert(argsInStr.begin() + dumpSecondParam, "--motion");
884     standbyStateManager_->DumpActivateMotion(argsInStr, result);
885     argsInStr.insert(argsInStr.begin() + dumpSecondParam, "--blocked");
886     standbyStateManager_->DumpActivateMotion(argsInStr, result);
887     argsInStr.insert(argsInStr.begin() + dumpSecondParam, "--halfhour");
888     standbyStateManager_->DumpActivateMotion(argsInStr, result);
889     argsInStr.insert(argsInStr.begin() + dumpSecondParam, "0");
890     standbyStateManager_->DumpActivateMotion(argsInStr, result);
891     EXPECT_TRUE(argsInStr.size() != 0);
892 }
893 
894 /**
895  * @tc.name: StandbyPluginUnitTest_038
896  * @tc.desc: test InputManagerListener.
897  * @tc.type: FUNC
898  * @tc.require:
899  */
900 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0038, TestSize.Level1)
901 {
902     auto inputManagerListener = std::make_shared<InputManagerListener>();
903     inputManagerListener->subscriberId_ = -1;
904     inputManagerListener->StopListener();
905     inputManagerListener->OnCallbackEvent(MMI::SwitchEvent::SWITCH_OFF);
906     inputManagerListener->OnCallbackEvent(MMI::SwitchEvent::SWITCH_ON);
907     EXPECT_TRUE(inputManagerListener->subscriberId_ <= 0);
908 }
909 
910 /**
911  * @tc.name: StandbyPluginUnitTest_039
912  * @tc.desc: test BackgroundTaskListener.
913  * @tc.type: FUNC
914  * @tc.require:
915  */
916 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_039, TestSize.Level1)
917 {
918     auto backgroundTaskListener = std::make_shared<BackgroundTaskListener>();
919     backgroundTaskListener->StartListener();
920     backgroundTaskListener->StopListener();
921     backgroundTaskListener->bgTaskListenerImpl_ = nullptr;
922     backgroundTaskListener->StartListener();
923     EXPECT_NE(backgroundTaskListener->StopListener(), ERR_OK);
924 }
925 
926 /**
927  * @tc.name: StandbyPluginUnitTest_040
928  * @tc.desc: test ListenerManagerAdapter.
929  * @tc.type: FUNC
930  * @tc.require:
931  */
932 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_040, TestSize.Level1)
933 {
934     StandbyConfigManager::GetInstance()->strategyList_.emplace_back("RUNNING_LOCK");
935     listenerManager_->StopListener();
936     listenerManager_->UnInit();
937     listenerManager_->StartListener();
938     listenerManager_->Init();
939     StandbyConfigManager::GetInstance()->strategyList_.emplace_back("NETWORK");
940     listenerManager_->StopListener();
941     listenerManager_->UnInit();
942     listenerManager_->StartListener();
943     listenerManager_->Init();
944     EXPECT_FALSE(listenerManager_->listenerPluginMap_.empty());
945 }
946 
947 /**
948  * @tc.name: StandbyPluginUnitTest_041
949  * @tc.desc: test StartTransitNextState.
950  * @tc.type: FUNC
951  * @tc.require:
952  */
953 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_041, TestSize.Level1)
954 {
955     standbyStateManager_->sleepStatePtr_->stateManager_.reset();
956     standbyStateManager_->sleepStatePtr_->TransitToPhaseInner(0, 0);
957     standbyStateManager_->sleepStatePtr_->StartTransitNextState(standbyStateManager_->sleepStatePtr_);
958     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
959     standbyStateManager_->sleepStatePtr_->stateManager_ = standbyStateManager_;
960     standbyStateManager_->isEvalution_ = true;
961     standbyStateManager_->sleepStatePtr_->nextState_ = 0;
962     standbyStateManager_->sleepStatePtr_->StartTransitNextState(standbyStateManager_->sleepStatePtr_);
963     SleepForFC();
964     EXPECT_FALSE(standbyStateManager_->sleepStatePtr_ == nullptr);
965 }
966 
967 /**
968  * @tc.name: StandbyPluginUnitTest_042
969  * @tc.desc: test StopTimedTask.
970  * @tc.type: FUNC
971  * @tc.require:
972  */
973 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_042, TestSize.Level1)
974 {
975     standbyStateManager_->workingStatePtr_->timedTaskMap_.emplace("", -1);
976     standbyStateManager_->workingStatePtr_->StopTimedTask("");
977     standbyStateManager_->workingStatePtr_->StopTimedTask("test");
978     standbyStateManager_->workingStatePtr_->DestroyAllTimedTask();
979     SleepForFC();
980     EXPECT_TRUE(standbyStateManager_->workingStatePtr_->timedTaskMap_.empty());
981 
982     standbyStateManager_->workingStatePtr_->stateManager_.reset();
983     standbyStateManager_->workingStatePtr_->EndState();
984     standbyStateManager_->workingStatePtr_->EndEvalCurrentState(false);
985     standbyStateManager_->workingStatePtr_->stateManager_ = standbyStateManager_;
986 }
987 
988 /**
989  * @tc.name: StandbyPluginUnitTest_043
990  * @tc.desc: test StopTimedTask.
991  * @tc.type: FUNC
992  * @tc.require:
993  */
994 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_043, TestSize.Level1)
995 {
996     standbyStateManager_->workingStatePtr_->timedTaskMap_.emplace("", -1);
997     standbyStateManager_->workingStatePtr_->StopTimedTask("");
998     standbyStateManager_->workingStatePtr_->StopTimedTask("test");
999     standbyStateManager_->workingStatePtr_->DestroyAllTimedTask();
1000     SleepForFC();
1001     EXPECT_TRUE(standbyStateManager_->workingStatePtr_->timedTaskMap_.empty());
1002 }
1003 
1004 /**
1005  * @tc.name: StandbyPluginUnitTest_044
1006  * @tc.desc: test SleepState.
1007  * @tc.type: FUNC
1008  * @tc.require:
1009  */
1010 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_044, TestSize.Level1)
1011 {
1012     std::string result {""};
1013     standbyStateManager_->sleepStatePtr_->ShellDump({"-D", "--repeat"}, result);
1014     standbyStateManager_->sleepStatePtr_->ShellDump({"-S", "--r"}, result);
1015     standbyStateManager_->sleepStatePtr_->ShellDump({"-S", "--repeat"}, result);
1016     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
1017     SleepForFC();
1018     EXPECT_TRUE(standbyStateManager_->workingStatePtr_->timedTaskMap_.empty());
1019 }
1020 }  // namespace DevStandbyMgr
1021 }  // namespace OHOS
1022