~ubuntu-branches/ubuntu/utopic/mir/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/unit-tests/graphics/android/test_hwc_display.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-03-10 19:28:46 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: package-import@ubuntu.com-20140310192846-rq9qm3ec26yrelo2
Tags: upstream-0.1.6+14.04.20140310
ImportĀ upstreamĀ versionĀ 0.1.6+14.04.20140310

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "mir/graphics/android/mir_native_window.h"
28
28
#include "mir_test_doubles/stub_driver_interpreter.h"
29
29
#include "mir_test_doubles/stub_display_buffer.h"
30
 
#include "mir_test_doubles/stub_display_device.h"
31
30
#include "mir_test_doubles/stub_buffer.h"
32
31
#include "mir_test_doubles/mock_framebuffer_bundle.h"
33
32
#include <memory>
37
36
namespace mga=mir::graphics::android;
38
37
namespace mtd=mir::test::doubles;
39
38
 
40
 
class AndroidDisplayBufferTest : public ::testing::Test
 
39
class AndroidDisplayBuffer : public ::testing::Test
41
40
{
42
41
protected:
43
42
    virtual void SetUp()
44
43
    {
45
44
        stub_buffer = std::make_shared<testing::NiceMock<mtd::StubBuffer>>();
46
 
        mock_display_device = std::make_shared<mtd::MockDisplayDevice>();
 
45
        mock_display_device = std::make_shared<testing::NiceMock<mtd::MockDisplayDevice>>();
47
46
        native_window = std::make_shared<mg::android::MirNativeWindow>(std::make_shared<mtd::StubDriverInterpreter>());
48
47
 
49
48
        visual_id = 5;
52
51
        dummy_context = mock_egl.fake_egl_context;
53
52
        testing::NiceMock<mtd::MockDisplayReport> report;
54
53
        gl_context = std::make_shared<mga::GLContext>(mga::to_mir_format(mock_egl.fake_visual_id),report);
55
 
        mock_fb_bundle = std::make_shared<mtd::MockFBBundle>();
 
54
        mock_fb_bundle = std::make_shared<testing::NiceMock<mtd::MockFBBundle>>();
 
55
 
 
56
        ON_CALL(*mock_fb_bundle, fb_format())
 
57
            .WillByDefault(testing::Return(mir_pixel_format_abgr_8888));
 
58
        ON_CALL(*mock_fb_bundle, fb_size())
 
59
            .WillByDefault(testing::Return(display_size));
56
60
    }
57
61
 
58
62
    testing::NiceMock<mtd::MockEGL> mock_egl;
67
71
    std::shared_ptr<ANativeWindow> native_window;
68
72
    std::shared_ptr<mtd::MockDisplayDevice> mock_display_device;
69
73
    std::shared_ptr<mtd::MockFBBundle> mock_fb_bundle;
 
74
    geom::Size const display_size{433,232};
70
75
};
71
76
 
72
 
TEST_F(AndroidDisplayBufferTest, test_post_update)
 
77
TEST_F(AndroidDisplayBuffer, can_post_update_with_gl_only)
73
78
{
74
79
    using namespace testing;
75
80
 
89
94
    db.post_update();
90
95
}
91
96
 
92
 
TEST_F(AndroidDisplayBufferTest, test_post_update_empty_list)
 
97
TEST_F(AndroidDisplayBuffer, performs_default_post_if_empty_list)
93
98
{
94
99
    using namespace testing;
95
100
 
111
116
    db.render_and_post_update(renderlist, render_fn);
112
117
}
113
118
 
114
 
TEST_F(AndroidDisplayBufferTest, test_post_update_list)
 
119
TEST_F(AndroidDisplayBuffer, posts_overlay_list)
115
120
{
116
121
    using namespace testing;
117
122
 
146
151
    });
147
152
}
148
153
 
149
 
TEST_F(AndroidDisplayBufferTest, defaults_to_normal_orientation)
 
154
TEST_F(AndroidDisplayBuffer, defaults_to_normal_orientation)
150
155
{
151
156
    mga::DisplayBuffer db(mock_fb_bundle, mock_display_device, native_window,
152
157
                          *gl_context);
154
159
    EXPECT_EQ(mir_orientation_normal, db.orientation());
155
160
}
156
161
 
157
 
TEST_F(AndroidDisplayBufferTest, orientation_is_passed_through)
 
162
TEST_F(AndroidDisplayBuffer, orientation_is_passed_through)
158
163
{
159
164
    mga::DisplayBuffer db(mock_fb_bundle, mock_display_device, native_window,
160
165
                          *gl_context);
164
169
                            mir_orientation_right,
165
170
                            mir_orientation_inverted})
166
171
    {
167
 
        db.orient(ori);
 
172
        auto config = db.configuration();
 
173
        config.orientation = ori;
 
174
        db.configure(config);
168
175
        EXPECT_EQ(ori, db.orientation());
169
176
    }
170
177
}
171
178
 
172
 
TEST_F(AndroidDisplayBufferTest, rotation_transposes_dimensions)
 
179
TEST_F(AndroidDisplayBuffer, rotation_transposes_dimensions)
173
180
{
174
181
    using namespace testing;
175
182
 
186
193
 
187
194
    EXPECT_EQ(normal, db.view_area().size);
188
195
 
189
 
    db.orient(mir_orientation_right);
 
196
    auto config = db.configuration();
 
197
 
 
198
    config.orientation = mir_orientation_right;
 
199
    db.configure(config);
190
200
    EXPECT_EQ(transposed, db.view_area().size);
191
201
 
192
 
    db.orient(mir_orientation_inverted);
 
202
    config.orientation = mir_orientation_inverted;
 
203
    db.configure(config);
193
204
    EXPECT_EQ(normal, db.view_area().size);
194
205
 
195
 
    db.orient(mir_orientation_left);
 
206
    config.orientation = mir_orientation_left;
 
207
    db.configure(config);
196
208
    EXPECT_EQ(transposed, db.view_area().size);
197
209
}
198
210
 
199
 
TEST_F(AndroidDisplayBufferTest, test_db_forwards_size_along)
 
211
TEST_F(AndroidDisplayBuffer, reports_correct_size)
200
212
{
201
213
    using namespace testing;
202
214
 
203
 
    geom::Size fake_display_size{223, 332};
204
 
    EXPECT_CALL(*mock_fb_bundle, fb_size())
205
 
        .Times(AnyNumber())
206
 
        .WillRepeatedly(Return(fake_display_size));
207
 
 
208
215
    mga::DisplayBuffer db(mock_fb_bundle, mock_display_device, native_window, *gl_context);
209
216
 
210
217
    auto view_area = db.view_area();
211
218
 
212
219
    geom::Point origin_pt{geom::X{0}, geom::Y{0}};
213
 
    EXPECT_EQ(view_area.size, fake_display_size);
214
 
    EXPECT_EQ(view_area.top_left, origin_pt);
 
220
    EXPECT_EQ(display_size, view_area.size);
 
221
    EXPECT_EQ(origin_pt, view_area.top_left);
215
222
}
216
223
 
217
 
TEST_F(AndroidDisplayBufferTest, db_egl_context_from_shared)
 
224
TEST_F(AndroidDisplayBuffer, creates_egl_context_from_shared_context)
218
225
{
219
226
    using namespace testing;
220
227
 
237
244
    testing::Mock::VerifyAndClearExpectations(&mock_egl);
238
245
}
239
246
 
240
 
TEST_F(AndroidDisplayBufferTest, egl_resource_creation_failure)
 
247
TEST_F(AndroidDisplayBuffer, fails_on_egl_resource_creation)
241
248
{
242
249
    using namespace testing;
243
250
    EXPECT_CALL(mock_egl, eglCreateContext(_,_,_,_))
259
266
    }, std::runtime_error);
260
267
}
261
268
 
262
 
TEST_F(AndroidDisplayBufferTest, make_current)
 
269
TEST_F(AndroidDisplayBuffer, can_make_current)
263
270
{
264
271
    using namespace testing;
265
272
    EGLContext fake_ctxt = reinterpret_cast<EGLContext>(0x4422);
285
292
    }, std::runtime_error);
286
293
}
287
294
 
288
 
TEST_F(AndroidDisplayBufferTest, release_current)
 
295
TEST_F(AndroidDisplayBuffer, release_current)
289
296
{
290
297
    using namespace testing;
291
298
 
295
302
    mga::DisplayBuffer db(mock_fb_bundle, mock_display_device, native_window, *gl_context);
296
303
    db.release_current();
297
304
}
 
305
 
 
306
TEST_F(AndroidDisplayBuffer, sets_display_power_mode_to_on_at_start)
 
307
{
 
308
    using namespace testing;
 
309
    mga::DisplayBuffer db(mock_fb_bundle, mock_display_device, native_window, *gl_context);
 
310
    auto config = db.configuration();
 
311
    EXPECT_EQ(mir_power_mode_on, config.power_mode);
 
312
}
 
313
 
 
314
TEST_F(AndroidDisplayBuffer, changes_display_power_mode)
 
315
{
 
316
    using namespace testing;
 
317
    mga::DisplayBuffer db(mock_fb_bundle, mock_display_device, native_window, *gl_context);
 
318
 
 
319
    Sequence seq;
 
320
    EXPECT_CALL(*mock_display_device, mode(mir_power_mode_off))
 
321
        .InSequence(seq);
 
322
    EXPECT_CALL(*mock_display_device, mode(mir_power_mode_on))
 
323
        .InSequence(seq);
 
324
 
 
325
    auto config = db.configuration();
 
326
    config.power_mode = mir_power_mode_off;
 
327
    db.configure(config);
 
328
 
 
329
    config = db.configuration();
 
330
    config.power_mode = mir_power_mode_on;
 
331
    db.configure(config); 
 
332
}
 
333
 
 
334
TEST_F(AndroidDisplayBuffer, disregards_double_display_power_mode_request)
 
335
{
 
336
    using namespace testing;
 
337
    mga::DisplayBuffer db(mock_fb_bundle, mock_display_device, native_window, *gl_context);
 
338
 
 
339
    EXPECT_CALL(*mock_display_device, mode(mir_power_mode_off))
 
340
        .Times(1);
 
341
 
 
342
    auto config = db.configuration();
 
343
    config.power_mode = mir_power_mode_off;
 
344
    db.configure(config);
 
345
    config.power_mode = mir_power_mode_suspend;
 
346
    db.configure(config);
 
347
    config.power_mode = mir_power_mode_standby;
 
348
    db.configure(config);
 
349
}
 
350
 
 
351
//configuration tests
 
352
TEST_F(AndroidDisplayBuffer, display_orientation_supported)
 
353
{
 
354
    using namespace testing;
 
355
 
 
356
    EXPECT_CALL(*mock_display_device, apply_orientation(mir_orientation_left))
 
357
        .Times(1)
 
358
        .WillOnce(Return(true));
 
359
 
 
360
    mga::DisplayBuffer db(mock_fb_bundle, mock_display_device, native_window, *gl_context);
 
361
 
 
362
    auto config = db.configuration();
 
363
    config.orientation = mir_orientation_left;
 
364
    db.configure(config); 
 
365
 
 
366
    config = db.configuration();
 
367
    EXPECT_EQ(mir_orientation_normal, config.orientation);
 
368
}
 
369
 
 
370
TEST_F(AndroidDisplayBuffer, display_orientation_not_supported)
 
371
{
 
372
    using namespace testing;
 
373
    EXPECT_CALL(*mock_display_device, apply_orientation(mir_orientation_left))
 
374
        .Times(1)
 
375
        .WillOnce(Return(false));
 
376
 
 
377
    mga::DisplayBuffer db(mock_fb_bundle, mock_display_device, native_window, *gl_context);
 
378
 
 
379
    auto config = db.configuration();
 
380
    config.orientation = mir_orientation_left;
 
381
    db.configure(config); 
 
382
 
 
383
    config = db.configuration();
 
384
    EXPECT_EQ(mir_orientation_left, config.orientation);
 
385
}
 
386
 
 
387
TEST_F(AndroidDisplayBuffer, incorrect_display_configure_throws)
 
388
{
 
389
    mga::DisplayBuffer db(mock_fb_bundle, mock_display_device, native_window, *gl_context);
 
390
    auto config = db.configuration();
 
391
    //error
 
392
    config.current_format = mir_pixel_format_invalid;
 
393
    EXPECT_THROW({
 
394
        db.configure(config);
 
395
    }, std::runtime_error); 
 
396
}
 
397
 
 
398
TEST_F(AndroidDisplayBuffer, android_display_configuration_info)
 
399
{
 
400
    mga::DisplayBuffer db(mock_fb_bundle, mock_display_device, native_window, *gl_context);
 
401
    auto disp_conf = db.configuration();
 
402
 
 
403
    ASSERT_EQ(1u, disp_conf.modes.size());
 
404
    auto& disp_mode = disp_conf.modes[0];
 
405
    EXPECT_EQ(display_size, disp_mode.size);
 
406
 
 
407
    EXPECT_EQ(mg::DisplayConfigurationOutputId{1}, disp_conf.id);
 
408
    EXPECT_EQ(mg::DisplayConfigurationCardId{0}, disp_conf.card_id);
 
409
    EXPECT_TRUE(disp_conf.connected);
 
410
    EXPECT_TRUE(disp_conf.used);
 
411
    auto origin = geom::Point{0,0};
 
412
    EXPECT_EQ(origin, disp_conf.top_left);
 
413
    EXPECT_EQ(0, disp_conf.current_mode_index);
 
414
 
 
415
    //TODO fill refresh rate accordingly
 
416
    //TODO fill physical_size_mm fields accordingly;
 
417
}