Add cpp files for HAL test
[platform/core/system/libdevice-node.git] / unittest / gtest_hal_touchscreen.cpp
1
2 #include <iostream>
3 #include <gtest/gtest.h>
4 #include "hw/common.h"
5 #include "hw/touchscreen.h"
6
7 using namespace std;
8
9 /*
10  * main class
11  */
12 struct hw_info *info;
13 struct touchscreen_device *touchscreen_dev;
14
15 class TOUCHSCREENHalTest : public testing::Test
16 {
17         public:
18                 virtual void SetUp()
19                 {
20
21                 }
22
23                 virtual void TearDown()
24                 {
25
26                 }
27 };
28
29 /*
30  * testcase
31  */
32 TEST_F(TOUCHSCREENHalTest, InitP)
33 {
34         int ret;
35
36         ret = hw_get_info(TOUCHSCREEN_HARDWARE_DEVICE_ID,
37                         (const struct hw_info **)&info);
38         if (ret < 0) {
39                 cout << "There is no device for touchscreen" << ret << endl;
40                 return;
41         } else {
42                 EXPECT_EQ(ret, 0) << "Fail to get hal for touchscreen (" << ret << ")";
43         }
44
45         if (!info || !info->open) {
46                 cout << "There is no function for info open" << endl;
47                 return;
48         }
49         ret = info->open(info, NULL, (struct hw_common**)&touchscreen_dev);
50         EXPECT_EQ(ret, 0) << "Fail to open touchscreen device (" << ret << ")";
51 }
52
53 TEST_F(TOUCHSCREENHalTest, SetstateP)
54 {
55         enum touchscreen_state state = TOUCHSCREEN_ON;
56         int ret;
57
58         if (!touchscreen_dev || !touchscreen_dev->set_state) {
59                 cout << "There is no function for set_state" << endl;
60                 return;
61         }
62         ret = touchscreen_dev->set_state(state);
63         EXPECT_EQ(ret, 0) << "Fail to set_state (" << ret << ")";
64 }
65
66 TEST_F(TOUCHSCREENHalTest, DeinitP)
67 {
68         int ret;
69
70         if (!info || !info->close) {
71                 cout << "There is no function for info close" << endl;
72                 return;
73         }
74         ret = info->close((struct hw_common *)touchscreen_dev);
75         EXPECT_EQ(ret, 0) << "Fail to close touchscreen device (" << ret << ")";
76 }
77
78 int main(int argc, char **argv)
79 {
80         testing::InitGoogleTest(&argc, argv);
81
82         return RUN_ALL_TESTS();
83 }