From 91fd4db10bce6d25e769893d5c81a0e19fac6623 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 4 Jun 2018 20:21:27 +0900 Subject: Add cpp files for HAL test Change-Id: I374e127cdccecd9d8642c31460cc57cd83eed260 Signed-off-by: lokilee73 --- unittest/gtest_hal_extcon.cpp | 97 +++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 59 deletions(-) mode change 100644 => 100755 unittest/gtest_hal_extcon.cpp (limited to 'unittest/gtest_hal_extcon.cpp') diff --git a/unittest/gtest_hal_extcon.cpp b/unittest/gtest_hal_extcon.cpp old mode 100644 new mode 100755 index 86e023c..cfb8c0f --- a/unittest/gtest_hal_extcon.cpp +++ b/unittest/gtest_hal_extcon.cpp @@ -1,7 +1,6 @@ #include #include -#include "hw/common.h" #include "hw/external_connection.h" using namespace std; @@ -9,6 +8,7 @@ using namespace std; /* * main class */ +struct hw_info *info; struct external_connection_device *ext_dev; class EXTCONHalTest : public testing::Test @@ -16,45 +16,12 @@ 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; } }; @@ -63,49 +30,48 @@ class EXTCONHalTest : public testing::Test */ 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, + ret = hw_get_info(EXTERNAL_CONNECTION_HARDWARE_DEVICE_ID, (const struct hw_info **)&info); - - EXPECT_NE(info, nullptr); - if (!info->open || !info->close) + if (ret < 0) { + cout << "There is no device for extcon" << ret << endl; return; - info->open(info, NULL, (struct hw_common**)&tmp); + } else { + EXPECT_EQ(ret, 0) << "Fail to load extcon hal (" << ret << ")"; + } - ret = info->close((struct hw_common *)tmp); - EXPECT_EQ(ret, 0); + if (!info || !info->open) { + cout << "There is no function for info open" << endl; + return; + } + ret = info->open(info, NULL, (struct hw_common**)&ext_dev); + EXPECT_EQ(ret, 0) << "Fail to open extcon device(" << ret << ")"; } 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) + if (!ext_dev || !ext_dev->register_changed_event) { + cout << "There is no function for register_changed_event" << endl; return; + } ret = ext_dev->register_changed_event(updated_cb, NULL); - ext_dev->unregister_changed_event(updated_cb); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, 0) << "Fail to register_changed_event (" << ret << ")"; } TEST_F(EXTCONHalTest, UnregisterChangedEventP) { - EXPECT_NE(ext_dev, nullptr); - if (!ext_dev->unregister_changed_event) + if (!ext_dev || !ext_dev->unregister_changed_event) { + cout << "There is no function for unregister_changed_event" << endl; return; - ext_dev->register_changed_event(updated_cb, NULL); + } ext_dev->unregister_changed_event(updated_cb); } @@ -113,11 +79,24 @@ TEST_F(EXTCONHalTest, GetCurrentStateP) { int ret; - EXPECT_NE(ext_dev, nullptr); - if (!ext_dev->get_current_state) + if (!ext_dev || !ext_dev->get_current_state) { + cout << "There is no function for unregister_changed_event" << endl; return; + } ret = ext_dev->get_current_state(updated_cb, NULL); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, 0) << "Fail to unregister_changed_event (" << ret << ")"; +} + +TEST_F(EXTCONHalTest, DeinitP) +{ + int ret; + + if (!info || !info->close) { + cout << "There is no function for info close" << endl; + return; + } + ret = info->close((struct hw_common *)ext_dev); + EXPECT_EQ(ret, 0) << "Fail to close extcon device(" << ret << ")"; } int main(int argc, char **argv) -- cgit v1.2.3