Mir

Merge lp:~robertcarr/mir/reduce-coupling-in-application-mediator-tests into lp:~mir-team/mir/trunk

Proposed by Robert Carr
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 490
Proposed branch: lp:~robertcarr/mir/reduce-coupling-in-application-mediator-tests
Merge into: lp:~mir-team/mir/trunk
Prerequisite: lp:~robertcarr/mir/dedupe-mock-session
Diff against target: 714 lines (+275/-212)
10 files modified
include/mir_test_doubles/mock_session.h (+4/-4)
include/mir_test_doubles/mock_session_store.h (+48/-0)
include/mir_test_doubles/mock_surface.h (+50/-0)
include/mir_test_doubles/stub_session.h (+63/-0)
include/mir_test_doubles/stub_session_store.h (+56/-0)
tests/integration-tests/cucumber/test_session_management_context.cpp (+3/-13)
tests/unit-tests/frontend/test_application_mediator.cpp (+38/-73)
tests/unit-tests/frontend/test_application_mediator_android.cpp (+5/-42)
tests/unit-tests/frontend/test_application_mediator_gbm.cpp (+5/-42)
tests/unit-tests/shell/test_application_session.cpp (+3/-38)
To merge this branch: bzr merge lp:~robertcarr/mir/reduce-coupling-in-application-mediator-tests
Reviewer Review Type Date Requested Status
Alexandros Frantzis (community) Approve
Alan Griffiths Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+152304@code.launchpad.net

Commit message

Reduce and code coupling in application mediator tests through usage of mock objects as opposed to a mix of stub and real objects.

Description of the change

Reduce duplication and coupling in application mediator tests through usage of mock objects rather than a mix of stubs and real objects (i.e. ApplicationSession).

Depends on the mock definition header (mock_session.h) introduced here:
https://code.launchpad.net/~robertcarr/mir/dedupe-mock-session/+merge/152287

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:475
http://jenkins.qa.ubuntu.com/job/mir-ci/18/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-quantal-amd64-ci/18//console

Click here to trigger a rebuild:
http://jenkins.qa.ubuntu.com/job/mir-ci/18//rebuild/?

review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

The changes introduces mocks where only stubs are needed (i.e. no behavioral testing is going on). Examples:

273 +class StubbedSession : public testing::NiceMock<mtd::MockSession>
412 + : session_store{std::make_shared<mtd::MockSessionStore>()},
503 + : session_store{std::make_shared<mtd::MockSessionStore>()},

review: Needs Fixing
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

116 - * it under the terms of the GNU General Public License version 3 as
117 + * it under the terms of the GNU Lesser General Public License version 3 as

My understanding of Canonical policy is that executables are GPL, only libraries are LGPL.

review: Needs Fixing
Revision history for this message
Robert Carr (robertcarr) wrote :

Alan: Fixed license...I didn't get the memo when things changed and got confused by review comments :)

Alf: Replaced MockSessionStore (test_application_mediator*) and MockSession in test_application_mediator.cpp with stubs...also removed the NiceMock on the surface

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:478
http://jenkins.qa.ubuntu.com/job/mir-ci/30/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-quantal-amd64-ci/30//console

Click here to trigger a rebuild:
http://jenkins.qa.ubuntu.com/job/mir-ci/30//rebuild/?

review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

I think some licenses are still wrong.

What's going on with StubSessionStore? There appear to be two identical derived classes in separate test files - and no other uses. If the idea is to deduplicate two stubs that were accidentally the same, then why end up with three, one of which has behaviour that isn't used?

I don't see the need to replace perfectly good stub classes using NiceMock to adapt mock classes to that need.

review: Needs Fixing
Revision history for this message
Robert Carr (robertcarr) wrote :

I've fixed StubSessionStore to be shared between test_application_mediator_gbm and test_application_mediator_android. test_application_mediator is still using a mock session store due to the behavior testing on close_session.

Likewise test_application_mediator is still using a mock surface in the stub session (test_application_mediator::StubSession::get_surface) in an attempt to add some specification to the interface between surface and application mediator (which methods of surface may application mediator access?). Ultimately I think we will end up with another interface here, but I think it's a mild improvement.

Revision history for this message
Robert Carr (robertcarr) wrote :

Fixed license headers

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:480
http://jenkins.qa.ubuntu.com/job/mir-ci/46/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-quantal-amd64-ci/47//console

Click here to trigger a rebuild:
http://jenkins.qa.ubuntu.com/job/mir-ci/46//rebuild/?

review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:481
http://jenkins.qa.ubuntu.com/job/mir-ci/48/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-quantal-amd64-ci/49//console

Click here to trigger a rebuild:
http://jenkins.qa.ubuntu.com/job/mir-ci/48//rebuild/?

review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

LBTM

review: Approve
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> Likewise test_application_mediator is still using a mock surface in the stub
> session (test_application_mediator::StubSession::get_surface) in an attempt to
> add some specification to the interface between surface and application
> mediator (which methods of surface may application mediator access?).

I don't understand how having a mock here will help, but I guess we can always
change it to a stub later as needed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/mir_test_doubles/mock_session.h'
2--- include/mir_test_doubles/mock_session.h 2013-03-07 21:35:30 +0000
3+++ include/mir_test_doubles/mock_session.h 2013-03-12 00:14:21 +0000
4@@ -1,16 +1,16 @@
5 /*
6 * Copyright © 2013 Canonical Ltd.
7 *
8- * This program is free software: you can redistribute it and/or modify
9- * it under the terms of the GNU General Public License version 3 as
10- * published by the Free Software Foundation.
11+ * This program is free software: you can redistribute it and/or modify it
12+ * under the terms of the GNU Lesser General Public License version 3,
13+ * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20- * You should have received a copy of the GNU General Public License
21+ * You should have received a copy of the GNU Lesser General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * Authored by: Robert Carr <robert.carr@canonical.com>
25
26=== added file 'include/mir_test_doubles/mock_session_store.h'
27--- include/mir_test_doubles/mock_session_store.h 1970-01-01 00:00:00 +0000
28+++ include/mir_test_doubles/mock_session_store.h 2013-03-12 00:14:21 +0000
29@@ -0,0 +1,48 @@
30+/*
31+ * Copyright © 2013 Canonical Ltd.
32+ *
33+ * This program is free software: you can redistribute it and/or modify
34+ * it under the terms of the GNU Lesser General Public License version 3 as
35+ * published by the Free Software Foundation.
36+ *
37+ * This program is distributed in the hope that it will be useful,
38+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
39+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40+ * GNU General Public License for more details.
41+ *
42+ * You should have received a copy of the GNU Lesser General Public License
43+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
44+ *
45+ * Authored by: Robert Carr <robert.carr@canonical.com>
46+ */
47+
48+#ifndef MIR_TEST_DOUBLES_MOCK_SESSION_STORE_H_
49+#define MIR_TEST_DOUBLES_MOCK_SESSION_STORE_H_
50+
51+#include "mir/shell/session_store.h"
52+
53+#include <gmock/gmock.h>
54+
55+namespace mir
56+{
57+namespace test
58+{
59+namespace doubles
60+{
61+
62+struct MockSessionStore : public shell::SessionStore
63+{
64+ MOCK_METHOD1(open_session, std::shared_ptr<shell::Session>(std::string const&));
65+ MOCK_METHOD1(close_session, void(std::shared_ptr<shell::Session> const&));
66+
67+ MOCK_METHOD2(tag_session_with_lightdm_id, void(std::shared_ptr<shell::Session> const&, int));
68+ MOCK_METHOD1(focus_session_with_lightdm_id, void(int));
69+
70+ MOCK_METHOD0(shutdown, void());
71+};
72+
73+}
74+}
75+} // namespace mir
76+
77+#endif // MIR_TEST_DOUBLES_MOCK_SESSION_STORE_H_
78
79=== added file 'include/mir_test_doubles/mock_surface.h'
80--- include/mir_test_doubles/mock_surface.h 1970-01-01 00:00:00 +0000
81+++ include/mir_test_doubles/mock_surface.h 2013-03-12 00:14:21 +0000
82@@ -0,0 +1,50 @@
83+/*
84+ * Copyright © 2013 Canonical Ltd.
85+ *
86+ * This program is free software: you can redistribute it and/or modify it
87+ * under the terms of the GNU Lesser General Public License version 3,
88+ * as published by the Free Software Foundation.
89+ *
90+ * This program is distributed in the hope that it will be useful,
91+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
92+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93+ * GNU General Public License for more details.
94+ *
95+ * You should have received a copy of the GNU Lesser General Public License
96+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
97+ *
98+ * Authored by: Robert Carr <robert.carr@canonical.com>
99+ */
100+
101+#ifndef MIR_TEST_DOUBLES_MOCK_SURFACE_H_
102+#define MIR_TEST_DOUBLES_MOCK_SURFACE_H_
103+
104+#include "mir/shell/surface.h"
105+
106+#include <memory>
107+
108+namespace mir
109+{
110+namespace test
111+{
112+namespace doubles
113+{
114+
115+struct MockSurface : public shell::Surface
116+{
117+ MOCK_METHOD0(hide, void());
118+ MOCK_METHOD0(show, void());
119+ MOCK_METHOD0(destroy, void());
120+ MOCK_METHOD0(shutdown, void());
121+ MOCK_METHOD0(advance_client_buffer, void());
122+
123+ MOCK_CONST_METHOD0(size, geometry::Size ());
124+ MOCK_CONST_METHOD0(pixel_format, geometry::PixelFormat ());
125+ MOCK_CONST_METHOD0(client_buffer, std::shared_ptr<compositor::Buffer> ());
126+};
127+
128+}
129+}
130+} // namespace mir
131+
132+#endif // MIR_TEST_DOUBLES_MOCK_SURFACE_H_
133
134=== added file 'include/mir_test_doubles/stub_session.h'
135--- include/mir_test_doubles/stub_session.h 1970-01-01 00:00:00 +0000
136+++ include/mir_test_doubles/stub_session.h 2013-03-12 00:14:21 +0000
137@@ -0,0 +1,63 @@
138+/*
139+ * Copyright © 2013 Canonical Ltd.
140+ *
141+ * This program is free software: you can redistribute it and/or modify it
142+ * under the terms of the GNU Lesser General Public License version 3,
143+ * as published by the Free Software Foundation.
144+ *
145+ * This program is distributed in the hope that it will be useful,
146+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
147+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148+ * GNU General Public License for more details.
149+ *
150+ * You should have received a copy of the GNU Lesser General Public License
151+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
152+ *
153+ * Authored by: Robert Carr <robert.carr@canonical.com>
154+ */
155+
156+#ifndef MIR_TEST_DOUBLES_STUB_SESSION_H_
157+#define MIR_TEST_DOUBLES_STUB_SESSION_H_
158+
159+#include "mir/shell/session.h"
160+
161+namespace mir
162+{
163+namespace test
164+{
165+namespace doubles
166+{
167+
168+struct StubSession : public shell::Session
169+{
170+ shell::SurfaceId create_surface(shell::SurfaceCreationParameters const& /* params */)
171+ {
172+ return shell::SurfaceId{0};
173+ }
174+ void destroy_surface(shell::SurfaceId /* surface */)
175+ {
176+ }
177+ std::shared_ptr<shell::Surface> get_surface(shell::SurfaceId /* surface */) const
178+ {
179+ return std::shared_ptr<shell::Surface>();
180+ }
181+ std::string name()
182+ {
183+ return std::string();
184+ }
185+ void shutdown()
186+ {
187+ }
188+ void hide()
189+ {
190+ }
191+ void show()
192+ {
193+ }
194+};
195+
196+}
197+}
198+} // namespace mir
199+
200+#endif // MIR_TEST_DOUBLES_STUB_SESSION_H_
201
202=== added file 'include/mir_test_doubles/stub_session_store.h'
203--- include/mir_test_doubles/stub_session_store.h 1970-01-01 00:00:00 +0000
204+++ include/mir_test_doubles/stub_session_store.h 2013-03-12 00:14:21 +0000
205@@ -0,0 +1,56 @@
206+/*
207+ * Copyright © 2013 Canonical Ltd.
208+ *
209+ * This program is free software: you can redistribute it and/or modify it
210+ * under the terms of the GNU Lesser General Public License version 3,
211+ * as published by the Free Software Foundation.
212+ *
213+ * This program is distributed in the hope that it will be useful,
214+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
215+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
216+ * GNU General Public License for more details.
217+ *
218+ * You should have received a copy of the GNU Lesser General Public License
219+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
220+ *
221+ * Authored by: Robert Carr <robert.carr@canonical.com>
222+ */
223+
224+#ifndef MIR_TEST_DOUBLES_STUB_SESSION_STORE_H_
225+#define MIR_TEST_DOUBLES_STUB_SESSION_STORE_H_
226+
227+#include "mir/shell/session_store.h"
228+#include "mir_test_doubles/stub_session.h"
229+
230+namespace mir
231+{
232+namespace test
233+{
234+namespace doubles
235+{
236+
237+class StubSessionStore : public shell::SessionStore
238+{
239+ std::shared_ptr<shell::Session> open_session(std::string const& /* name */)
240+ {
241+ return std::make_shared<StubSession>();
242+ }
243+ void close_session(std::shared_ptr<shell::Session> const& /* session */)
244+ {
245+ }
246+ void tag_session_with_lightdm_id(std::shared_ptr<shell::Session> const& /* session */, int /* id */)
247+ {
248+ }
249+ void focus_session_with_lightdm_id(int /* id */)
250+ {
251+ }
252+ void shutdown()
253+ {
254+ }
255+};
256+
257+}
258+}
259+} // namespace mir
260+
261+#endif // MIR_TEST_DOUBLES_STUB_SESSION_STORE_H_
262
263=== modified file 'tests/integration-tests/cucumber/test_session_management_context.cpp'
264--- tests/integration-tests/cucumber/test_session_management_context.cpp 2013-03-07 21:35:30 +0000
265+++ tests/integration-tests/cucumber/test_session_management_context.cpp 2013-03-12 00:14:21 +0000
266@@ -25,6 +25,7 @@
267 #include "mir/graphics/viewable_area.h"
268
269 #include "mir_test_doubles/mock_session.h"
270+#include "mir_test_doubles/mock_session_store.h"
271 #include "mir_test/fake_shared.h"
272
273 #include <gtest/gtest.h>
274@@ -52,17 +53,6 @@
275 MOCK_METHOD0(the_drawer, std::shared_ptr<mc::Drawer>());
276 };
277
278-struct MockSessionStore : public msh::SessionStore
279-{
280- MOCK_METHOD1(open_session, std::shared_ptr<msh::Session>(std::string const&));
281- MOCK_METHOD1(close_session, void(std::shared_ptr<msh::Session> const&));
282-
283- MOCK_METHOD2(tag_session_with_lightdm_id, void(std::shared_ptr<msh::Session> const&, int));
284- MOCK_METHOD1(focus_session_with_lightdm_id, void(int));
285-
286- MOCK_METHOD0(shutdown, void());
287-};
288-
289 struct MockSurface : public msh::Surface
290 {
291 MOCK_METHOD0(hide, void());
292@@ -109,7 +99,7 @@
293 ctx = std::make_shared<mtc::SessionManagementContext>(server_configuration);
294 }
295 MockServerConfiguration server_configuration;
296- MockSessionStore session_store;
297+ mtd::MockSessionStore session_store;
298 std::shared_ptr<mtc::SessionManagementContext> ctx;
299
300 static msh::SurfaceId const test_surface_id;
301@@ -143,7 +133,7 @@
302 using namespace ::testing;
303
304 MockServerConfiguration server_configuration;
305- MockSessionStore session_store;
306+ mtd::MockSessionStore session_store;
307
308 EXPECT_CALL(server_configuration, the_session_store()).Times(1)
309 .WillOnce(Return(mt::fake_shared<msh::SessionStore>(session_store)));
310
311=== modified file 'tests/unit-tests/frontend/test_application_mediator.cpp'
312--- tests/unit-tests/frontend/test_application_mediator.cpp 2013-03-08 19:20:24 +0000
313+++ tests/unit-tests/frontend/test_application_mediator.cpp 2013-03-12 00:14:21 +0000
314@@ -23,14 +23,16 @@
315 #include "mir/frontend/application_mediator.h"
316 #include "mir/frontend/resource_cache.h"
317 #include "mir/shell/application_session.h"
318-#include "mir/shell/session_store.h"
319-#include "mir/shell/surface_factory.h"
320 #include "mir/graphics/display.h"
321 #include "mir/graphics/platform.h"
322 #include "mir/graphics/platform_ipc_package.h"
323 #include "mir/surfaces/surface.h"
324-#include "mir_test_doubles/null_buffer_bundle.h"
325 #include "mir_test_doubles/null_display.h"
326+#include "mir_test_doubles/mock_session_store.h"
327+#include "mir_test_doubles/mock_surface.h"
328+#include "mir_test_doubles/stub_buffer.h"
329+#include "mir_test_doubles/stub_session.h"
330+#include "mir_test/fake_shared.h"
331
332 #include "src/surfaces/proxy_surface.h"
333
334@@ -46,73 +48,34 @@
335 namespace geom = mir::geometry;
336 namespace mp = mir::protobuf;
337 namespace msh = mir::shell;
338-namespace mtd = mir::test::doubles;
339+namespace mt = mir::test;
340+namespace mtd = mt::doubles;
341
342 namespace
343 {
344
345-/*
346- * TODO: Fix design so that it's possible to unit-test ApplicationMediator
347- * without having to create doubles for classes so deep in its dependency
348- * hierarchy, and needing to resort to ugly tricks to get the information
349- * we need (e.g. see DestructionRecordingSession below).
350- *
351- * In particular, it would be nice if both mf::Session and ms::Surface were
352- * stubable/mockable.
353- */
354-
355-class DestructionRecordingSession : public msh::ApplicationSession
356-{
357-public:
358- DestructionRecordingSession(std::shared_ptr<msh::SurfaceFactory> const& surface_factory)
359- : msh::ApplicationSession{surface_factory, "Stub"}
360- {
361- destroyed = false;
362- }
363-
364- ~DestructionRecordingSession() { destroyed = true; }
365-
366- static bool destroyed;
367-};
368-
369-bool DestructionRecordingSession::destroyed{true};
370-
371-class StubSurfaceFactory : public msh::SurfaceFactory
372-{
373- public:
374- std::shared_ptr<msh::Surface> create_surface(const msh::SurfaceCreationParameters& /*params*/)
375- {
376- auto surface = std::make_shared<ms::Surface>("DummySurface",
377- std::make_shared<mtd::NullBufferBundle>());
378- surfaces.push_back(surface);
379-
380- return std::make_shared<ms::BasicProxySurface>(std::weak_ptr<ms::Surface>(surface));
381- }
382-
383-private:
384- std::vector<std::shared_ptr<ms::Surface>> surfaces;
385-};
386-
387-class StubSessionStore : public msh::SessionStore
388-{
389-public:
390- StubSessionStore()
391- : factory{std::make_shared<StubSurfaceFactory>()}
392- {
393- }
394-
395- std::shared_ptr<msh::Session> open_session(std::string const& /*name*/)
396- {
397- return std::make_shared<DestructionRecordingSession>(factory);
398- }
399-
400- void close_session(std::shared_ptr<msh::Session> const& /*session*/) {}
401-
402- void shutdown() {}
403- void tag_session_with_lightdm_id(std::shared_ptr<msh::Session> const&, int) {}
404- void focus_session_with_lightdm_id(int) {}
405-
406- std::shared_ptr<msh::SurfaceFactory> factory;
407+class StubbedSession : public mtd::StubSession
408+{
409+public:
410+ StubbedSession()
411+ {
412+ using namespace ::testing;
413+
414+ mock_surface = std::make_shared<mtd::MockSurface>();
415+
416+ EXPECT_CALL(*mock_surface, size()).Times(AnyNumber()).WillRepeatedly(Return(geom::Size()));
417+ EXPECT_CALL(*mock_surface, pixel_format()).Times(AnyNumber()).WillRepeatedly(Return(geom::PixelFormat()));
418+ EXPECT_CALL(*mock_surface, client_buffer()).Times(AnyNumber()).WillRepeatedly(Return(mt::fake_shared(stub_buffer)));
419+ EXPECT_CALL(*mock_surface, advance_client_buffer()).Times(AnyNumber());
420+ }
421+
422+ std::shared_ptr<msh::Surface> get_surface(msh::SurfaceId /* surface */) const
423+ {
424+ return mock_surface;
425+ }
426+
427+ std::shared_ptr<mtd::MockSurface> mock_surface;
428+ mtd::StubBuffer stub_buffer;
429 };
430
431 class MockGraphicBufferAllocator : public mc::GraphicBufferAllocator
432@@ -157,7 +120,7 @@
433 struct ApplicationMediatorTest : public ::testing::Test
434 {
435 ApplicationMediatorTest()
436- : session_store{std::make_shared<StubSessionStore>()},
437+ : session_store{std::make_shared<testing::NiceMock<mtd::MockSessionStore>>()},
438 graphics_platform{std::make_shared<StubPlatform>()},
439 graphics_display{std::make_shared<mtd::NullDisplay>()},
440 buffer_allocator{std::make_shared<testing::NiceMock<MockGraphicBufferAllocator>>()},
441@@ -167,9 +130,12 @@
442 buffer_allocator, report, resource_cache},
443 null_callback{google::protobuf::NewPermanentCallback(google::protobuf::DoNothing)}
444 {
445+ using namespace ::testing;
446+
447+ ON_CALL(*session_store, open_session(_)).WillByDefault(Return(std::make_shared<StubbedSession>()));
448 }
449
450- std::shared_ptr<msh::SessionStore> const session_store;
451+ std::shared_ptr<testing::NiceMock<mtd::MockSessionStore>> const session_store;
452 std::shared_ptr<mg::Platform> const graphics_platform;
453 std::shared_ptr<mg::Display> const graphics_display;
454 std::shared_ptr<testing::NiceMock<MockGraphicBufferAllocator>> const buffer_allocator;
455@@ -183,16 +149,15 @@
456
457 TEST_F(ApplicationMediatorTest, disconnect_releases_session)
458 {
459+ using namespace ::testing;
460+
461 mp::ConnectParameters connect_parameters;
462 mp::Connection connection;
463+
464+ EXPECT_CALL(*session_store, close_session(_)).Times(1);
465
466 mediator.connect(nullptr, &connect_parameters, &connection, null_callback.get());
467-
468- EXPECT_FALSE(DestructionRecordingSession::destroyed);
469-
470 mediator.disconnect(nullptr, nullptr, nullptr, null_callback.get());
471-
472- EXPECT_TRUE(DestructionRecordingSession::destroyed);
473 }
474
475 TEST_F(ApplicationMediatorTest, calling_methods_before_connect_throws)
476
477=== modified file 'tests/unit-tests/frontend/test_application_mediator_android.cpp'
478--- tests/unit-tests/frontend/test_application_mediator_android.cpp 2013-03-06 12:54:33 +0000
479+++ tests/unit-tests/frontend/test_application_mediator_android.cpp 2013-03-12 00:14:21 +0000
480@@ -22,12 +22,14 @@
481 #include "mir/frontend/resource_cache.h"
482 #include "mir/shell/application_session.h"
483 #include "mir/shell/session_store.h"
484-#include "mir/shell/surface_factory.h"
485+#include "mir/shell/surface_creation_parameters.h"
486 #include "mir/graphics/display.h"
487 #include "mir/graphics/platform.h"
488 #include "mir/graphics/platform_ipc_package.h"
489
490 #include "mir_test_doubles/null_display.h"
491+#include "mir_test_doubles/mock_session.h"
492+#include "mir_test_doubles/stub_session_store.h"
493
494 #include <gtest/gtest.h>
495
496@@ -44,45 +46,6 @@
497 namespace
498 {
499
500-/*
501- * TODO: Fix design so that it's possible to unit-test ApplicationMediator
502- * without having to create doubles for classes so deep in its dependency
503- * hierarchy.
504- *
505- * In particular, it would be nice if mf::Session was stubable/mockable.
506- */
507-
508-class StubSurfaceFactory : public msh::SurfaceFactory
509-{
510- public:
511- std::shared_ptr<msh::Surface> create_surface(const msh::SurfaceCreationParameters& /*params*/)
512- {
513- return std::shared_ptr<msh::Surface>();
514- }
515-};
516-
517-class StubSessionStore : public msh::SessionStore
518-{
519-public:
520- StubSessionStore()
521- : factory{std::make_shared<StubSurfaceFactory>()}
522- {
523- }
524-
525- std::shared_ptr<msh::Session> open_session(std::string const& /*name*/)
526- {
527- return std::make_shared<msh::ApplicationSession>(factory, "stub");
528- }
529-
530- void close_session(std::shared_ptr<msh::Session> const& /*session*/) {}
531- void tag_session_with_lightdm_id(std::shared_ptr<msh::Session> const& /*session*/, int /*id*/) {}
532- void focus_session_with_lightdm_id(int /*id*/) {}
533-
534- void shutdown() {}
535-
536- std::shared_ptr<msh::SurfaceFactory> factory;
537-};
538-
539 class StubGraphicBufferAllocator : public mc::GraphicBufferAllocator
540 {
541 public:
542@@ -122,7 +85,7 @@
543 struct ApplicationMediatorAndroidTest : public ::testing::Test
544 {
545 ApplicationMediatorAndroidTest()
546- : session_store{std::make_shared<StubSessionStore>()},
547+ : session_store{std::make_shared<mtd::StubSessionStore>()},
548 graphics_platform{std::make_shared<StubPlatform>()},
549 graphics_display{std::make_shared<mtd::NullDisplay>()},
550 buffer_allocator{std::make_shared<StubGraphicBufferAllocator>()},
551@@ -134,7 +97,7 @@
552 {
553 }
554
555- std::shared_ptr<msh::SessionStore> const session_store;
556+ std::shared_ptr<StubSessionStore> const session_store;
557 std::shared_ptr<StubPlatform> const graphics_platform;
558 std::shared_ptr<mg::Display> const graphics_display;
559 std::shared_ptr<mc::GraphicBufferAllocator> const buffer_allocator;
560
561=== modified file 'tests/unit-tests/frontend/test_application_mediator_gbm.cpp'
562--- tests/unit-tests/frontend/test_application_mediator_gbm.cpp 2013-03-06 12:54:33 +0000
563+++ tests/unit-tests/frontend/test_application_mediator_gbm.cpp 2013-03-12 00:14:21 +0000
564@@ -22,7 +22,7 @@
565 #include "mir/frontend/resource_cache.h"
566 #include "mir/shell/application_session.h"
567 #include "mir/shell/session_store.h"
568-#include "mir/shell/surface_factory.h"
569+#include "mir/shell/surface_creation_parameters.h"
570 #include "mir/graphics/display.h"
571 #include "mir/graphics/drm_authenticator.h"
572 #include "mir/graphics/platform.h"
573@@ -32,6 +32,8 @@
574 #include <boost/throw_exception.hpp>
575
576 #include "mir_test_doubles/null_display.h"
577+#include "mir_test_doubles/mock_session.h"
578+#include "mir_test_doubles/stub_session_store.h"
579
580 #include <gtest/gtest.h>
581 #include <gmock/gmock.h>
582@@ -47,45 +49,6 @@
583 namespace
584 {
585
586-/*
587- * TODO: Fix design so that it's possible to unit-test ApplicationMediator
588- * without having to create doubles for classes so deep in its dependency
589- * hierarchy.
590- *
591- * In particular, it would be nice if msh::ApplicationSession was stubable/mockable.
592- */
593-
594-class StubSurfaceFactory : public msh::SurfaceFactory
595-{
596- public:
597- std::shared_ptr<msh::Surface> create_surface(const msh::SurfaceCreationParameters& /*params*/)
598- {
599- return std::shared_ptr<msh::Surface>();
600- }
601-};
602-
603-class StubSessionStore : public msh::SessionStore
604-{
605-public:
606- StubSessionStore()
607- : factory{std::make_shared<StubSurfaceFactory>()}
608- {
609- }
610-
611- std::shared_ptr<msh::Session> open_session(std::string const& /*name*/)
612- {
613- return std::make_shared<msh::ApplicationSession>(factory, "stub");
614- }
615-
616- void close_session(std::shared_ptr<msh::Session> const& /*session*/) {}
617-
618- void shutdown() {}
619- void tag_session_with_lightdm_id(std::shared_ptr<msh::Session> const&, int) {}
620- void focus_session_with_lightdm_id(int) {}
621-
622- std::shared_ptr<msh::SurfaceFactory> factory;
623-};
624-
625 class StubGraphicBufferAllocator : public mc::GraphicBufferAllocator
626 {
627 public:
628@@ -127,7 +90,7 @@
629 struct ApplicationMediatorGBMTest : public ::testing::Test
630 {
631 ApplicationMediatorGBMTest()
632- : session_store{std::make_shared<StubSessionStore>()},
633+ : session_store{std::make_shared<mtd::StubSessionStore>()},
634 mock_platform{std::make_shared<MockAuthenticatingPlatform>()},
635 graphics_display{std::make_shared<mtd::NullDisplay>()},
636 buffer_allocator{std::make_shared<StubGraphicBufferAllocator>()},
637@@ -139,7 +102,7 @@
638 {
639 }
640
641- std::shared_ptr<msh::SessionStore> const session_store;
642+ std::shared_ptr<mtd::StubSessionStore> const session_store;
643 std::shared_ptr<MockAuthenticatingPlatform> const mock_platform;
644 std::shared_ptr<mg::Display> const graphics_display;
645 std::shared_ptr<mc::GraphicBufferAllocator> const buffer_allocator;
646
647=== modified file 'tests/unit-tests/shell/test_application_session.cpp'
648--- tests/unit-tests/shell/test_application_session.cpp 2013-03-06 12:54:33 +0000
649+++ tests/unit-tests/shell/test_application_session.cpp 2013-03-12 00:14:21 +0000
650@@ -21,6 +21,7 @@
651 #include "mir/shell/surface_creation_parameters.h"
652 #include "mir_test/fake_shared.h"
653 #include "mir_test_doubles/mock_surface_factory.h"
654+#include "mir_test_doubles/mock_surface.h"
655
656 #include "src/surfaces/proxy_surface.h"
657
658@@ -33,47 +34,11 @@
659 namespace mt = mir::test;
660 namespace mtd = mir::test::doubles;
661
662-namespace
663-{
664-class MockSurface : public msh::Surface
665-{
666-public:
667- MockSurface(std::weak_ptr<ms::Surface> const& surface) :
668- impl(surface)
669- {
670- using namespace testing;
671-
672- ON_CALL(*this, hide()).WillByDefault(Invoke(&impl, &ms::BasicProxySurface::hide));
673- ON_CALL(*this, show()).WillByDefault(Invoke(&impl, &ms::BasicProxySurface::show));
674- ON_CALL(*this, destroy()).WillByDefault(Invoke(&impl, &ms::BasicProxySurface::destroy));
675- ON_CALL(*this, shutdown()).WillByDefault(Invoke(&impl, &ms::BasicProxySurface::shutdown));
676- ON_CALL(*this, advance_client_buffer()).WillByDefault(Invoke(&impl, &ms::BasicProxySurface::advance_client_buffer));
677-
678- ON_CALL(*this, size()).WillByDefault(Invoke(&impl, &ms::BasicProxySurface::size));
679- ON_CALL(*this, pixel_format()).WillByDefault(Invoke(&impl, &ms::BasicProxySurface::pixel_format));
680- ON_CALL(*this, client_buffer()).WillByDefault(Invoke(&impl, &ms::BasicProxySurface::client_buffer));
681- }
682-
683- MOCK_METHOD0(hide, void());
684- MOCK_METHOD0(show, void());
685- MOCK_METHOD0(destroy, void());
686- MOCK_METHOD0(shutdown, void());
687- MOCK_METHOD0(advance_client_buffer, void());
688-
689- MOCK_CONST_METHOD0(size, mir::geometry::Size ());
690- MOCK_CONST_METHOD0(pixel_format, mir::geometry::PixelFormat ());
691- MOCK_CONST_METHOD0(client_buffer, std::shared_ptr<mc::Buffer> ());
692-
693-private:
694- ms::BasicProxySurface impl;
695-};
696-}
697-
698 TEST(ApplicationSession, create_and_destroy_surface)
699 {
700 using namespace ::testing;
701
702- auto const mock_surface = std::make_shared<MockSurface>(std::shared_ptr<ms::Surface>());
703+ auto const mock_surface = std::make_shared<mtd::MockSurface>();
704 mtd::MockSurfaceFactory surface_factory;
705 ON_CALL(surface_factory, create_surface(_)).WillByDefault(Return(mock_surface));
706
707@@ -93,7 +58,7 @@
708 {
709 using namespace ::testing;
710
711- auto const mock_surface = std::make_shared<MockSurface>(std::shared_ptr<ms::Surface>());
712+ auto const mock_surface = std::make_shared<mtd::MockSurface>();
713 mtd::MockSurfaceFactory surface_factory;
714 ON_CALL(surface_factory, create_surface(_)).WillByDefault(Return(mock_surface));
715

Subscribers

People subscribed via source and target branches