1 /*
2 * Copyright (c) 2024-2025 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 WorkSchedSystemPolicy systemPolicy;
67 PowerMgr::PowerMgrClient::GetInstance().SetDeviceMode(PowerMgr::PowerMode::NORMAL_MODE);
68 int32_t ret = powerModePolicy_->GetPolicyMaxRunning(systemPolicy);
69 EXPECT_EQ(ret, 3);
70 }
71
72 /**
73 * @tc.name: GetPolicyMaxRunning_002
74 * @tc.desc: Test PowerModePolicy GetPolicyMaxRunning.
75 * @tc.type: FUNC
76 * @tc.require: I974IQ
77 */
78 HWTEST_F(PowerModePolicyTest, GetPolicyMaxRunning_002, TestSize.Level1)
79 {
80 WorkSchedSystemPolicy systemPolicy;
81 PowerMgr::PowerMgrClient::GetInstance().SetDeviceMode(PowerMgr::PowerMode::PERFORMANCE_MODE);
82 int32_t ret = powerModePolicy_->GetPolicyMaxRunning(systemPolicy);
83 EXPECT_EQ(ret, 3);
84 }
85
86 /**
87 * @tc.name: GetPolicyMaxRunning_003
88 * @tc.desc: Test PowerModePolicy GetPolicyMaxRunning.
89 * @tc.type: FUNC
90 * @tc.require: I974IQ
91 */
92 HWTEST_F(PowerModePolicyTest, GetPolicyMaxRunning_003, TestSize.Level1)
93 {
94 WorkSchedSystemPolicy systemPolicy;
95 PowerMgr::PowerMgrClient::GetInstance().SetDeviceMode(PowerMgr::PowerMode::POWER_MODE_MIN);
96 int32_t ret = powerModePolicy_->GetPolicyMaxRunning(systemPolicy);
97 EXPECT_EQ(ret, 3);
98 }
99 }
100 }
101