From 416f484a85121547948a7a1e68a9c2fe847532a9 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 11 Mar 2021 15:11:07 +0900 Subject: [PATCH] haltest: add test for board Change-Id: I5397e82b32ed9f2c745aadfc11221523791d59cc Signed-off-by: Youngjae Cho --- haltest/CMakeLists.txt | 3 ++- haltest/board.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ haltest/haltest.h | 12 +++++++++--- 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 haltest/board.cpp diff --git a/haltest/CMakeLists.txt b/haltest/CMakeLists.txt index 34a4cf0..7fddc66 100644 --- a/haltest/CMakeLists.txt +++ b/haltest/CMakeLists.txt @@ -35,7 +35,8 @@ 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/battery.cpp) + ${CMAKE_SOURCE_DIR}/haltest/battery.cpp + ${CMAKE_SOURCE_DIR}/haltest/board.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/board.cpp b/haltest/board.cpp new file mode 100644 index 0000000..356c2c0 --- /dev/null +++ b/haltest/board.cpp @@ -0,0 +1,44 @@ +#include "haltest.h" +#include "hal-board.h" + +class BOARD : public testing::Test { + protected: + void SetUp() override {} + + void TearDown() override {} +}; + +TEST_F(BOARD, GetBackendP) +{ + int ret_val; + + ret_val = hal_device_board_get_backend(); + EXPECT_EQ(ret_val, 0) << "Failed to get board device (" << ret_val << ")"; +} + +TEST_F(BOARD, GetDeviceSerialP) +{ + int ret_val; + char *serial = nullptr; + + ret_val = hal_device_board_get_device_serial(&serial); + EXPECT_EQ(ret_val, 0) << "Failed to get device serial (" << ret_val << ")"; + EXPECT_NE(serial, nullptr) << "Failed to get device serial (nullptr)"; + + if (ret_val == 0 && serial) + DEBUG_MESSAGE("Serial=%s", serial); + + free(serial); +} + +TEST_F(BOARD, GetDeviceRevisionP) +{ + int ret_val; + int revision; + + ret_val = hal_device_board_get_device_revision(&revision); + EXPECT_EQ(ret_val, 0) << "Failed to get device revision (" << ret_val << ")"; + + if (ret_val == 0) + DEBUG_MESSAGE("Revision=%d", revision); +} diff --git a/haltest/haltest.h b/haltest/haltest.h index 8576f55..32a3d4d 100644 --- a/haltest/haltest.h +++ b/haltest/haltest.h @@ -34,13 +34,20 @@ namespace testing } } -#define SKIP_MESSAGE(args...) \ +#define SKIP_MESSAGE(fmt, args...) \ do { \ testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, "[ SKIPPED ] "); \ - testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, ##args); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, fmt, ##args); \ testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, "\n"); \ } while (0) +#define DEBUG_MESSAGE(fmt, args...) \ +do { \ + testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN, "[ DEBUG ] "); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_DEFAULT, fmt, ##args); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_DEFAULT, "\n"); \ +} while (0) + #define FEATURE_BATTERY "http://tizen.org/feature/battery" #define FEATURE_DISPLAY "http://tizen.org/feature/display" #define FEATURE_LED "http://tizen.org/feature/led" @@ -48,5 +55,4 @@ do { \ #define FEATURE_THERMISTOR "http://tizen.org/feature/thermistor.ap" #define FEATURE_BEZEL "http://tizen.org/feature/input.rotating_bezel" - #endif /* __HALTEST_H__ */ -- 2.7.4