• 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_mode_module_native_test.h"
17 
18 using namespace testing::ext;
19 using namespace OHOS::PowerMgr;
20 using namespace OHOS;
21 using namespace std;
22 
SetUpTestCase()23 void PowerModeModuleNativeTest::SetUpTestCase()
24 {
25 }
26 
TearDownTestCase()27 void PowerModeModuleNativeTest::TearDownTestCase()
28 {
29 }
30 
SetUp()31 void PowerModeModuleNativeTest::SetUp()
32 {
33 }
34 
TearDown()35 void PowerModeModuleNativeTest::TearDown()
36 {
37 }
38 
OnPowerModeChanged(PowerMode mode)39 void PowerModeTestCallback::OnPowerModeChanged(PowerMode mode)
40 {
41     POWER_HILOGI(LABEL_TEST, "PowerModeTestCallback::OnPowerModeChanged.");
42 }
43 
44 namespace {
45 using ModeActionPolicy = std::function<void(bool)>;
46 
47 /**
48  * @tc.name: PowerModeModuleNativeTest001
49  * @tc.desc: test callback in PowerModeModule
50  */
51 HWTEST_F (PowerModeModuleNativeTest, PowerModeModuleNativeTest001, TestSize.Level0)
52 {
53     shared_ptr<PowerModeModule> powerModeModuleTest = make_shared<PowerModeModule>();
54     powerModeModuleTest->mode_ = PowerMode::PERFORMANCE_MODE;
55     powerModeModuleTest->PublishPowerModeEvent();
56     powerModeModuleTest->mode_ = PowerMode::EXTREME_POWER_SAVE_MODE;
57     powerModeModuleTest->PublishPowerModeEvent();
58     powerModeModuleTest->mode_ = static_cast<PowerMode>(POWERMODE);
59     powerModeModuleTest->PublishPowerModeEvent();
60 
61     sptr<IPowerModeCallback> object = new PowerModeTestCallback();
62     powerModeModuleTest->AddPowerModeCallback(object);
63     powerModeModuleTest->Prepare();
64     powerModeModuleTest->AddPowerModeCallback(nullptr);
65     powerModeModuleTest->DelPowerModeCallback(object);
66     powerModeModuleTest->DelPowerModeCallback(nullptr);
67 
68     powerModeModuleTest->callbackMgr_ = nullptr;
69     powerModeModuleTest->Prepare();
70     powerModeModuleTest->AddPowerModeCallback(object);
71     powerModeModuleTest->DelPowerModeCallback(object);
72     powerModeModuleTest->started_ = true;
73     PowerMode mode = PowerMode::PERFORMANCE_MODE;
74     powerModeModuleTest->EnableMode(mode, true);
75 
76     powerModeModuleTest->mode_ = PowerMode::PERFORMANCE_MODE;
77     powerModeModuleTest->SetModeItem(mode);
78     EXPECT_EQ(mode, powerModeModuleTest->GetModeItem());
79     mode = static_cast<PowerMode>(POWERMODE);
80     powerModeModuleTest->SetModeItem(mode);
81 
82     shared_ptr<PowerModeModule::CallbackManager> powerModeModuleManager =
83                                             make_shared<PowerModeModule::CallbackManager>();
84     powerModeModuleManager->OnRemoteDied(nullptr);
85 
86     POWER_HILOGI(LABEL_TEST, "PowerModeModuleNativeTest001 end.");
87 }
88 
89 /**
90  * @tc.name: PowerModePolicyNativeTest003
91  * @tc.desc: test GetPowerMode in PowerModePolicy
92  * @tc.type: FUNC
93  */
94 HWTEST_F (PowerModeModuleNativeTest, PowerModePolicyNativeTest003, TestSize.Level0)
95 {
96     PowerModePolicy *powerModePolicyTest = new PowerModePolicy();
97     EXPECT_TRUE(powerModePolicyTest->GetPowerModeValuePolicy(MODEITEM) == INIT_VALUE_FALSE);
98     EXPECT_TRUE(powerModePolicyTest->GetPolicyFromMap(MODEITEM) == INIT_VALUE_FALSE);
99     EXPECT_TRUE(powerModePolicyTest->GetRecoverPolicyFromMap(MODEITEM) == INIT_VALUE_FALSE);
100     EXPECT_TRUE(powerModePolicyTest->GetPowerModeRecoverPolicy(MODEITEM) == INIT_VALUE_FALSE);
101     powerModePolicyTest->ReadRecoverPolicy(READODE);
102     powerModePolicyTest->CompareModeItem(MODEITEM, MODEITEM);
103     ModeActionPolicy action;
104     powerModePolicyTest->AddAction(MODEITEM, action);
105     EXPECT_TRUE(powerModePolicyTest->GetPowerModeRecoverPolicy(MODEITEM) == INIT_VALUE_FALSE);
106     EXPECT_TRUE(powerModePolicyTest->GetRecoverPolicyFromMap(MODEITEM) == INIT_VALUE_FALSE);
107 
108     POWER_HILOGI(LABEL_TEST, "PowerModePolicyNativeTest003 end.");
109 }
110 }
111