• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 
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: SetDeviceModeTest001
48  * @tc.desc: test SetDeviceMode in proxy
49  * @tc.type: FUNC
50  */
51 HWTEST_F (PowerSetModeTest, SetModeTest001, TestSize.Level0)
52 {
53     sleep(SLEEP_WAIT_TIME_S);
54     GTEST_LOG_(INFO) << "SetModeTest001: SetMode start.";
55     auto& powerMgrClient = PowerMgrClient::GetInstance();
56 
57     PowerMode mode1 = PowerMode::POWER_SAVE_MODE;
58     if (true) {
59         powerMgrClient.SetDeviceMode(mode1);
60         EXPECT_EQ(mode1, powerMgrClient.GetDeviceMode());
61     }
62     sleep(SLEEP_WAIT_TIME_S);
63     PowerMode mode2 = PowerMode::PERFORMANCE_MODE;
64     if (true) {
65         powerMgrClient.SetDeviceMode(mode2);
66         EXPECT_EQ(mode2, powerMgrClient.GetDeviceMode());
67     }
68     sleep(SLEEP_WAIT_TIME_S);
69     PowerMode mode3 = PowerMode::EXTREME_POWER_SAVE_MODE;
70     if (true) {
71         powerMgrClient.SetDeviceMode(mode3);
72         EXPECT_EQ(mode3, powerMgrClient.GetDeviceMode());
73     }
74 
75     GTEST_LOG_(INFO) << "SetModeTest001: SetMode end.";
76 }
77 
78 /**
79  * @tc.name: SaveModeTest001
80  * @tc.desc: test StartXMlParse
81  * @tc.type: FUNC
82  */
83 HWTEST_F (PowerSetModeTest, SaveModeTest001, TestSize.Level0)
84 {
85     auto mode = std::make_shared<PowerSaveMode>();
86     int32_t ret = mode->GetSleepTime(0);
87     EXPECT_TRUE(ret == -1);
88 }
89 }