#include #include #include "hw/common.h" #include "hw/touchscreen.h" using namespace std; /* * main class */ struct touchscreen_device *touchscreen_dev; 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; } }; /* * testcase */ TEST_F(TOUCHSCREENHalTest, InitP) { EXPECT_NE(touchscreen_dev, nullptr); } TEST_F(TOUCHSCREENHalTest, SetstateP) { enum touchscreen_state state = TOUCHSCREEN_ON; int ret; EXPECT_NE(touchscreen_dev, nullptr); if (!touchscreen_dev->set_state) return; ret = touchscreen_dev->set_state(state); EXPECT_EQ(ret, 0) << "Failed to enable touchscreen (" << ret << ")"; } int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }