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

« back to all changes in this revision

Viewing changes to tests/unit-tests/scene/test_application_session.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:
49
49
{
50
50
    return std::make_shared<mtd::MockSurface>(std::make_shared<mtd::StubSurfaceBuilder>());
51
51
}
 
52
 
 
53
class MockSnapshotStrategy : public ms::SnapshotStrategy
 
54
{
 
55
public:
 
56
    ~MockSnapshotStrategy() noexcept {}
 
57
 
 
58
    MOCK_METHOD2(take_snapshot_of,
 
59
                void(std::shared_ptr<msh::SurfaceBufferAccess> const&,
 
60
                     msh::SnapshotCallback const&));
 
61
};
 
62
 
 
63
struct MockSnapshotCallback
 
64
{
 
65
    void operator()(msh::Snapshot const& snapshot)
 
66
    {
 
67
        operator_call(snapshot);
 
68
    }
 
69
    MOCK_METHOD1(operator_call, void(msh::Snapshot const&));
 
70
};
 
71
 
 
72
MATCHER(IsNullSnapshot, "")
 
73
{
 
74
    return arg.size == mir::geometry::Size{} &&
 
75
           arg.stride == mir::geometry::Stride{} &&
 
76
           arg.pixels == nullptr;
 
77
}
52
78
}
53
79
 
54
80
TEST(ApplicationSession, create_and_destroy_surface)
234
260
    }, std::runtime_error);
235
261
}
236
262
 
237
 
TEST(ApplicationSession, uses_snapshot_strategy)
238
 
{
239
 
    using namespace ::testing;
240
 
 
241
 
    class MockSnapshotStrategy : public ms::SnapshotStrategy
242
 
    {
243
 
    public:
244
 
        ~MockSnapshotStrategy() noexcept {}
245
 
 
246
 
        MOCK_METHOD2(take_snapshot_of,
247
 
                    void(std::shared_ptr<msh::SurfaceBufferAccess> const&,
248
 
                         msh::SnapshotCallback const&));
249
 
    };
250
 
 
 
263
TEST(ApplicationSession, takes_snapshot_of_default_surface)
 
264
{
 
265
    using namespace ::testing;
 
266
 
 
267
    mtd::MockSurfaceFactory surface_factory;
 
268
    mtd::NullEventSink sender;
 
269
    auto const default_surface = make_mock_surface();
 
270
    auto const default_surface_buffer_access =
 
271
        std::static_pointer_cast<msh::SurfaceBufferAccess>(default_surface);
 
272
    auto const snapshot_strategy = std::make_shared<MockSnapshotStrategy>();
 
273
 
 
274
    EXPECT_CALL(surface_factory, create_surface(_,_,_,_))
 
275
        .WillOnce(Return(default_surface));
 
276
 
 
277
    EXPECT_CALL(*snapshot_strategy,
 
278
                take_snapshot_of(default_surface_buffer_access, _));
 
279
 
 
280
    ms::ApplicationSession app_session(
 
281
        mt::fake_shared(surface_factory),
 
282
        __LINE__,
 
283
        "Foo",
 
284
        snapshot_strategy,
 
285
        std::make_shared<msh::NullSessionListener>(),
 
286
        mt::fake_shared(sender));
 
287
 
 
288
    auto surface = app_session.create_surface(msh::SurfaceCreationParameters{});
 
289
    app_session.take_snapshot(msh::SnapshotCallback());
 
290
    app_session.destroy_surface(surface);
 
291
}
 
292
 
 
293
TEST(ApplicationSession, returns_null_snapshot_if_no_default_surface)
 
294
{
 
295
    using namespace ::testing;
 
296
 
 
297
    mtd::NullEventSink sender;
 
298
    mtd::MockSurfaceFactory surface_factory;
251
299
    auto snapshot_strategy = std::make_shared<MockSnapshotStrategy>();
252
 
    mtd::NullEventSink sender;
253
 
    mtd::MockSurfaceFactory surface_factory;
 
300
    MockSnapshotCallback mock_snapshot_callback;
 
301
 
254
302
    ms::ApplicationSession app_session(
255
303
        mt::fake_shared(surface_factory),
256
304
        __LINE__,
259
307
        std::make_shared<msh::NullSessionListener>(),
260
308
        mt::fake_shared(sender));
261
309
 
262
 
    EXPECT_CALL(*snapshot_strategy, take_snapshot_of(_,_));
 
310
    EXPECT_CALL(*snapshot_strategy, take_snapshot_of(_,_)).Times(0);
 
311
    EXPECT_CALL(mock_snapshot_callback, operator_call(IsNullSnapshot()));
263
312
 
264
 
    app_session.take_snapshot(msh::SnapshotCallback());
 
313
    app_session.take_snapshot(std::ref(mock_snapshot_callback));
265
314
}
266
315
 
267
316
namespace