51
50
std::shared_ptr<mir::graphics::NativeBuffer> buffer;
55
53
class AndroidNativeWindowTest : public ::testing::Test
60
using namespace testing;
62
mock_driver_interpreter = std::make_shared<NiceMock<MockAndroidDriverInterpreter>>();
65
std::shared_ptr<MockAndroidDriverInterpreter> mock_driver_interpreter;
56
std::shared_ptr<MockAndroidDriverInterpreter> const mock_driver_interpreter =
57
std::make_shared<testing::NiceMock<MockAndroidDriverInterpreter>>();
58
mga::MirNativeWindow mir_native_window{mock_driver_interpreter};
59
ANativeWindow& window = mir_native_window;
60
int const failure_code{-1};
68
65
TEST_F(AndroidNativeWindowTest, native_window_swapinterval)
70
67
using namespace testing;
72
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
74
ASSERT_NE(nullptr, window->setSwapInterval);
75
EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
77
window->setSwapInterval(window.get(), 1);
78
Mock::VerifyAndClearExpectations(window.get());
80
EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
82
window->setSwapInterval(window.get(), 2);
83
Mock::VerifyAndClearExpectations(window.get());
69
ASSERT_NE(nullptr, window.setSwapInterval);
70
EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
72
window.setSwapInterval(&window, 1);
73
Mock::VerifyAndClearExpectations(mock_driver_interpreter.get());
75
EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
77
window.setSwapInterval(&window, 2);
78
Mock::VerifyAndClearExpectations(mock_driver_interpreter.get());
85
80
EXPECT_CALL(*mock_driver_interpreter, sync_to_display(false))
87
window->setSwapInterval(window.get(), 0);
82
window.setSwapInterval(&window, 0);
90
85
/* Query hook tests */
93
88
using namespace testing;
95
int returned_width, width = 271828;
96
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
91
int const width = 271828;
98
ASSERT_NE(nullptr, window->query);
93
ASSERT_NE(nullptr, window.query);
99
94
EXPECT_CALL(*mock_driver_interpreter, driver_requests_info(NATIVE_WINDOW_WIDTH))
101
96
.WillOnce(Return(width));
103
window->query(window.get(), NATIVE_WINDOW_WIDTH ,&returned_width);
98
window.query(&window, NATIVE_WINDOW_WIDTH ,&returned_width);
105
100
EXPECT_EQ(width, returned_width);
108
103
/* perform hook tests */
109
104
TEST_F(AndroidNativeWindowTest, native_window_perform_hook_callable)
112
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
106
int const format = 4;
114
108
EXPECT_CALL(*mock_driver_interpreter, dispatch_driver_request_format(format))
117
ASSERT_NE(nullptr, window->perform);
118
window->perform(window.get(), NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
111
ASSERT_NE(nullptr, window.perform);
112
window.perform(&window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
121
115
/* setSwapInterval hook tests */
122
116
TEST_F(AndroidNativeWindowTest, native_window_setswapinterval_hook_callable)
125
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
127
ASSERT_NE(nullptr, window->setSwapInterval);
128
window->setSwapInterval(window.get(), swap);
120
ASSERT_NE(nullptr, window.setSwapInterval);
121
window.setSwapInterval(&window, swap);
131
124
/* dequeue hook tests */
195
183
TEST_F(AndroidNativeWindowTest, native_window_queue_hook_callable)
197
185
ANativeWindowBuffer* tmp = nullptr;
198
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
200
ASSERT_NE(nullptr, window->queueBuffer);
201
window->queueBuffer(window.get(), tmp, -1);
187
ASSERT_NE(nullptr, window.queueBuffer);
188
window.queueBuffer(&window, tmp, -1);
204
191
TEST_F(AndroidNativeWindowTest, native_window_queue_passes_buffer_back)
206
193
using namespace testing;
207
194
ANativeWindowBuffer buffer;
208
195
int fence_fd = 33;
209
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
211
197
EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer, fence_fd))
214
window->queueBuffer(window.get(), &buffer, fence_fd);
200
window.queueBuffer(&window, &buffer, fence_fd);
217
203
TEST_F(AndroidNativeWindowTest, native_window_queue_deprecated_hook_callable)
219
205
ANativeWindowBuffer* tmp = nullptr;
220
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
222
ASSERT_NE(nullptr, window->queueBuffer_DEPRECATED);
223
window->queueBuffer_DEPRECATED(window.get(), tmp);
207
ASSERT_NE(nullptr, window.queueBuffer_DEPRECATED);
208
window.queueBuffer_DEPRECATED(&window, tmp);
226
211
TEST_F(AndroidNativeWindowTest, native_window_queue_deprecated_passes_buffer_back)
228
213
using namespace testing;
229
214
ANativeWindowBuffer buffer;
230
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
232
216
EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer,_))
235
window->queueBuffer_DEPRECATED(window.get(), &buffer);
219
window.queueBuffer_DEPRECATED(&window, &buffer);
238
222
/* cancel hook tests */
239
223
TEST_F(AndroidNativeWindowTest, native_window_cancel_hooks_callable)
241
225
ANativeWindowBuffer* tmp = nullptr;
242
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
244
ASSERT_NE(nullptr, window->cancelBuffer_DEPRECATED);
245
ASSERT_NE(nullptr, window->cancelBuffer);
246
window->cancelBuffer_DEPRECATED(window.get(), tmp);
247
window->cancelBuffer(window.get(), tmp, -1);
227
ASSERT_NE(nullptr, window.cancelBuffer_DEPRECATED);
228
ASSERT_NE(nullptr, window.cancelBuffer);
229
window.cancelBuffer_DEPRECATED(&window, tmp);
230
window.cancelBuffer(&window, tmp, -1);
250
233
/* lock hook tests */
251
234
TEST_F(AndroidNativeWindowTest, native_window_lock_hook_callable)
253
236
ANativeWindowBuffer* tmp = 0x0;
254
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
256
ASSERT_NE(nullptr, window->lockBuffer_DEPRECATED);
257
window->lockBuffer_DEPRECATED(window.get(), tmp);
238
ASSERT_NE(nullptr, window.lockBuffer_DEPRECATED);
239
window.lockBuffer_DEPRECATED(&window, tmp);
260
242
TEST_F(AndroidNativeWindowTest, native_window_incref_hook_callable)
262
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
264
ASSERT_NE(nullptr, window->common.incRef);
265
window->common.incRef(NULL);
244
ASSERT_NE(nullptr, window.common.incRef);
245
window.common.incRef(NULL);
268
248
TEST_F(AndroidNativeWindowTest, native_window_decref_hook_callable)
270
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
272
ASSERT_NE(nullptr, window->common.decRef);
273
window->common.decRef(NULL);
250
ASSERT_NE(nullptr, window.common.decRef);
251
window.common.decRef(NULL);
276
254
TEST_F(AndroidNativeWindowTest, native_window_dequeue_deprecated_has_proper_rc)
278
256
ANativeWindowBuffer* tmp;
279
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
281
auto ret = window->dequeueBuffer_DEPRECATED(window.get(), &tmp);
258
auto ret = window.dequeueBuffer_DEPRECATED(&window, &tmp);
282
259
EXPECT_EQ(0, ret);
302
277
EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer, _))
305
std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
306
auto rc = window->cancelBuffer(window.get(), &buffer, fence_fd);
280
auto rc = window.cancelBuffer(&window, &buffer, fence_fd);
307
281
EXPECT_EQ(0, rc);
284
TEST_F(AndroidNativeWindowTest, returns_error_on_dequeue_buffer_failure)
286
using namespace testing;
288
EXPECT_CALL(*mock_driver_interpreter, driver_requests_buffer())
289
.WillOnce(Throw(std::runtime_error("")))
290
.WillOnce(Throw(std::runtime_error("")));
292
EXPECT_THAT(window.dequeueBuffer(&window, nullptr, nullptr), Eq(failure_code));
293
EXPECT_THAT(window.dequeueBuffer_DEPRECATED(&window, nullptr), Eq(failure_code));
296
TEST_F(AndroidNativeWindowTest, returns_error_on_queue_buffer_failure)
298
using namespace testing;
300
EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(_, _))
301
.WillOnce(Throw(std::runtime_error("")))
302
.WillOnce(Throw(std::runtime_error("")));
304
EXPECT_THAT(window.queueBuffer(&window, nullptr, 0), Eq(failure_code));
305
EXPECT_THAT(window.queueBuffer_DEPRECATED(&window, nullptr), Eq(failure_code));
308
TEST_F(AndroidNativeWindowTest, returns_error_on_cancel_buffer_failure)
310
using namespace testing;
312
EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(_, _))
313
.WillOnce(Throw(std::runtime_error("")))
314
.WillOnce(Throw(std::runtime_error("")));
316
EXPECT_THAT(window.cancelBuffer(&window, nullptr, 0), Eq(failure_code));
317
EXPECT_THAT(window.cancelBuffer_DEPRECATED(&window, nullptr), Eq(failure_code));
320
TEST_F(AndroidNativeWindowTest, returns_error_on_query_failure)
322
using namespace testing;
324
EXPECT_CALL(*mock_driver_interpreter, driver_requests_info(_))
325
.WillOnce(Throw(std::runtime_error("")));
327
EXPECT_THAT(window.query(&window, 0, nullptr), Eq(failure_code));
330
TEST_F(AndroidNativeWindowTest, returns_error_on_perform_failure)
332
using namespace testing;
334
EXPECT_CALL(*mock_driver_interpreter, dispatch_driver_request_format(_))
335
.WillOnce(Throw(std::runtime_error("")));
337
auto perform = [this] (int key, ...)
341
EXPECT_THAT(window.perform(&window, key, args), Eq(failure_code));
344
perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT, 0);