From a876f27928e4ae178db80d1b2216cfbfe95b6e5f Mon Sep 17 00:00:00 2001 From: yanxuejun12 Date: Thu, 11 Sep 2025 10:19:47 +0800 Subject: [PATCH] fix: check for null before using the pointer Signed-off-by: yanxuejun12 --- .../src/battery_interface_impl.cpp | 34 ++++++++ .../hdi_service/test/unittest/BUILD.gn | 4 + .../unittest/src/hdi_battery_config_test.cpp | 3 + .../test/unittest/src/hdi_interface_test.cpp | 83 +++++++++++++++++++ .../test/unittest/src/hdi_service_test.cpp | 36 ++++++++ 5 files changed, 160 insertions(+) diff --git a/battery/interfaces/hdi_service/src/battery_interface_impl.cpp b/battery/interfaces/hdi_service/src/battery_interface_impl.cpp index bc31020bb1..24bbf46aea 100644 --- a/battery/interfaces/hdi_service/src/battery_interface_impl.cpp +++ b/battery/interfaces/hdi_service/src/battery_interface_impl.cpp @@ -199,6 +199,7 @@ int32_t BatteryInterfaceImpl::GetRemainEnergy(int32_t& remainEnergy) int32_t BatteryInterfaceImpl::GetBatteryInfo(BatteryInfo& info) { if (powerSupplyProvider_ == nullptr) { + BATTERY_HILOGE(COMP_HDI, "GetBatteryInfo powerSupplyProvider_ is nullptr"); return HDF_FAILURE; } @@ -227,6 +228,10 @@ int32_t BatteryInterfaceImpl::SetChargingLimit(const std::vector& auto& batteryConfig = BatteryConfig::GetInstance(); BatteryConfig::ChargerConfig chargerConfig = batteryConfig.GetChargerConfig(); + if (powerSupplyProvider_ == nullptr) { + BATTERY_HILOGE(COMP_HDI, "SetChargingLimit powerSupplyProvider_ is nullptr"); + return HDF_FAILURE; + } return powerSupplyProvider_->SetChargingLimit(chargingLimit, chargerConfig.currentPath, chargerConfig.voltagePath); } @@ -236,6 +241,10 @@ int32_t BatteryInterfaceImpl::GetChargeType(ChargeType& chargeType) BatteryConfig::ChargerConfig chargerConfig = batteryConfig.GetChargerConfig(); int32_t type = static_cast(CHARGE_TYPE_NONE); + if (powerSupplyProvider_ == nullptr) { + BATTERY_HILOGE(COMP_HDI, "GetChargeType powerSupplyProvider_ is nullptr"); + return HDF_FAILURE; + } int32_t ret = powerSupplyProvider_->ParseChargeType(&type, chargerConfig.chargeTypePath); if (ret != HDF_SUCCESS) { return ret; @@ -248,6 +257,11 @@ int32_t BatteryInterfaceImpl::GetChargeType(ChargeType& chargeType) int32_t BatteryInterfaceImpl::SetBatteryConfig(const std::string& sceneName, const std::string& value) { Battery::BatteryXCollie batteryXcollie("Battery_SetBatteryConfig"); + if (powerSupplyProvider_ == nullptr) { + BATTERY_HILOGE(COMP_HDI, "SetBatteryConfig powerSupplyProvider_ is nullptr"); + return HDF_FAILURE; + } + auto& batteryConfig = BatteryConfig::GetInstance(); std::map chargeSceneConfigMap = batteryConfig.GetChargeSceneConfigMap(); @@ -269,6 +283,12 @@ int32_t BatteryInterfaceImpl::SetBatteryConfig(const std::string& sceneName, con int32_t BatteryInterfaceImpl::GetBatteryConfig(const std::string& sceneName, std::string& value) { Battery::BatteryXCollie batteryXcollie("Battery_GetBatteryConfig"); + if (powerSupplyProvider_ == nullptr) { + BATTERY_HILOGE(COMP_HDI, "GetBatteryConfig powerSupplyProvider_ is nullptr"); + value = ""; + return HDF_FAILURE; + } + auto& batteryConfig = BatteryConfig::GetInstance(); std::map chargeSceneConfigMap = batteryConfig.GetChargeSceneConfigMap(); @@ -292,6 +312,12 @@ int32_t BatteryInterfaceImpl::GetBatteryConfig(const std::string& sceneName, std int32_t BatteryInterfaceImpl::IsBatteryConfigSupported(const std::string& sceneName, bool& value) { Battery::BatteryXCollie batteryXcollie("Battery_IsBatteryConfigSupported"); + if (powerSupplyProvider_ == nullptr) { + BATTERY_HILOGE(COMP_HDI, "IsBatteryConfigSupported powerSupplyProvider_ is nullptr"); + value = false; + return HDF_FAILURE; + } + auto& batteryConfig = BatteryConfig::GetInstance(); std::map chargeSceneConfigMap = batteryConfig.GetChargeSceneConfigMap(); @@ -329,6 +355,10 @@ int32_t BatteryInterfaceImpl::IsBatteryConfigSupported(const std::string& sceneN int32_t BatteryInterfaceImpl::AddBatteryDeathRecipient(const sptr& callback) { + if (callback == nullptr) { + BATTERY_HILOGE(COMP_HDI, "AddBatteryDeathRecipient callback is nullptr"); + return HDF_FAILURE; + } const sptr& remote = OHOS::HDI::hdi_objcast(callback); bool result = remote->AddDeathRecipient(g_deathRecipient); if (!result) { @@ -357,6 +387,10 @@ int32_t BatteryInterfaceImpl::RemoveBatteryDeathRecipient(const sptr& object) { + if (interfaceImpl_ == nullptr) { + BATTERY_HILOGE(COMP_HDI, "OnRemoteDied interfaceImpl_ is nullptr"); + return; + } interfaceImpl_->UnRegister(); } } // namespace V2_0 diff --git a/battery/interfaces/hdi_service/test/unittest/BUILD.gn b/battery/interfaces/hdi_service/test/unittest/BUILD.gn index 1e1af9b6d3..f6c026d357 100644 --- a/battery/interfaces/hdi_service/test/unittest/BUILD.gn +++ b/battery/interfaces/hdi_service/test/unittest/BUILD.gn @@ -73,6 +73,8 @@ ohos_unittest("hdi_unittest_battery") { configs = [ ":module_private_config" ] + deps = [ "../..:libbattery_interface_service_2.0" ] + if (is_standard_system) { external_deps = [ "drivers_interface_battery:libbattery_proxy_2.0", @@ -86,6 +88,8 @@ ohos_unittest("hdi_unittest_battery") { } else { external_deps = [ "hilog:libhilog" ] } + + defines = [ "GTEST" ] } group("unittest") { diff --git a/battery/interfaces/hdi_service/test/unittest/src/hdi_battery_config_test.cpp b/battery/interfaces/hdi_service/test/unittest/src/hdi_battery_config_test.cpp index f0b94a2530..f0d5b197eb 100644 --- a/battery/interfaces/hdi_service/test/unittest/src/hdi_battery_config_test.cpp +++ b/battery/interfaces/hdi_service/test/unittest/src/hdi_battery_config_test.cpp @@ -16,6 +16,7 @@ #include "hdi_battery_config_test.h" #include "battery_config.h" +#include "battery_log.h" using namespace OHOS::HDI::Battery; using namespace OHOS::HDI::Battery::V2_0; @@ -50,6 +51,7 @@ namespace { */ HWTEST_F(HdiBatteryConfigTest, HdiBatteryConfigTest001, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiBatteryConfigTest001 function start!"); std::string jsonStr = R"({"current_limit": {"path": "/test/current_limit"}})"; cJSON* parseResult = cJSON_Parse(jsonStr.c_str()); ASSERT_TRUE(parseResult); @@ -70,5 +72,6 @@ HWTEST_F(HdiBatteryConfigTest, HdiBatteryConfigTest001, TestSize.Level0) g_configTest.ParseChargerConfig(parseResult); EXPECT_TRUE(g_configTest.chargerConfig_.chargeTypePath == "/test/type"); DestroyJsonValue(parseResult); + BATTERY_HILOGI(LABEL_TEST, "HdiBatteryConfigTest001 function end!"); } } diff --git a/battery/interfaces/hdi_service/test/unittest/src/hdi_interface_test.cpp b/battery/interfaces/hdi_service/test/unittest/src/hdi_interface_test.cpp index d3c127a6a1..0a01172356 100644 --- a/battery/interfaces/hdi_service/test/unittest/src/hdi_interface_test.cpp +++ b/battery/interfaces/hdi_service/test/unittest/src/hdi_interface_test.cpp @@ -15,10 +15,15 @@ #include "hdi_interface_test.h" +#ifdef GTEST +#define private public +#define protected public +#endif #include #include "v2_0/battery_interface_proxy.h" #include "v2_0/types.h" #include "battery_log.h" +#include "battery_interface_impl.h" using namespace OHOS::HDI::Battery; using namespace OHOS::HDI::Battery::V2_0; @@ -70,6 +75,7 @@ namespace { */ HWTEST_F (HdiInterfaceTest, HdiInterfaceTest001, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiInterfaceTest001 function start!"); std::string currentPath = "/data/service/el0/battery/current_limit"; CreateFile(currentPath, ""); ChargingLimit scLimit; @@ -97,6 +103,7 @@ HWTEST_F (HdiInterfaceTest, HdiInterfaceTest001, TestSize.Level0) } } EXPECT_EQ(true, chargeLimitStr == writeChargeInfo); + BATTERY_HILOGI(LABEL_TEST, "HdiInterfaceTest001 function end!"); } /** @@ -106,6 +113,7 @@ HWTEST_F (HdiInterfaceTest, HdiInterfaceTest001, TestSize.Level0) */ HWTEST_F (HdiInterfaceTest, HdiInterfaceTest002, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiInterfaceTest002 function start!"); std::string voltagePath = "/data/service/el0/battery/voltage_limit"; CreateFile(voltagePath, ""); ChargingLimit scLimit; @@ -133,6 +141,7 @@ HWTEST_F (HdiInterfaceTest, HdiInterfaceTest002, TestSize.Level0) } } EXPECT_EQ(true, voltageLimitStr == writeVoltageInfo); + BATTERY_HILOGI(LABEL_TEST, "HdiInterfaceTest002 function end!"); } /** @@ -142,9 +151,83 @@ HWTEST_F (HdiInterfaceTest, HdiInterfaceTest002, TestSize.Level0) */ HWTEST_F (HdiInterfaceTest, HdiInterfaceTest003, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiInterfaceTest003 function start!"); string sceneName = "testScene"; string value = ""; int32_t result = g_batteryInterface->SetBatteryConfig(sceneName, value); EXPECT_EQ(true, result == HDF_ERR_NOT_SUPPORT); + BATTERY_HILOGI(LABEL_TEST, "HdiInterfaceTest003 function end!"); +} + +/** + * @tc.name: HdiInterfaceTest004 + * @tc.desc: Test BatteryInterface nullptr + * @tc.type: FUNC + */ +HWTEST_F (HdiInterfaceTest, HdiInterfaceTest004, TestSize.Level0) +{ + BATTERY_HILOGI(LABEL_TEST, "HdiInterfaceTest004 function start!"); + BatteryInterfaceImpl *service = nullptr; + service = new (std::nothrow) BatteryInterfaceImpl(); + if (service != nullptr) { + service->powerSupplyProvider_ = nullptr; + std::string voltagePath = "/data/service/el0/battery/voltage_limit"; + CreateFile(voltagePath, ""); + ChargingLimit scLimit; + scLimit.type = TYPE_VOLTAGE; + scLimit.protocol = "sc"; + scLimit.value = 2000; + ChargingLimit buckLimit; + buckLimit.type = TYPE_VOLTAGE; + buckLimit.protocol = "buck"; + buckLimit.value = 3000; + std::vector chargeLimitList; + chargeLimitList.push_back(scLimit); + chargeLimitList.push_back(buckLimit); + int32_t result = service->SetChargingLimit(chargeLimitList); + EXPECT_EQ(HDF_FAILURE, result); + V2_0::BatteryInfo event; + result = service->GetBatteryInfo(event); + EXPECT_EQ(HDF_FAILURE, result); + ChargeType chargeType = ChargeType::CHARGE_TYPE_WIRED_SUPER_QUICK; + result = service->GetChargeType(chargeType); + EXPECT_EQ(HDF_FAILURE, result); + result = service->AddBatteryDeathRecipient(nullptr); + EXPECT_EQ(HDF_FAILURE, result); + } + sptr deathRecipient = nullptr; + deathRecipient = new BatteryInterfaceImpl::BatteryDeathRecipient(nullptr); + if (deathRecipient != nullptr) { + wptr remoteObj = nullptr; + deathRecipient->OnRemoteDied(remoteObj); + } + BATTERY_HILOGI(LABEL_TEST, "HdiInterfaceTest004 function end!"); +} + +/** + * @tc.name: HdiInterfaceTest005 + * @tc.desc: Test BatteryInterface nullptr + * @tc.type: FUNC + */ +HWTEST_F (HdiInterfaceTest, HdiInterfaceTest005, TestSize.Level0) +{ + BATTERY_HILOGI(LABEL_TEST, "HdiInterfaceTest005 function start!"); + BatteryInterfaceImpl *service = nullptr; + service = new (std::nothrow) BatteryInterfaceImpl(); + if (service != nullptr) { + service->powerSupplyProvider_ = nullptr; + std::string sceneName = "testScene"; + std::string value = ""; + int32_t result = service->SetBatteryConfig(sceneName, value); + EXPECT_EQ(HDF_FAILURE, result); + result = service->GetBatteryConfig(sceneName, value); + EXPECT_EQ("", value); + EXPECT_EQ(HDF_FAILURE, result); + bool flag = true; + result = service->IsBatteryConfigSupported(sceneName, flag); + EXPECT_EQ(false, flag); + EXPECT_EQ(HDF_FAILURE, result); + } + BATTERY_HILOGI(LABEL_TEST, "HdiInterfaceTest005 function end!"); } } diff --git a/battery/interfaces/hdi_service/test/unittest/src/hdi_service_test.cpp b/battery/interfaces/hdi_service/test/unittest/src/hdi_service_test.cpp index 341f44fc63..7c64208a46 100644 --- a/battery/interfaces/hdi_service/test/unittest/src/hdi_service_test.cpp +++ b/battery/interfaces/hdi_service/test/unittest/src/hdi_service_test.cpp @@ -796,12 +796,14 @@ static bool IsNotMock() */ HWTEST_F(HdiServiceTest, ProviderIsNotNull, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "ProviderIsNotNull function start!"); ASSERT_TRUE(giver_ != nullptr); if (!IsNotMock()) { giver_->SetSysFilePath(MOCK_BATTERY_PATH); BATTERY_HILOGI(LABEL_TEST, "Is mock test"); } giver_->InitPowerSupplySysfs(); + BATTERY_HILOGI(LABEL_TEST, "ProviderIsNotNull function end!"); } /** @@ -811,6 +813,7 @@ HWTEST_F(HdiServiceTest, ProviderIsNotNull, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService001, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService001 function start!"); int32_t temperature = 0; if (IsNotMock()) { giver_->ParseTemperature(&temperature); @@ -824,6 +827,7 @@ HWTEST_F(HdiServiceTest, HdiService001, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService001::temperature=%{public}d.", temperature); ASSERT_TRUE(temperature == 567); } + BATTERY_HILOGI(LABEL_TEST, "HdiService001 function end!"); } /** @@ -833,6 +837,7 @@ HWTEST_F(HdiServiceTest, HdiService001, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService002, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService002 function start!"); int32_t voltage = 0; if (IsNotMock()) { giver_->ParseVoltage(&voltage); @@ -846,6 +851,7 @@ HWTEST_F(HdiServiceTest, HdiService002, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "Not Mock HdiService002::voltage=%{public}d", voltage); ASSERT_TRUE(voltage == 4123456); } + BATTERY_HILOGI(LABEL_TEST, "HdiService002 function end!"); } /** @@ -855,6 +861,7 @@ HWTEST_F(HdiServiceTest, HdiService002, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService003, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService003 function start!"); int32_t capacity = -1; if (IsNotMock()) { giver_->ParseCapacity(&capacity); @@ -868,6 +875,7 @@ HWTEST_F(HdiServiceTest, HdiService003, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService003::capacity=%{public}d", capacity); ASSERT_TRUE(capacity == 11); } + BATTERY_HILOGI(LABEL_TEST, "HdiService003 function end!"); } /** @@ -877,6 +885,7 @@ HWTEST_F(HdiServiceTest, HdiService003, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService004, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService004 function start!"); int32_t healthState = -1; if (IsNotMock()) { giver_->ParseHealthState(&healthState); @@ -891,6 +900,7 @@ HWTEST_F(HdiServiceTest, HdiService004, TestSize.Level0) ASSERT_TRUE(PowerSupplyProvider::BatteryHealthState(healthState) == PowerSupplyProvider::BatteryHealthState::BATTERY_HEALTH_GOOD); } + BATTERY_HILOGI(LABEL_TEST, "HdiService004 function end!"); } /** @@ -900,6 +910,7 @@ HWTEST_F(HdiServiceTest, HdiService004, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService005, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService005 function start!"); int32_t pluggedType = PowerSupplyProvider::PLUGGED_TYPE_NONE; if (IsNotMock()) { giver_->ParsePluggedType(&pluggedType); @@ -915,6 +926,7 @@ HWTEST_F(HdiServiceTest, HdiService005, TestSize.Level0) ASSERT_TRUE(PowerSupplyProvider::BatteryPluggedType(pluggedType) == PowerSupplyProvider::BatteryPluggedType::PLUGGED_TYPE_WIRELESS); } + BATTERY_HILOGI(LABEL_TEST, "HdiService005 function end!"); } /** @@ -924,6 +936,7 @@ HWTEST_F(HdiServiceTest, HdiService005, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService006, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService006 function start!"); int32_t chargeState = PowerSupplyProvider::CHARGE_STATE_RESERVED; if (IsNotMock()) { giver_->ParseChargeState(&chargeState); @@ -938,6 +951,7 @@ HWTEST_F(HdiServiceTest, HdiService006, TestSize.Level0) ASSERT_TRUE(PowerSupplyProvider::BatteryChargeState(chargeState) == PowerSupplyProvider::BatteryChargeState::CHARGE_STATE_DISABLE); } + BATTERY_HILOGI(LABEL_TEST, "HdiService006 function end!"); } /** @@ -947,6 +961,7 @@ HWTEST_F(HdiServiceTest, HdiService006, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService007, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService007 function start!"); int32_t chargeCounter = -1; if (IsNotMock()) { giver_->ParseChargeCounter(&chargeCounter); @@ -960,6 +975,7 @@ HWTEST_F(HdiServiceTest, HdiService007, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService007::chargeCounter=%{public}d.", chargeCounter); ASSERT_TRUE(chargeCounter == 12345); } + BATTERY_HILOGI(LABEL_TEST, "HdiService007 function end!"); } /** @@ -969,6 +985,7 @@ HWTEST_F(HdiServiceTest, HdiService007, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService008, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService008 function start!"); int8_t present = -1; if (IsNotMock()) { giver_->ParsePresent(&present); @@ -981,6 +998,7 @@ HWTEST_F(HdiServiceTest, HdiService008, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService008::present=%{public}d.", present); ASSERT_TRUE(present == 1); } + BATTERY_HILOGI(LABEL_TEST, "HdiService008 function end!"); } /** @@ -990,6 +1008,7 @@ HWTEST_F(HdiServiceTest, HdiService008, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService009, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService009 function start!"); std::string technology = "invalid"; if (IsNotMock()) { giver_->ParseTechnology(technology); @@ -1004,6 +1023,7 @@ HWTEST_F(HdiServiceTest, HdiService009, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService009::technology=%{public}s.", technology.c_str()); ASSERT_TRUE(technology == "Li"); } + BATTERY_HILOGI(LABEL_TEST, "HdiService009 function end!"); } /** @@ -1013,6 +1033,7 @@ HWTEST_F(HdiServiceTest, HdiService009, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService010, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService010 function start!"); using namespace OHOS::HDI::Battery::V2_0; BatteryThread bt; @@ -1021,6 +1042,7 @@ HWTEST_F(HdiServiceTest, HdiService010, TestSize.Level0) ASSERT_TRUE(fd > 0); close(fd); + BATTERY_HILOGI(LABEL_TEST, "HdiService010 function end!"); } /** @@ -1030,6 +1052,7 @@ HWTEST_F(HdiServiceTest, HdiService010, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService011, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService011 function start!"); const int32_t CHARGE_STATE_ENABLE = 1; BatteryThread bt; @@ -1038,6 +1061,7 @@ HWTEST_F(HdiServiceTest, HdiService011, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService011::epollInterval=%{public}d.", epollInterval); ASSERT_TRUE(epollInterval == 2000); + BATTERY_HILOGI(LABEL_TEST, "HdiService011 function end!"); } /** @@ -1047,6 +1071,7 @@ HWTEST_F(HdiServiceTest, HdiService011, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService012, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService012 function start!"); const int32_t CHARGE_STATE_NONE = 0; BatteryThread bt; @@ -1055,6 +1080,7 @@ HWTEST_F(HdiServiceTest, HdiService012, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService012::epollInterval=%{public}d.", epollInterval); ASSERT_TRUE(epollInterval == -1); + BATTERY_HILOGI(LABEL_TEST, "HdiService012 function end!"); } /** @@ -1064,6 +1090,7 @@ HWTEST_F(HdiServiceTest, HdiService012, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService013, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService013 function start!"); void* service = nullptr; BatteryThread bt; @@ -1073,6 +1100,7 @@ HWTEST_F(HdiServiceTest, HdiService013, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService013::epollFd=%{public}d", epollFd); ASSERT_TRUE(epollFd > 0); + BATTERY_HILOGI(LABEL_TEST, "HdiService013 function end!"); } /** @@ -1082,6 +1110,7 @@ HWTEST_F(HdiServiceTest, HdiService013, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService023, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService023 function start!"); int32_t totalEnergy = 0; if (IsNotMock()) { giver_->ParseTotalEnergy(&totalEnergy); @@ -1095,6 +1124,7 @@ HWTEST_F(HdiServiceTest, HdiService023, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService023::totalEnergy=%{public}d.", totalEnergy); ASSERT_TRUE(totalEnergy == 4000000); } + BATTERY_HILOGI(LABEL_TEST, "HdiService023 function end!"); } /** @@ -1104,6 +1134,7 @@ HWTEST_F(HdiServiceTest, HdiService023, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService024, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService024 function start!"); int32_t currentAvg = HDF_FAILURE; if (IsNotMock()) { giver_->ParseCurrentAverage(¤tAvg); @@ -1117,6 +1148,7 @@ HWTEST_F(HdiServiceTest, HdiService024, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService024::currentAvg=%{public}d.", currentAvg); ASSERT_TRUE(currentAvg == 1000); } + BATTERY_HILOGI(LABEL_TEST, "HdiService024 function end!"); } /** @@ -1126,6 +1158,7 @@ HWTEST_F(HdiServiceTest, HdiService024, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService025, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService025 function start!"); int32_t currentNow = 0; if (IsNotMock()) { giver_->ParseCurrentNow(¤tNow); @@ -1139,6 +1172,7 @@ HWTEST_F(HdiServiceTest, HdiService025, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService025::currentNow=%{public}d.", currentNow); ASSERT_TRUE(currentNow == 1000); } + BATTERY_HILOGI(LABEL_TEST, "HdiService025 function end!"); } /** @@ -1148,6 +1182,7 @@ HWTEST_F(HdiServiceTest, HdiService025, TestSize.Level0) */ HWTEST_F(HdiServiceTest, HdiService026, TestSize.Level0) { + BATTERY_HILOGI(LABEL_TEST, "HdiService026 function start!"); int32_t chargeNow = 0; if (IsNotMock()) { giver_->ParseRemainEnergy(&chargeNow); @@ -1161,5 +1196,6 @@ HWTEST_F(HdiServiceTest, HdiService026, TestSize.Level0) BATTERY_HILOGI(LABEL_TEST, "HdiService026::chargeNow=%{public}d.", chargeNow); ASSERT_TRUE(chargeNow == 1000); } + BATTERY_HILOGI(LABEL_TEST, "HdiService026 function end!"); } } // namespace HdiServiceTest -- Gitee