Add cpp files for HAL test
[platform/core/system/libdevice-node.git] / unittest / gtest_hal_display.cpp
1
2 #include <iostream>
3 #include <gtest/gtest.h>
4 #include "hw/display.h"
5
6 using namespace std;
7
8 /*
9  * main class
10  */
11
12 #define LOWBATTERY "LowBattery"
13
14 struct hw_info *info;
15 struct display_device *display_dev;
16
17 class DISPLAYHalTest : public testing::Test
18 {
19         public:
20                 virtual void SetUp()
21                 {
22
23                 }
24
25                 virtual void TearDown()
26                 {
27
28                 }
29 };
30
31 /*
32  * testcase
33  */
34 TEST_F(DISPLAYHalTest, InitP)
35 {
36         int ret;
37
38         ret = hw_get_info(DISPLAY_HARDWARE_DEVICE_ID,
39                         (const struct hw_info **)&info);
40         if (ret < 0) {
41                 cout << "There is no device for display" << ret << endl;
42                 return;
43         } else {
44                 EXPECT_EQ(ret, 0) << "Fail to load display hal (" << ret << ")";
45         }
46
47         if (!info || !info->open) {
48                 cout << "There is no function for info open" << endl;
49                 return;
50         }
51         ret = info->open(info, NULL, (struct hw_common**)&display_dev);
52         EXPECT_EQ(ret, 0) << "Fail to open display device (" << ret << ")";
53 }
54
55 TEST_F(DISPLAYHalTest, GetMaxBrightnessP)
56 {
57         int ret;
58         int max;
59
60         if (!display_dev || !display_dev->get_max_brightness) {
61                 cout << "There is no function for get_max_brightness" << endl;
62                 return;
63         }
64         ret = display_dev->get_max_brightness(&max);
65         EXPECT_EQ(ret, 0) << "Fail to get_max_brightness (" << ret << ")";
66 }
67
68 TEST_F(DISPLAYHalTest, GetBrightnessP)
69 {
70         int ret;
71         int brt;
72
73         if (!display_dev || !display_dev->get_brightness) {
74                 cout << "There is no function for get_brightness" << endl;
75                 return;
76         }
77         ret = display_dev->get_brightness(&brt);
78         EXPECT_EQ(ret, 0) << "Fail to get_brightness (" << ret << ")";
79 }
80
81 TEST_F(DISPLAYHalTest, SetBrightnessP)
82 {
83         int ret;
84         int max;
85
86         if (!display_dev || !display_dev->get_max_brightness) {
87                 cout << "There is no function for get_max_brightness" << endl;
88                 return;
89         }
90         ret = display_dev->get_max_brightness(&max);
91         EXPECT_EQ(ret, 0) << "Fail to get_max_brightness (" << ret << ")";
92
93         if (!display_dev || !display_dev->set_brightness) {
94                 cout << "There is no function for set_brightness" << endl;
95                 return;
96         }
97         ret = display_dev->set_brightness(max);
98         EXPECT_EQ(ret, 0) << "Fail to set_brightness (" << ret << ")";
99 }
100
101 TEST_F(DISPLAYHalTest, GetAutoBrightnessP)
102 {
103         int ret;
104         int brt;
105         float lmax = 0, lmin = 0, light = 0;
106
107         if (!display_dev || !display_dev->get_auto_brightness) {
108                 cout << "There is no function for get_auto_brightness" << endl;
109                 return;
110         }
111         ret = display_dev->get_auto_brightness(lmax, lmin, light, &brt);
112         EXPECT_GE(ret, 0) << "Fail to set_brightness (" << ret << ")";
113 }
114
115 TEST_F(DISPLAYHalTest, GetStateP)
116 {
117         int ret;
118         enum display_state state;
119
120         if (!display_dev || !display_dev->get_state) {
121                 cout << "There is no function for get_state" << endl;
122                 return;
123         }
124         ret = display_dev->get_state(&state);
125         EXPECT_GE(ret, 0) << "Fail to get_state (" << ret << ")";
126 }
127
128 TEST_F(DISPLAYHalTest, SetStateP)
129 {
130         int ret;
131
132         if (!display_dev || !display_dev->set_state) {
133                 cout << "There is no function for set_state" << endl;
134                 return;
135         }
136         ret = display_dev->set_state(DISPLAY_ON);
137         EXPECT_GE(ret, 0) << "Fail to set_state (" << ret << ")";
138 }
139
140 TEST_F(DISPLAYHalTest, GetMaxFrameRateP)
141 {
142         int ret;
143         int max;
144
145         if (!display_dev || !display_dev->get_max_frame_rate) {
146                 cout << "There is no function for get_max_frame_rate" << endl;
147                 return;
148         }
149         ret = display_dev->get_max_frame_rate(&max);
150         EXPECT_GE(ret, 0) << "Fail to get_max_frame_rate (" << ret << ")";
151 }
152
153 TEST_F(DISPLAYHalTest, GetMinFrameRateP)
154 {
155         int ret;
156         int min;
157
158         if (!display_dev || !display_dev->get_min_frame_rate) {
159                 cout << "There is no function for get_min_frame_rate" << endl;
160                 return;
161         }
162         ret = display_dev->get_min_frame_rate(&min);
163         EXPECT_GE(ret, 0) << "Fail to get_min_frame_rate (" << ret << ")";
164 }
165
166 TEST_F(DISPLAYHalTest, SetFrameRateP)
167 {
168         int ret;
169         int max;
170
171         if (!display_dev || !display_dev->get_max_frame_rate) {
172                 cout << "There is no function for get_max_frame_rate" << endl;
173                 return;
174         }
175         ret = display_dev->get_max_frame_rate(&max);
176         EXPECT_GE(ret, 0) << "Fail to get_max_frame_rate (" << ret << ")";
177
178         if (!display_dev->set_frame_rate) {
179                 cout << "There is no function for set_frame_rate" << endl;
180                 return;
181         }
182         ret = display_dev->set_frame_rate(max);
183         EXPECT_GE(ret, 0) << "Fail to set_frame_rate (" << ret << ")";
184 }
185
186 TEST_F(DISPLAYHalTest, DeinitP)
187 {
188         int ret;
189
190         if (!info || !info->close) {
191                 cout << "There is no function for info close" << endl;
192                 return;
193         }
194         ret = info->close((struct hw_common *)display_dev);
195         EXPECT_GE(ret, 0) << "Fail to close display device (" << ret << ")";
196 }
197
198 int main(int argc, char **argv)
199 {
200         testing::InitGoogleTest(&argc, argv);
201
202         return RUN_ALL_TESTS();
203 }