#include #include #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(); }