diff options
author | pr.jung <pr.jung@samsung.com> | 2018-04-04 14:00:59 +0900 |
---|---|---|
committer | Hyotaek Shim <hyotaek.shim@samsung.com> | 2018-04-05 14:00:07 +0900 |
commit | ee6db1e22eab278f0c9c7d534b591608218b53bb (patch) | |
tree | ab4eb0564ad31b09e3d2bce346600b000332bf9a | |
parent | 9ef88c98641c6f0136a03360de688ddc9a33a639 (diff) | |
download | libdevice-node-ee6db1e22eab278f0c9c7d534b591608218b53bb.tar.gz libdevice-node-ee6db1e22eab278f0c9c7d534b591608218b53bb.tar.bz2 libdevice-node-ee6db1e22eab278f0c9c7d534b591608218b53bb.zip |
gtest: Add gtest for led
Change-Id: I0d3c88dd1131fb4262d54b766002043c4a1ee333
Signed-off-by: pr.jung <pr.jung@samsung.com>
Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com>
-rw-r--r-- | packaging/libdevice-node.spec | 11 | ||||
-rw-r--r-- | unittest/gtest_hal_rgb.cpp | 108 |
2 files changed, 117 insertions, 2 deletions
diff --git a/packaging/libdevice-node.spec b/packaging/libdevice-node.spec index 782d7fd..689c1de 100644 --- a/packaging/libdevice-node.spec +++ b/packaging/libdevice-node.spec @@ -11,7 +11,6 @@ BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) - BuildRequires: pkgconfig(gmock) %description @@ -24,6 +23,12 @@ Requires: %{name} = %{version}-%{release} %description devel Library to control OAL APIs (devel) +%package -n device-hal-tc +Summary: Device HAL(Hardware Abstraction Layer) Test Cases +Requires: %{name} = %{version}-%{release} + +%description -n device-hal-tc +Device HAL(Hardware Abstraction Layer) Test Cases %prep %setup -q @@ -45,10 +50,12 @@ make %{?jobs:-j%jobs} %{_libdir}/*.so.* %manifest %{name}.manifest %license LICENSE.APLv2 -%{_bindir}/gtest* %files devel %{_includedir}/device-node/*.h %{_includedir}/hw/*.h %{_libdir}/*.so %{_libdir}/pkgconfig/*.pc + +%files -n device-hal-tc +%{_bindir}/gtest* diff --git a/unittest/gtest_hal_rgb.cpp b/unittest/gtest_hal_rgb.cpp new file mode 100644 index 0000000..d330fc0 --- /dev/null +++ b/unittest/gtest_hal_rgb.cpp @@ -0,0 +1,108 @@ + +#include <iostream> +#include <gtest/gtest.h> +#include "hw/common.h" +#include "hw/led.h" + +using namespace std; + +/* + * main class + */ +struct led_device *rgb_dev; + +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 (!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; + } +}; + +/* + * testcase + */ +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, + (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_GE(ret, 0); +} + +TEST_F(RGBHalTest, SetStateP) +{ + struct led_state state; + int ret; + + EXPECT_NE(rgb_dev, nullptr); + if (!rgb_dev->set_state) + 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); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} |