From e8b8fa0e092b6c47ae2ae545f380948d6ec7bb09 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 22 Mar 2021 11:27:15 +0900 Subject: [PATCH] haltest: add test for external connection Change-Id: Iac27765780744d880459517e43e4b2f3e3445512 Signed-off-by: Youngjae Cho --- haltest/external_connection.cpp | 86 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 haltest/external_connection.cpp diff --git a/haltest/external_connection.cpp b/haltest/external_connection.cpp new file mode 100644 index 0000000..6d7e0d0 --- /dev/null +++ b/haltest/external_connection.cpp @@ -0,0 +1,86 @@ +#include + +#include "haltest.h" +#include "hal-external_connection.h" + + +/* Define Classes */ +class EXTCON : public testing::Test +{ + protected: + static void SetUpHalTestSuite() { + int ret_val; + + ret_val = hal_device_external_connection_get_backend(); + ASSERT_EQ(ret_val, 0) << strerr("Failed to get extcon backend", ret_val); + + EXTCON::supported = true; + } + + void SetUp() override {} + + void TearDown() override {} + + static void TearDownHalTestSuite() {} + + static bool supported; +}; + +bool EXTCON::supported = false; + +// dummy +static void __updated_cb(struct connection_info *info, void *data) +{ + EXPECT_NE(info, nullptr) << "Failed to get information"; +} + +TEST_F(EXTCON, RegisterChangedEventP) +{ + int ret_val; + + if (!EXTCON::supported) { + SKIP_MESSAGE("External connection not supported"); + return; + } + + ret_val = hal_device_external_connection_register_changed_event(__updated_cb, NULL); + if (ret_val == -ENODEV) { + SKIP_MESSAGE("Not supported HAL"); + return; + } + ASSERT_EQ(ret_val, 0) << strerr("Failed to register changed event callback", ret_val); +} + +TEST_F(EXTCON, UnregisterChangedEventP) +{ + int ret_val; + + if (!EXTCON::supported) { + SKIP_MESSAGE("External connection not supported"); + return; + } + + ret_val = hal_device_external_connection_unregister_changed_event(__updated_cb); + if (ret_val == -ENODEV) { + SKIP_MESSAGE("Not supported HAL"); + return; + } + ASSERT_EQ(ret_val, 0) << strerr("Failed to unregister changed event callback", ret_val); +} + +TEST_F(EXTCON, GetCurrentStateP) +{ + int ret_val; + + if (!EXTCON::supported) { + SKIP_MESSAGE("External connection not supported"); + return; + } + + ret_val = hal_device_external_connection_get_current_state(__updated_cb, NULL); + if (ret_val == -ENODEV) { + SKIP_MESSAGE("Not supported HAL"); + return; + } + ASSERT_EQ(ret_val, 0) << strerr("Failed to get current state", ret_val); +} -- 2.7.4