Mir

Merge lp:~robertcarr/mir/cleanup-session-manager-unit-test into lp:~mir-team/mir/trunk

Proposed by Robert Carr
Status: Merged
Approved by: Robert Carr
Approved revision: no longer in the source branch.
Merged at revision: 471
Proposed branch: lp:~robertcarr/mir/cleanup-session-manager-unit-test
Merge into: lp:~mir-team/mir/trunk
Diff against target: 155 lines (+27/-59)
1 file modified
tests/unit-tests/sessions/test_session_manager.cpp (+27/-59)
To merge this branch: bzr merge lp:~robertcarr/mir/cleanup-session-manager-unit-test
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alan Griffiths Approve
Alexandros Frantzis (community) Approve
Review via email: mp+151866@code.launchpad.net

Commit message

Reduce code duplication in session manager unit test to ease refactoring.

Description of the change

Reduce code duplication in session manager unit test to ease refactoring.

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 :

34 + std::shared_ptr<msess::SessionManager> session_manager;

We could make this a normal object instead of a shared_ptr, by using the Test fixture constructor, instead of SetUp(), to initialize the fixture.

In general, I prefer using the constructor since it allows us to initialize members objects (like session_manager in this case) and also to have const members variables. Of course, there are a few cases when we need to use SetUp(), as mentioned in the linked FAQ below.

See https://code.google.com/p/googletest/wiki/V1_6_FAQ#Should_I_use_the_constructor/destructor_of_the_test_fixture_or_t

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

Good idea!

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

22 +
23 +

A couple of extra spaces introduce here, but nothing to block on.

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

Apart from the merge conflicts looks OK.

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

Trunk merged.

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

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

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

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/unit-tests/sessions/test_session_manager.cpp'
2--- tests/unit-tests/sessions/test_session_manager.cpp 2013-03-06 12:54:33 +0000
3+++ tests/unit-tests/sessions/test_session_manager.cpp 2013-03-06 18:15:25 +0000
4@@ -64,22 +64,30 @@
5 MOCK_METHOD1(set_focus_to, void(std::shared_ptr<msh::Session> const&));
6 };
7
8-}
9-
10-TEST(SessionManager, open_and_close_session)
11+struct SessionManagerSetup : public testing::Test
12 {
13- using namespace ::testing;
14+ SessionManagerSetup()
15+ : session_manager(mt::fake_shared(surface_factory),
16+ mt::fake_shared(container),
17+ mt::fake_shared(sequence),
18+ mt::fake_shared(focus_setter))
19+ {
20+ }
21+
22 mtd::MockSurfaceFactory surface_factory;
23 MockSessionContainer container;
24 MockFocusSequence sequence;
25 MockFocusSetter focus_setter;
26
27- msh::SessionManager session_manager(
28- mt::fake_shared(surface_factory),
29- mt::fake_shared(container),
30- mt::fake_shared(sequence),
31- mt::fake_shared(focus_setter));
32-
33+ msh::SessionManager session_manager;
34+};
35+
36+}
37+
38+TEST_F(SessionManagerSetup, open_and_close_session)
39+{
40+ using namespace ::testing;
41+
42 EXPECT_CALL(container, insert_session(_)).Times(1);
43 EXPECT_CALL(container, remove_session(_)).Times(1);
44 EXPECT_CALL(focus_setter, set_focus_to(_));
45@@ -91,19 +99,9 @@
46 session_manager.close_session(session);
47 }
48
49-TEST(SessionManager, closing_session_removes_surfaces)
50+TEST_F(SessionManagerSetup, closing_session_removes_surfaces)
51 {
52 using namespace ::testing;
53- mtd::MockSurfaceFactory surface_factory;
54- MockSessionContainer container;
55- MockFocusSequence sequence;
56- MockFocusSetter mechanism;
57-
58- msh::SessionManager session_manager(
59- mt::fake_shared(surface_factory),
60- mt::fake_shared(container),
61- mt::fake_shared(sequence),
62- mt::fake_shared(mechanism));
63
64 EXPECT_CALL(surface_factory, create_surface(_)).Times(1);
65 std::shared_ptr<ms::BufferBundle> buffer_bundle(new mtd::NullBufferBundle());
66@@ -117,8 +115,8 @@
67 EXPECT_CALL(container, insert_session(_)).Times(1);
68 EXPECT_CALL(container, remove_session(_)).Times(1);
69
70- EXPECT_CALL(mechanism, set_focus_to(_)).Times(1);
71- EXPECT_CALL(mechanism, set_focus_to(std::shared_ptr<msh::Session>())).Times(1);
72+ EXPECT_CALL(focus_setter, set_focus_to(_)).Times(1);
73+ EXPECT_CALL(focus_setter, set_focus_to(std::shared_ptr<msh::Session>())).Times(1);
74
75 EXPECT_CALL(sequence, default_focus()).WillOnce(Return((std::shared_ptr<msh::Session>())));
76
77@@ -128,64 +126,34 @@
78 session_manager.close_session(session);
79 }
80
81-TEST(SessionManager, new_applications_receive_focus)
82+TEST_F(SessionManagerSetup, new_applications_receive_focus)
83 {
84 using namespace ::testing;
85- mtd::MockSurfaceFactory surface_factory;
86- MockSessionContainer container;
87- MockFocusSequence sequence;
88- MockFocusSetter mechanism;
89 std::shared_ptr<msh::Session> new_session;
90
91- msh::SessionManager session_manager(
92- mt::fake_shared(surface_factory),
93- mt::fake_shared(container),
94- mt::fake_shared(sequence),
95- mt::fake_shared(mechanism));
96-
97 EXPECT_CALL(container, insert_session(_)).Times(1);
98- EXPECT_CALL(mechanism, set_focus_to(_)).WillOnce(SaveArg<0>(&new_session));
99+ EXPECT_CALL(focus_setter, set_focus_to(_)).WillOnce(SaveArg<0>(&new_session));
100
101 auto session = session_manager.open_session("Visual Basic Studio");
102 EXPECT_EQ(session, new_session);
103 }
104
105-TEST(SessionManager, apps_selected_by_id_receive_focus)
106+TEST_F(SessionManagerSetup, apps_selected_by_id_receive_focus)
107 {
108 using namespace ::testing;
109- mtd::MockSurfaceFactory surface_factory;
110- NiceMock<MockSessionContainer> container;
111- MockFocusSequence sequence;
112- NiceMock<MockFocusSetter> mechanism;
113-
114- msh::SessionManager session_manager(
115- mt::fake_shared(surface_factory),
116- mt::fake_shared(container),
117- mt::fake_shared(sequence),
118- mt::fake_shared(mechanism));
119
120 auto session1 = session_manager.open_session("Visual Basic Studio");
121 auto session2 = session_manager.open_session("IntelliJ IDEA");
122
123 session_manager.tag_session_with_lightdm_id(session1, 1);
124
125- EXPECT_CALL(mechanism, set_focus_to(session1));
126+ EXPECT_CALL(focus_setter, set_focus_to(session1));
127 session_manager.focus_session_with_lightdm_id(1);
128 }
129
130-TEST(SessionManager, closing_apps_selected_by_id_changes_focus)
131+TEST_F(SessionManagerSetup, closing_apps_selected_by_id_changes_focus)
132 {
133 using namespace ::testing;
134- mtd::MockSurfaceFactory surface_factory;
135- NiceMock<MockSessionContainer> container;
136- MockFocusSequence sequence;
137- NiceMock<MockFocusSetter> mechanism;
138-
139- msh::SessionManager session_manager(
140- mt::fake_shared(surface_factory),
141- mt::fake_shared(container),
142- mt::fake_shared(sequence),
143- mt::fake_shared(mechanism));
144
145 auto session1 = session_manager.open_session("Visual Basic Studio");
146 auto session2 = session_manager.open_session("IntelliJ IDEA");
147@@ -194,7 +162,7 @@
148 session_manager.focus_session_with_lightdm_id(1);
149
150 EXPECT_CALL(sequence, default_focus()).WillOnce(Return(session2));
151- EXPECT_CALL(mechanism, set_focus_to(session2));
152+ EXPECT_CALL(focus_setter, set_focus_to(session2));
153
154 session_manager.close_session(session1);
155 }

Subscribers

People subscribed via source and target branches