summaryrefslogtreecommitdiff
path: root/unittest/gtest_hal_extcon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittest/gtest_hal_extcon.cpp')
-rw-r--r--unittest/gtest_hal_extcon.cpp128
1 files changed, 128 insertions, 0 deletions
diff --git a/unittest/gtest_hal_extcon.cpp b/unittest/gtest_hal_extcon.cpp
new file mode 100644
index 0000000..86e023c
--- /dev/null
+++ b/unittest/gtest_hal_extcon.cpp
@@ -0,0 +1,128 @@
+
+#include <iostream>
+#include <gtest/gtest.h>
+#include "hw/common.h"
+#include "hw/external_connection.h"
+
+using namespace std;
+
+/*
+ * main class
+ */
+struct external_connection_device *ext_dev;
+
+class EXTCONHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+ struct hw_info *info;
+ int ret;
+ ret = hw_get_info(EXTERNAL_CONNECTION_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ if (ret < 0) {
+ // access(EXTCON_PATH, R_OK)?
+ cout << "Fail to load extcon hal(" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+ if (!info->open) {
+ cout << "Failed to open extcon device; open(NULL)" << endl;
+ assert(true);
+ return;
+ }
+
+ ret = info->open(info, NULL, (struct hw_common**)&ext_dev);
+ if (ret < 0 || !ext_dev) {
+ cout << "Failed to get extcon device structure (" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+
+ return;
+ }
+
+ virtual void TearDown()
+ {
+ struct hw_info *info;
+
+ info = ext_dev->common.info;
+ if (!info)
+ free(ext_dev);
+ else
+ info->close((struct hw_common *)ext_dev);
+ ext_dev = NULL;
+
+ return;
+ }
+};
+
+/*
+ * testcase
+ */
+TEST_F(EXTCONHalTest, InitP)
+{
+ EXPECT_NE(ext_dev, nullptr);
+}
+
+TEST_F(EXTCONHalTest, DeinitP)
+{
+ struct external_connection_device *tmp;
+ struct hw_info *info;
+ int ret;
+
+ hw_get_info(EXTERNAL_CONNECTION_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ EXPECT_NE(info, nullptr);
+ if (!info->open || !info->close)
+ return;
+ info->open(info, NULL, (struct hw_common**)&tmp);
+
+ ret = info->close((struct hw_common *)tmp);
+ EXPECT_EQ(ret, 0);
+}
+
+static void updated_cb(struct connection_info *info, void *data)
+{
+}
+
+TEST_F(EXTCONHalTest, RegisterChangedEventP)
+{
+ int ret;
+
+ EXPECT_NE(ext_dev, nullptr);
+ if (!ext_dev->register_changed_event)
+ return;
+ ret = ext_dev->register_changed_event(updated_cb, NULL);
+ ext_dev->unregister_changed_event(updated_cb);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(EXTCONHalTest, UnregisterChangedEventP)
+{
+ EXPECT_NE(ext_dev, nullptr);
+ if (!ext_dev->unregister_changed_event)
+ return;
+ ext_dev->register_changed_event(updated_cb, NULL);
+ ext_dev->unregister_changed_event(updated_cb);
+}
+
+TEST_F(EXTCONHalTest, GetCurrentStateP)
+{
+ int ret;
+
+ EXPECT_NE(ext_dev, nullptr);
+ if (!ext_dev->get_current_state)
+ return;
+ ret = ext_dev->get_current_state(updated_cb, NULL);
+ EXPECT_EQ(ret, 0);
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}