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
=== modified file 'tests/unit-tests/sessions/test_session_manager.cpp'
--- tests/unit-tests/sessions/test_session_manager.cpp 2013-03-06 12:54:33 +0000
+++ tests/unit-tests/sessions/test_session_manager.cpp 2013-03-06 18:15:25 +0000
@@ -64,22 +64,30 @@
64 MOCK_METHOD1(set_focus_to, void(std::shared_ptr<msh::Session> const&));64 MOCK_METHOD1(set_focus_to, void(std::shared_ptr<msh::Session> const&));
65};65};
6666
67}67struct SessionManagerSetup : public testing::Test
68
69TEST(SessionManager, open_and_close_session)
70{68{
71 using namespace ::testing;69 SessionManagerSetup()
70 : session_manager(mt::fake_shared(surface_factory),
71 mt::fake_shared(container),
72 mt::fake_shared(sequence),
73 mt::fake_shared(focus_setter))
74 {
75 }
76
72 mtd::MockSurfaceFactory surface_factory;77 mtd::MockSurfaceFactory surface_factory;
73 MockSessionContainer container;78 MockSessionContainer container;
74 MockFocusSequence sequence;79 MockFocusSequence sequence;
75 MockFocusSetter focus_setter;80 MockFocusSetter focus_setter;
7681
77 msh::SessionManager session_manager(82 msh::SessionManager session_manager;
78 mt::fake_shared(surface_factory),83};
79 mt::fake_shared(container),84
80 mt::fake_shared(sequence),85}
81 mt::fake_shared(focus_setter));86
8287TEST_F(SessionManagerSetup, open_and_close_session)
88{
89 using namespace ::testing;
90
83 EXPECT_CALL(container, insert_session(_)).Times(1);91 EXPECT_CALL(container, insert_session(_)).Times(1);
84 EXPECT_CALL(container, remove_session(_)).Times(1);92 EXPECT_CALL(container, remove_session(_)).Times(1);
85 EXPECT_CALL(focus_setter, set_focus_to(_));93 EXPECT_CALL(focus_setter, set_focus_to(_));
@@ -91,19 +99,9 @@
91 session_manager.close_session(session);99 session_manager.close_session(session);
92}100}
93101
94TEST(SessionManager, closing_session_removes_surfaces)102TEST_F(SessionManagerSetup, closing_session_removes_surfaces)
95{103{
96 using namespace ::testing;104 using namespace ::testing;
97 mtd::MockSurfaceFactory surface_factory;
98 MockSessionContainer container;
99 MockFocusSequence sequence;
100 MockFocusSetter mechanism;
101
102 msh::SessionManager session_manager(
103 mt::fake_shared(surface_factory),
104 mt::fake_shared(container),
105 mt::fake_shared(sequence),
106 mt::fake_shared(mechanism));
107105
108 EXPECT_CALL(surface_factory, create_surface(_)).Times(1);106 EXPECT_CALL(surface_factory, create_surface(_)).Times(1);
109 std::shared_ptr<ms::BufferBundle> buffer_bundle(new mtd::NullBufferBundle());107 std::shared_ptr<ms::BufferBundle> buffer_bundle(new mtd::NullBufferBundle());
@@ -117,8 +115,8 @@
117 EXPECT_CALL(container, insert_session(_)).Times(1);115 EXPECT_CALL(container, insert_session(_)).Times(1);
118 EXPECT_CALL(container, remove_session(_)).Times(1);116 EXPECT_CALL(container, remove_session(_)).Times(1);
119117
120 EXPECT_CALL(mechanism, set_focus_to(_)).Times(1);118 EXPECT_CALL(focus_setter, set_focus_to(_)).Times(1);
121 EXPECT_CALL(mechanism, set_focus_to(std::shared_ptr<msh::Session>())).Times(1);119 EXPECT_CALL(focus_setter, set_focus_to(std::shared_ptr<msh::Session>())).Times(1);
122120
123 EXPECT_CALL(sequence, default_focus()).WillOnce(Return((std::shared_ptr<msh::Session>())));121 EXPECT_CALL(sequence, default_focus()).WillOnce(Return((std::shared_ptr<msh::Session>())));
124122
@@ -128,64 +126,34 @@
128 session_manager.close_session(session);126 session_manager.close_session(session);
129}127}
130128
131TEST(SessionManager, new_applications_receive_focus)129TEST_F(SessionManagerSetup, new_applications_receive_focus)
132{130{
133 using namespace ::testing;131 using namespace ::testing;
134 mtd::MockSurfaceFactory surface_factory;
135 MockSessionContainer container;
136 MockFocusSequence sequence;
137 MockFocusSetter mechanism;
138 std::shared_ptr<msh::Session> new_session;132 std::shared_ptr<msh::Session> new_session;
139133
140 msh::SessionManager session_manager(
141 mt::fake_shared(surface_factory),
142 mt::fake_shared(container),
143 mt::fake_shared(sequence),
144 mt::fake_shared(mechanism));
145
146 EXPECT_CALL(container, insert_session(_)).Times(1);134 EXPECT_CALL(container, insert_session(_)).Times(1);
147 EXPECT_CALL(mechanism, set_focus_to(_)).WillOnce(SaveArg<0>(&new_session));135 EXPECT_CALL(focus_setter, set_focus_to(_)).WillOnce(SaveArg<0>(&new_session));
148136
149 auto session = session_manager.open_session("Visual Basic Studio");137 auto session = session_manager.open_session("Visual Basic Studio");
150 EXPECT_EQ(session, new_session);138 EXPECT_EQ(session, new_session);
151}139}
152140
153TEST(SessionManager, apps_selected_by_id_receive_focus)141TEST_F(SessionManagerSetup, apps_selected_by_id_receive_focus)
154{142{
155 using namespace ::testing;143 using namespace ::testing;
156 mtd::MockSurfaceFactory surface_factory;
157 NiceMock<MockSessionContainer> container;
158 MockFocusSequence sequence;
159 NiceMock<MockFocusSetter> mechanism;
160
161 msh::SessionManager session_manager(
162 mt::fake_shared(surface_factory),
163 mt::fake_shared(container),
164 mt::fake_shared(sequence),
165 mt::fake_shared(mechanism));
166144
167 auto session1 = session_manager.open_session("Visual Basic Studio");145 auto session1 = session_manager.open_session("Visual Basic Studio");
168 auto session2 = session_manager.open_session("IntelliJ IDEA");146 auto session2 = session_manager.open_session("IntelliJ IDEA");
169147
170 session_manager.tag_session_with_lightdm_id(session1, 1);148 session_manager.tag_session_with_lightdm_id(session1, 1);
171149
172 EXPECT_CALL(mechanism, set_focus_to(session1));150 EXPECT_CALL(focus_setter, set_focus_to(session1));
173 session_manager.focus_session_with_lightdm_id(1);151 session_manager.focus_session_with_lightdm_id(1);
174}152}
175153
176TEST(SessionManager, closing_apps_selected_by_id_changes_focus)154TEST_F(SessionManagerSetup, closing_apps_selected_by_id_changes_focus)
177{155{
178 using namespace ::testing;156 using namespace ::testing;
179 mtd::MockSurfaceFactory surface_factory;
180 NiceMock<MockSessionContainer> container;
181 MockFocusSequence sequence;
182 NiceMock<MockFocusSetter> mechanism;
183
184 msh::SessionManager session_manager(
185 mt::fake_shared(surface_factory),
186 mt::fake_shared(container),
187 mt::fake_shared(sequence),
188 mt::fake_shared(mechanism));
189157
190 auto session1 = session_manager.open_session("Visual Basic Studio");158 auto session1 = session_manager.open_session("Visual Basic Studio");
191 auto session2 = session_manager.open_session("IntelliJ IDEA");159 auto session2 = session_manager.open_session("IntelliJ IDEA");
@@ -194,7 +162,7 @@
194 session_manager.focus_session_with_lightdm_id(1);162 session_manager.focus_session_with_lightdm_id(1);
195163
196 EXPECT_CALL(sequence, default_focus()).WillOnce(Return(session2));164 EXPECT_CALL(sequence, default_focus()).WillOnce(Return(session2));
197 EXPECT_CALL(mechanism, set_focus_to(session2));165 EXPECT_CALL(focus_setter, set_focus_to(session2));
198166
199 session_manager.close_session(session1);167 session_manager.close_session(session1);
200}168}

Subscribers

People subscribed via source and target branches