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