44
45
static geom::Size const display_size{433,232};
46
class AndroidTestFramebufferInit : public ::testing::Test
47
class AndroidDisplayTest : public ::testing::Test
49
50
virtual void SetUp()
51
52
using namespace testing;
53
native_win = std::make_shared<NiceMock<mtd::MockAndroidFramebufferWindow>>();
55
/* silence uninteresting warning messages */
56
53
mock_egl.silence_uninteresting();
58
EXPECT_CALL(*native_win, android_native_window_type())
60
EXPECT_CALL(*native_win, android_display_egl_config(_))
63
56
mock_display_report = std::make_shared<NiceMock<mtd::MockDisplayReport>>();
64
stub_display_support = std::make_shared<mtd::StubDisplaySupportProvider>(display_size);
57
stub_display_device = std::make_shared<mtd::StubDisplayDevice>(display_size);
58
auto stub_driver_interpreter = std::make_shared<mtd::StubDriverInterpreter>(display_size, visual_id);
59
native_win = std::make_shared<mg::android::MirNativeWindow>(stub_driver_interpreter);
65
60
db_factory = std::make_shared<mga::DisplayBufferFactory>();
68
64
std::shared_ptr<mga::DisplayBufferFactory> db_factory;
69
65
std::shared_ptr<mtd::MockDisplayReport> mock_display_report;
70
std::shared_ptr<mtd::MockAndroidFramebufferWindow> native_win;
71
std::shared_ptr<mtd::StubDisplaySupportProvider> stub_display_support;
66
std::shared_ptr<ANativeWindow> native_win;
67
std::shared_ptr<mtd::StubDisplayDevice> stub_display_device;
72
68
mtd::MockEGL mock_egl;
75
TEST_F(AndroidTestFramebufferInit, eglGetDisplay)
71
TEST_F(AndroidDisplayTest, eglChooseConfig_attributes)
73
using namespace testing;
77
EXPECT_CALL(mock_egl, eglChooseConfig(mock_egl.fake_egl_display, _, _, _, _))
81
SetArgPointee<2>(mock_egl.fake_configs),
82
SetArgPointee<4>(mock_egl.fake_configs_num),
85
mga::AndroidDisplay display(native_win, db_factory, stub_display_device, mock_display_report);
88
bool surface_bit_correct = false;
89
bool renderable_bit_correct = false;
90
while(attr[i] != EGL_NONE)
92
if ((attr[i] == EGL_SURFACE_TYPE) && (attr[i+1] == EGL_WINDOW_BIT))
94
surface_bit_correct = true;
96
if ((attr[i] == EGL_RENDERABLE_TYPE) && (attr[i+1] == EGL_OPENGL_ES2_BIT))
98
renderable_bit_correct = true;
103
EXPECT_EQ(EGL_NONE, attr[i]);
104
EXPECT_TRUE(surface_bit_correct);
105
EXPECT_TRUE(renderable_bit_correct);
108
TEST_F(AndroidDisplayTest, queries_with_enough_room_for_all_potential_cfg)
110
using namespace testing;
115
EXPECT_CALL(mock_egl, eglGetConfigs(mock_egl.fake_egl_display, NULL, 0, _))
118
SetArgPointee<3>(num_cfg),
121
EXPECT_CALL(mock_egl, eglChooseConfig(mock_egl.fake_egl_display, _, _, num_cfg, _))
125
SetArgPointee<2>(mock_egl.fake_configs),
126
SetArgPointee<4>(mock_egl.fake_configs_num),
129
mga::AndroidDisplay display(native_win, db_factory, stub_display_device, mock_display_report);
131
/* should be able to ref this spot */
132
EGLint test_last_spot = attr[num_cfg-1];
133
EXPECT_EQ(test_last_spot, test_last_spot);
137
TEST_F(AndroidDisplayTest, creates_with_proper_visual_id_mixed_valid_invalid)
139
using namespace testing;
141
EGLConfig cfg, chosen_cfg;
143
int bad_id = visual_id + 1;
145
EXPECT_CALL(mock_egl, eglGetConfigAttrib(mock_egl.fake_egl_display, _, EGL_NATIVE_VISUAL_ID, _))
148
SetArgPointee<3>(bad_id),
151
SetArgPointee<3>(visual_id),
154
.WillRepeatedly(DoAll(
155
SetArgPointee<3>(bad_id),
158
EXPECT_CALL(mock_egl, eglCreateContext(_,_,_,_))
159
.WillRepeatedly(DoAll(
160
SaveArg<1>(&chosen_cfg),
161
Return(mock_egl.fake_egl_context)));
163
mga::AndroidDisplay display(native_win, db_factory, stub_display_device, mock_display_report);
165
Mock::VerifyAndClearExpectations(&mock_egl);
166
EXPECT_EQ(cfg, chosen_cfg);
169
TEST_F(AndroidDisplayTest, without_proper_visual_id_throws)
171
using namespace testing;
172
int bad_id = visual_id + 1;
173
EXPECT_CALL(mock_egl, eglGetConfigAttrib(mock_egl.fake_egl_display, _, EGL_NATIVE_VISUAL_ID, _))
174
.WillRepeatedly(DoAll(
175
SetArgPointee<3>(bad_id),
180
mga::AndroidDisplay display(native_win, db_factory, stub_display_device, mock_display_report);
181
}, std::runtime_error );
184
TEST_F(AndroidDisplayTest, eglGetDisplay)
77
186
using namespace testing;
79
188
EXPECT_CALL(mock_egl, eglGetDisplay(EGL_DEFAULT_DISPLAY))
82
mga::AndroidDisplay display(native_win, db_factory, stub_display_support, mock_display_report );
191
mga::AndroidDisplay display(native_win, db_factory, stub_display_device, mock_display_report );
85
TEST_F(AndroidTestFramebufferInit, eglGetDisplay_failure)
194
TEST_F(AndroidDisplayTest, eglGetDisplay_failure)
87
196
using namespace testing;
91
200
.WillOnce(Return((EGLDisplay)EGL_NO_DISPLAY));
94
mga::AndroidDisplay display(native_win, db_factory, stub_display_support, mock_display_report );
203
mga::AndroidDisplay display(native_win, db_factory, stub_display_device, mock_display_report );
95
204
}, std::runtime_error );
98
TEST_F(AndroidTestFramebufferInit, eglInitialize)
207
TEST_F(AndroidDisplayTest, eglInitialize)
100
209
using namespace testing;
102
211
EXPECT_CALL(mock_egl, eglInitialize(mock_egl.fake_egl_display, _, _))
105
mga::AndroidDisplay display(native_win, db_factory, stub_display_support, mock_display_report );
214
mga::AndroidDisplay display(native_win, db_factory, stub_display_device, mock_display_report );
108
TEST_F(AndroidTestFramebufferInit, eglInitialize_failure)
217
TEST_F(AndroidDisplayTest, eglInitialize_failure)
110
219
using namespace testing;
150
mga::AndroidDisplay display(native_win, db_factory, stub_display_support, mock_display_report );
259
mga::AndroidDisplay display(native_win, db_factory, stub_display_device, mock_display_report );
151
260
}, std::runtime_error );
154
TEST_F(AndroidTestFramebufferInit, eglCreateWindowSurface_requests_config)
156
using namespace testing;
157
EGLConfig fake_config = (EGLConfig) 0x3432;
158
EXPECT_CALL(*native_win, android_display_egl_config(_))
160
.WillRepeatedly(Return(fake_config));
161
EXPECT_CALL(mock_egl, eglCreateWindowSurface(mock_egl.fake_egl_display, fake_config, _, _))
164
mga::AndroidDisplay display(native_win, db_factory, stub_display_support, mock_display_report );
167
TEST_F(AndroidTestFramebufferInit, eglCreateWindowSurface_nullarg)
263
TEST_F(AndroidDisplayTest, eglCreateWindowSurface_nullarg)
169
265
using namespace testing;
171
267
EXPECT_CALL(mock_egl, eglCreateWindowSurface(mock_egl.fake_egl_display, _, _, NULL))
174
mga::AndroidDisplay display(native_win, db_factory, stub_display_support, mock_display_report );
270
mga::AndroidDisplay display(native_win, db_factory, stub_display_device, mock_display_report );
177
TEST_F(AndroidTestFramebufferInit, eglCreateWindowSurface_uses_native_window_type)
273
TEST_F(AndroidDisplayTest, eglCreateWindowSurface_uses_native_window_type)
179
275
using namespace testing;
180
EGLNativeWindowType egl_window = (EGLNativeWindowType)0x4443;
182
EXPECT_CALL(*native_win, android_native_window_type())
184
.WillOnce(Return(egl_window));
185
EXPECT_CALL(mock_egl, eglCreateWindowSurface(mock_egl.fake_egl_display, _, egl_window,_))
276
EXPECT_CALL(mock_egl, eglCreateWindowSurface(mock_egl.fake_egl_display, _, native_win.get(),_))
188
mga::AndroidDisplay display(native_win, db_factory, stub_display_support, mock_display_report );
279
mga::AndroidDisplay display(native_win, db_factory, stub_display_device, mock_display_report );
191
TEST_F(AndroidTestFramebufferInit, eglCreateWindowSurface_failure)
282
TEST_F(AndroidDisplayTest, eglCreateWindowSurface_failure)
193
284
using namespace testing;
194
285
EXPECT_CALL(mock_egl, eglCreateWindowSurface(mock_egl.fake_egl_display,_,_,_))