Mir

Merge lp:~kdub/mir/msh-surface-no-builder into lp:~mir-team/mir/trunk

Proposed by Kevin DuBois
Status: Work in progress
Proposed branch: lp:~kdub/mir/msh-surface-no-builder
Merge into: lp:~mir-team/mir/trunk
Diff against target: 760 lines (+105/-232)
11 files modified
include/server/mir/shell/surface.h (+6/-7)
include/test/mir_test_doubles/mock_surface.h (+3/-2)
src/server/shell/surface.cpp (+11/-11)
src/server/shell/surface_source.cpp (+8/-2)
tests/behavior-tests/session_management_context.cpp (+4/-5)
tests/integration-tests/cucumber/test_session_management_context.cpp (+1/-2)
tests/unit-tests/frontend/test_session_mediator.cpp (+1/-1)
tests/unit-tests/shell/test_application_session.cpp (+7/-11)
tests/unit-tests/shell/test_session_manager.cpp (+6/-4)
tests/unit-tests/shell/test_single_visibility_focus_mechanism.cpp (+1/-2)
tests/unit-tests/shell/test_surface.cpp (+57/-185)
To merge this branch: bzr merge lp:~kdub/mir/msh-surface-no-builder
Reviewer Review Type Date Requested Status
Alexandros Frantzis (community) Needs Information
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+171933@code.launchpad.net

Commit message

msh:: begin changes by digging the destruction of the ms::Surface out of msh::Surface. This makes the constructor for msh::Surface much simpler.

Description of the change

msh:: begin changes by digging the destruction of the ms::Surface out of msh::Surface. This makes the constructor for msh::Surface much simpler.

this is a 'stable intermediate change' from my spike on how to clean up msh::Surface to make it more mockable/testable/cleaner. There are TODO's noting the next steps to take.
The obvious wart is in SurfaceSource, where we pass a std::function for the destruction of the ms::Surface. This will is nicely eliminated by having a complimentary "destroy_surface_for" function to the "create_surface_for" function present in the current SessionManager

From the spike on cleaning this area of the code, (which I've decided to land in bitesized chunks), I isolated a few problems:

1) The ms::Surface is not acquired by the shell in a good RAII way. The surface stack is passed all around shell, when really, the SessionManager in shell should be aware of the SurfaceStack, and manage the Session classes for each client
2) There are a few builder clasess that have weird lifetimes for their underlying factories. In my spike branch, I eliminated two of these.
3) SurfaceController is a bit redundant, what we have in the system today is trending towards an MVC view of the stack that's a little more fine grained than what we had planned many months ago.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> The obvious wart is in SurfaceSource, where we pass a std::function for the
> destruction of the ms::Surface. This will is nicely eliminated by having a
> complimentary "destroy_surface_for" function to the "create_surface_for"
> function present in the current SessionManager.

With this planned change a shell::Surface will not know how to properly destroy itself (e.g. remove itself from the SurfaceStack). Introducing SessionManager::destroy_surface_for() will solve this for surfaces that are explicitly released by the application, but I am not clear what's the plan for properly destroying surfaces when a session is shut down or when the mir server is shut down. Will SessionManager::close_session() iterate over a session's surfaces and call destroy_surface_for() for each one?

review: Needs Information
Revision history for this message
Kevin DuBois (kdub) wrote :

> > The obvious wart is in SurfaceSource, where we pass a std::function for the
> > destruction of the ms::Surface. This will is nicely eliminated by having a
> > complimentary "destroy_surface_for" function to the "create_surface_for"
> > function present in the current SessionManager.
>
> With this planned change a shell::Surface will not know how to properly
> destroy itself (e.g. remove itself from the SurfaceStack). Introducing
> SessionManager::destroy_surface_for() will solve this for surfaces that are
> explicitly released by the application, but I am not clear what's the plan for
> properly destroying surfaces when a session is shut down or when the mir
> server is shut down. Will SessionManager::close_session() iterate over a
> session's surfaces and call destroy_surface_for() for each one?

I have been iterating on this for a bit, the solution is to have a proxy surface to decouple the lifetimes. However, doing this exposed the tight linkage between input and the surface stack, so this branch is not dependendant on remove-surface-target. Will switch back to WIP for a day or two until that lands

Unmerged revisions

796. By Kevin DuBois

remove commented code

795. By Kevin DuBois

make a todo comment noting where we have a stable intermediate form

794. By Kevin DuBois

clean up references to the builder throughout the tests. re-enable all msh surface tests

793. By Kevin DuBois

trim the constructor from the unused params

792. By Kevin DuBois

test to pass

791. By Kevin DuBois

flip the switch on the constructor (1 failing tes)

790. By Kevin DuBois

finish adding constructor del function to move msh::Surface to more raii

789. By Kevin DuBois

wrap the destruction into a functor. this is a temporary measure

788. By Kevin DuBois

rethink approach to be gentler to compile

787. By Kevin DuBois

update surafce test so it doesnt touch builder

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/server/mir/shell/surface.h'
2--- include/server/mir/shell/surface.h 2013-06-25 19:27:35 +0000
3+++ include/server/mir/shell/surface.h 2013-06-27 23:29:26 +0000
4@@ -26,6 +26,7 @@
5
6 #include "mir_toolkit/common.h"
7
8+#include <functional>
9 #include <string>
10
11 namespace mir
12@@ -38,19 +39,17 @@
13 namespace shell
14 {
15 class InputTargeter;
16-class SurfaceBuilder;
17-struct SurfaceCreationParameters;
18
19 class Surface : public frontend::Surface
20 {
21 public:
22 Surface(
23- std::shared_ptr<SurfaceBuilder> const& builder,
24- SurfaceCreationParameters const& params);
25+ std::weak_ptr<surfaces::Surface> const& surface,
26+ std::function<void(std::weak_ptr<surfaces::Surface>)> const& destroyer);
27
28 Surface(
29- std::shared_ptr<SurfaceBuilder> const& builder,
30- SurfaceCreationParameters const& params,
31+ std::weak_ptr<surfaces::Surface> const& surface,
32+ std::function<void(std::weak_ptr<surfaces::Surface>)> const& destroyer,
33 frontend::SurfaceId id,
34 std::shared_ptr<events::EventSink> const& sink);
35
36@@ -93,7 +92,6 @@
37 bool set_state(MirSurfaceState s);
38 void notify_change(MirSurfaceAttrib attrib, int value);
39
40- std::shared_ptr<SurfaceBuilder> const builder;
41 std::weak_ptr<mir::surfaces::Surface> const surface;
42
43 frontend::SurfaceId const id;
44@@ -101,6 +99,7 @@
45
46 MirSurfaceType type_value;
47 MirSurfaceState state_value;
48+ std::function<void(std::weak_ptr<surfaces::Surface>)> destr;
49 };
50 }
51 }
52
53=== modified file 'include/test/mir_test_doubles/mock_surface.h'
54--- include/test/mir_test_doubles/mock_surface.h 2013-06-25 05:42:49 +0000
55+++ include/test/mir_test_doubles/mock_surface.h 2013-06-27 23:29:26 +0000
56@@ -36,8 +36,9 @@
57
58 struct MockSurface : public shell::Surface
59 {
60- MockSurface(std::shared_ptr<shell::SurfaceBuilder> const& builder) :
61- shell::Surface(builder, shell::a_surface())
62+ MockSurface() :
63+ shell::Surface(std::weak_ptr<surfaces::Surface>(),
64+ [](std::weak_ptr<surfaces::Surface>){})
65 {
66 }
67
68
69=== modified file 'src/server/shell/surface.cpp'
70--- src/server/shell/surface.cpp 2013-06-25 19:28:56 +0000
71+++ src/server/shell/surface.cpp 2013-06-27 23:29:26 +0000
72@@ -35,28 +35,28 @@
73 namespace ms = mir::surfaces;
74
75 msh::Surface::Surface(
76- std::shared_ptr<SurfaceBuilder> const& builder,
77- shell::SurfaceCreationParameters const& params,
78+ std::weak_ptr<ms::Surface> const& surface,
79+ std::function<void(std::weak_ptr<ms::Surface>)> const& destroyer,
80 frontend::SurfaceId id,
81 std::shared_ptr<events::EventSink> const& sink)
82- : builder(builder),
83- surface(builder->create_surface(params)),
84+ : surface(surface),
85 id(id),
86 event_sink(sink),
87 type_value(mir_surface_type_normal),
88- state_value(mir_surface_state_restored)
89+ state_value(mir_surface_state_restored),
90+ destr(destroyer)
91 {
92 }
93
94 msh::Surface::Surface(
95- std::shared_ptr<SurfaceBuilder> const& builder,
96- shell::SurfaceCreationParameters const& params)
97- : builder(builder),
98- surface(builder->create_surface(params)),
99+ std::weak_ptr<ms::Surface> const& surface,
100+ std::function<void(std::weak_ptr<ms::Surface>)> const& destroyer)
101+ : surface(surface),
102 id(),
103 event_sink(),
104 type_value(mir_surface_type_normal),
105- state_value(mir_surface_state_restored)
106+ state_value(mir_surface_state_restored),
107+ destr(destroyer)
108 {
109 }
110
111@@ -106,7 +106,7 @@
112
113 void msh::Surface::destroy()
114 {
115- builder->destroy_surface(surface);
116+ destr(surface);
117 }
118
119 void msh::Surface::force_requests_to_complete()
120
121=== modified file 'src/server/shell/surface_source.cpp'
122--- src/server/shell/surface_source.cpp 2013-05-21 22:03:29 +0000
123+++ src/server/shell/surface_source.cpp 2013-06-27 23:29:26 +0000
124@@ -41,9 +41,15 @@
125 frontend::SurfaceId id,
126 std::shared_ptr<events::EventSink> const& sink)
127 {
128+ //TODO: this is still messy. We should only have a simple make_shared here, and the builder
129+ //should exist up in the SessionManager
130+ auto surface = surface_builder->create_surface(params);
131+ auto fn = [this](std::weak_ptr<ms::Surface> s){
132+ surface_builder->destroy_surface(s);
133+ };
134 return std::make_shared<Surface>(
135- surface_builder,
136- params,
137+ surface,
138+ fn,
139 id,
140 sink);
141 }
142
143=== modified file 'tests/behavior-tests/session_management_context.cpp'
144--- tests/behavior-tests/session_management_context.cpp 2013-06-12 10:27:50 +0000
145+++ tests/behavior-tests/session_management_context.cpp 2013-06-27 23:29:26 +0000
146@@ -37,6 +37,7 @@
147
148 namespace mf = mir::frontend;
149 namespace msh = mir::shell;
150+namespace ms = mir::surfaces;
151 namespace mg = mir::graphics;
152 namespace mc = mir::compositor;
153 namespace geom = mir::geometry;
154@@ -65,18 +66,16 @@
155 {
156 }
157
158- std::shared_ptr<msh::Surface> create_surface(const msh::SurfaceCreationParameters& params,
159+ std::shared_ptr<msh::Surface> create_surface(const msh::SurfaceCreationParameters&,
160 frontend::SurfaceId id,
161 std::shared_ptr<events::EventSink> const& sink) override
162 {
163 return std::make_shared<msh::Surface>(
164- mt::fake_shared(surface_builder),
165- params,
166+ std::weak_ptr<ms::Surface>(),
167+ [](std::weak_ptr<surfaces::Surface>){},
168 id,
169 sink);
170 }
171-
172- mtd::StubSurfaceBuilder surface_builder;
173 };
174
175 class SizedDisplay : public mg::Display
176
177=== modified file 'tests/integration-tests/cucumber/test_session_management_context.cpp'
178--- tests/integration-tests/cucumber/test_session_management_context.cpp 2013-05-21 17:16:43 +0000
179+++ tests/integration-tests/cucumber/test_session_management_context.cpp 2013-06-27 23:29:26 +0000
180@@ -24,7 +24,6 @@
181 #include "mir/graphics/viewable_area.h"
182
183 #include "mir_test_doubles/mock_session.h"
184-#include "mir_test_doubles/stub_surface_builder.h"
185 #include "mir_test_doubles/mock_surface.h"
186 #include "mir_test_doubles/mock_shell.h"
187 #include "mir_test/fake_shared.h"
188@@ -136,7 +135,7 @@
189 using namespace ::testing;
190
191 mtd::MockSession session;
192- mtd::MockSurface surface(std::make_shared<mtd::StubSurfaceBuilder>());
193+ mtd::MockSurface surface;
194
195 EXPECT_CALL(shell, open_session(test_window_name, _)).Times(1)
196 .WillOnce(Return(mt::fake_shared<mf::Session>(session)));
197
198=== modified file 'tests/unit-tests/frontend/test_session_mediator.cpp'
199--- tests/unit-tests/frontend/test_session_mediator.cpp 2013-06-25 05:42:49 +0000
200+++ tests/unit-tests/frontend/test_session_mediator.cpp 2013-06-27 23:29:26 +0000
201@@ -62,7 +62,7 @@
202 {
203 using namespace ::testing;
204
205- mock_surface = std::make_shared<mtd::MockSurface>(mt::fake_shared(surface_builder));
206+ mock_surface = std::make_shared<mtd::MockSurface>();
207 mock_buffer = std::make_shared<NiceMock<mtd::MockBuffer>>(geom::Size(), geom::Stride(), geom::PixelFormat());
208
209 EXPECT_CALL(*mock_surface, size()).Times(AnyNumber()).WillRepeatedly(Return(geom::Size()));
210
211=== modified file 'tests/unit-tests/shell/test_application_session.cpp'
212--- tests/unit-tests/shell/test_application_session.cpp 2013-05-21 18:24:52 +0000
213+++ tests/unit-tests/shell/test_application_session.cpp 2013-06-27 23:29:26 +0000
214@@ -22,7 +22,6 @@
215 #include "mir_test/fake_shared.h"
216 #include "mir_test_doubles/mock_surface_factory.h"
217 #include "mir_test_doubles/mock_surface.h"
218-#include "mir_test_doubles/stub_surface_builder.h"
219 #include "mir_test_doubles/stub_surface.h"
220
221 #include "mir/shell/surface.h"
222@@ -43,8 +42,7 @@
223 {
224 using namespace ::testing;
225
226- mtd::StubSurfaceBuilder surface_builder;
227- auto const mock_surface = std::make_shared<mtd::MockSurface>(mt::fake_shared(surface_builder));
228+ auto const mock_surface = std::make_shared<mtd::MockSurface>();
229
230 mtd::MockSurfaceFactory surface_factory;
231 ON_CALL(surface_factory, create_surface(_, _, _)).WillByDefault(Return(mock_surface));
232@@ -65,15 +63,14 @@
233 using namespace ::testing;
234
235 mtd::MockSurfaceFactory surface_factory;
236- mtd::StubSurfaceBuilder surface_builder;
237 {
238 InSequence seq;
239 EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1)
240- .WillOnce(Return(std::make_shared<NiceMock<mtd::MockSurface>>(mt::fake_shared(surface_builder))));
241- EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1)
242- .WillOnce(Return(std::make_shared<NiceMock<mtd::MockSurface>>(mt::fake_shared(surface_builder))));
243- EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1)
244- .WillOnce(Return(std::make_shared<NiceMock<mtd::MockSurface>>(mt::fake_shared(surface_builder))));
245+ .WillOnce(Return(std::make_shared<NiceMock<mtd::MockSurface>>()));
246+ EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1)
247+ .WillOnce(Return(std::make_shared<NiceMock<mtd::MockSurface>>()));
248+ EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1)
249+ .WillOnce(Return(std::make_shared<NiceMock<mtd::MockSurface>>()));
250 }
251
252 msh::ApplicationSession app_session(mt::fake_shared(surface_factory), "Foo");
253@@ -100,8 +97,7 @@
254 {
255 using namespace ::testing;
256
257- mtd::StubSurfaceBuilder surface_builder;
258- auto const mock_surface = std::make_shared<mtd::MockSurface>(mt::fake_shared(surface_builder));
259+ auto const mock_surface = std::make_shared<mtd::MockSurface>();
260
261 mtd::MockSurfaceFactory surface_factory;
262 ON_CALL(surface_factory, create_surface(_, _, _)).WillByDefault(Return(mock_surface));
263
264=== modified file 'tests/unit-tests/shell/test_session_manager.cpp'
265--- tests/unit-tests/shell/test_session_manager.cpp 2013-06-19 16:41:13 +0000
266+++ tests/unit-tests/shell/test_session_manager.cpp 2013-06-27 23:29:26 +0000
267@@ -109,8 +109,9 @@
268
269 ON_CALL(surface_factory, create_surface(_, _, _)).WillByDefault(
270 Return(std::make_shared<msh::Surface>(
271- mt::fake_shared(surface_builder),
272- msh::a_surface())));
273+ std::weak_ptr<ms::Surface>(),
274+ [](std::weak_ptr<ms::Surface>){}
275+ )));
276
277
278 EXPECT_CALL(container, insert_session(_)).Times(1);
279@@ -144,8 +145,9 @@
280 using namespace ::testing;
281 ON_CALL(surface_factory, create_surface(_, _, _)).WillByDefault(
282 Return(std::make_shared<msh::Surface>(
283- mt::fake_shared(surface_builder),
284- msh::a_surface())));
285+ std::weak_ptr<ms::Surface>(),
286+ [](std::weak_ptr<ms::Surface>){}
287+ )));
288
289 // Once for session creation and once for surface creation
290 {
291
292=== modified file 'tests/unit-tests/shell/test_single_visibility_focus_mechanism.cpp'
293--- tests/unit-tests/shell/test_single_visibility_focus_mechanism.cpp 2013-06-12 15:36:31 +0000
294+++ tests/unit-tests/shell/test_single_visibility_focus_mechanism.cpp 2013-06-27 23:29:26 +0000
295@@ -29,7 +29,6 @@
296 #include "mir_test_doubles/mock_surface_factory.h"
297 #include "mir_test_doubles/stub_surface.h"
298 #include "mir_test_doubles/mock_surface.h"
299-#include "mir_test_doubles/stub_surface_builder.h"
300 #include "mir_test_doubles/stub_input_targeter.h"
301 #include "mir_test_doubles/mock_input_targeter.h"
302
303@@ -95,7 +94,7 @@
304 using namespace ::testing;
305
306 NiceMock<MockShellSession> app1;
307- mtd::MockSurface mock_surface(std::make_shared<mtd::StubSurfaceBuilder>());
308+ mtd::MockSurface mock_surface;
309 {
310 InSequence seq;
311 EXPECT_CALL(app1, default_surface()).Times(1)
312
313=== modified file 'tests/unit-tests/shell/test_surface.cpp'
314--- tests/unit-tests/shell/test_surface.cpp 2013-06-25 19:27:35 +0000
315+++ tests/unit-tests/shell/test_surface.cpp 2013-06-27 23:29:26 +0000
316@@ -23,7 +23,6 @@
317 #include "mir/shell/surface_builder.h"
318
319 #include "mir_test_doubles/stub_buffer_stream.h"
320-#include "mir_test_doubles/mock_buffer_stream.h"
321 #include "mir_test_doubles/mock_buffer.h"
322 #include "mir_test_doubles/stub_buffer.h"
323 #include "mir_test_doubles/mock_input_targeter.h"
324@@ -46,152 +45,57 @@
325
326 namespace
327 {
328-class StubSurfaceBuilder : public msh::SurfaceBuilder
329-{
330-public:
331- StubSurfaceBuilder() :
332- stub_buffer_stream_(std::make_shared<mtd::StubBufferStream>()),
333- dummy_surface()
334- {
335- }
336-
337- std::weak_ptr<ms::Surface> create_surface(msh::SurfaceCreationParameters const& )
338- {
339- dummy_surface = std::make_shared<ms::Surface>(msh::a_surface().name, msh::a_surface().top_left, stub_buffer_stream_,
340- std::shared_ptr<mi::InputChannel>(), []{});
341- return dummy_surface;
342- }
343-
344- void destroy_surface(std::weak_ptr<ms::Surface> const& )
345- {
346- reset_surface();
347- }
348-
349- void reset_surface()
350- {
351- dummy_surface.reset();
352- }
353-
354- std::shared_ptr<mtd::StubBufferStream> stub_buffer_stream()
355- {
356- return stub_buffer_stream_;
357- }
358-
359-private:
360- std::shared_ptr<mtd::StubBufferStream> const stub_buffer_stream_;
361- std::shared_ptr<ms::Surface> dummy_surface;
362-};
363-
364-class MockSurfaceBuilder : public msh::SurfaceBuilder
365-{
366-public:
367- MockSurfaceBuilder()
368- {
369- using namespace testing;
370- ON_CALL(*this, create_surface(_)).
371- WillByDefault(Invoke(&self, &StubSurfaceBuilder::create_surface));
372-
373- ON_CALL(*this, destroy_surface(_)).
374- WillByDefault(Invoke(&self, &StubSurfaceBuilder::destroy_surface));
375- }
376-
377- MOCK_METHOD1(create_surface, std::weak_ptr<ms::Surface> (const msh::SurfaceCreationParameters&));
378-
379- MOCK_METHOD1(destroy_surface, void (std::weak_ptr<ms::Surface> const&));
380-
381-private:
382- StubSurfaceBuilder self;
383-};
384-
385-typedef testing::NiceMock<mtd::MockBufferStream> StubBufferStream;
386-
387-
388 struct ShellSurface : testing::Test
389 {
390- std::shared_ptr<StubBufferStream> const buffer_stream;
391- StubSurfaceBuilder surface_builder;
392+ std::shared_ptr<mtd::StubBufferStream> const stub_buffer_stream;
393+ std::shared_ptr<ms::Surface> weak_surface;
394
395 ShellSurface() :
396- buffer_stream(std::make_shared<StubBufferStream>())
397+ stub_buffer_stream(std::make_shared<mtd::StubBufferStream>())
398 {
399 using namespace testing;
400
401- ON_CALL(*buffer_stream, stream_size()).WillByDefault(Return(geom::Size()));
402- ON_CALL(*buffer_stream, get_stream_pixel_format()).WillByDefault(Return(geom::PixelFormat::abgr_8888));
403- ON_CALL(*buffer_stream, secure_client_buffer()).WillByDefault(Return(std::shared_ptr<mtd::StubBuffer>()));
404+ weak_surface = std::make_shared<ms::Surface>(std::string("oov"), geom::Point(),
405+ stub_buffer_stream,
406+ std::shared_ptr<mi::InputChannel>(), [](){});
407 }
408 };
409 }
410
411-TEST_F(ShellSurface, creation_and_destruction)
412-{
413- using namespace testing;
414-
415- msh::SurfaceCreationParameters const params;
416- MockSurfaceBuilder surface_builder;
417-
418- InSequence sequence;
419- EXPECT_CALL(surface_builder, create_surface(params)).Times(1);
420- EXPECT_CALL(surface_builder, destroy_surface(_)).Times(1);
421-
422- msh::Surface test(
423- mt::fake_shared(surface_builder),
424- params);
425-}
426-
427-TEST_F(ShellSurface, creation_throws_means_no_destroy)
428-{
429- using namespace testing;
430-
431- msh::SurfaceCreationParameters const params;
432- MockSurfaceBuilder surface_builder;
433-
434- InSequence sequence;
435- EXPECT_CALL(surface_builder, create_surface(params)).Times(1)
436- .WillOnce(Throw(std::runtime_error(__PRETTY_FUNCTION__)));
437- EXPECT_CALL(surface_builder, destroy_surface(_)).Times(Exactly(0));
438-
439- EXPECT_THROW({
440- msh::Surface test(
441- mt::fake_shared(surface_builder),
442- params);
443- }, std::runtime_error);
444-}
445-
446+//TODO: this should be eliminated with the msh cleanup --kdub
447 TEST_F(ShellSurface, destroy)
448 {
449- using namespace testing;
450- MockSurfaceBuilder surface_builder;
451-
452- InSequence sequence;
453- EXPECT_CALL(surface_builder, create_surface(_)).Times(AnyNumber());
454- EXPECT_CALL(surface_builder, destroy_surface(_)).Times(0);
455-
456- msh::Surface test(
457- mt::fake_shared(surface_builder),
458- msh::a_surface());
459-
460- Mock::VerifyAndClearExpectations(&test);
461- EXPECT_CALL(surface_builder, destroy_surface(_)).Times(1);
462-
463- // Check destroy_surface is called immediately
464+ bool destroy_called = false;
465+ {
466+ msh::Surface test(weak_surface,[&](std::weak_ptr<ms::Surface>)
467+ {
468+ destroy_called = true;
469+ });
470+ }
471+ EXPECT_TRUE(destroy_called);
472+}
473+
474+TEST_F(ShellSurface, destroy_manual)
475+{
476+ bool destroy_called = false;
477+ msh::Surface test(weak_surface,[&](std::weak_ptr<ms::Surface>)
478+ {
479+ destroy_called = true;
480+ });
481+
482 test.destroy();
483-
484- Mock::VerifyAndClearExpectations(&test);
485- EXPECT_CALL(surface_builder, destroy_surface(_)).Times(0);
486+ EXPECT_TRUE(destroy_called);
487 }
488
489 TEST_F(ShellSurface, size_throw_behavior)
490 {
491- msh::Surface test(
492- mt::fake_shared(surface_builder),
493- msh::a_surface());
494+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
495
496 EXPECT_NO_THROW({
497 test.size();
498 });
499
500- surface_builder.reset_surface();
501+ weak_surface.reset();
502
503 EXPECT_THROW({
504 test.size();
505@@ -200,15 +104,13 @@
506
507 TEST_F(ShellSurface, top_left_throw_behavior)
508 {
509- msh::Surface test(
510- mt::fake_shared(surface_builder),
511- msh::a_surface());
512+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
513
514 EXPECT_NO_THROW({
515 test.top_left();
516 });
517
518- surface_builder.reset_surface();
519+ weak_surface.reset();
520
521 EXPECT_THROW({
522 test.top_left();
523@@ -217,15 +119,13 @@
524
525 TEST_F(ShellSurface, name_throw_behavior)
526 {
527- msh::Surface test(
528- mt::fake_shared(surface_builder),
529- msh::a_surface());
530+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
531
532 EXPECT_NO_THROW({
533 test.name();
534 });
535
536- surface_builder.reset_surface();
537+ weak_surface.reset();
538
539 EXPECT_THROW({
540 test.name();
541@@ -234,15 +134,13 @@
542
543 TEST_F(ShellSurface, pixel_format_throw_behavior)
544 {
545- msh::Surface test(
546- mt::fake_shared(surface_builder),
547- msh::a_surface());
548+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
549
550 EXPECT_NO_THROW({
551 test.pixel_format();
552 });
553
554- surface_builder.reset_surface();
555+ weak_surface.reset();
556
557 EXPECT_THROW({
558 test.pixel_format();
559@@ -251,15 +149,13 @@
560
561 TEST_F(ShellSurface, hide_throw_behavior)
562 {
563- msh::Surface test(
564- mt::fake_shared(surface_builder),
565- msh::a_surface());
566+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
567
568 EXPECT_NO_THROW({
569 test.hide();
570 });
571
572- surface_builder.reset_surface();
573+ weak_surface.reset();
574
575 EXPECT_THROW({
576 test.hide();
577@@ -268,15 +164,13 @@
578
579 TEST_F(ShellSurface, show_throw_behavior)
580 {
581- msh::Surface test(
582- mt::fake_shared(surface_builder),
583- msh::a_surface());
584+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
585
586 EXPECT_NO_THROW({
587 test.show();
588 });
589
590- surface_builder.reset_surface();
591+ weak_surface.reset();
592
593 EXPECT_THROW({
594 test.show();
595@@ -285,15 +179,13 @@
596
597 TEST_F(ShellSurface, visible_throw_behavior)
598 {
599- msh::Surface test(
600- mt::fake_shared(surface_builder),
601- msh::a_surface());
602+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
603
604 EXPECT_NO_THROW({
605 test.visible();
606 });
607
608- surface_builder.reset_surface();
609+ weak_surface.reset();
610
611 EXPECT_THROW({
612 test.visible();
613@@ -302,15 +194,13 @@
614
615 TEST_F(ShellSurface, destroy_throw_behavior)
616 {
617- msh::Surface test(
618- mt::fake_shared(surface_builder),
619- msh::a_surface());
620+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
621
622 EXPECT_NO_THROW({
623 test.destroy();
624 });
625
626- surface_builder.reset_surface();
627+ weak_surface.reset();
628
629 EXPECT_NO_THROW({
630 test.destroy();
631@@ -319,15 +209,13 @@
632
633 TEST_F(ShellSurface, force_request_to_complete_throw_behavior)
634 {
635- msh::Surface test(
636- mt::fake_shared(surface_builder),
637- msh::a_surface());
638+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
639
640 EXPECT_NO_THROW({
641 test.force_requests_to_complete();
642 });
643
644- surface_builder.reset_surface();
645+ weak_surface.reset();
646
647 EXPECT_NO_THROW({
648 test.force_requests_to_complete();
649@@ -336,15 +224,13 @@
650
651 TEST_F(ShellSurface, advance_client_buffer_throw_behavior)
652 {
653- msh::Surface test(
654- mt::fake_shared(surface_builder),
655- msh::a_surface());
656+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
657
658 EXPECT_NO_THROW({
659 test.advance_client_buffer();
660 });
661
662- surface_builder.reset_surface();
663+ weak_surface.reset();
664
665 EXPECT_THROW({
666 test.advance_client_buffer();
667@@ -353,11 +239,9 @@
668
669 TEST_F(ShellSurface, input_fds_throw_behavior)
670 {
671- msh::Surface test(
672- mt::fake_shared(surface_builder),
673- msh::a_surface());
674+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
675
676- surface_builder.reset_surface();
677+ weak_surface.reset();
678
679 EXPECT_THROW({
680 test.server_input_fd();
681@@ -371,12 +255,10 @@
682 {
683 using namespace testing;
684
685- msh::Surface surf(
686- mt::fake_shared(surface_builder),
687- msh::a_surface());
688+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
689
690 EXPECT_THROW({
691- surf.configure(static_cast<MirSurfaceAttrib>(111), 222);
692+ test.configure(static_cast<MirSurfaceAttrib>(111), 222);
693 }, std::logic_error);
694 }
695
696@@ -384,9 +266,7 @@
697 {
698 using namespace testing;
699
700- msh::Surface surf(
701- mt::fake_shared(surface_builder),
702- msh::a_surface());
703+ msh::Surface surf(weak_surface,[](std::weak_ptr<ms::Surface>){});
704
705 EXPECT_EQ(mir_surface_type_normal, surf.type());
706
707@@ -418,9 +298,7 @@
708 {
709 using namespace testing;
710
711- msh::Surface surf(
712- mt::fake_shared(surface_builder),
713- msh::a_surface());
714+ msh::Surface surf(weak_surface,[](std::weak_ptr<ms::Surface>){});
715
716 EXPECT_EQ(mir_surface_state_restored, surf.state());
717
718@@ -452,9 +330,7 @@
719 {
720 using namespace ::testing;
721
722- msh::Surface test(
723- mt::fake_shared(surface_builder),
724- msh::a_surface());
725+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
726
727 mtd::MockInputTargeter targeter;
728 EXPECT_CALL(targeter, focus_changed(_)).Times(1);
729@@ -466,10 +342,8 @@
730 {
731 using namespace ::testing;
732
733- msh::Surface test(
734- mt::fake_shared(surface_builder),
735- msh::a_surface());
736- surface_builder.reset_surface();
737+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
738+ weak_surface.reset();
739
740 mtd::StubInputTargeter targeter;
741
742@@ -480,9 +354,7 @@
743
744 TEST_F(ShellSurface, with_most_recent_buffer_do_uses_compositor_buffer)
745 {
746- msh::Surface test(
747- mt::fake_shared(surface_builder),
748- msh::a_surface());
749+ msh::Surface test(weak_surface,[](std::weak_ptr<ms::Surface>){});
750
751 mc::Buffer* buf_ptr{nullptr};
752
753@@ -492,6 +364,6 @@
754 buf_ptr = &buffer;
755 });
756
757- EXPECT_EQ(surface_builder.stub_buffer_stream()->stub_compositor_buffer.get(),
758+ EXPECT_EQ(stub_buffer_stream->stub_compositor_buffer.get(),
759 buf_ptr);
760 }

Subscribers

People subscribed via source and target branches