1 /*
2  * Copyright (c) 2022 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 "battery_info_test.h"
17 
18 #include <string>
19 
20 #include "battery_info.h"
21 #include "battery_log.h"
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace PowerMgr {
27 namespace {
28 std::shared_ptr<BatteryInfo> g_infoTest = nullptr;
29 } // namespace
30 
SetUpTestCase()31 void BatteryInfoTest::SetUpTestCase()
32 {
33     g_infoTest = std::make_shared<BatteryInfo>();
34 }
35 
TearDownTestCase()36 void BatteryInfoTest::TearDownTestCase()
37 {
38     g_infoTest = nullptr;
39 }
40 
41 /**
42  * @tc.name: BatteryInfo001
43  * @tc.desc: BatteryInfo GetRemainEnergy function test
44  * @tc.type: FUNC
45  */
46 HWTEST_F(BatteryInfoTest, BatteryInfo001, TestSize.Level1)
47 {
48     BATTERY_HILOGD(LABEL_TEST, "BatteryInfo001 begin");
49     const int32_t remainEnergy = 100;
50     g_infoTest->SetRemainEnergy(remainEnergy);
51     EXPECT_EQ(g_infoTest->GetRemainEnergy(), remainEnergy);
52     BATTERY_HILOGD(LABEL_TEST, "BatteryInfo001 end");
53 }
54 
55 /**
56  * @tc.name: BatteryInfo002
57  * @tc.desc: BatteryInfo GetChargeType and SetChargeType function test
58  * @tc.type: FUNC
59  */
60 HWTEST_F(BatteryInfoTest, BatteryInfo002, TestSize.Level1)
61 {
62     BATTERY_HILOGD(LABEL_TEST, "BatteryInfo002 begin");
63     const ChargeType none = ChargeType::WIRED_NORMAL;
64     g_infoTest->SetChargeType(none);
65     EXPECT_EQ(g_infoTest->GetChargeType(), none);
66     BATTERY_HILOGD(LABEL_TEST, "BatteryInfo002 end");
67 }
68 } // namespace PowerMgr
69 } // namespace OHOS