summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlokilee73 <changjoo.lee@samsung.com>2018-06-04 20:21:27 +0900
committerlokilee73 <changjoo.lee@samsung.com>2018-06-14 23:15:24 +0900
commit91fd4db10bce6d25e769893d5c81a0e19fac6623 (patch)
tree97aa341466c89b4a58c9521e48d310fbc73f7e36
parent04536eb028c67b819cfeb1147c288d4f24347e91 (diff)
downloadlibdevice-node-91fd4db10bce6d25e769893d5c81a0e19fac6623.tar.gz
libdevice-node-91fd4db10bce6d25e769893d5c81a0e19fac6623.tar.bz2
libdevice-node-91fd4db10bce6d25e769893d5c81a0e19fac6623.zip
Add cpp files for HAL test
Change-Id: I374e127cdccecd9d8642c31460cc57cd83eed260 Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
-rwxr-xr-x[-rw-r--r--]hw/usb_gadget.h22
-rwxr-xr-xpackaging/libdevice-node.spec1
-rwxr-xr-xunittest/CMakeLists.txt1
-rwxr-xr-x[-rw-r--r--]unittest/gtest_hal_battery.cpp109
-rwxr-xr-x[-rw-r--r--]unittest/gtest_hal_cpu.cpp98
-rwxr-xr-x[-rw-r--r--]unittest/gtest_hal_display.cpp149
-rwxr-xr-x[-rw-r--r--]unittest/gtest_hal_extcon.cpp97
-rwxr-xr-x[-rw-r--r--]unittest/gtest_hal_ir.cpp105
-rwxr-xr-x[-rw-r--r--]unittest/gtest_hal_rgb.cpp88
-rwxr-xr-xunittest/gtest_hal_thermal.cpp110
-rwxr-xr-x[-rw-r--r--]unittest/gtest_hal_touchscreen.cpp72
-rwxr-xr-xunittest/gtest_hal_usb_client.cpp223
-rwxr-xr-xunittest/gtest_hal_usb_gadget.cpp98
-rwxr-xr-xunittest/unittest.h36
14 files changed, 815 insertions, 394 deletions
diff --git a/hw/usb_gadget.h b/hw/usb_gadget.h
index fb8288e..f99aa4c 100644..100755
--- a/hw/usb_gadget.h
+++ b/hw/usb_gadget.h
@@ -63,8 +63,8 @@ typedef enum {
struct usb_function {
int function_group;
int id;
- char *name;
- char *instance;
+ const char *name;
+ const char *instance;
int (*clone)(struct usb_function *func, struct usb_function **_clone);
void (*free_func)(struct usb_function *func);
@@ -128,8 +128,8 @@ typedef enum {
static void free_simple_func_content(struct usb_function *func)
{
- free(func->name);
- free(func->instance);
+ free((void *)func->name);
+ free((void *)func->instance);
}
static void free_simple_func(struct usb_function *func)
@@ -150,8 +150,8 @@ static int clone_simple_func_to(struct usb_function *func,
return 0;
free_strs:
- free(other->name);
- free(other->instance);
+ free((void *)other->name);
+ free((void *)other->instance);
return -ENOMEM;
}
@@ -164,7 +164,7 @@ static int clone_simple_func(struct usb_function *func,
if (!func || !clone)
return -EINVAL;
- other = malloc(sizeof(*other));
+ other = (struct usb_function *)malloc(sizeof(*other));
if (!other)
goto out;
@@ -186,8 +186,8 @@ out:
.id = _id, \
.name = #_name, \
.instance = "default", \
+ .clone = clone_simple_func, \
.free_func = free_simple_func, \
- .clone = clone_simple_func, \
}
DEFINE_SIMPLE_USB_FUNCTION(USB_FUNCTION_ACM, acm);
@@ -206,7 +206,7 @@ static void free_func_with_service(struct usb_function *func)
fws = container_of(func, struct usb_function_with_service, func);
free_simple_func_content(func);
- free(fws->service);
+ free((void *)fws->service);
free(fws);
}
@@ -220,7 +220,7 @@ static int clone_func_with_service(struct usb_function *func,
if (!func || !clone)
return -EINVAL;
- other = malloc(sizeof(*other));
+ other = (struct usb_function_with_service *)malloc(sizeof(*other));
if (!other)
goto out;
@@ -254,8 +254,8 @@ out:
.id = _id, \
.name = #_name, \
.instance = "default", \
- .free_func = free_func_with_service, \
.clone = clone_func_with_service, \
+ .free_func = free_func_with_service, \
}, \
.service = _service, \
}
diff --git a/packaging/libdevice-node.spec b/packaging/libdevice-node.spec
index d4e2c7f..0aef2a2 100755
--- a/packaging/libdevice-node.spec
+++ b/packaging/libdevice-node.spec
@@ -12,6 +12,7 @@ BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(gio-2.0)
BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(capi-system-info)
%description
development package of library to control OAL APIs
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
index e3f7305..dbdd022 100755
--- a/unittest/CMakeLists.txt
+++ b/unittest/CMakeLists.txt
@@ -11,6 +11,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/${INC_DIR})
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/hw)
SET(REQUIRES_LIST ${REQUIRES_LIST}
+ capi-system-info
glib-2.0
gio-2.0
gmock
diff --git a/unittest/gtest_hal_battery.cpp b/unittest/gtest_hal_battery.cpp
index 731d881..b7a5946 100644..100755
--- a/unittest/gtest_hal_battery.cpp
+++ b/unittest/gtest_hal_battery.cpp
@@ -1,59 +1,36 @@
#include <iostream>
#include <gtest/gtest.h>
-#include "hw/common.h"
+#include <system_info.h>
#include "hw/battery.h"
+#include "unittest.h"
using namespace std;
/*
* main class
*/
+struct hw_info *info;
struct battery_device *battery_dev;
+static bool need_featurecheck = true;
class BATTERYHalTest : public testing::Test
{
public:
virtual void SetUp()
{
- struct hw_info *info;
int ret;
- ret = hw_get_info(BATTERY_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
- if (ret < 0) {
- cout << "Fail to load battery hal(" << ret << ")" << endl;
- assert(true);
- return;
+ if (need_featurecheck) {
+ ret = system_info_get_platform_bool(FEATURE_BATTERY, &supported);
+ EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
+ need_featurecheck = false;
}
- if (!info->open) {
- cout << "Failed to open battery device; open(NULL)" << endl;
- assert(true);
- return;
- }
-
- ret = info->open(info, NULL, (struct hw_common**)&battery_dev);
- if (ret < 0 || !battery_dev) {
- cout << "Failed to get battery device structure (" << ret << ")" << endl;
- assert(true);
- return;
- }
-
- return;
}
virtual void TearDown()
{
- struct hw_info *info;
- info = battery_dev->common.info;
- if (!info)
- free(battery_dev);
- else
- info->close((struct hw_common *)battery_dev);
- battery_dev = NULL;
-
- return;
}
};
@@ -62,49 +39,52 @@ class BATTERYHalTest : public testing::Test
*/
TEST_F(BATTERYHalTest, InitP)
{
- EXPECT_NE(battery_dev, nullptr);
-}
-
-TEST_F(BATTERYHalTest, DeinitP)
-{
- struct battery_device *tmp;
- struct hw_info *info;
int ret;
- hw_get_info(BATTERY_HARDWARE_DEVICE_ID,
+ if (!supported)
+ return;
+
+ ret = hw_get_info(BATTERY_HARDWARE_DEVICE_ID,
(const struct hw_info **)&info);
+ EXPECT_EQ(ret, 0) << "Fail to load battery hal (" << ret << ")";
- EXPECT_NE(info, nullptr);
- if (!info->open || !info->close)
+ if (!info->open) {
+ cout << "There is no function for info open" << endl;
return;
- info->open(info, NULL, (struct hw_common**)&tmp);
-
- ret = info->close((struct hw_common *)tmp);
- EXPECT_EQ(ret, 0);
+ }
+ ret = info->open(info, NULL, (struct hw_common**)&battery_dev);
+ EXPECT_EQ(ret, 0) << "Fail to open battery device(" << ret << ")";
}
static void updated_cb(struct battery_info *info, void *data)
{
+
}
TEST_F(BATTERYHalTest, RegisterChangedEventP)
{
int ret;
- EXPECT_NE(battery_dev, nullptr);
- if (!battery_dev->register_changed_event)
+ if (!supported)
+ return;
+
+ if (!battery_dev->register_changed_event) {
+ cout << "There is no function for register_changed_event" << endl;
return;
+ }
ret = battery_dev->register_changed_event(updated_cb, NULL);
- battery_dev->unregister_changed_event(updated_cb);
- EXPECT_EQ(ret, 0);
+ EXPECT_EQ(ret, 0) << "Fail to register_changed_event (" << ret << ")";
}
TEST_F(BATTERYHalTest, UnregisterChangedEventP)
{
- EXPECT_NE(battery_dev, nullptr);
- if (!battery_dev->unregister_changed_event)
+ if (!supported)
+ return;
+
+ if (!battery_dev->unregister_changed_event) {
+ cout << "There is no function for unregister_changed_event" << endl;
return;
- battery_dev->register_changed_event(updated_cb, NULL);
+ }
battery_dev->unregister_changed_event(updated_cb);
}
@@ -112,11 +92,30 @@ TEST_F(BATTERYHalTest, GetCurrentStateP)
{
int ret;
- EXPECT_NE(battery_dev, nullptr);
- if (!battery_dev->get_current_state)
+ if (!supported)
return;
+
+ if (!battery_dev->get_current_state) {
+ cout << "There is no function for get_current_state" << endl;
+ return;
+ }
ret = battery_dev->get_current_state(updated_cb, NULL);
- EXPECT_EQ(ret, 0);
+ EXPECT_EQ(ret, 0) << "Fail to get_current_state (" << ret << ")";
+}
+
+TEST_F(BATTERYHalTest, DeinitP)
+{
+ int ret;
+
+ if (!supported)
+ return;
+
+ if (!info->close) {
+ cout << "There is no function for info close" << endl;
+ return;
+ }
+ ret = info->close((struct hw_common *)battery_dev);
+ EXPECT_EQ(ret, 0) << "Fail to close battery device(" << ret << ")";
}
int main(int argc, char **argv)
diff --git a/unittest/gtest_hal_cpu.cpp b/unittest/gtest_hal_cpu.cpp
index 5747865..e1541fa 100644..100755
--- a/unittest/gtest_hal_cpu.cpp
+++ b/unittest/gtest_hal_cpu.cpp
@@ -1,7 +1,6 @@
#include <iostream>
#include <gtest/gtest.h>
-#include "hw/common.h"
#include "hw/cpu.h"
using namespace std;
@@ -12,6 +11,7 @@ using namespace std;
#define LOWBATTERY "LowBattery"
+struct hw_info *info;
struct cpu_device *cpu_dev;
class CPUHalTest : public testing::Test
@@ -19,44 +19,12 @@ class CPUHalTest : public testing::Test
public:
virtual void SetUp()
{
- struct hw_info *info;
- int ret;
- ret = hw_get_info(CPU_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
-
- if (ret < 0) {
- cout << "Fail to load cpu hal(" << ret << ")" << endl;
- assert(true);
- return;
- }
- if (!info->open) {
- cout << "Failed to open cpu device; open(NULL)" << endl;
- assert(true);
- return;
- }
-
- ret = info->open(info, NULL, (struct hw_common**)&cpu_dev);
- if (ret < 0 || !cpu_dev) {
- cout << "Failed to get cpu device structure (" << ret << ")" << endl;
- assert(true);
- return;
- }
-
- return;
+
}
virtual void TearDown()
{
- struct hw_info *info;
-
- info = cpu_dev->common.info;
- if (!info)
- free(cpu_dev);
- else
- info->close((struct hw_common *)cpu_dev);
- cpu_dev = NULL;
- return;
}
};
@@ -65,51 +33,63 @@ class CPUHalTest : public testing::Test
*/
TEST_F(CPUHalTest, InitP)
{
- EXPECT_NE(cpu_dev, nullptr);
-}
-
-TEST_F(CPUHalTest, DeinitP)
-{
- struct cpu_device *tmp;
- struct hw_info *info;
int ret;
- hw_get_info(CPU_HARDWARE_DEVICE_ID,
+ ret = hw_get_info(CPU_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 cpu " << ret << endl;
return;
- info->open(info, NULL, (struct hw_common**)&tmp);
-
- ret = info->close((struct hw_common *)tmp);
- EXPECT_EQ(ret, 0);
+ } else {
+ EXPECT_EQ(ret, 0) << "Fail to load cpu hal (" << ret << ")";
+ }
+ if (!info || !info->open) {
+ cout << "There is no function for info open" << endl;
+ return;
+ }
+ ret = info->open(info, NULL, (struct hw_common**)&cpu_dev);
+ EXPECT_EQ(ret, 0) << "Fail to open cpu device (" << ret << ")";
}
TEST_F(CPUHalTest, StartBoostP)
{
int ret;
- EXPECT_NE(cpu_dev, nullptr);
- if (!cpu_dev->start_boost)
+ if (!cpu_dev || !cpu_dev->start_boost) {
+ cout << "There is no function for start_boost" << endl;
return;
- // prprpr TODO
+ }
+
+ // prprpr TODO
ret = cpu_dev->start_boost((void *)LOWBATTERY);
- cpu_dev->stop_boost((void *)LOWBATTERY);
- EXPECT_EQ(ret, 0);
+ EXPECT_EQ(ret, 0) << "Fail to start_boost (" << ret << ")";
}
TEST_F(CPUHalTest, StopBoostP)
{
int ret;
- EXPECT_NE(cpu_dev, nullptr);
- if (!cpu_dev->stop_boost)
+ if (!cpu_dev || !cpu_dev->stop_boost) {
+ cout << "There is no function for stop_boost" << endl;
return;
- // prprpr TODO
- cpu_dev->start_boost((void *)LOWBATTERY);
+ }
+
+ // prprpr TODO
ret = cpu_dev->stop_boost((void *)LOWBATTERY);
- EXPECT_EQ(ret, 0);
+ EXPECT_EQ(ret, 0) << "Fail to stop_boost (" << ret << ")";
+}
+
+TEST_F(CPUHalTest, DeinitP)
+{
+ int ret;
+
+ if (!info || !info->close) {
+ cout << "There is no function for info close" << endl;
+ return;
+ }
+
+ ret = info->close((struct hw_common *)cpu_dev);
+ EXPECT_EQ(ret, 0) << "Fail to open cpu device (" << ret << ")";
}
int main(int argc, char **argv)
diff --git a/unittest/gtest_hal_display.cpp b/unittest/gtest_hal_display.cpp
index 8e76036..98e71cb 100644..100755
--- a/unittest/gtest_hal_display.cpp
+++ b/unittest/gtest_hal_display.cpp
@@ -1,7 +1,6 @@
#include <iostream>
#include <gtest/gtest.h>
-#include "hw/common.h"
#include "hw/display.h"
using namespace std;
@@ -12,6 +11,7 @@ using namespace std;
#define LOWBATTERY "LowBattery"
+struct hw_info *info;
struct display_device *display_dev;
class DISPLAYHalTest : public testing::Test
@@ -19,44 +19,12 @@ class DISPLAYHalTest : public testing::Test
public:
virtual void SetUp()
{
- struct hw_info *info;
- int ret;
- ret = hw_get_info(DISPLAY_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
-
- if (ret < 0) {
- cout << "Fail to load cpu hal(" << ret << ")" << endl;
- assert(true);
- return;
- }
- if (!info->open) {
- cout << "Failed to open cpu device; open(NULL)" << endl;
- assert(true);
- return;
- }
-
- ret = info->open(info, NULL, (struct hw_common**)&display_dev);
- if (ret < 0 || !display_dev) {
- cout << "Failed to get cpu device structure (" << ret << ")" << endl;
- assert(true);
- return;
- }
-
- return;
+
}
virtual void TearDown()
{
- struct hw_info *info;
-
- info = display_dev->common.info;
- if (!info)
- free(display_dev);
- else
- info->close((struct hw_common *)display_dev);
- display_dev = NULL;
- return;
}
};
@@ -65,25 +33,23 @@ class DISPLAYHalTest : public testing::Test
*/
TEST_F(DISPLAYHalTest, InitP)
{
- EXPECT_NE(display_dev, nullptr);
-}
-
-TEST_F(DISPLAYHalTest, DeinitP)
-{
- struct display_device *tmp;
- struct hw_info *info;
int ret;
- hw_get_info(DISPLAY_HARDWARE_DEVICE_ID,
+ ret = hw_get_info(DISPLAY_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 display" << ret << endl;
return;
- info->open(info, NULL, (struct hw_common**)&tmp);
+ } else {
+ EXPECT_EQ(ret, 0) << "Fail to load display 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**)&display_dev);
+ EXPECT_EQ(ret, 0) << "Fail to open display device (" << ret << ")";
}
TEST_F(DISPLAYHalTest, GetMaxBrightnessP)
@@ -91,11 +57,12 @@ TEST_F(DISPLAYHalTest, GetMaxBrightnessP)
int ret;
int max;
- EXPECT_NE(display_dev, nullptr);
- if (!display_dev->get_max_brightness)
+ if (!display_dev || !display_dev->get_max_brightness) {
+ cout << "There is no function for get_max_brightness" << endl;
return;
+ }
ret = display_dev->get_max_brightness(&max);
- EXPECT_EQ(ret, 0);
+ EXPECT_EQ(ret, 0) << "Fail to get_max_brightness (" << ret << ")";
}
TEST_F(DISPLAYHalTest, GetBrightnessP)
@@ -103,11 +70,12 @@ TEST_F(DISPLAYHalTest, GetBrightnessP)
int ret;
int brt;
- EXPECT_NE(display_dev, nullptr);
- if (!display_dev->get_brightness)
+ if (!display_dev || !display_dev->get_brightness) {
+ cout << "There is no function for get_brightness" << endl;
return;
+ }
ret = display_dev->get_brightness(&brt);
- EXPECT_EQ(ret, 0);
+ EXPECT_EQ(ret, 0) << "Fail to get_brightness (" << ret << ")";
}
TEST_F(DISPLAYHalTest, SetBrightnessP)
@@ -115,12 +83,19 @@ TEST_F(DISPLAYHalTest, SetBrightnessP)
int ret;
int max;
- EXPECT_NE(display_dev, nullptr);
- if (!display_dev->set_brightness)
+ if (!display_dev || !display_dev->get_max_brightness) {
+ cout << "There is no function for get_max_brightness" << endl;
return;
+ }
ret = display_dev->get_max_brightness(&max);
+ EXPECT_EQ(ret, 0) << "Fail to get_max_brightness (" << ret << ")";
+
+ if (!display_dev || !display_dev->set_brightness) {
+ cout << "There is no function for set_brightness" << endl;
+ return;
+ }
ret = display_dev->set_brightness(max);
- EXPECT_EQ(ret, 0);
+ EXPECT_EQ(ret, 0) << "Fail to set_brightness (" << ret << ")";
}
TEST_F(DISPLAYHalTest, GetAutoBrightnessP)
@@ -129,11 +104,12 @@ TEST_F(DISPLAYHalTest, GetAutoBrightnessP)
int brt;
float lmax = 0, lmin = 0, light = 0;
- EXPECT_NE(display_dev, nullptr);
- if (!display_dev->get_auto_brightness)
+ if (!display_dev || !display_dev->get_auto_brightness) {
+ cout << "There is no function for get_auto_brightness" << endl;
return;
+ }
ret = display_dev->get_auto_brightness(lmax, lmin, light, &brt);
- EXPECT_GE(ret, 0);
+ EXPECT_GE(ret, 0) << "Fail to set_brightness (" << ret << ")";
}
TEST_F(DISPLAYHalTest, GetStateP)
@@ -141,22 +117,24 @@ TEST_F(DISPLAYHalTest, GetStateP)
int ret;
enum display_state state;
- EXPECT_NE(display_dev, nullptr);
- if (!display_dev->get_state)
+ if (!display_dev || !display_dev->get_state) {
+ cout << "There is no function for get_state" << endl;
return;
+ }
ret = display_dev->get_state(&state);
- EXPECT_GE(ret, 0);
+ EXPECT_GE(ret, 0) << "Fail to get_state (" << ret << ")";
}
TEST_F(DISPLAYHalTest, SetStateP)
{
int ret;
- EXPECT_NE(display_dev, nullptr);
- if (!display_dev->set_state)
+ if (!display_dev || !display_dev->set_state) {
+ cout << "There is no function for set_state" << endl;
return;
+ }
ret = display_dev->set_state(DISPLAY_ON);
- EXPECT_GE(ret, 0);
+ EXPECT_GE(ret, 0) << "Fail to set_state (" << ret << ")";
}
TEST_F(DISPLAYHalTest, GetMaxFrameRateP)
@@ -164,11 +142,12 @@ TEST_F(DISPLAYHalTest, GetMaxFrameRateP)
int ret;
int max;
- EXPECT_NE(display_dev, nullptr);
- if (!display_dev->get_max_frame_rate)
+ if (!display_dev || !display_dev->get_max_frame_rate) {
+ cout << "There is no function for get_max_frame_rate" << endl;
return;
+ }
ret = display_dev->get_max_frame_rate(&max);
- EXPECT_GE(ret, 0);
+ EXPECT_GE(ret, 0) << "Fail to get_max_frame_rate (" << ret << ")";
}
TEST_F(DISPLAYHalTest, GetMinFrameRateP)
@@ -176,11 +155,12 @@ TEST_F(DISPLAYHalTest, GetMinFrameRateP)
int ret;
int min;
- EXPECT_NE(display_dev, nullptr);
- if (!display_dev->get_min_frame_rate)
+ if (!display_dev || !display_dev->get_min_frame_rate) {
+ cout << "There is no function for get_min_frame_rate" << endl;
return;
+ }
ret = display_dev->get_min_frame_rate(&min);
- EXPECT_GE(ret, 0);
+ EXPECT_GE(ret, 0) << "Fail to get_min_frame_rate (" << ret << ")";
}
TEST_F(DISPLAYHalTest, SetFrameRateP)
@@ -188,12 +168,31 @@ TEST_F(DISPLAYHalTest, SetFrameRateP)
int ret;
int max;
- EXPECT_NE(display_dev, nullptr);
- if (!display_dev->set_frame_rate)
+ if (!display_dev || !display_dev->get_max_frame_rate) {
+ cout << "There is no function for get_max_frame_rate" << endl;
return;
+ }
ret = display_dev->get_max_frame_rate(&max);
+ EXPECT_GE(ret, 0) << "Fail to get_max_frame_rate (" << ret << ")";
+
+ if (!display_dev->set_frame_rate) {
+ cout << "There is no function for set_frame_rate" << endl;
+ return;
+ }
ret = display_dev->set_frame_rate(max);
- EXPECT_GE(ret, 0);
+ EXPECT_GE(ret, 0) << "Fail to set_frame_rate (" << ret << ")";
+}
+
+TEST_F(DISPLAYHalTest, DeinitP)
+{
+ int ret;
+
+ if (!info || !info->close) {
+ cout << "There is no function for info close" << endl;
+ return;
+ }
+ ret = info->close((struct hw_common *)display_dev);
+ EXPECT_GE(ret, 0) << "Fail to close display device (" << ret << ")";
}
int main(int argc, char **argv)
diff --git a/unittest/gtest_hal_extcon.cpp b/unittest/gtest_hal_extcon.cpp
index 86e023c..cfb8c0f 100644..100755
--- a/unittest/gtest_hal_extcon.cpp
+++ b/unittest/gtest_hal_extcon.cpp
@@ -1,7 +1,6 @@
#include <iostream>
#include <gtest/gtest.h>
-#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)
diff --git a/unittest/gtest_hal_ir.cpp b/unittest/gtest_hal_ir.cpp
index 144a4c0..4b77f20 100644..100755
--- a/unittest/gtest_hal_ir.cpp
+++ b/unittest/gtest_hal_ir.cpp
@@ -1,59 +1,36 @@
#include <iostream>
#include <gtest/gtest.h>
-#include "hw/common.h"
+#include <system_info.h>
#include "hw/ir.h"
+#include "unittest.h"
using namespace std;
/*
* main class
*/
+struct hw_info *info;
struct ir_device *ir_dev;
+static bool need_featurecheck = true;
class IRHalTest : public testing::Test
{
public:
virtual void SetUp()
{
- struct hw_info *info;
int ret;
- ret = hw_get_info(IR_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
- if (ret < 0) {
- cout << "Fail to load ir hal(" << ret << ")" << endl;
- assert(true);
- return;
+ if (need_featurecheck) {
+ ret = system_info_get_platform_bool(FEATURE_IR, &supported);
+ EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
+ need_featurecheck = false;
}
- if (!info->open) {
- cout << "Failed to open ir device; open(NULL)" << endl;
- assert(true);
- return;
- }
-
- ret = info->open(info, NULL, (struct hw_common**)&ir_dev);
- if (ret < 0 || !ir_dev) {
- cout << "Failed to get ir device structure (" << ret << ")" << endl;
- assert(true);
- return;
- }
-
- return;
}
virtual void TearDown()
{
- struct hw_info *info;
-
- info = ir_dev->common.info;
- if (!info)
- free(ir_dev);
- else
- info->close((struct hw_common *)ir_dev);
- ir_dev = NULL;
- return;
}
};
@@ -62,40 +39,68 @@ class IRHalTest : public testing::Test
*/
TEST_F(IRHalTest, InitP)
{
- EXPECT_NE(ir_dev, nullptr);
-}
-
-TEST_F(IRHalTest, DeinitP)
-{
- struct ir_device *tmp;
- struct hw_info *info;
int ret;
- hw_get_info(IR_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
-
- EXPECT_NE(info, nullptr);
- EXPECT_NE(info->open, nullptr);
- info->open(info, NULL, (struct hw_common**)&tmp);
+ if (!supported)
+ return;
- ret = info->close((struct hw_common *)tmp);
- EXPECT_EQ(ret, 0);
+ ret = hw_get_info(IR_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+ EXPECT_EQ(ret, 0) << "Fail to get hal for ir (" << ret << ")";
+
+ if (!info->open) {
+ cout << "There is no function for info open" << endl;
+ return;
+ }
+ ret = info->open(info, NULL, (struct hw_common**)&ir_dev);
+ EXPECT_EQ(ret, 0) << "Fail to open ir device (" << ret << ")";
}
TEST_F(IRHalTest, IsAvailableP)
{
+ int ret;
bool val;
- EXPECT_NE(ir_dev, nullptr);
- ir_dev->is_available(&val);
+ if (!supported)
+ return;
+
+ if (!ir_dev->is_available) {
+ cout << "There is no function for is_available" << endl;
+ return;
+ }
+ ret = ir_dev->is_available(&val);
+ EXPECT_EQ(ret, 0) << "Fail to is_available (" << ret << ")";
}
TEST_F(IRHalTest, TransmitP)
{
+ int ret;
int pattern[5] = {100, 200, 300, 400, 500};
- EXPECT_NE(ir_dev, nullptr);
- ir_dev->transmit(pattern, 5);
+ if (!supported)
+ return;
+
+ if (!ir_dev->transmit) {
+ cout << "There is no function for transmit" << endl;
+ return;
+ }
+ ret = ir_dev->transmit(pattern, 5);
+ EXPECT_EQ(ret, 0) << "Fail to transmit (" << ret << ")";
+}
+
+TEST_F(IRHalTest, DeinitP)
+{
+ int ret;
+
+ if (!supported)
+ return;
+
+ if (!info->close) {
+ cout << "There is no function for info close" << endl;
+ return;
+ }
+ ret = info->close((struct hw_common *)ir_dev);
+ EXPECT_EQ(ret, 0) << "Fail to close ir device (" << ret << ")";
}
int main(int argc, char **argv)
diff --git a/unittest/gtest_hal_rgb.cpp b/unittest/gtest_hal_rgb.cpp
index d330fc0..d3325be 100644..100755
--- a/unittest/gtest_hal_rgb.cpp
+++ b/unittest/gtest_hal_rgb.cpp
@@ -1,59 +1,36 @@
#include <iostream>
#include <gtest/gtest.h>
-#include "hw/common.h"
+#include <system_info.h>
#include "hw/led.h"
+#include "unittest.h"
using namespace std;
/*
* main class
*/
+struct hw_info *info;
struct led_device *rgb_dev;
+static bool need_featurecheck = true;
class RGBHalTest : public testing::Test
{
public:
virtual void SetUp()
{
- struct hw_info *info;
int ret;
- ret = hw_get_info(LED_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
- if (ret < 0) {
- cout << "Fail to load led hal(" << ret << ")" << endl;
- assert(true);
- return;
+ if (need_featurecheck) {
+ ret = system_info_get_platform_bool(FEATURE_LED, &supported);
+ EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
+ need_featurecheck = false;
}
- if (!info->open) {
- cout << "Failed to open led device; open(NULL)" << endl;
- assert(true);
- return;
- }
-
- ret = info->open(info, LED_ID_NOTIFICATION, (struct hw_common**)&rgb_dev);
- if (ret < 0 || !rgb_dev) {
- cout << "Failed to get led notification device structure (" << ret << ")" << endl;
- assert(true);
- return;
- }
-
- return;
}
virtual void TearDown()
{
- struct hw_info *info;
-
- info = rgb_dev->common.info;
- if (!info)
- free(rgb_dev);
- else
- info->close((struct hw_common *)rgb_dev);
- rgb_dev = NULL;
- return;
}
};
@@ -62,25 +39,21 @@ class RGBHalTest : public testing::Test
*/
TEST_F(RGBHalTest, InitP)
{
- EXPECT_NE(rgb_dev, nullptr);
-}
-
-TEST_F(RGBHalTest, DeinitP)
-{
- struct led_device *tmp;
- struct hw_info *info;
int ret;
- hw_get_info(LED_HARDWARE_DEVICE_ID,
+ if (!supported)
+ return;
+
+ ret = hw_get_info(LED_HARDWARE_DEVICE_ID,
(const struct hw_info **)&info);
+ EXPECT_EQ(ret, 0) << "Fail to get hal for rgb (" << ret << ")";
- EXPECT_NE(info, nullptr);
- if (!info->open || !info->close)
+ if (!info->open) {
+ cout << "There is no function for info open" << endl;
return;
- info->open(info, NULL, (struct hw_common**)&tmp);
-
- ret = info->close((struct hw_common *)tmp);
- EXPECT_GE(ret, 0);
+ }
+ ret = info->open(info, LED_ID_NOTIFICATION, (struct hw_common**)&rgb_dev);
+ EXPECT_EQ(ret, 0) << "Fail to open rgb device (" << ret << ")";
}
TEST_F(RGBHalTest, SetStateP)
@@ -88,16 +61,35 @@ TEST_F(RGBHalTest, SetStateP)
struct led_state state;
int ret;
- EXPECT_NE(rgb_dev, nullptr);
- if (!rgb_dev->set_state)
+ if (!supported)
return;
+ if (!rgb_dev->set_state) {
+ cout << "There is no function for set_state" << endl;
+ return;
+ }
+
state.type = LED_TYPE_BLINK;
state.color = 0xFFFFFF;
state.duty_on = 500;
state.duty_off = 500;
ret = rgb_dev->set_state(&state);
- EXPECT_GE(ret, 0);
+ EXPECT_GE(ret, 0) << "Fail to set_state (" << ret << ")";
+}
+
+TEST_F(RGBHalTest, DeinitP)
+{
+ int ret;
+
+ if (!supported)
+ return;
+
+ if (!info->close) {
+ cout << "There is no function for info close" << endl;
+ return;
+ }
+ ret = info->close((struct hw_common *)rgb_dev);
+ EXPECT_GE(ret, 0) << "Fail to close rgb device (" << ret << ")";
}
int main(int argc, char **argv)
diff --git a/unittest/gtest_hal_thermal.cpp b/unittest/gtest_hal_thermal.cpp
new file mode 100755
index 0000000..9d0838b
--- /dev/null
+++ b/unittest/gtest_hal_thermal.cpp
@@ -0,0 +1,110 @@
+
+#include <iostream>
+#include <gtest/gtest.h>
+#include <system_info.h>
+#include "hw/thermal.h"
+#include "unittest.h"
+
+using namespace std;
+
+/*
+ * main class
+ */
+struct hw_info *info;
+struct thermal_device *thermal_dev;
+
+class THERMALHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+
+ }
+
+ virtual void TearDown()
+ {
+
+ }
+};
+
+/*
+ * testcase
+ */
+TEST_F(THERMALHalTest, InitP)
+{
+ int ret;
+
+ ret = hw_get_info(THERMAL_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+ if (ret < 0) {
+ cout << "There is no device for thermal" << ret << endl;
+ return;
+ } else {
+ EXPECT_EQ(ret, 0) << "Fail to get hal for thermal (" << ret << ")";
+ }
+
+ if (!info || !info->open) {
+ cout << "There is no function for info open" << endl;
+ return;
+ }
+ ret = info->open(info, NULL, (struct hw_common**)&thermal_dev);
+ EXPECT_EQ(ret, 0) << "Fail to open thermal device (" << ret << ")";
+}
+
+TEST_F(THERMALHalTest, GetStateP)
+{
+ struct thermal_info thermal;
+ int ret;
+
+ if (!thermal_dev || !thermal_dev->get_state) {
+ cout << "There is no function for get_state" << endl;
+ return;
+ }
+ ret = thermal_dev->get_state(&thermal);
+ EXPECT_EQ(ret, 0) << "Fail to get_state (" << ret << ")";
+}
+
+static void updated_cb(struct thermal_info *info, void *data)
+{
+
+}
+
+TEST_F(THERMALHalTest, RegisterChangedEventP)
+{
+ int ret;
+
+ if (!thermal_dev || !thermal_dev->register_changed_event) {
+ cout << "There is no function for register_changed_event" << endl;
+ return;
+ }
+ ret = thermal_dev->register_changed_event(updated_cb, NULL);
+ EXPECT_EQ(ret, 0) << "Fail to register_changed_event (" << ret << ")";
+}
+
+TEST_F(THERMALHalTest, UnregisterChangedEventP)
+{
+ if (!thermal_dev || !thermal_dev->unregister_changed_event) {
+ cout << "There is no function for unregister_changed_event" << endl;
+ return;
+ }
+ thermal_dev->unregister_changed_event(updated_cb);
+}
+
+TEST_F(THERMALHalTest, DeinitP)
+{
+ int ret;
+
+ if (!info || !info->close) {
+ cout << "There is no function for info close" << endl;
+ return;
+ }
+ ret = info->close((struct hw_common *)thermal_dev);
+ EXPECT_EQ(ret, 0) << "Fail to close thermal device (" << ret << ")";
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
diff --git a/unittest/gtest_hal_touchscreen.cpp b/unittest/gtest_hal_touchscreen.cpp
index 07cf6dc..046cef8 100644..100755
--- a/unittest/gtest_hal_touchscreen.cpp
+++ b/unittest/gtest_hal_touchscreen.cpp
@@ -9,6 +9,7 @@ using namespace std;
/*
* main class
*/
+struct hw_info *info;
struct touchscreen_device *touchscreen_dev;
class TOUCHSCREENHalTest : public testing::Test
@@ -16,44 +17,12 @@ class TOUCHSCREENHalTest : public testing::Test
public:
virtual void SetUp()
{
- struct hw_info *info;
- int ret;
- ret = hw_get_info(TOUCHSCREEN_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
-
- if (ret < 0) {
- cout << "Fail to load touchscreen hal(" << ret << ")" << endl;
- assert(true);
- return;
- }
- if (!info->open) {
- cout << "Failed to open touchscreen device; open(NULL)" << endl;
- assert(true);
- return;
- }
-
- ret = info->open(info, NULL, (struct hw_common**)&touchscreen_dev);
- if (ret < 0 || !touchscreen_dev) {
- cout << "Failed to get touchscreen device structure (" << ret << ")" << endl;
- assert(true);
- return;
- }
-
- return;
+
}
virtual void TearDown()
{
- struct hw_info *info;
-
- info = touchscreen_dev->common.info;
- if (!info)
- free(touchscreen_dev);
- else
- info->close((struct hw_common *)touchscreen_dev);
- touchscreen_dev = NULL;
- return;
}
};
@@ -62,7 +31,23 @@ class TOUCHSCREENHalTest : public testing::Test
*/
TEST_F(TOUCHSCREENHalTest, InitP)
{
- EXPECT_NE(touchscreen_dev, nullptr);
+ int ret;
+
+ ret = hw_get_info(TOUCHSCREEN_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+ if (ret < 0) {
+ cout << "There is no device for touchscreen" << ret << endl;
+ return;
+ } else {
+ EXPECT_EQ(ret, 0) << "Fail to get hal for touchscreen (" << ret << ")";
+ }
+
+ if (!info || !info->open) {
+ cout << "There is no function for info open" << endl;
+ return;
+ }
+ ret = info->open(info, NULL, (struct hw_common**)&touchscreen_dev);
+ EXPECT_EQ(ret, 0) << "Fail to open touchscreen device (" << ret << ")";
}
TEST_F(TOUCHSCREENHalTest, SetstateP)
@@ -70,11 +55,24 @@ TEST_F(TOUCHSCREENHalTest, SetstateP)
enum touchscreen_state state = TOUCHSCREEN_ON;
int ret;
- EXPECT_NE(touchscreen_dev, nullptr);
- if (!touchscreen_dev->set_state)
+ if (!touchscreen_dev || !touchscreen_dev->set_state) {
+ cout << "There is no function for set_state" << endl;
return;
+ }
ret = touchscreen_dev->set_state(state);
- EXPECT_EQ(ret, 0) << "Failed to enable touchscreen (" << ret << ")";
+ EXPECT_EQ(ret, 0) << "Fail to set_state (" << ret << ")";
+}
+
+TEST_F(TOUCHSCREENHalTest, DeinitP)
+{
+ int ret;
+
+ if (!info || !info->close) {
+ cout << "There is no function for info close" << endl;
+ return;
+ }
+ ret = info->close((struct hw_common *)touchscreen_dev);
+ EXPECT_EQ(ret, 0) << "Fail to close touchscreen device (" << ret << ")";
}
int main(int argc, char **argv)
diff --git a/unittest/gtest_hal_usb_client.cpp b/unittest/gtest_hal_usb_client.cpp
new file mode 100755
index 0000000..9686d6a
--- /dev/null
+++ b/unittest/gtest_hal_usb_client.cpp
@@ -0,0 +1,223 @@
+
+#include <iostream>
+#include <gtest/gtest.h>
+#include <system_info.h>
+#include "hw/usb_client.h"
+#include "unittest.h"
+
+using namespace std;
+
+/*
+ * main class
+ */
+struct hw_info *info;
+struct usb_client *client_dev;
+struct usb_gadget *gadget_dev;
+struct usb_gadget_id gadget_id;
+struct usb_gadget_translator *gadget_translator;
+static bool need_modelcheck = true;
+
+#define MODEL_NAME "http://tizen.org/system/model_name"
+
+class USBCLIENTHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+ int ret;
+ char *model_name = NULL;
+
+ if (need_modelcheck) {
+ ret = system_info_get_platform_string(MODEL_NAME, &model_name);
+ EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
+
+ if (!strncmp(model_name, "artik", 5)) {
+ supported = true;
+ } else {
+ supported = false;
+ }
+ cout << "supported " << supported << endl;
+ need_modelcheck = false;
+ }
+ }
+
+ virtual void TearDown()
+ {
+
+ }
+};
+
+/*
+ * testcase
+ */
+TEST_F(USBCLIENTHalTest, InitP)
+{
+ int ret;
+
+ if (!supported)
+ return;
+
+ ret = hw_get_info(USB_CLIENT_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+ if (ret < 0) {
+ cout << "There is no device for usb client" << ret << endl;
+ return;
+ } else {
+ EXPECT_EQ(ret, 0) << "Fail to get hal for usb client (" << ret << ")";
+ }
+ if (!info || !info->open) {
+ cout << "There is no function for info open" << endl;
+ return;
+ }
+ ret = info->open(info, NULL, (struct hw_common**)&client_dev);
+ EXPECT_EQ(ret, 0) << "Fail to open usb client device (" << ret << ")";
+ EXPECT_NE(client_dev, nullptr) << "Fail to get usb client device structure";
+
+ ret = hw_get_info(USB_GADGET_DEVICE_ID,
+ (const struct hw_info **)&info);
+ if (ret < 0) {
+ cout << "There is no device for usb gadget" << ret << endl;
+ return;
+ } else {
+ EXPECT_EQ(ret, 0) << "Fail to get hal for usb gadget (" << ret << ")";
+ }
+
+ if (!info || !info->open) {
+ cout << "There is no function for info open" << endl;
+ return;
+ }
+ ret = info->open(info, NULL, (struct hw_common**)&gadget_translator);
+ EXPECT_EQ(ret, 0) << "Fail to open usb gadget device (" << ret << ")";
+}
+
+TEST_F(USBCLIENTHalTest, EnableP)
+{
+ int ret;
+ char str[256];
+
+ if (!supported)
+ return;
+
+ //dummy code to prevent error for not used function
+ snprintf(str, 255, "%s,", _available_funcs[2]->name);
+
+ if (!client_dev || !client_dev->enable) {
+ cout << "There is no function for enable" << endl;
+ return;
+ }
+ ret = client_dev->enable(client_dev);
+ EXPECT_EQ(ret, 0) << "Fail to enable (" << ret << ")";
+}
+
+TEST_F(USBCLIENTHalTest, ReConfigureGadgetP)
+{
+ int ret;
+
+ if (!supported)
+ return;
+
+ if (!gadget_translator || !gadget_translator->id_to_gadget) {
+ cout << "There is no function for id_to_gadget" << endl;
+ return;
+ }
+ gadget_id.function_mask = 7;
+ ret = gadget_translator->id_to_gadget(&gadget_id, &gadget_dev);
+ EXPECT_EQ(ret, 0) << "Fail to id_to_gadget (" << ret << ")";
+
+ if (!client_dev || !client_dev->disable) {
+ cout << "There is no function for disable" << endl;
+ return;
+ }
+ ret = client_dev->disable(client_dev);
+ EXPECT_EQ(ret, 0) << "Fail to disable (" << ret << ")";
+
+ if (!client_dev || !client_dev->reconfigure_gadget) {
+ cout << "There is no function for reconfigure_gadget" << endl;
+ return;
+ }
+ ret = client_dev->reconfigure_gadget(client_dev, gadget_dev);
+ EXPECT_EQ(ret, 0) << "Fail to reconfigure_gadget (" << ret << ")";
+}
+
+TEST_F(USBCLIENTHalTest, IsGadgetSupportedP)
+{
+ bool flag;
+
+ if (!supported)
+ return;
+
+ if (!client_dev || !client_dev->is_gadget_supported) {
+ cout << "There is no function for is_gadget_supported" << endl;
+ return;
+ }
+ flag = client_dev->is_gadget_supported(client_dev, gadget_dev);
+ EXPECT_EQ(flag, true) << "Fail to is_gadget_supported (" << flag << ")";
+}
+
+TEST_F(USBCLIENTHalTest, IsFunctionSupportedP)
+{
+ bool flag;
+
+ if (!supported)
+ return;
+
+ if (!client_dev || !client_dev->is_function_supported) {
+ cout << "There is no function for is_function_supported" << endl;
+ return;
+ }
+ flag = client_dev->is_function_supported(client_dev, *gadget_dev->funcs);
+ EXPECT_EQ(flag, true) << "Fail to is_function_supported (" << flag << ")";
+}
+
+TEST_F(USBCLIENTHalTest, GetCurrentGadgetP)
+{
+ int ret;
+
+ if (!supported)
+ return;
+
+ if (!client_dev || !client_dev->get_current_gadget) {
+ cout << "There is no function for get_current_gadget" << endl;
+ return;
+ }
+ ret = client_dev->get_current_gadget(client_dev, &gadget_dev);
+ EXPECT_EQ(ret, 0) << "Fail to get_current_gadget (" << ret << ")";
+}
+
+TEST_F(USBCLIENTHalTest, DisableP)
+{
+ int ret;
+
+ if (!supported)
+ return;
+
+ if (!client_dev || !client_dev->disable) {
+ cout << "There is no function for disable" << endl;
+ return;
+ }
+ ret = client_dev->disable(client_dev);
+ EXPECT_EQ(ret, 0) << "Fail to disable (" << ret << ")";
+}
+
+TEST_F(USBCLIENTHalTest, DeinitP)
+{
+ int ret;
+
+ if (!supported)
+ return;
+
+ if (!info || !info->close) {
+ cout << "There is no function for info close" << endl;
+ return;
+ }
+ ret = info->close((struct hw_common *)client_dev);
+ EXPECT_EQ(ret, 0) << "Fail to close usb client device (" << ret << ")";
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
+
diff --git a/unittest/gtest_hal_usb_gadget.cpp b/unittest/gtest_hal_usb_gadget.cpp
new file mode 100755
index 0000000..4b567c2
--- /dev/null
+++ b/unittest/gtest_hal_usb_gadget.cpp
@@ -0,0 +1,98 @@
+
+#include <iostream>
+#include <gtest/gtest.h>
+#include <system_info.h>
+#include "hw/usb_gadget.h"
+#include "unittest.h"
+
+using namespace std;
+
+/*
+ * main class
+ */
+struct hw_info *info;
+struct usb_gadget *gadget_dev;
+struct usb_gadget_translator *gadget_translator;
+
+class USBGADGETHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+
+ }
+
+ virtual void TearDown()
+ {
+
+ }
+};
+
+/*
+ * testcase
+ */
+TEST_F(USBGADGETHalTest, InitP)
+{
+ int ret;
+
+ ret = hw_get_info(USB_GADGET_DEVICE_ID,
+ (const struct hw_info **)&info);
+ if (ret < 0) {
+ cout << "There is no device for usb gadget" << ret << endl;
+ return;
+ } else {
+ EXPECT_EQ(ret, 0) << "Fail to get hal for usb gadget (" << ret << ")";
+ }
+
+ if (!info || !info->open) {
+ cout << "There is no function for info open" << endl;
+ return;
+ }
+ ret = info->open(info, NULL, (struct hw_common**)&gadget_translator);
+ EXPECT_EQ(ret, 0) << "Fail to open usb gadget device (" << ret << ")";
+}
+
+TEST_F(USBGADGETHalTest, IdToGadget)
+{
+ struct usb_gadget_id gadget_id;
+ int ret;
+ char str[256];
+
+ if (!gadget_translator || !gadget_translator->id_to_gadget) {
+ cout << "There is no function for id_to_gadget" << endl;
+ return;
+ }
+ //dummy code to prevent error for not used function
+ snprintf(str, 255, "%s,", _available_funcs[2]->name);
+ gadget_id.function_mask = 7;
+ ret = gadget_translator->id_to_gadget(&gadget_id, &gadget_dev);
+ EXPECT_EQ(ret, 0) << "Fail to id_to_gadget (" << ret << ")";
+}
+
+TEST_F(USBGADGETHalTest, CleanUpGadget)
+{
+ if (!gadget_translator || !gadget_translator->cleanup_gadget) {
+ cout << "There is no function for cleanup_gadget" << endl;
+ return;
+ }
+ gadget_translator->cleanup_gadget(gadget_dev);
+}
+
+TEST_F(USBGADGETHalTest, DeinitP)
+{
+ int ret;
+
+ if (!info || !info->close) {
+ cout << "There is no function for info close" << endl;
+ return;
+ }
+ ret = info->close((struct hw_common *)gadget_translator);
+ EXPECT_EQ(ret, 0) << "Fail to close usb gadget device (" << ret << ")";
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
diff --git a/unittest/unittest.h b/unittest/unittest.h
new file mode 100755
index 0000000..e418093
--- /dev/null
+++ b/unittest/unittest.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __LIBDEVICENODE_UNITTEST_H__
+#define __LIBDEVICENODE_UNITTEST_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib.h>
+
+#define FEATURE_BATTERY "http://tizen.org/feature/battery"
+#define FEATURE_LED "http://tizen.org/feature/led"
+#define FEATURE_IR "http://tizen.org/feature/consumer_ir"
+
+bool supported;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBDEVICENODE_UNITTEST_H__ */