diff options
Diffstat (limited to 'unittest/gtest_hal_rgb.cpp')
-rwxr-xr-x[-rw-r--r--] | unittest/gtest_hal_rgb.cpp | 88 |
1 files changed, 40 insertions, 48 deletions
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) |