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 "battery_sys_test.h" 17 18 #include "battery_config.h" 19 #include "battery_log.h" 20 21 using namespace testing::ext; 22 using namespace OHOS::HDI::Battery; 23 using namespace OHOS::HDI::Battery::V2_0; 24 using namespace std; 25 26 namespace { 27 static auto &g_batteryconfig = BatteryConfig::GetInstance(); 28 } // namespace 29 30 namespace { 31 /** 32 * @tc.name: BatteryConfig001 33 * @tc.desc: Parse config 34 * @tc.type: FUNC 35 */ 36 37 HWTEST_F(BatterySysTest, BatterySysTest_01, TestSize.Level1) 38 { 39 ASSERT_TRUE(g_batteryconfig.ParseConfig()); 40 } 41 42 /** 43 * 44 * @tc.name: BatterySysTest_002 45 * @tc.desc: Parse config 46 * @tc.type: FUNC 47 */ 48 49 HWTEST_F(BatterySysTest, BatterySysTest_02, TestSize.Level1) 50 { 51 BATTERY_HILOGD(LABEL_TEST, "BatteryConfig002 begin"); 52 const std::vector<BatteryConfig::LightConfig> lightConf = g_batteryconfig.GetLightConfig(); 53 ASSERT_TRUE(lightConf.size()); 54 55 uint32_t maxRgb = (255 << 16) | (255 << 8) | 255; 56 for (uint32_t i = 0; i < lightConf.size(); ++i) { 57 // The value ranges from 0 to 100 58 BATTERY_HILOGD(LABEL_TEST, "lightConf[i].beginSoc: %{public}d:", lightConf[i].beginSoc); 59 ASSERT_TRUE(lightConf[i].beginSoc >= 0 && lightConf[i].beginSoc <= 100); 60 ASSERT_TRUE(lightConf[i].endSoc >= 0 && lightConf[i].endSoc <= 100); 61 // The start range is smaller than the end range 62 ASSERT_TRUE(lightConf[i].beginSoc < lightConf[i].endSoc); 63 // The value ranges from 0 to maxRgb 64 ASSERT_TRUE(lightConf[i].rgb >= 0 && lightConf[i].rgb <= maxRgb); 65 } 66 BATTERY_HILOGD(LABEL_TEST, "BatteryConfig002 end"); 67 } 68 69 /** 70 * @tc.name: BatteryConfig001 71 * @tc.desc: test power conf 72 * @tc.type: FUNC 73 */ 74 HWTEST_F(BatterySysTest, BatteryConfig001, TestSize.Level1) 75 { 76 BATTERY_HILOGI(LABEL_TEST, "BatteryConfig001 begin"); 77 const std::map<std::string, BatteryConfig::ChargeSceneConfig> 78 chargeSceneConfigMap = g_batteryconfig.GetChargeSceneConfigMap(); 79 if (chargeSceneConfigMap.size() == 0) { 80 BATTERY_HILOGI(LABEL_TEST, "BatteryConfig001 chargeSceneConfigMap is empty"); 81 return; 82 } 83 for (auto it = chargeSceneConfigMap.begin(); it != chargeSceneConfigMap.end(); it++) { 84 ASSERT_TRUE(!(it->first).empty()); 85 86 auto chargeSceneConfig = it->second; 87 ASSERT_TRUE(!chargeSceneConfig.setPath.empty() || !chargeSceneConfig.getPath.empty() 88 || !chargeSceneConfig.supportPath.empty()); 89 } 90 BATTERY_HILOGI(LABEL_TEST, "BatteryConfig001 end"); 91 } 92 93 /** 94 * @tc.name: BatteryConfig002 95 * @tc.desc: test refactor GetChargerConf 96 * @tc.type: FUNC 97 */ 98 HWTEST_F(BatterySysTest, BatteryConfig002, TestSize.Level1) 99 { 100 BATTERY_HILOGI(LABEL_TEST, "BatteryConfig002 begin"); 101 const BatteryConfig::ChargerConfig chargerConf = g_batteryconfig.GetChargerConfig(); 102 ASSERT_TRUE(chargerConf.currentPath.size()); 103 ASSERT_TRUE(chargerConf.voltagePath.size()); 104 ASSERT_TRUE(chargerConf.chargeTypePath.size()); 105 106 BATTERY_HILOGI(LABEL_TEST, "BatteryConfig002 end"); 107 } 108 }