1 /* 2 * Copyright (c) 2024 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 "battery_impl.h" 18 #include "SharedData.h" 19 20 namespace { TEST(BatteryModuleImplTest,GetBatteryStatusTest)21 TEST(BatteryModuleImplTest, GetBatteryStatusTest) 22 { 23 double minLvl = 0.0; 24 double curLvl = 0.5; 25 double maxLvl = 1.0; 26 SharedData<uint8_t>(SharedDataType::BATTERY_STATUS, (uint8_t)ChargeState::NOCHARGE, 27 (uint8_t)ChargeState::NOCHARGE, (uint8_t)ChargeState::CHARGING); 28 SharedData<double>(SharedDataType::BATTERY_LEVEL, curLvl, minLvl, maxLvl); 29 bool *charging = nullptr; 30 double *level = nullptr; 31 int32_t ret = GetBatteryStatus(charging, level); 32 EXPECT_EQ(ret, -1); // -1 is function return value 33 34 bool testCharging = true; 35 double testLevel = 0.0; 36 int32_t ret1 = GetBatteryStatus(&testCharging, level); 37 EXPECT_EQ(ret1, -1); // -1 is function return value 38 39 int32_t ret2 = GetBatteryStatus(&testCharging, &testLevel); 40 EXPECT_EQ(ret2, 0); // 0 is function return value 41 EXPECT_FALSE(testCharging); 42 EXPECT_EQ(testLevel, curLvl); 43 } 44 }