1 /*
2 * Copyright (c) 2021-2022 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_device_mode_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
31 using namespace testing::ext;
32 using namespace OHOS::PowerMgr;
33 using namespace OHOS;
34 using namespace std;
35
36
OnPowerModeChanged(PowerMode mode)37 void PowerDeviceModeTest::PowerModeTest1Callback::OnPowerModeChanged(PowerMode mode)
38 {
39 POWER_HILOGD(LABEL_TEST, "PowerModeTest1Callback::OnPowerModeChanged.");
40 }
41
OnPowerModeChanged(PowerMode mode)42 void PowerDeviceModeTest::PowerModeTest2Callback::OnPowerModeChanged(PowerMode mode)
43 {
44 POWER_HILOGD(LABEL_TEST, "PowerModeTest2Callback::OnPowerModeChanged.");
45 }
46
47 namespace {
48 /**
49 * @tc.name: PowerStateCallback001
50 * @tc.desc: test PowerStateCallback
51 * @tc.type: FUNC
52 */
53 HWTEST_F (PowerDeviceModeTest, PowerDeviceModeCallback001, TestSize.Level0)
54 {
55 auto& powerMgrClient = PowerMgrClient::GetInstance();
56 sptr<IPowerModeCallback> cb1 = new PowerModeTest1Callback();
57 powerMgrClient.RegisterPowerModeCallback(cb1);
58 POWER_HILOGD(LABEL_TEST, "PowerDeviceModeCallback001 1.");
59 {
60 sptr<IPowerModeCallback> cb2 = new PowerModeTest2Callback();
61 powerMgrClient.UnRegisterPowerModeCallback(cb2);
62 POWER_HILOGD(LABEL_TEST, "PowerDeviceModeCallback001 2.");
63 powerMgrClient.RegisterPowerModeCallback(cb2);
64 POWER_HILOGD(LABEL_TEST, "PowerDeviceModeCallback001 3.");
65 powerMgrClient.RegisterPowerModeCallback(cb2);
66 POWER_HILOGD(LABEL_TEST, "PowerDeviceModeCallback001 4.");
67 }
68 powerMgrClient.UnRegisterPowerModeCallback(cb1);
69 POWER_HILOGD(LABEL_TEST, "PowerDeviceModeTest::PowerDeviceModeCallback001 end.");
70 }
71
72 /**
73 * @tc.name: SetDeviceModeTest001
74 * @tc.desc: test SetDeviceMode in proxy
75 * @tc.type: FUNC
76 */
77 HWTEST_F (PowerDeviceModeTest, SetDeviceModeTest001, TestSize.Level2)
78 {
79 sleep(SLEEP_WAIT_TIME_S);
80 GTEST_LOG_(INFO) << "SetDeviceModeTest001: SetDeviceMode start.";
81 auto& powerMgrClient = PowerMgrClient::GetInstance();
82
83 PowerMode mode = PowerMode::POWER_SAVE_MODE;
84 if (false) {
85 powerMgrClient.SetDeviceMode(mode);
86 }
87
88 GTEST_LOG_(INFO) << "SetDeviceModeTest001: SetDeviceMode end.";
89 }
90
91 /**
92 * @tc.name: GetDeviceModeTest001
93 * @tc.desc: test GetDeviceMode in proxy
94 * @tc.type: FUNC
95 */
96 HWTEST_F (PowerDeviceModeTest, GetDeviceModeTest001, TestSize.Level2)
97 {
98 PowerMode mode = PowerMode::NORMAL_MODE;
99 sleep(SLEEP_WAIT_TIME_S);
100 GTEST_LOG_(INFO) << "GetDeviceModeTest001: GetDeviceMode start.";
101 auto& powerMgrClient = PowerMgrClient::GetInstance();
102
103 if (false) {
104 mode = powerMgrClient.GetDeviceMode();
105 }
106 }
107 }