~brandontschaefer/mir/add-mir-chrome-none

« back to all changes in this revision

Viewing changes to tests/unit-tests/client/test_protobuf_rpc_channel.cpp

Simplify SurfaceMap's single object functions.

Also make them safer and more powerful by replacing raw pointers with
shared pointers. That's the reason I need this - to get a shared
pointer.

Approved by mir-ci-bot, Alan Griffiths.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
 
60
60
struct MockSurfaceMap : mcl::SurfaceMap
61
61
{
62
 
    MOCK_CONST_METHOD2(with_surface_do,
63
 
        void(mir::frontend::SurfaceId, std::function<void(MirSurface*)> const&));
64
 
    MOCK_CONST_METHOD2(with_stream_do,
65
 
        void(mir::frontend::BufferStreamId, std::function<void(MirBufferStream*)> const&));
 
62
    MOCK_CONST_METHOD1(surface, std::shared_ptr<MirSurface>(mir::frontend::SurfaceId));
 
63
    MOCK_CONST_METHOD1(stream, std::shared_ptr<MirBufferStream>(mir::frontend::BufferStreamId));
66
64
    MOCK_CONST_METHOD1(with_all_streams_do,
67
65
        void(std::function<void(MirBufferStream*)> const&));
68
66
    MOCK_CONST_METHOD1(buffer, std::shared_ptr<mcl::MirBuffer>(int));
74
72
class StubSurfaceMap : public mcl::SurfaceMap
75
73
{
76
74
public:
77
 
    void with_surface_do(
78
 
        mir::frontend::SurfaceId, std::function<void(MirSurface*)> const&) const override
 
75
    std::shared_ptr<MirSurface> surface(mir::frontend::SurfaceId) const override
79
76
    {
 
77
        return {};
80
78
    }
81
 
    void with_stream_do(
82
 
        mir::frontend::BufferStreamId, std::function<void(MirBufferStream*)> const&) const override
 
79
    std::shared_ptr<MirBufferStream> stream(mir::frontend::BufferStreamId) const override
83
80
    {
 
81
        return {};
84
82
    }
85
83
    void with_all_streams_do(std::function<void(MirBufferStream*)> const&) const override
86
84
    {
796
794
    auto mock_buffer_factory = std::make_shared<MockBufferFactory>();
797
795
    auto mock_client_buffer = std::make_shared<mtd::MockClientBuffer>();
798
796
    auto buf = std::make_shared<mcl::Buffer>(buffer_cb, nullptr, buffer_id, mock_client_buffer, nullptr, mir_buffer_usage_software);
799
 
    EXPECT_CALL(*stream_map, with_stream_do(mir::frontend::BufferStreamId{stream_id},_))
 
797
    EXPECT_CALL(*stream_map, stream(mir::frontend::BufferStreamId{stream_id}))
800
798
        .Times(1);
801
799
 
802
800
    auto transport = std::make_unique<NiceMock<MockStreamTransport>>();