• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #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_log.h"
23 #include "power_mgr_service.h"
24 #include "power_state_machine.h"
25 #include "sp_singleton.h"
26 #include "wakeup_controller.h"
27 
28 using namespace testing::ext;
29 using namespace OHOS::PowerMgr;
30 using namespace OHOS;
31 using namespace std;
32 static sptr<PowerMgrService> g_service;
33 
SetUpTestCase(void)34 void PowerGetControllerMockTest::SetUpTestCase(void)
35 {
36     g_service = DelayedSpSingleton<PowerMgrService>::GetInstance();
37     g_service->OnStart();
38 }
39 
TearDownTestCase(void)40 void PowerGetControllerMockTest::TearDownTestCase(void)
41 {
42     g_service->OnStop();
43     DelayedSpSingleton<PowerMgrService>::DestroyInstance();
44 }
45 
46 namespace {
47 /**
48  * @tc.name: PowerGetControllerMockTest001
49  * @tc.desc: test GetSourceList(exception)
50  * @tc.type: FUNC
51  * @tc.require: issueI7G6OY
52  */
53 HWTEST_F(PowerGetControllerMockTest, PowerGetControllerMockTest001, TestSize.Level1)
54 {
55     GTEST_LOG_(INFO) << "PowerGetControllerMockTest001 function start!";
56     POWER_HILOGI(LABEL_TEST, "PowerGetControllerMockTest001 start");
57     std::shared_ptr<PowerStateMachine> stateMachine = g_service->GetPowerStateMachine();
58     std::shared_ptr<WakeupController> wakeupController_ = std::make_shared<WakeupController>(stateMachine);
59     EXPECT_TRUE(wakeupController_ != nullptr);
60     wakeupController_->Wakeup();
61 #ifdef HAS_MULTIMODALINPUT_INPUT_PART
62     InputCallback* callback = new InputCallback();
63     std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent = OHOS::MMI::KeyEvent::Create();
64     keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
65     keyEvent->SetKeyCode(OHOS::MMI::KeyEvent::KEYCODE_F1);
66     callback->OnInputEvent(keyEvent);
67     EXPECT_TRUE(callback != nullptr);
68     delete callback;
69 #endif
70     POWER_HILOGI(LABEL_TEST, "PowerGetControllerMockTest001 function end!");
71     GTEST_LOG_(INFO) << "PowerGetControllerMockTest001: end";
72 }
73 } // namespace
74