1 /* 2 * Copyright (c) 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 "battery_charger_test.h" 17 #include "battery_log.h" 18 19 #ifdef GTEST 20 #define private public 21 #define protected public 22 #endif 23 #ifdef ENABLE_CHARGER 24 #include "graphic_dev.h" 25 #include "power_supply_provider.h" 26 #include "display_drv.h" 27 #endif 28 29 using namespace testing::ext; 30 31 namespace OHOS { 32 namespace PowerMgr { 33 namespace { 34 #ifdef ENABLE_CHARGER 35 constexpr int32_t MAX_BUFF_SIZE = 128; 36 #endif 37 } 38 39 /** 40 * @tc.name: BatteryCharger001 41 * @tc.desc: Test charger 42 * @tc.type: FUNC 43 * @tc.require: issueIBYDPK 44 */ 45 #ifdef ENABLE_CHARGER 46 HWTEST_F(BatteryChargerTest, BatteryCharger001, TestSize.Level1) 47 { 48 BATTERY_HILOGI(LABEL_TEST, "BatteryCharger001 begin"); 49 std::unique_ptr<GraphicDev> sfDev_ = std::make_unique<GraphicDev>(); 50 std::unique_ptr<DisplayDrv> fbdrv_ = nullptr; 51 fbdrv_ = sfDev_->MakeDrv(DevType::FB_DEVICE); 52 std::unique_ptr<DisplayDrv> drmdrv_ = nullptr; 53 drmdrv_ = sfDev_->MakeDrv(DevType::DRM_DEVICE); 54 EXPECT_TRUE(fbdrv_ == nullptr || fbdrv_->Init() || sfDev_->GetDevType() != DevType::FB_DEVICE); 55 EXPECT_TRUE(drmdrv_ == nullptr || drmdrv_->Init() || sfDev_->GetDevType() != DevType::DRM_DEVICE); 56 BATTERY_HILOGI(LABEL_TEST, "BatteryCharger001 end"); 57 } 58 #endif 59 60 /** 61 * @tc.name: BatteryCharger002 62 * @tc.desc: Test charger 63 * @tc.type: FUNC 64 * @tc.require: issueIBYDPK 65 */ 66 #ifdef ENABLE_CHARGER 67 HWTEST_F(BatteryChargerTest, BatteryCharger002, TestSize.Level1) 68 { 69 BATTERY_HILOGI(LABEL_TEST, "BatteryCharger002 begin"); 70 std::unique_ptr<PowerSupplyProvider> provider_ = std::make_unique<PowerSupplyProvider>(); 71 provider_->InitBatteryPath(); 72 provider_->InitPowerSupplySysfs(); 73 int32_t temperature = 0; 74 EXPECT_EQ(provider_->ParseTemperature(&temperature), HDF_SUCCESS); 75 int32_t capacity_ = 0; 76 EXPECT_EQ(provider_->ParseCapacity(&capacity_), HDF_SUCCESS); 77 int32_t chargeState_ = 0; 78 EXPECT_EQ(provider_->ParseChargeState(&chargeState_), HDF_SUCCESS); 79 char buf[MAX_BUFF_SIZE] = {0}; 80 EXPECT_NE(provider_->ReadBatterySysfsToBuff("", buf, sizeof(buf)), HDF_SUCCESS); 81 BATTERY_HILOGI(LABEL_TEST, "BatteryCharger002 end"); 82 } 83 #endif 84 } // namespace PowerMgr 85 } // namespace OHOS 86