• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "gtest/gtest.h"
17 #include "hilog/log.h"
18 #include "battery_info.h"
19 #include "battery_framework.h"
20 
21 #undef LOG_TAG
22 #define LOG_TAG "BATTERYMGR_LITE"
23 
24 using namespace std;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 class BatterymgrInterfacesTest : public testing::Test {
29 protected:
SetUpTestCase(void)30     static void SetUpTestCase(void) {}
TearDownTestCase(void)31     static void TearDownTestCase(void) {}
32 };
33 
34 /**
35  * @tc.name: BatteryMgrInterfaceTest001
36  * @tc.desc: Test the interface Battery::GetBatSoc.
37  * @tc.type: FUNC
38  */
39 HWTEST_F (BatterymgrInterfacesTest, BatteryMgrInterfaceTest001, TestSize.Level0)
40 {
41     HILOG_INFO(HILOG_MODULE_APP, "BatteryMgrInterfaceTest001 called");
42     int32_t soc = GetBatSoc();
43     EXPECT_EQ ((soc >= 0 && soc <= 100), 1) << "GetBatterySoc ret = " << soc << endl;
44 };
45 
46 /**
47  * @tc.name: BatteryMgrInterfaceTest002
48  * @tc.desc: Test the interface Battery::GetChargingStatus().
49  * @tc.type: FUNC
50  */
51 HWTEST_F (BatterymgrInterfacesTest, BatteryMgrInterfaceTest002, TestSize.Level0)
52 {
53     HILOG_INFO(HILOG_MODULE_APP, "BatteryMgrInterfaceTest002 called");
54     BatteryChargeState status = GetChargingStatus();
55     EXPECT_EQ ((status >= CHARGE_STATE_NONE && status <= CHARGE_STATE_BUTT), 1)
56         << "GetChargingStatus ret = " << status << endl;
57 };
58 
59 /**
60  * @tc.name: BatteryMgrInterfaceTest003
61  * @tc.desc: Test the interface Battery::GetHealthStatus().
62  * @tc.type: FUNC
63  */
64 HWTEST_F (BatterymgrInterfacesTest, BatteryMgrInterfaceTest003, TestSize.Level0)
65 {
66     HILOG_INFO(HILOG_MODULE_APP, "BatteryMgrInterfaceTest003 called");
67     BatteryHealthState status = GetHealthStatus();
68     EXPECT_EQ ((status >= HEALTH_STATE_UNKNOWN && status <= HEALTH_STATE_BUTT), 1)
69         << "GetHealthStatus ret = " << status << endl;
70 };
71 
72 /**
73  * @tc.name: BatteryMgrInterfaceTest004
74  * @tc.desc: Test the interface Battery::GetPluggedType
75  * @tc.type: FUNC
76  */
77 HWTEST_F (BatterymgrInterfacesTest, BatteryMgrInterfaceTest004, TestSize.Level0)
78 {
79     HILOG_INFO(HILOG_MODULE_APP, "BatteryMgrInterfaceTest004 called");
80     BatteryPluggedType status = GetPluggedType();
81     EXPECT_EQ ((status >= PLUGGED_TYPE_NONE && status <= PLUGGED_TYPE_BUTT), 1)
82         << "GetPluggedType ret = " << status << endl;
83 };
84 
85 /**
86  * @tc.name: BatteryMgrInterfaceTest005
87  * @tc.desc: Test the interface Battery::GetBatVoltage
88  * @tc.type: FUNC
89  */
90 HWTEST_F (BatterymgrInterfacesTest, BatteryMgrInterfaceTest005, TestSize.Level0)
91 {
92     HILOG_INFO(HILOG_MODULE_APP, "BatteryMgrInterfaceTest005 called");
93     int32_t voltage = GetBatVoltage();
94     EXPECT_EQ ((voltage >= 0 && voltage <= 100), 1)
95         << "GetBatVoltage ret = " << voltage << endl;
96 };
97 
98 /**
99  * @tc.name: BatteryMgrInterfaceTest006
100  * @tc.desc: Test the interface Battery::GetBatTemperature
101  * @tc.type: FUNC
102  */
103 HWTEST_F (BatterymgrInterfacesTest, BatteryMgrInterfaceTest006, TestSize.Level0)
104 {
105     HILOG_INFO(HILOG_MODULE_APP, "BatteryMgrInterfaceTest007 called");
106     int32_t temperature = GetBatTemperature();
107     EXPECT_EQ ((temperature >= 0 && temperature <= 100), 1)
108         << "GetBatTemperature ret = " << temperature << endl;
109 };
110 
111 /**
112  * @tc.name: BatteryMgrInterfaceTest007
113  * @tc.desc: Test the interface Battery::GetBatTechnology
114  * @tc.type: FUNC
115  */
116 HWTEST_F (BatterymgrInterfacesTest, BatteryMgrInterfaceTest007, TestSize.Level0)
117 {
118     HILOG_INFO(HILOG_MODULE_APP, "BatteryMgrInterfaceTest006 called");
119     char *technology = GetBatTechnology();
120     EXPECT_EQ (strcmp(technology, "Ternary_Lithium"), 0)
121         << "GetBatTechnology ret = " << technology << endl;
122 };
123 };