• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 <functional>
17 #include <gtest/gtest.h>
18 
19 #include "policy/power_mode_policy.h"
20 #include "work_policy_manager.h"
21 #include "work_scheduler_service.h"
22 #include "battery_srv_client.h"
23 #include "power_mgr_client.h"
24 #include "power_mode_info.h"
25 
26 
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace PowerMgr {
GetChargingStatus()31 BatteryChargeState BatterySrvClient::GetChargingStatus()
32 {
33     return BatteryChargeState::CHARGE_STATE_NONE;
34 }
35 }
36 namespace WorkScheduler {
37 class PowerModePolicyTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
TearDownTestCase()40     static void TearDownTestCase() {};
SetUp()41     void SetUp() {};
TearDown()42     void TearDown() {};
43     static std::shared_ptr<WorkPolicyManager> workPolicyManager_;
44     static std::shared_ptr<PowerModePolicy> powerModePolicy_;
45 };
46 
47 std::shared_ptr<PowerModePolicy> PowerModePolicyTest::powerModePolicy_ = nullptr;
48 std::shared_ptr<WorkPolicyManager> PowerModePolicyTest::workPolicyManager_ = nullptr;
49 
SetUpTestCase()50 void PowerModePolicyTest::SetUpTestCase()
51 {
52     std::shared_ptr<WorkSchedulerService> workSchedulerService_ = std::make_shared<WorkSchedulerService>();
53     workSchedulerService_->Start();
54     workPolicyManager_ = std::make_shared<WorkPolicyManager>(workSchedulerService_);
55     powerModePolicy_ = std::make_shared<PowerModePolicy>(workPolicyManager_);
56 }
57 
58 /**
59  * @tc.name: GetPolicyMaxRunning_001
60  * @tc.desc: Test PowerModePolicy GetPolicyMaxRunning.
61  * @tc.type: FUNC
62  * @tc.require: I974IQ
63  */
64 HWTEST_F(PowerModePolicyTest, GetPolicyMaxRunning_001, TestSize.Level1)
65 {
66     PowerMgr::PowerMgrClient::GetInstance().SetDeviceMode(PowerMgr::PowerMode::NORMAL_MODE);
67     int32_t ret = powerModePolicy_->GetPolicyMaxRunning();
68     EXPECT_EQ(ret, 3);
69 }
70 
71 /**
72  * @tc.name: GetPolicyMaxRunning_002
73  * @tc.desc: Test PowerModePolicy GetPolicyMaxRunning.
74  * @tc.type: FUNC
75  * @tc.require: I974IQ
76  */
77 HWTEST_F(PowerModePolicyTest, GetPolicyMaxRunning_002, TestSize.Level1)
78 {
79     PowerMgr::PowerMgrClient::GetInstance().SetDeviceMode(PowerMgr::PowerMode::PERFORMANCE_MODE);
80     int32_t ret = powerModePolicy_->GetPolicyMaxRunning();
81     EXPECT_EQ(ret, 3);
82 }
83 
84 /**
85  * @tc.name: GetPolicyMaxRunning_003
86  * @tc.desc: Test PowerModePolicy GetPolicyMaxRunning.
87  * @tc.type: FUNC
88  * @tc.require: I974IQ
89  */
90 HWTEST_F(PowerModePolicyTest, GetPolicyMaxRunning_003, TestSize.Level1)
91 {
92     PowerMgr::PowerMgrClient::GetInstance().SetDeviceMode(PowerMgr::PowerMode::POWER_MODE_MIN);
93     int32_t ret = powerModePolicy_->GetPolicyMaxRunning();
94     EXPECT_EQ(ret, 3);
95 }
96 
97 /**
98  * @tc.name: GetPolicyName_001
99  * @tc.desc: Test PowerModePolicy GetPolicyName.
100  * @tc.type: FUNC
101  * @tc.require: I974IQ
102  */
103 HWTEST_F(PowerModePolicyTest, GetPolicyName_001, TestSize.Level1)
104 {
105     std::string ret = powerModePolicy_->GetPolicyName();
106     EXPECT_EQ(ret, "POWER_MODE_POLICY");
107 }
108 }
109 }
110