Mir

Merge lp:~alan-griffiths/mir/migrate-tests-to-miral into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Gerry Boland
Approved revision: no longer in the source branch.
Merged at revision: 4260
Proposed branch: lp:~alan-griffiths/mir/migrate-tests-to-miral
Merge into: lp:mir
Diff against target: 319 lines (+114/-37)
6 files modified
include/test/mir_test_framework/async_server_runner.h (+13/-1)
include/test/mir_test_framework/canonical_window_manager_policy.h (+38/-0)
tests/CMakeLists.txt (+4/-0)
tests/acceptance-tests/test_client_surfaces.cpp (+47/-24)
tests/mir_test_framework/async_server_runner.cpp (+10/-2)
tests/performance-tests/CMakeLists.txt (+2/-10)
To merge this branch: bzr merge lp:~alan-griffiths/mir/migrate-tests-to-miral
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+330907@code.launchpad.net

Commit message

Migrate ClientSurfaces.* tests to miral APIs

Description of the change

Migrate ClientSurfaces.* tests to miral APIs

This is the first of a number of tests that rely on the legacy window management code. (I.e. include/test/mir/shell/canonical_window_manager.h)

The changes to mtf::AsyncServerRunner make it feasible to migrate the remaining tests and then ditch that legacy code.

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:4254
https://mir-jenkins.ubuntu.com/job/mir-ci/3667/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/5019
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/5251
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/5239
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/5239
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/5239
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5062/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/3667/rebuild

review: Approve (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/test/mir_test_framework/async_server_runner.h'
2--- include/test/mir_test_framework/async_server_runner.h 2017-07-28 17:00:43 +0000
3+++ include/test/mir_test_framework/async_server_runner.h 2017-09-18 11:45:09 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright © 2014 Canonical Ltd.
7+ * Copyright © 2014-2017 Canonical Ltd.
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 or 3,
11@@ -23,6 +23,7 @@
12 #include "mir/test/auto_unblock_thread.h"
13
14 #include "mir/server.h"
15+#include "miral/set_window_management_policy.h"
16
17 #include <condition_variable>
18 #include <list>
19@@ -56,10 +57,21 @@
20
21 mir::Server server;
22
23+ template<typename Policy, typename ...Args>
24+ void override_window_management_policy(Args& ... args)
25+ {
26+ set_window_management_policy =
27+ miral::set_window_management_policy<Policy>(args...);
28+ }
29+
30 private:
31 std::list<TemporaryEnvironmentValue> env;
32 mir::test::AutoJoinThread server_thread;
33
34+ // Once we migrate away from "legacy" window management stubs this can become
35+ // SetWindowManagementPolicy set_window_management_policy;
36+ std::function<void(mir::Server&)> set_window_management_policy;
37+
38 std::mutex mutex;
39 std::condition_variable started;
40 bool server_running{false};
41
42=== added file 'include/test/mir_test_framework/canonical_window_manager_policy.h'
43--- include/test/mir_test_framework/canonical_window_manager_policy.h 1970-01-01 00:00:00 +0000
44+++ include/test/mir_test_framework/canonical_window_manager_policy.h 2017-09-18 11:45:09 +0000
45@@ -0,0 +1,38 @@
46+/*
47+ * Copyright © 2017 Canonical Ltd.
48+ *
49+ * This program is free software: you can redistribute it and/or modify it
50+ * under the terms of the GNU General Public License version 2 or 3,
51+ * as published by the Free Software Foundation.
52+ *
53+ * This program is distributed in the hope that it will be useful,
54+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
55+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56+ * GNU General Public License for more details.
57+ *
58+ * You should have received a copy of the GNU General Public License
59+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
60+ *
61+ * Authored by: Alan Griffiths <alan@octopull.co.uk>
62+ */
63+
64+#ifndef MIR_TEST_FRAMEWORK_CANONICAL_WINDOW_MANAGER_POLICY_H
65+#define MIR_TEST_FRAMEWORK_CANONICAL_WINDOW_MANAGER_POLICY_H
66+
67+#include <miral/canonical_window_manager.h>
68+
69+namespace mir_test_framework
70+{
71+struct CanonicalWindowManagerPolicy : miral::CanonicalWindowManagerPolicy
72+{
73+ using miral::CanonicalWindowManagerPolicy::CanonicalWindowManagerPolicy;
74+
75+ bool handle_keyboard_event(MirKeyboardEvent const*) override { return false; }
76+
77+ bool handle_pointer_event(MirPointerEvent const*) override { return false; }
78+
79+ bool handle_touch_event(MirTouchEvent const*) override { return false; }
80+};
81+}
82+
83+#endif //MIR_TEST_FRAMEWORK_CANONICAL_WINDOW_MANAGER_POLICY_H
84
85=== modified file 'tests/CMakeLists.txt'
86--- tests/CMakeLists.txt 2017-09-07 05:58:13 +0000
87+++ tests/CMakeLists.txt 2017-09-18 11:45:09 +0000
88@@ -43,6 +43,7 @@
89 # public headers (only public headers should be accessed by acceptance tests)
90 include_directories(
91 ${PROJECT_SOURCE_DIR}/include/platform
92+ ${PROJECT_SOURCE_DIR}/include/miral
93 ${PROJECT_SOURCE_DIR}/include/server
94 ${PROJECT_SOURCE_DIR}/include/client
95 ${PROJECT_SOURCE_DIR}/include/common
96@@ -100,13 +101,16 @@
97 )
98
99 target_link_libraries(mir-test-assist
100+PUBLIC
101 mirclient
102+ miral
103 mirserver
104
105 mir-test-doubles-platform-static
106 ${Boost_LIBRARIES}
107 ${GTEST_BOTH_LIBRARIES}
108 ${GMOCK_LIBRARY}
109+PRIVATE
110 ${GMOCK_MAIN_LIBRARY}
111 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
112 )
113
114=== modified file 'tests/acceptance-tests/test_client_surfaces.cpp'
115--- tests/acceptance-tests/test_client_surfaces.cpp 2017-07-28 17:00:43 +0000
116+++ tests/acceptance-tests/test_client_surfaces.cpp 2017-09-18 11:45:09 +0000
117@@ -1,5 +1,5 @@
118 /*
119- * Copyright © 2012-2014 Canonical Ltd.
120+ * Copyright © 2012-2017 Canonical Ltd.
121 *
122 * This program is free software: you can redistribute it and/or modify
123 * it under the terms of the GNU General Public License version 2 or 3 as
124@@ -19,13 +19,15 @@
125 #include "mir_toolkit/mir_client_library.h"
126 #include "mir_toolkit/debug/surface.h"
127
128-#include "mir/test/doubles/mock_window_manager.h"
129+#include "miral/application_info.h"
130
131 #include "mir/scene/session.h"
132 #include "mir/geometry/rectangle.h"
133
134+#include "mir_test_framework/canonical_window_manager_policy.h"
135 #include "mir_test_framework/connected_client_headless_server.h"
136 #include "mir_test_framework/any_surface.h"
137+
138 #include "mir/test/validity_matchers.h"
139 #include "mir/test/fake_shared.h"
140
141@@ -36,14 +38,31 @@
142 #include <mutex>
143
144 namespace mtf = mir_test_framework;
145-namespace mtd = mir::test::doubles;
146 namespace msh = mir::shell;
147 namespace ms = mir::scene;
148 namespace mt = mir::test;
149 namespace mg = mir::geometry;
150+using namespace testing;
151
152 namespace
153 {
154+struct MockWindowManagementPolicy : mtf::CanonicalWindowManagerPolicy
155+{
156+ MockWindowManagementPolicy(
157+ miral::WindowManagerTools const& tools,
158+ MockWindowManagementPolicy*& self) :
159+ mtf::CanonicalWindowManagerPolicy(tools)
160+ {
161+ self = this;
162+ ON_CALL(*this, place_new_window(_, _)).WillByDefault(ReturnArg<1>());
163+ }
164+
165+ MOCK_METHOD2(place_new_window,
166+ miral::WindowSpecification(miral::ApplicationInfo const& app_info, miral::WindowSpecification const& request_parameters));
167+
168+ MOCK_METHOD1(advise_new_window, void (miral::WindowInfo const& window_info));
169+};
170+
171 struct ClientSurfaces : mtf::ConnectedClientHeadlessServer
172 {
173 static const int max_surface_count = 5;
174@@ -51,14 +70,13 @@
175
176 void SetUp() override
177 {
178- server.override_the_window_manager_builder([this](msh::FocusController*)
179- {
180- return mt::fake_shared(window_manager);
181- });
182- ConnectedClientHeadlessServer::SetUp();
183+ override_window_management_policy<MockWindowManagementPolicy>(mock_wm_policy);
184+ mtf::ConnectedClientHeadlessServer::SetUp();
185+
186+ ASSERT_THAT(mock_wm_policy, NotNull());
187 }
188
189- testing::NiceMock<mtd::MockWindowManager> window_manager;
190+ MockWindowManagementPolicy* mock_wm_policy = 0;
191 };
192 }
193 #pragma GCC diagnostic push
194@@ -351,22 +369,27 @@
195
196 std::shared_ptr<ms::Surface> parent_surface;
197 InSequence seq;
198- EXPECT_CALL(window_manager, add_surface(_,_,_)).WillOnce(Invoke([&parent_surface](auto session, auto params, auto builder)
199- {
200- auto id = builder(session, params);
201- parent_surface = session->surface(id);
202- return id;
203- }));
204- EXPECT_CALL(window_manager, add_surface(_,_,_)).WillOnce(Invoke([&parent_surface, server_rect, edge_attachment](auto session, auto params, auto builder)
205- {
206- EXPECT_THAT(params.parent.lock(), Eq(parent_surface));
207- EXPECT_TRUE(params.aux_rect.is_set());
208- EXPECT_THAT(params.aux_rect.value(), Eq(server_rect));
209- EXPECT_TRUE(params.edge_attachment.is_set());
210- EXPECT_THAT(params.edge_attachment.value(), Eq(edge_attachment));
211+ EXPECT_CALL(*mock_wm_policy, place_new_window(_, _)).Times(1);
212+ EXPECT_CALL(*mock_wm_policy, advise_new_window(_)).WillOnce(Invoke([&parent_surface](auto const& info)
213+ {
214+ parent_surface = info.window();
215+ }));
216
217- return builder(session, params);
218- }));
219+ EXPECT_CALL(*mock_wm_policy, place_new_window(_, _)).WillOnce(Invoke([&](auto const&, auto const& params)
220+ {
221+ EXPECT_TRUE(params.parent().is_set());
222+ EXPECT_THAT(params.parent().value().lock(), Eq(parent_surface));
223+ EXPECT_TRUE(params.aux_rect().is_set());
224+ EXPECT_THAT(params.aux_rect().value(), Eq(server_rect));
225+ EXPECT_TRUE(params.window_placement_gravity().is_set());
226+ EXPECT_THAT(params.window_placement_gravity().value(), Eq(mir_placement_gravity_northwest));
227+ EXPECT_TRUE(params.aux_rect_placement_gravity().is_set());
228+ EXPECT_THAT(params.aux_rect_placement_gravity().value(), Eq(mir_placement_gravity_northeast));
229+ EXPECT_TRUE(params.placement_hints().is_set());
230+ EXPECT_THAT(params.placement_hints().value(), Eq(mir_placement_hints_flip_x));
231+ return params;
232+ }));
233+ EXPECT_CALL(*mock_wm_policy, advise_new_window(_)).Times(1);
234
235 auto window = mtf::make_any_surface(connection);
236
237
238=== modified file 'tests/mir_test_framework/async_server_runner.cpp'
239--- tests/mir_test_framework/async_server_runner.cpp 2017-08-30 11:59:02 +0000
240+++ tests/mir_test_framework/async_server_runner.cpp 2017-09-18 11:45:09 +0000
241@@ -1,5 +1,5 @@
242 /*
243- * Copyright © 2014 Canonical Ltd.
244+ * Copyright © 2014-2017 Canonical Ltd.
245 *
246 * This program is free software: you can redistribute it and/or modify it
247 * under the terms of the GNU General Public License version 2 or 3,
248@@ -18,12 +18,14 @@
249
250 #include "mir_test_framework/async_server_runner.h"
251 #include "mir_test_framework/command_line_server_configuration.h"
252+#include "mir_test_framework/canonical_window_manager_policy.h"
253
254 #include "mir/fd.h"
255 #include "mir/main_loop.h"
256 #include "mir/geometry/rectangle.h"
257 #include "mir/options/option.h"
258 #include "mir/test/doubles/null_logger.h"
259+#include <miral/set_window_management_policy.h>
260 #include <mir/shell/canonical_window_manager.h>
261
262 #include <boost/throw_exception.hpp>
263@@ -42,7 +44,8 @@
264 std::chrono::seconds const timeout{20};
265 }
266
267-mtf::AsyncServerRunner::AsyncServerRunner()
268+mtf::AsyncServerRunner::AsyncServerRunner() :
269+ set_window_management_policy{[](auto&){}}
270 {
271 configure_from_commandline(server);
272
273@@ -56,6 +59,9 @@
274
275 return result;
276 });
277+ // TODO This is here to support tests that rely on the legacy window management code
278+ // once they go, then we can set set_window_management_policy appropriately, kill this
279+ // and remove msh::CanonicalWindowManager
280 server.override_the_window_manager_builder([this](msh::FocusController* focus_controller)
281 {
282 #pragma GCC diagnostic push
283@@ -74,6 +80,8 @@
284
285 void mtf::AsyncServerRunner::start_server()
286 {
287+ set_window_management_policy(server);
288+
289 server.add_init_callback([&]
290 {
291 auto const main_loop = server.the_main_loop();
292
293=== modified file 'tests/performance-tests/CMakeLists.txt'
294--- tests/performance-tests/CMakeLists.txt 2017-05-08 03:04:26 +0000
295+++ tests/performance-tests/CMakeLists.txt 2017-09-18 11:45:09 +0000
296@@ -17,11 +17,7 @@
297 )
298 add_dependencies(mir_glmark2_performance_test GMock)
299 target_link_libraries(mir_glmark2_performance_test
300- mir-test-static
301- mir-test-framework-static
302- mir-test-doubles-static
303- mirserver
304- ${GTEST_BOTH_LIBRARIES}
305+ mir-test-assist
306 )
307
308 add_library(mir_system_performance_test STATIC
309@@ -40,10 +36,6 @@
310 test_client_startup.cpp
311 )
312 target_link_libraries(mir_client_startup_performance_test
313- mir-test-static
314- mir-test-framework-static
315- mir-test-doubles-static
316- mirserver
317- ${GTEST_BOTH_LIBRARIES}
318+ mir-test-assist
319 )
320

Subscribers

People subscribed via source and target branches