diff options
author | Youngjae Cho <y0.cho@samsung.com> | 2021-03-10 17:16:21 +0900 |
---|---|---|
committer | Hyotaek Shim <hyotaek.shim@samsung.com> | 2021-03-11 06:47:43 +0000 |
commit | e8e1eec75e781a2f30f06e81cbbe46cbc8d875aa (patch) | |
tree | 3d1307eb9cd0a3f1df064ad4b42ae34bbd27a8ac | |
parent | 13e4c0b33c4490a02ba91e8de707964c691c933b (diff) | |
download | device-e8e1eec75e781a2f30f06e81cbbe46cbc8d875aa.tar.gz device-e8e1eec75e781a2f30f06e81cbbe46cbc8d875aa.tar.bz2 device-e8e1eec75e781a2f30f06e81cbbe46cbc8d875aa.zip |
haltest: add test for battery
Change-Id: I4d2404bb448d03596ee7367c594d86c480851340
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
-rw-r--r-- | haltest/CMakeLists.txt | 3 | ||||
-rw-r--r-- | haltest/battery.cpp | 78 |
2 files changed, 80 insertions, 1 deletions
diff --git a/haltest/CMakeLists.txt b/haltest/CMakeLists.txt index 37313df..34a4cf0 100644 --- a/haltest/CMakeLists.txt +++ b/haltest/CMakeLists.txt @@ -34,7 +34,8 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") SET(src ${CMAKE_SOURCE_DIR}/haltest/main.cpp - ${CMAKE_SOURCE_DIR}/haltest/display.cpp) + ${CMAKE_SOURCE_DIR}/haltest/display.cpp + ${CMAKE_SOURCE_DIR}/haltest/battery.cpp) ADD_EXECUTABLE(${PROJECT_NAME} ${src}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${gtest_LDFLAGS} ${gtest_pkgs_LDFLAGS} -ldl ${HALAPI_LIBRARY}) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/hal) diff --git a/haltest/battery.cpp b/haltest/battery.cpp new file mode 100644 index 0000000..973f926 --- /dev/null +++ b/haltest/battery.cpp @@ -0,0 +1,78 @@ +#include <system_info.h> + +#include "haltest.h" +#include "hal-battery.h" + +class BATTERY : public testing::Test { + protected: + void SetUp() override { + int ret; + + ret = system_info_get_platform_bool(FEATURE_BATTERY, &battery_supported); + ASSERT_EQ(ret, SYSTEM_INFO_ERROR_NONE) << "Failed to get battery feature"; + } + + void TearDown() override {} + + bool battery_supported; +}; + +// dummy +static void __changed_cb(struct battery_info *info, void *data) {} + +TEST_F(BATTERY, GetBackendP) +{ + int ret; + + if (!battery_supported) { + SKIP_MESSAGE("Battery not supported"); + return; + } + + ret = hal_device_battery_get_backend(); + EXPECT_EQ(ret, 0) << "Failed to get battery device (" << ret << ")"; +} + +TEST_F(BATTERY, RegisterChangedEventP) +{ + int ret; + + if (!battery_supported) { + SKIP_MESSAGE("Battery not supported"); + return; + } + + ret = hal_device_battery_register_changed_event(__changed_cb, NULL); + EXPECT_EQ(ret, 0) << "Failed to register changed callback"; +} + +TEST_F(BATTERY, UnregisterChangedEventP) +{ + int ret; + + if (!battery_supported) { + SKIP_MESSAGE("Battery not supported"); + return; + } + + ret = hal_device_battery_register_changed_event(__changed_cb, NULL); + ASSERT_EQ(ret, 0) << "Failed to register changed callback"; + + if (ret == 0) { + ret = hal_device_battery_unregister_changed_event(__changed_cb); + EXPECT_EQ(ret, 0) << "Failed to unregister changed callback"; + } +} + +TEST_F(BATTERY, GetCurrentStateP) +{ + int ret; + + if (!battery_supported) { + SKIP_MESSAGE("Battery not supported"); + return; + } + + ret = hal_device_battery_get_current_state(__changed_cb, NULL); + EXPECT_EQ(ret, 0) << "Failed to get current state"; +} |