1 /*
2 * Copyright (c) 2021 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 "power_shutdown_test.h"
17
18 #include <iostream>
19
20 #include <datetime_ex.h>
21 #include <gtest/gtest.h>
22 #include <if_system_ability_manager.h>
23 #include <ipc_skeleton.h>
24 #include <string_ex.h>
25
26 #include "power_common.h"
27 #include "power_mgr_client.h"
28 #include "power_mgr_service.h"
29 #include "power_state_machine.h"
30 #include "sys_param.h"
31
32 using namespace testing::ext;
33 using namespace OHOS::PowerMgr;
34 using namespace OHOS;
35 using namespace std;
36
37
ShutdownCallback()38 void PowerShutdownTest::PowerShutdownTest1Callback::ShutdownCallback()
39 {
40 POWER_HILOGD(MODULE_SERVICE, "PowerShutdownTest1Callback::ShutdownCallback.");
41 }
42
ShutdownCallback()43 void PowerShutdownTest::PowerShutdownTest2Callback::ShutdownCallback()
44 {
45 POWER_HILOGD(MODULE_SERVICE, "PowerShutdownTest2Callback::ShutdownCallback.");
46 }
47
48 namespace {
49 /**
50 * @tc.name: PowerShutdownCallback001
51 * @tc.desc: test ShutdownCallback
52 * @tc.type: FUNC
53 */
54 HWTEST_F (PowerShutdownTest, PowerShutdownCallback001, TestSize.Level0)
55 {
56 auto& powerMgrClient = PowerMgrClient::GetInstance();
57 sptr<IShutdownCallback> cb1 = new PowerShutdownTest1Callback();
58 powerMgrClient.RegisterShutdownCallback(cb1);
59 POWER_HILOGD(MODULE_SERVICE, "PowerShutdownCallback001 1.");
60 {
61 sptr<IShutdownCallback> cb2 = new PowerShutdownTest2Callback();
62 powerMgrClient.UnRegisterShutdownCallback(cb2);
63 POWER_HILOGD(MODULE_SERVICE, "PowerShutdownCallback001 2.");
64 powerMgrClient.RegisterShutdownCallback(cb2);
65 POWER_HILOGD(MODULE_SERVICE, "PowerShutdownCallback001 3.");
66 powerMgrClient.RegisterShutdownCallback(cb2);
67 POWER_HILOGD(MODULE_SERVICE, "PowerShutdownCallback001 4.");
68 }
69 powerMgrClient.UnRegisterShutdownCallback(cb1);
70 POWER_HILOGD(MODULE_SERVICE, "PowerShutdownTest::PowerShutdownCallback001 end.");
71 }
72
73 /**
74 * @tc.name: ShutDownDeviceTest001
75 * @tc.desc: test ShutDownDevice in proxy
76 * @tc.type: FUNC
77 */
78 HWTEST_F (PowerShutdownTest, ShutDownDeviceTest001, TestSize.Level2)
79 {
80 sleep(SLEEP_WAIT_TIME_S);
81 GTEST_LOG_(INFO) << "ShutDownDeviceTest001: ShutDownDevice start.";
82 auto& powerMgrClient = PowerMgrClient::GetInstance();
83
84 if (false) {
85 powerMgrClient.ShutDownDevice(string("ShutDownDeviceTest001"));
86 }
87
88 GTEST_LOG_(INFO) << "ShutDownDeviceTest001: ShutDownDevice end.";
89 }
90 }