haltest: add test for external connection 36/255636/2
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 22 Mar 2021 02:27:15 +0000 (11:27 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 22 Mar 2021 04:59:07 +0000 (13:59 +0900)
Change-Id: Iac27765780744d880459517e43e4b2f3e3445512
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
haltest/external_connection.cpp [new file with mode: 0644]

diff --git a/haltest/external_connection.cpp b/haltest/external_connection.cpp
new file mode 100644 (file)
index 0000000..6d7e0d0
--- /dev/null
@@ -0,0 +1,86 @@
+#include <system_info.h>
+
+#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);
+}