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

« back to all changes in this revision

Viewing changes to tests/unit-tests/client/test_connection_resource_map.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:
56
56
TEST_F(ConnectionResourceMap, maps_surface_when_surface_inserted)
57
57
{
58
58
    using namespace testing;
59
 
    auto surface_called = false;
60
59
    mcl::ConnectionSurfaceMap map;
61
60
    map.insert(surface_id, surface);
62
 
    map.with_surface_do(surface_id, [&](MirSurface* surf) {
63
 
        EXPECT_THAT(surf, Eq(surface.get()));
64
 
        surface_called = true;
65
 
    });
66
 
 
67
 
    EXPECT_TRUE(surface_called);
 
61
    EXPECT_EQ(surface, map.surface(surface_id));
68
62
}
69
63
 
70
64
TEST_F(ConnectionResourceMap, removes_surface_when_surface_removed)
73
67
    mcl::ConnectionSurfaceMap map;
74
68
    map.insert(surface_id, surface);
75
69
    map.erase(surface_id);
76
 
    EXPECT_THROW({
77
 
        map.with_stream_do(stream_id, [](MirBufferStream*){});
78
 
    }, std::runtime_error);
 
70
    EXPECT_FALSE(map.stream(stream_id));
79
71
}
80
72
 
81
73
TEST_F(ConnectionResourceMap, maps_streams)
82
74
{
83
75
    using namespace testing;
84
 
    auto stream_called = false;
85
76
    mcl::ConnectionSurfaceMap map;
86
77
    map.insert(stream_id, stream);
87
 
    map.with_stream_do(stream_id, [&](MirBufferStream* str) {
88
 
        EXPECT_THAT(str, Eq(stream.get()));
89
 
        stream_called = true;
90
 
    });
91
 
    EXPECT_TRUE(stream_called);
 
78
    EXPECT_EQ(stream, map.stream(stream_id));
92
79
    map.erase(stream_id);
93
80
}
94
81
 
126
113
    mcl::ConnectionSurfaceMap map;
127
114
    map.insert(buffer_id, buffer);
128
115
    map.insert(surface_id, surface);
129
 
 
130
 
    map.with_surface_do(surface_id,
131
 
        [this, &map](auto) {
132
 
            EXPECT_THAT(map.buffer(buffer_id), Eq(buffer));
133
 
        });
 
116
    EXPECT_EQ(buffer, map.buffer(buffer_id));
134
117
}
135
118
 
136
119
TEST_F(ConnectionResourceMap, can_insert_retrieve_erase_render_surface)