50
50
return std::make_shared<mtd::MockSurface>(std::make_shared<mtd::StubSurfaceBuilder>());
53
class MockSnapshotStrategy : public ms::SnapshotStrategy
56
~MockSnapshotStrategy() noexcept {}
58
MOCK_METHOD2(take_snapshot_of,
59
void(std::shared_ptr<msh::SurfaceBufferAccess> const&,
60
msh::SnapshotCallback const&));
63
struct MockSnapshotCallback
65
void operator()(msh::Snapshot const& snapshot)
67
operator_call(snapshot);
69
MOCK_METHOD1(operator_call, void(msh::Snapshot const&));
72
MATCHER(IsNullSnapshot, "")
74
return arg.size == mir::geometry::Size{} &&
75
arg.stride == mir::geometry::Stride{} &&
76
arg.pixels == nullptr;
54
80
TEST(ApplicationSession, create_and_destroy_surface)
234
260
}, std::runtime_error);
237
TEST(ApplicationSession, uses_snapshot_strategy)
239
using namespace ::testing;
241
class MockSnapshotStrategy : public ms::SnapshotStrategy
244
~MockSnapshotStrategy() noexcept {}
246
MOCK_METHOD2(take_snapshot_of,
247
void(std::shared_ptr<msh::SurfaceBufferAccess> const&,
248
msh::SnapshotCallback const&));
263
TEST(ApplicationSession, takes_snapshot_of_default_surface)
265
using namespace ::testing;
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>();
274
EXPECT_CALL(surface_factory, create_surface(_,_,_,_))
275
.WillOnce(Return(default_surface));
277
EXPECT_CALL(*snapshot_strategy,
278
take_snapshot_of(default_surface_buffer_access, _));
280
ms::ApplicationSession app_session(
281
mt::fake_shared(surface_factory),
285
std::make_shared<msh::NullSessionListener>(),
286
mt::fake_shared(sender));
288
auto surface = app_session.create_surface(msh::SurfaceCreationParameters{});
289
app_session.take_snapshot(msh::SnapshotCallback());
290
app_session.destroy_surface(surface);
293
TEST(ApplicationSession, returns_null_snapshot_if_no_default_surface)
295
using namespace ::testing;
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;
254
302
ms::ApplicationSession app_session(
255
303
mt::fake_shared(surface_factory),
259
307
std::make_shared<msh::NullSessionListener>(),
260
308
mt::fake_shared(sender));
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()));
264
app_session.take_snapshot(msh::SnapshotCallback());
313
app_session.take_snapshot(std::ref(mock_snapshot_callback));