1 /*
2  * Copyright (c) 2021-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 
16 #include "power_set_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>
25 #include <string_ex.h>
26 
27 #include "config_policy_utils.h"
28 #include "power_common.h"
29 #include "power_mgr_client.h"
30 #include "power_mgr_service.h"
31 #include "power_save_mode.h"
32 #include "power_state_machine.h"
33 
34 using namespace testing::ext;
35 using namespace OHOS::PowerMgr;
36 using namespace OHOS;
37 using namespace std;
38 
GetOneCfgFile(const char *pathSuffix, char *buf, unsigned int bufLength)39 char* GetOneCfgFile(const char *pathSuffix, char *buf, unsigned int bufLength)
40 {
41     std::string ret = "/";
42     return const_cast<char*>(ret.c_str());
43 }
44 
45 namespace {
46 /**
47  * @tc.name: SetModeTest001
48  * @tc.desc: test SetDeviceMode in proxy
49  * @tc.type: FUNC
50  */
HWTEST_F(PowerSetModeTest, SetModeTest001, TestSize.Level0)51 HWTEST_F (PowerSetModeTest, SetModeTest001, TestSize.Level0)
52 {
53     POWER_HILOGD(LABEL_TEST, "SetModeTest001 start.");
54     sleep(SLEEP_WAIT_TIME_S);
55     GTEST_LOG_(INFO) << "SetModeTest001: SetMode start.";
56     auto& powerMgrClient = PowerMgrClient::GetInstance();
57 
58     PowerMode mode1 = PowerMode::POWER_SAVE_MODE;
59     if (true) {
60         powerMgrClient.SetDeviceMode(mode1);
61         EXPECT_EQ(mode1, powerMgrClient.GetDeviceMode());
62     }
63     sleep(SLEEP_WAIT_TIME_S);
64     PowerMode mode2 = PowerMode::PERFORMANCE_MODE;
65     if (true) {
66         powerMgrClient.SetDeviceMode(mode2);
67         EXPECT_EQ(mode2, powerMgrClient.GetDeviceMode());
68     }
69     sleep(SLEEP_WAIT_TIME_S);
70     PowerMode mode3 = PowerMode::EXTREME_POWER_SAVE_MODE;
71     if (true) {
72         powerMgrClient.SetDeviceMode(mode3);
73         EXPECT_EQ(mode3, powerMgrClient.GetDeviceMode());
74     }
75     POWER_HILOGD(LABEL_TEST, "SetModeTest001 end.");
76     GTEST_LOG_(INFO) << "SetModeTest001: SetMode end.";
77 }
78 
79 /**
80  * @tc.name: SaveModeTest001
81  * @tc.desc: test StartXMlParse
82  * @tc.type: FUNC
83  */
HWTEST_F(PowerSetModeTest, SaveModeTest001, TestSize.Level0)84 HWTEST_F (PowerSetModeTest, SaveModeTest001, TestSize.Level0)
85 {
86     POWER_HILOGD(LABEL_TEST, "SaveModeTest001 start.");
87     auto mode = std::make_shared<PowerSaveMode>();
88     int32_t ret = mode->GetSleepTime(0);
89     EXPECT_TRUE(ret == -1);
90     POWER_HILOGD(LABEL_TEST, "SaveModeTest001 end.");
91 }
92 }