summaryrefslogtreecommitdiff
path: root/unittest/gtest_hal_display.cpp
blob: 98e71cb357eec1de0105828982e10fdc5466fd04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

#include <iostream>
#include <gtest/gtest.h>
#include "hw/display.h"

using namespace std;

/*
 * main class
 */

#define LOWBATTERY "LowBattery"

struct hw_info *info;
struct display_device *display_dev;

class DISPLAYHalTest : public testing::Test
{
	public:
		virtual void SetUp()
		{

		}

		virtual void TearDown()
		{

		}
};

/*
 * testcase
 */
TEST_F(DISPLAYHalTest, InitP)
{
	int ret;

	ret = hw_get_info(DISPLAY_HARDWARE_DEVICE_ID,
			(const struct hw_info **)&info);
	if (ret < 0) {
		cout << "There is no device for display" << ret << endl;
		return;
	} else {
		EXPECT_EQ(ret, 0) << "Fail to load display hal (" << ret << ")";
	}

	if (!info || !info->open) {
		cout << "There is no function for info open" << endl;
		return;
	}
	ret = info->open(info, NULL, (struct hw_common**)&display_dev);
	EXPECT_EQ(ret, 0) << "Fail to open display device (" << ret << ")";
}

TEST_F(DISPLAYHalTest, GetMaxBrightnessP)
{
	int ret;
	int max;

	if (!display_dev || !display_dev->get_max_brightness) {
		cout << "There is no function for get_max_brightness" << endl;
		return;
	}
	ret = display_dev->get_max_brightness(&max);
	EXPECT_EQ(ret, 0) << "Fail to get_max_brightness (" << ret << ")";
}

TEST_F(DISPLAYHalTest, GetBrightnessP)
{
	int ret;
	int brt;

	if (!display_dev || !display_dev->get_brightness) {
		cout << "There is no function for get_brightness" << endl;
		return;
	}
	ret = display_dev->get_brightness(&brt);
	EXPECT_EQ(ret, 0) << "Fail to get_brightness (" << ret << ")";
}

TEST_F(DISPLAYHalTest, SetBrightnessP)
{
	int ret;
	int max;

	if (!display_dev || !display_dev->get_max_brightness) {
		cout << "There is no function for get_max_brightness" << endl;
		return;
	}
	ret = display_dev->get_max_brightness(&max);
	EXPECT_EQ(ret, 0) << "Fail to get_max_brightness (" << ret << ")";

	if (!display_dev || !display_dev->set_brightness) {
		cout << "There is no function for set_brightness" << endl;
		return;
	}
	ret = display_dev->set_brightness(max);
	EXPECT_EQ(ret, 0) << "Fail to set_brightness (" << ret << ")";
}

TEST_F(DISPLAYHalTest, GetAutoBrightnessP)
{
	int ret;
	int brt;
	float lmax = 0, lmin = 0, light = 0;

	if (!display_dev || !display_dev->get_auto_brightness) {
		cout << "There is no function for get_auto_brightness" << endl;
		return;
	}
	ret = display_dev->get_auto_brightness(lmax, lmin, light, &brt);
	EXPECT_GE(ret, 0) << "Fail to set_brightness (" << ret << ")";
}

TEST_F(DISPLAYHalTest, GetStateP)
{
	int ret;
	enum display_state state;

	if (!display_dev || !display_dev->get_state) {
		cout << "There is no function for get_state" << endl;
		return;
	}
	ret = display_dev->get_state(&state);
	EXPECT_GE(ret, 0) << "Fail to get_state (" << ret << ")";
}

TEST_F(DISPLAYHalTest, SetStateP)
{
	int ret;

	if (!display_dev || !display_dev->set_state) {
		cout << "There is no function for set_state" << endl;
		return;
	}
	ret = display_dev->set_state(DISPLAY_ON);
	EXPECT_GE(ret, 0) << "Fail to set_state (" << ret << ")";
}

TEST_F(DISPLAYHalTest, GetMaxFrameRateP)
{
	int ret;
	int max;

	if (!display_dev || !display_dev->get_max_frame_rate) {
		cout << "There is no function for get_max_frame_rate" << endl;
		return;
	}
	ret = display_dev->get_max_frame_rate(&max);
	EXPECT_GE(ret, 0) << "Fail to get_max_frame_rate (" << ret << ")";
}

TEST_F(DISPLAYHalTest, GetMinFrameRateP)
{
	int ret;
	int min;

	if (!display_dev || !display_dev->get_min_frame_rate) {
		cout << "There is no function for get_min_frame_rate" << endl;
		return;
	}
	ret = display_dev->get_min_frame_rate(&min);
	EXPECT_GE(ret, 0) << "Fail to get_min_frame_rate (" << ret << ")";
}

TEST_F(DISPLAYHalTest, SetFrameRateP)
{
	int ret;
	int max;

	if (!display_dev || !display_dev->get_max_frame_rate) {
		cout << "There is no function for get_max_frame_rate" << endl;
		return;
	}
	ret = display_dev->get_max_frame_rate(&max);
	EXPECT_GE(ret, 0) << "Fail to get_max_frame_rate (" << ret << ")";

	if (!display_dev->set_frame_rate) {
		cout << "There is no function for set_frame_rate" << endl;
		return;
	}
	ret = display_dev->set_frame_rate(max);
	EXPECT_GE(ret, 0) << "Fail to set_frame_rate (" << ret << ")";
}

TEST_F(DISPLAYHalTest, DeinitP)
{
	int ret;

	if (!info || !info->close) {
		cout << "There is no function for info close" << endl;
		return;
	}
	ret = info->close((struct hw_common *)display_dev);
	EXPECT_GE(ret, 0) << "Fail to close display device (" << ret << ")";
}

int main(int argc, char **argv)
{
	testing::InitGoogleTest(&argc, argv);

	return RUN_ALL_TESTS();
}