~ubuntu-branches/ubuntu/vivid/mir/vivid

« back to all changes in this revision

Viewing changes to tests/unit-tests/client/android/test_android_native_window.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Cemil Azizoglu, Ubuntu daily release
  • Date: 2014-08-11 19:52:06 UTC
  • mfrom: (1.1.71)
  • Revision ID: package-import@ubuntu.com-20140811195206-zoak8m13t0ii3699
Tags: 0.6.0+14.10.20140811-0ubuntu1
[ Cemil Azizoglu ]
* New upstream release 0.6.0 (https://launchpad.net/mir/+milestone/0.6.0)
  - mirclient ABI unchanged at 8. Clients do not need rebuilding.
  - mirserver ABI bumped to 24. Servers need rebuilding, but probably don't
    need modification:
    . Host lifecycle event listener for nested servers introduced.
    . Add query function to BasicSurface.
    . The (deprecated) function the_ipc_factory() is now removed.
    . Removed legacy support for overriding the focus controller or the
      frontend shell.
    . Added support for a common type for managing fd's.
    . Moved testdraw library to examples directory.
    . Added support for droping stale frames when a surface becomes exposed.
  - Enhancements:
    . Split underlying data transport out of MirSocketRpcChannel.
    . Introduced two new client-side functions : mir_surface_get_focus and
      mir_surface_get_visibility.
    . Added symbolic names for cursors.
    . Made "shared" code a true shared library.
    . Provide linker scripts to control symbols exported by [mesa|android]
      libmirclientplatform.
    . Correct xcursor loader test to fail properly instead of segfaulting.
    . Make mir::Fd type copy constructible.
    . Miscellaneous packaging related enhancements.
    . Miscellaneous build related enhancements.
    . Added automated test cases for detecting ABI breakage.
    . examples/fingerpaint: Enable frame dropping so it's faster and more
      responsive.
    . mirprotobuf folded into new libmircommon.
    . Don't propagate exceptions to graphics driver code.
    . Dropped unused/minimally used dependencies : boost-filesystem,
      boost-thread, boost-chrono, boost-regex.
    . platform: provide support for customizing Mir's behavior when a
      fatal_error occurs.
    . Expose an interface for touch visualization.
  - Bugs fixed:
    . Mir servers crash with SIGABRT - assertion failed at
      buffer_queue.cpp:136 - "!pending_client_notifications.empty()"
      (LP: #1335481)
    . [regression][hammerhead] Mir fails to start on Nexus 5 & 10 as it
      fails to turn vsync signal on (LP: #1345533)
    . [qtcomp] Random crash in Mir input when running AP tests: [terminate
      called after throwing an instance of '...' what(): assign: File exists]
      when constructing a mir::AsioMainLoop::FDHandler (LP: #1346952)
    . CI builds fail when trying to install libmircommon-dev (LP: #1348518)
    . [regression] Mir 0.6 GL clients crash immediately on startup (Mesa is
      trying to use X11 instead of Mir) (LP: #1350163)
    . qmlscene crashed with SIGSEGV in _M_release() on quit (LP: #1342694)
    . Clients cannot create surfaces when the screen is off (LP: #1344024)
    . The packaging of headers and libraries is confused (LP: #1347522)
    . [regression] Intermittent CI failure in
      ClientLibrary.receives_surface_dpi_value (LP: #1348095)
    . Installing mir-demos also unexpectedly installs *-dev packages
      (LP: #1297100)
    . mir_unit_tests: XCursorLoader.loads_cursors_from_testing_theme crashes
      on N4 (LP: #1342029)
    . [performance] Mir is spending at least 8% of its time in
       __android_log_print() (LP: #1343074)
    . [performance] Mir demo shell spends ~12% of its time in vector
      allocation under DemoRenderer::tessellate_*() (LP: #1349698)
    . mir_client_library_debug.h functions do not have C linkage
      (LP: #1349742)
    . mir client API is missing getters for some surface attributes
      (LP: #1336553)
    . Building Mir outputs lots of warnings about Android logging functions
      in 3rd_party/ (LP: #1348467)
    . The "shared" code should be a shared library (LP: #1341502)
    . Finish the removal of mirprotobuf library (LP: #1351133)
    . Release overlay buffers when screen is turned off (LP: #1350961)
    . mir_demo_server_shell --disable-overlays false renders incorrectly
      on android (partial fix for LP: #1348330)
    . Remember to honor MIR_ENABLE_TESTS and not emit tests if it's disabled
      (LP: #1352800)
    . Make it easier to separate command line options used by Mir from those
      used elsewhere (LP: #1351255)
    . Expose create_native_platform in libmirplatformgraphics.so
      (LP: #1353658)
    . Add versioning and pkg config to libmirplatform (LP: #1293944)
    . unity-system-compositor FTBFS against Mir: undefined reference to
      `...@MIR_CLIENT_8' (LP: #1355021)

[ Ubuntu daily release ]
* New rebuild forced

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "mir/graphics/android/android_driver_interpreter.h"
21
21
#include "src/client/mir_client_surface.h"
22
22
#include "mir_test_doubles/mock_android_native_buffer.h"
23
 
#include "mir_test_doubles/mock_fence.h"
24
23
 
25
24
#include <gmock/gmock.h>
26
25
#include <gtest/gtest.h>
50
49
 
51
50
    std::shared_ptr<mir::graphics::NativeBuffer> buffer;
52
51
};
53
 
}
54
52
 
55
53
class AndroidNativeWindowTest : public ::testing::Test
56
54
{
57
55
protected:
58
 
    virtual void SetUp()
59
 
    {
60
 
        using namespace testing;
61
 
 
62
 
        mock_driver_interpreter = std::make_shared<NiceMock<MockAndroidDriverInterpreter>>();
63
 
    }
64
 
 
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};
66
61
};
67
62
 
 
63
}
 
64
 
68
65
TEST_F(AndroidNativeWindowTest, native_window_swapinterval)
69
66
{
70
67
    using namespace testing;
71
68
 
72
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
73
 
 
74
 
    ASSERT_NE(nullptr, window->setSwapInterval);
75
 
    EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
76
 
        .Times(1);
77
 
    window->setSwapInterval(window.get(), 1);
78
 
    Mock::VerifyAndClearExpectations(window.get());
79
 
 
80
 
    EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
81
 
        .Times(1);
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))
 
71
        .Times(1);
 
72
    window.setSwapInterval(&window, 1);
 
73
    Mock::VerifyAndClearExpectations(mock_driver_interpreter.get());
 
74
 
 
75
    EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
 
76
        .Times(1);
 
77
    window.setSwapInterval(&window, 2);
 
78
    Mock::VerifyAndClearExpectations(mock_driver_interpreter.get());
84
79
 
85
80
    EXPECT_CALL(*mock_driver_interpreter, sync_to_display(false))
86
81
        .Times(1);
87
 
    window->setSwapInterval(window.get(), 0);
 
82
    window.setSwapInterval(&window, 0);
88
83
}
89
84
 
90
85
/* Query hook tests */
92
87
{
93
88
    using namespace testing;
94
89
 
95
 
    int returned_width, width = 271828;
96
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
 
90
    int returned_width;
 
91
    int const width = 271828;
97
92
 
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))
100
95
        .Times(1)
101
96
        .WillOnce(Return(width));
102
97
 
103
 
    window->query(window.get(), NATIVE_WINDOW_WIDTH ,&returned_width);
 
98
    window.query(&window, NATIVE_WINDOW_WIDTH ,&returned_width);
104
99
 
105
100
    EXPECT_EQ(width, returned_width);
106
101
}
108
103
/* perform hook tests */
109
104
TEST_F(AndroidNativeWindowTest, native_window_perform_hook_callable)
110
105
{
111
 
    int format = 4;
112
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
 
106
    int const format = 4;
113
107
 
114
108
    EXPECT_CALL(*mock_driver_interpreter, dispatch_driver_request_format(format))
115
109
        .Times(1);
116
110
 
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);
119
113
}
120
114
 
121
115
/* setSwapInterval hook tests */
122
116
TEST_F(AndroidNativeWindowTest, native_window_setswapinterval_hook_callable)
123
117
{
124
 
    int swap = 2;
125
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
 
118
    int const swap = 2;
126
119
 
127
 
    ASSERT_NE(nullptr, window->setSwapInterval);
128
 
    window->setSwapInterval(window.get(), swap);
 
120
    ASSERT_NE(nullptr, window.setSwapInterval);
 
121
    window.setSwapInterval(&window, swap);
129
122
}
130
123
 
131
124
/* dequeue hook tests */
133
126
{
134
127
    ANativeWindowBuffer* returned_buffer;
135
128
    int fence_fd;
136
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
137
129
 
138
 
    ASSERT_NE(nullptr, window->dequeueBuffer);
139
 
    window->dequeueBuffer(window.get(), &returned_buffer, &fence_fd);
 
130
    ASSERT_NE(nullptr, window.dequeueBuffer);
 
131
    window.dequeueBuffer(&window, &returned_buffer, &fence_fd);
140
132
}
141
133
 
142
134
TEST_F(AndroidNativeWindowTest, native_window_dequeue_returns_right_buffer)
152
144
        .Times(1)
153
145
        .WillOnce(Return(mock_buffer.get()));
154
146
 
155
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
156
 
 
157
147
    int fence_fd;
158
148
    ANativeWindowBuffer* returned_buffer;
159
 
    window->dequeueBuffer(window.get(), &returned_buffer, &fence_fd);
 
149
    window.dequeueBuffer(&window, &returned_buffer, &fence_fd);
160
150
 
161
151
    EXPECT_EQ(mock_buffer->anwb(), returned_buffer);
162
152
    EXPECT_EQ(fake_fd, fence_fd);
165
155
TEST_F(AndroidNativeWindowTest, native_window_dequeue_deprecated_hook_callable)
166
156
{
167
157
    ANativeWindowBuffer* tmp;
168
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
169
158
 
170
 
    ASSERT_NE(nullptr, window->dequeueBuffer_DEPRECATED);
171
 
    window->dequeueBuffer_DEPRECATED(window.get(), &tmp);
 
159
    ASSERT_NE(nullptr, window.dequeueBuffer_DEPRECATED);
 
160
    window.dequeueBuffer_DEPRECATED(&window, &tmp);
172
161
}
173
162
 
174
163
TEST_F(AndroidNativeWindowTest, native_window_dequeue_deprecated_returns_right_buffer)
177
166
 
178
167
    ANativeWindowBuffer* returned_buffer;
179
168
    auto mock_buffer = std::make_shared<NiceMock<mtd::MockAndroidNativeBuffer>>();
180
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
181
169
 
182
170
    EXPECT_CALL(*mock_driver_interpreter, driver_requests_buffer())
183
171
        .Times(1)
187
175
    EXPECT_CALL(*mock_buffer, copy_fence())
188
176
        .Times(0);
189
177
 
190
 
    window->dequeueBuffer_DEPRECATED(window.get(), &returned_buffer);
 
178
    window.dequeueBuffer_DEPRECATED(&window, &returned_buffer);
191
179
    EXPECT_EQ(mock_buffer->anwb(), returned_buffer);
192
180
}
193
181
 
195
183
TEST_F(AndroidNativeWindowTest, native_window_queue_hook_callable)
196
184
{
197
185
    ANativeWindowBuffer* tmp = nullptr;
198
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
199
186
 
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);
202
189
}
203
190
 
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);
210
196
 
211
197
    EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer, fence_fd))
212
198
        .Times(1);
213
199
 
214
 
    window->queueBuffer(window.get(), &buffer, fence_fd);
 
200
    window.queueBuffer(&window, &buffer, fence_fd);
215
201
}
216
202
 
217
203
TEST_F(AndroidNativeWindowTest, native_window_queue_deprecated_hook_callable)
218
204
{
219
205
    ANativeWindowBuffer* tmp = nullptr;
220
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
221
206
 
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);
224
209
}
225
210
 
226
211
TEST_F(AndroidNativeWindowTest, native_window_queue_deprecated_passes_buffer_back)
227
212
{
228
213
    using namespace testing;
229
214
    ANativeWindowBuffer buffer;
230
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
231
215
 
232
216
    EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer,_))
233
217
        .Times(1);
234
218
 
235
 
    window->queueBuffer_DEPRECATED(window.get(), &buffer);
 
219
    window.queueBuffer_DEPRECATED(&window, &buffer);
236
220
}
237
221
 
238
222
/* cancel hook tests */
239
223
TEST_F(AndroidNativeWindowTest, native_window_cancel_hooks_callable)
240
224
{
241
225
    ANativeWindowBuffer* tmp = nullptr;
242
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
243
226
 
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);
248
231
}
249
232
 
250
233
/* lock hook tests */
251
234
TEST_F(AndroidNativeWindowTest, native_window_lock_hook_callable)
252
235
{
253
236
    ANativeWindowBuffer* tmp = 0x0;
254
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
255
237
 
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);
258
240
}
259
241
 
260
242
TEST_F(AndroidNativeWindowTest, native_window_incref_hook_callable)
261
243
{
262
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
263
 
 
264
 
    ASSERT_NE(nullptr, window->common.incRef);
265
 
    window->common.incRef(NULL);
 
244
    ASSERT_NE(nullptr, window.common.incRef);
 
245
    window.common.incRef(NULL);
266
246
}
267
247
 
268
248
TEST_F(AndroidNativeWindowTest, native_window_decref_hook_callable)
269
249
{
270
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
271
 
 
272
 
    ASSERT_NE(nullptr, window->common.decRef);
273
 
    window->common.decRef(NULL);
 
250
    ASSERT_NE(nullptr, window.common.decRef);
 
251
    window.common.decRef(NULL);
274
252
}
275
253
 
276
254
TEST_F(AndroidNativeWindowTest, native_window_dequeue_deprecated_has_proper_rc)
277
255
{
278
256
    ANativeWindowBuffer* tmp;
279
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
280
257
 
281
 
    auto ret = window->dequeueBuffer_DEPRECATED(window.get(), &tmp);
 
258
    auto ret = window.dequeueBuffer_DEPRECATED(&window, &tmp);
282
259
    EXPECT_EQ(0, ret);
283
260
}
284
261
 
287
264
    ANativeWindowBuffer* tmp;
288
265
    int fencefd;
289
266
 
290
 
    std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
291
 
 
292
 
    auto ret = window->dequeueBuffer(window.get(), &tmp, &fencefd);
 
267
    auto ret = window.dequeueBuffer(&window, &tmp, &fencefd);
293
268
    EXPECT_EQ(0, ret);
294
269
}
295
270
 
302
277
    EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer, _))
303
278
        .Times(1);
304
279
 
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);
308
282
}
 
283
 
 
284
TEST_F(AndroidNativeWindowTest, returns_error_on_dequeue_buffer_failure)
 
285
{
 
286
    using namespace testing;
 
287
 
 
288
    EXPECT_CALL(*mock_driver_interpreter, driver_requests_buffer())
 
289
        .WillOnce(Throw(std::runtime_error("")))
 
290
        .WillOnce(Throw(std::runtime_error("")));
 
291
 
 
292
    EXPECT_THAT(window.dequeueBuffer(&window, nullptr, nullptr), Eq(failure_code));
 
293
    EXPECT_THAT(window.dequeueBuffer_DEPRECATED(&window, nullptr), Eq(failure_code));
 
294
}
 
295
 
 
296
TEST_F(AndroidNativeWindowTest, returns_error_on_queue_buffer_failure)
 
297
{
 
298
    using namespace testing;
 
299
 
 
300
    EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(_, _))
 
301
        .WillOnce(Throw(std::runtime_error("")))
 
302
        .WillOnce(Throw(std::runtime_error("")));
 
303
 
 
304
    EXPECT_THAT(window.queueBuffer(&window, nullptr, 0), Eq(failure_code));
 
305
    EXPECT_THAT(window.queueBuffer_DEPRECATED(&window, nullptr), Eq(failure_code));
 
306
}
 
307
 
 
308
TEST_F(AndroidNativeWindowTest, returns_error_on_cancel_buffer_failure)
 
309
{
 
310
    using namespace testing;
 
311
 
 
312
    EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(_, _))
 
313
        .WillOnce(Throw(std::runtime_error("")))
 
314
        .WillOnce(Throw(std::runtime_error("")));
 
315
 
 
316
    EXPECT_THAT(window.cancelBuffer(&window, nullptr, 0), Eq(failure_code));
 
317
    EXPECT_THAT(window.cancelBuffer_DEPRECATED(&window, nullptr), Eq(failure_code));
 
318
}
 
319
 
 
320
TEST_F(AndroidNativeWindowTest, returns_error_on_query_failure)
 
321
{
 
322
    using namespace testing;
 
323
 
 
324
    EXPECT_CALL(*mock_driver_interpreter, driver_requests_info(_))
 
325
        .WillOnce(Throw(std::runtime_error("")));
 
326
 
 
327
    EXPECT_THAT(window.query(&window, 0, nullptr), Eq(failure_code));
 
328
}
 
329
 
 
330
TEST_F(AndroidNativeWindowTest, returns_error_on_perform_failure)
 
331
{
 
332
    using namespace testing;
 
333
 
 
334
    EXPECT_CALL(*mock_driver_interpreter, dispatch_driver_request_format(_))
 
335
        .WillOnce(Throw(std::runtime_error("")));
 
336
 
 
337
    auto perform = [this] (int key, ...)
 
338
    {
 
339
        va_list args;
 
340
        va_start(args, key);
 
341
        EXPECT_THAT(window.perform(&window, key, args), Eq(failure_code));
 
342
        va_end(args);
 
343
    };
 
344
    perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT, 0);
 
345
}