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 #include "power_getcontroller_mock_test.h"
16 
17 #ifdef POWERMGR_GTEST
18 #define private   public
19 #define protected public
20 #endif
21 
22 #include "power_mgr_service.h"
23 #include "power_state_machine.h"
24 #include "sp_singleton.h"
25 #include "wakeup_controller.h"
26 
27 using namespace testing::ext;
28 using namespace OHOS::PowerMgr;
29 using namespace OHOS;
30 using namespace std;
31 static sptr<PowerMgrService> g_service;
32 
SetUpTestCase(void)33 void PowerGetControllerMockTest::SetUpTestCase(void)
34 {
35     g_service = DelayedSpSingleton<PowerMgrService>::GetInstance();
36     g_service->OnStart();
37 }
38 
TearDownTestCase(void)39 void PowerGetControllerMockTest::TearDownTestCase(void)
40 {
41     g_service->OnStop();
42     DelayedSpSingleton<PowerMgrService>::DestroyInstance();
43 }
44 
45 namespace {
46 /**
47  * @tc.name: PowerGetControllerMockTest001
48  * @tc.desc: test GetSourceList(exception)
49  * @tc.type: FUNC
50  * @tc.require: issueI7G6OY
51  */
52 HWTEST_F(PowerGetControllerMockTest, PowerGetControllerMockTest001, TestSize.Level0)
53 {
54     GTEST_LOG_(INFO) << "PowerGetControllerMockTest001: start";
55     std::shared_ptr<PowerStateMachine> stateMachine = g_service->GetPowerStateMachine();
56     std::shared_ptr<WakeupController> wakeupController_ = std::make_shared<WakeupController>(stateMachine);
57     EXPECT_TRUE(wakeupController_ != nullptr);
58     wakeupController_->Wakeup();
59 
60     InputCallback* callback = new InputCallback();
61     std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent = OHOS::MMI::KeyEvent::Create();
62     keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
63     keyEvent->SetKeyCode(OHOS::MMI::KeyEvent::KEYCODE_F1);
64     callback->OnInputEvent(keyEvent);
65     EXPECT_TRUE(callback != nullptr);
66     delete callback;
67     GTEST_LOG_(INFO) << "PowerGetControllerMockTest001:  end";
68 }
69 } // namespace
70