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

« back to all changes in this revision

Viewing changes to tests/unit-tests/scene/test_surface.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:
1
1
/*
2
 
 * Copyright Ā© 2012 Canonical Ltd.
 
2
 * Copyright Ā© 2012-2014 Canonical Ltd.
3
3
 *
4
4
 * This program is free software: you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License version 3 as
17
17
 */
18
18
 
19
19
#include "src/server/scene/basic_surface.h"
20
 
#include "src/server/scene/surface_data.h"
21
 
#include "mir/scene/scene_report.h"
 
20
#include "src/server/report/null_report_factory.h"
22
21
#include "mir/shell/surface_creation_parameters.h"
23
22
#include "mir/input/input_channel.h"
24
23
 
41
40
namespace geom = mir::geometry;
42
41
namespace mt = mir::test;
43
42
namespace mtd = mt::doubles;
 
43
namespace mr = mir::report;
44
44
 
45
45
namespace
46
46
{
172
172
        rect = geom::Rectangle{geom::Point{geom::X{0}, geom::Y{0}}, size};
173
173
        stride = geom::Stride{4 * size.width.as_uint32_t()};
174
174
        mock_buffer_stream = std::make_shared<testing::NiceMock<mtd::MockBufferStream>>();
175
 
        stub_data = std::make_shared<ms::SurfaceData>( 
176
 
            surface_name, rect, change_notification, false);
177
175
 
178
176
        ON_CALL(*mock_buffer_stream, swap_client_buffers(_, _))
179
177
            .WillByDefault(InvokeArgument<1>(&stub_buffer));
180
178
    }
181
179
 
182
 
    std::shared_ptr<ms::SurfaceData> stub_data;
183
180
    std::string surface_name;
184
181
    std::shared_ptr<testing::NiceMock<mtd::MockBufferStream>> mock_buffer_stream;
185
182
    MirPixelFormat pf;
186
183
    geom::Stride stride;
187
184
    geom::Size size;
188
185
    geom::Rectangle rect;
189
 
    std::shared_ptr<ms::SceneReport> const report = std::make_shared<ms::NullSceneReport>();
 
186
    std::shared_ptr<ms::SceneReport> const report = mr::null_scene_report();
190
187
    std::function<void()> change_notification;
191
188
    int notification_count;
192
189
    mtd::StubBuffer stub_buffer;
194
191
 
195
192
}
196
193
 
197
 
TEST_F(SurfaceCreation, test_surface_returns_same_state)
198
 
{
199
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
200
 
 
201
 
    EXPECT_EQ(stub_data, surf.compositing_criteria());
202
 
}
203
 
 
204
194
TEST_F(SurfaceCreation, test_surface_queries_stream_for_pf)
205
195
{
206
196
    using namespace testing;
207
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
197
    ms::BasicSurface surf(
 
198
        surface_name,
 
199
        rect,
 
200
        change_notification,
 
201
        false,
 
202
        mock_buffer_stream,
 
203
        std::shared_ptr<mi::InputChannel>(),
 
204
        report);
208
205
 
209
206
    EXPECT_CALL(*mock_buffer_stream, get_stream_pixel_format())
210
207
        .Times(1)
217
214
 
218
215
TEST_F(SurfaceCreation, test_surface_gets_right_name)
219
216
{
220
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
217
    ms::BasicSurface surf(
 
218
        surface_name,
 
219
        rect,
 
220
        change_notification,
 
221
        false,
 
222
        mock_buffer_stream,
 
223
        std::shared_ptr<mi::InputChannel>(),
 
224
        report);
 
225
 
221
226
    EXPECT_EQ(surface_name, surf.name());
222
227
}
223
228
 
224
229
TEST_F(SurfaceCreation, test_surface_queries_state_for_size)
225
230
{
226
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
231
    ms::BasicSurface surf(
 
232
        surface_name,
 
233
        rect,
 
234
        change_notification,
 
235
        false,
 
236
        mock_buffer_stream,
 
237
        std::shared_ptr<mi::InputChannel>(),
 
238
        report);
 
239
 
227
240
    EXPECT_EQ(size, surf.size());
228
241
}
229
242
 
230
243
TEST_F(SurfaceCreation, test_surface_next_buffer)
231
244
{
232
245
    using namespace testing;
233
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
246
    ms::BasicSurface surf(
 
247
        surface_name,
 
248
        rect,
 
249
        change_notification,
 
250
        false,
 
251
        mock_buffer_stream,
 
252
        std::shared_ptr<mi::InputChannel>(),
 
253
        report);
 
254
 
234
255
    mtd::StubBuffer graphics_resource;
235
256
 
236
257
    EXPECT_CALL(*mock_buffer_stream, swap_client_buffers(_, _))
248
269
 
249
270
    mtd::StubBuffer stub_buffer;
250
271
 
251
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
272
    ms::BasicSurface surf(
 
273
        surface_name,
 
274
        rect,
 
275
        change_notification,
 
276
        false,
 
277
        mock_buffer_stream,
 
278
        std::shared_ptr<mi::InputChannel>(),
 
279
        report);
 
280
 
252
281
    EXPECT_CALL(*mock_buffer_stream, swap_client_buffers(_, _))
253
282
        .Times(1)
254
283
        .WillOnce(InvokeArgument<1>(&stub_buffer));
260
289
 
261
290
TEST_F(SurfaceCreation, test_surface_gets_top_left)
262
291
{
263
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
292
    ms::BasicSurface surf(
 
293
        surface_name,
 
294
        rect,
 
295
        change_notification,
 
296
        false,
 
297
        mock_buffer_stream,
 
298
        std::shared_ptr<mi::InputChannel>(),
 
299
        report);
264
300
 
265
301
    auto ret_top_left = surf.top_left();
266
302
    EXPECT_EQ(geom::Point(), ret_top_left);
270
306
{
271
307
    geom::Point p{55, 66};
272
308
 
273
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
309
    ms::BasicSurface surf(
 
310
        surface_name,
 
311
        rect,
 
312
        change_notification,
 
313
        false,
 
314
        mock_buffer_stream,
 
315
        std::shared_ptr<mi::InputChannel>(),
 
316
        report);
 
317
 
274
318
    surf.move_to(p);
275
319
    EXPECT_EQ(p, surf.top_left());
276
320
}
283
327
    EXPECT_CALL(*mock_buffer_stream, resize(new_size))
284
328
        .Times(1);
285
329
 
286
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
330
    ms::BasicSurface surf(
 
331
        surface_name,
 
332
        rect,
 
333
        change_notification,
 
334
        false,
 
335
        mock_buffer_stream,
 
336
        std::shared_ptr<mi::InputChannel>(),
 
337
        report);
287
338
 
288
339
    ASSERT_NE(new_size, surf.size());
289
340
    EXPECT_TRUE(surf.resize(new_size));
298
349
    EXPECT_CALL(*mock_buffer_stream, resize(new_size))
299
350
        .Times(1);
300
351
 
301
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
352
    ms::BasicSurface surf(
 
353
        surface_name,
 
354
        rect,
 
355
        change_notification,
 
356
        false,
 
357
        mock_buffer_stream,
 
358
        std::shared_ptr<mi::InputChannel>(),
 
359
        report);
302
360
 
303
361
    ASSERT_NE(new_size, surf.size());
304
362
 
318
376
        .Times(1)
319
377
        .WillOnce(Throw(std::runtime_error("bad resize")));
320
378
 
321
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
379
    ms::BasicSurface surf(
 
380
        surface_name,
 
381
        rect,
 
382
        change_notification,
 
383
        false,
 
384
        mock_buffer_stream,
 
385
        std::shared_ptr<mi::InputChannel>(),
 
386
        report);
322
387
 
323
388
    EXPECT_THROW({
324
389
        surf.resize(new_size);
341
406
    };
342
407
 
343
408
    ms::BasicSurface surf(
344
 
        stub_data,
 
409
        surface_name,
 
410
        rect,
 
411
        change_notification,
 
412
        false,
345
413
        mock_buffer_stream,
346
414
        std::shared_ptr<mi::InputChannel>(),
347
415
        report);
360
428
TEST_F(SurfaceCreation, test_get_input_channel)
361
429
{
362
430
    auto mock_channel = std::make_shared<MockInputChannel>();
363
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, mock_channel, report);
 
431
    ms::BasicSurface surf(
 
432
        surface_name,
 
433
        rect,
 
434
        change_notification,
 
435
        false,
 
436
        mock_buffer_stream,
 
437
        mock_channel,
 
438
        report);
 
439
 
364
440
    EXPECT_EQ(mock_channel, surf.input_channel());
365
441
}
366
442
 
369
445
    using namespace testing;
370
446
 
371
447
    float alpha = 0.5f;
372
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
448
    ms::BasicSurface surf(
 
449
        surface_name,
 
450
        rect,
 
451
        change_notification,
 
452
        false,
 
453
        mock_buffer_stream,
 
454
        std::shared_ptr<mi::InputChannel>(),
 
455
        report);
373
456
 
374
457
    surf.set_alpha(alpha);
375
 
    //a bit unintuitive. hopefully goes away when BasicSurface merges with CompositingCriteria
376
 
    auto compositing_criteria = surf.compositing_criteria();
377
 
    EXPECT_FLOAT_EQ(alpha, compositing_criteria->alpha());
 
458
    EXPECT_FLOAT_EQ(alpha, surf.alpha());
378
459
}
379
460
 
380
461
TEST_F(SurfaceCreation, test_surface_force_requests_to_complete)
383
464
 
384
465
    EXPECT_CALL(*mock_buffer_stream, force_requests_to_complete()).Times(Exactly(1));
385
466
 
386
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
467
    ms::BasicSurface surf(
 
468
        surface_name,
 
469
        rect,
 
470
        change_notification,
 
471
        false,
 
472
        mock_buffer_stream,
 
473
        std::shared_ptr<mi::InputChannel>(),
 
474
        report);
 
475
 
387
476
    surf.force_requests_to_complete();
388
477
}
389
478
 
394
483
    EXPECT_CALL(*mock_buffer_stream, allow_framedropping(true))
395
484
        .Times(1);
396
485
 
397
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
486
    ms::BasicSurface surf(
 
487
        surface_name,
 
488
        rect,
 
489
        change_notification,
 
490
        false,
 
491
        mock_buffer_stream,
 
492
        std::shared_ptr<mi::InputChannel>(),
 
493
        report);
 
494
 
398
495
    surf.allow_framedropping(true);
399
496
}
400
497
 
401
498
TEST_F(SurfaceCreation, test_surface_next_buffer_tells_state_on_first_frame)
402
499
{
403
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
500
    ms::BasicSurface surf(
 
501
        surface_name,
 
502
        rect,
 
503
        change_notification,
 
504
        false,
 
505
        mock_buffer_stream,
 
506
        std::shared_ptr<mi::InputChannel>(),
 
507
        report);
 
508
 
404
509
    mg::Buffer* buffer{nullptr};
405
510
 
406
511
    auto const complete = [&buffer](mg::Buffer* new_buffer){ buffer = new_buffer; };
416
521
{
417
522
    using namespace testing;
418
523
 
419
 
    ms::BasicSurface surf(stub_data, mock_buffer_stream, std::shared_ptr<mi::InputChannel>(), report);
 
524
    ms::BasicSurface surf(
 
525
        surface_name,
 
526
        rect,
 
527
        change_notification,
 
528
        false,
 
529
        mock_buffer_stream,
 
530
        std::shared_ptr<mi::InputChannel>(),
 
531
        report);
 
532
 
420
533
    EXPECT_THROW({
421
534
            surf.client_input_fd();
422
535
    }, std::logic_error);
425
538
    int const client_fd = 13;
426
539
    EXPECT_CALL(channel, client_fd()).Times(1).WillOnce(Return(client_fd));
427
540
 
428
 
    ms::BasicSurface input_surf(stub_data, mock_buffer_stream,mt::fake_shared(channel), report);
 
541
    ms::BasicSurface input_surf(
 
542
        surface_name,
 
543
        rect,
 
544
        change_notification,
 
545
        false,
 
546
        mock_buffer_stream,mt::fake_shared(channel),
 
547
        report);
 
548
 
429
549
    EXPECT_EQ(client_fd, input_surf.client_input_fd());
430
550
}