Merge lp:~alan-griffiths/mir/another-acceptance-test-uses-mir-Server-API into lp:mir
- another-acceptance-test-uses-mir-Server-API
- Merge into development-branch
Proposed by
Alan Griffiths
Status: | Work in progress |
---|---|
Proposed branch: | lp:~alan-griffiths/mir/another-acceptance-test-uses-mir-Server-API |
Merge into: | lp:mir |
Prerequisite: | lp:~alan-griffiths/mir/some-acceptance-tests-use-mir-Server-API |
Diff against target: |
583 lines (+219/-121) 11 files modified
include/server/mir/server.h (+9/-0) server-ABI-sha1sums (+1/-1) src/server/server.cpp (+9/-0) src/server/symbols.map (+2/-0) tests/acceptance-tests/test_client_library.cpp (+2/-21) tests/acceptance-tests/test_prompt_session_client_api.cpp (+114/-98) tests/include/mir_test_framework/headless_in_process_server.h (+36/-0) tests/include/mir_test_framework/headless_test.h (+3/-0) tests/mir_test_framework/CMakeLists.txt (+1/-0) tests/mir_test_framework/headless_in_process_server.cpp (+36/-0) tests/mir_test_framework/headless_test.cpp (+6/-1) |
To merge this branch: | bzr merge lp:~alan-griffiths/mir/another-acceptance-test-uses-mir-Server-API |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mir development team | Pending | ||
Review via email: mp+239581@code.launchpad.net |
Commit message
test: Move another of the acceptance test suites [PromptSessionC
Description of the change
test: Move another of the acceptance test suites [PromptSessionC
It cleans up the "HeadlessInProc
To post a comment you must log in.
- 2003. By Alan Griffiths
-
merge lp:~alan-griffiths/mir/some-acceptance-tests-use-mir-Server-API
- 2004. By Alan Griffiths
-
Revert accidental deletions in debian
- 2005. By Alan Griffiths
-
Delete debug code
- 2006. By Alan Griffiths
-
Reduce diff
- 2007. By Alan Griffiths
-
merge lp:~alan-griffiths/mir/some-acceptance-tests-use-mir-Server-API
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'include/server/mir/server.h' |
2 | --- include/server/mir/server.h 2014-10-24 18:38:24 +0000 |
3 | +++ include/server/mir/server.h 2014-10-24 18:38:25 +0000 |
4 | @@ -35,6 +35,7 @@ |
5 | class PlacementStrategy; |
6 | class SessionListener; |
7 | class PromptSessionListener; |
8 | +class PromptSessionManager; |
9 | class SurfaceConfigurator; |
10 | class SessionCoordinator; |
11 | class SurfaceCoordinator; |
12 | @@ -211,6 +212,9 @@ |
13 | /// \return the prompt session listener. |
14 | auto the_prompt_session_listener() const -> std::shared_ptr<scene::PromptSessionListener>; |
15 | |
16 | + /// \return the prompt session manager. |
17 | + auto the_prompt_session_manager() const ->std::shared_ptr<scene::PromptSessionManager>; |
18 | + |
19 | /// \return the session authorizer. |
20 | auto the_session_authorizer() const -> std::shared_ptr<frontend::SessionAuthorizer>; |
21 | |
22 | @@ -247,6 +251,11 @@ |
23 | /// using the format "fd://%d". |
24 | /// \param connect_handler callback to be invoked when the client connects |
25 | auto open_client_socket(ConnectHandler const& connect_handler) -> int; |
26 | + |
27 | + /// Get a file descriptor that can be used to connect a prompt provider |
28 | + /// It can be passed to another process, or used directly with mir_connect() |
29 | + /// using the format "fd://%d". |
30 | + auto open_prompt_socket() -> int; |
31 | /** @} */ |
32 | private: |
33 | void apply_settings() const; |
34 | |
35 | === modified file 'server-ABI-sha1sums' |
36 | --- server-ABI-sha1sums 2014-10-24 18:38:24 +0000 |
37 | +++ server-ABI-sha1sums 2014-10-24 18:38:25 +0000 |
38 | @@ -95,7 +95,7 @@ |
39 | 993e9f458ffc4288d304413f3fa0b1dcc95a093d include/server/mir/scene/surface_observer.h |
40 | 7ef3e99901168cda296d74d05a979f47bf9c3ff1 include/server/mir/server_action_queue.h |
41 | 8d83a51c278b8b71866d2178d9b6387c1f91a7d0 include/server/mir/server_configuration.h |
42 | -2ead070cf169e59015edfd94ca84295ac5adcdd6 include/server/mir/server.h |
43 | +54faba134ab52958228db3ccc19d45aff7068ca6 include/server/mir/server.h |
44 | 86098b500339bfccd07a9bed8298f75a68b18f5c include/server/mir/server_status_listener.h |
45 | 860c04f32b60e680140148dc9dc2295de145b9c1 include/server/mir/shell/display_layout.h |
46 | 6a2107b01feae13060d5c305804906e53c52e0be include/server/mir/shell/focus_controller.h |
47 | |
48 | === modified file 'src/server/server.cpp' |
49 | --- src/server/server.cpp 2014-10-24 18:38:24 +0000 |
50 | +++ src/server/server.cpp 2014-10-24 18:38:25 +0000 |
51 | @@ -61,6 +61,7 @@ |
52 | MACRO(the_session_authorizer)\ |
53 | MACRO(the_session_coordinator)\ |
54 | MACRO(the_session_listener)\ |
55 | + MACRO(the_prompt_session_manager)\ |
56 | MACRO(the_shell_display_layout)\ |
57 | MACRO(the_surface_configurator)\ |
58 | MACRO(the_surface_coordinator) |
59 | @@ -310,6 +311,14 @@ |
60 | BOOST_THROW_EXCEPTION(std::logic_error("Cannot open connection when not running")); |
61 | } |
62 | |
63 | +auto mir::Server::open_prompt_socket() -> int |
64 | +{ |
65 | + if (auto const config = self->server_config) |
66 | + return config->the_prompt_connector()->client_socket_fd(); |
67 | + |
68 | + BOOST_THROW_EXCEPTION(std::logic_error("Cannot open connection when not running")); |
69 | +} |
70 | + |
71 | auto mir::Server::open_client_socket(ConnectHandler const& connect_handler) -> int |
72 | { |
73 | if (auto const config = self->server_config) |
74 | |
75 | === modified file 'src/server/symbols.map' |
76 | --- src/server/symbols.map 2014-10-24 18:38:24 +0000 |
77 | +++ src/server/symbols.map 2014-10-24 18:38:25 +0000 |
78 | @@ -394,6 +394,7 @@ |
79 | mir::Server::exited_normally*; |
80 | mir::Server::get_options*; |
81 | mir::Server::open_client_socket*; |
82 | + mir::Server::open_prompt_socket*; |
83 | mir::Server::override_the_compositor*; |
84 | mir::Server::override_the_cursor_listener*; |
85 | mir::Server::override_the_gl_config*; |
86 | @@ -423,6 +424,7 @@ |
87 | mir::Server::the_graphics_platform*; |
88 | mir::Server::the_main_loop*; |
89 | mir::Server::the_prompt_session_listener*; |
90 | + mir::Server::the_prompt_session_manager*; |
91 | mir::Server::the_session_authorizer*; |
92 | mir::Server::the_session_coordinator*; |
93 | mir::Server::the_session_listener*; |
94 | |
95 | === modified file 'tests/acceptance-tests/test_client_library.cpp' |
96 | --- tests/acceptance-tests/test_client_library.cpp 2014-10-24 18:38:24 +0000 |
97 | +++ tests/acceptance-tests/test_client_library.cpp 2014-10-24 18:38:25 +0000 |
98 | @@ -19,7 +19,7 @@ |
99 | #include "mir_toolkit/mir_client_library.h" |
100 | #include "mir_toolkit/mir_client_library_debug.h" |
101 | |
102 | -#include "mir_test_framework/headless_test.h" |
103 | +#include "mir_test_framework/headless_in_process_server.h" |
104 | #include "mir_test_framework/using_stub_client_platform.h" |
105 | |
106 | #include "src/client/client_buffer.h" |
107 | @@ -50,28 +50,9 @@ |
108 | namespace mc = mir::compositor; |
109 | namespace mcl = mir::client; |
110 | namespace mtf = mir_test_framework; |
111 | - |
112 | namespace |
113 | { |
114 | -struct HeadlessInProcessServer : mir_test_framework::HeadlessTest |
115 | -{ |
116 | - HeadlessInProcessServer() |
117 | - { |
118 | - add_to_environment("MIR_SERVER_NO_FILE", ""); |
119 | - } |
120 | - |
121 | - void SetUp() override |
122 | - { |
123 | - start_server(); |
124 | - } |
125 | - |
126 | - void TearDown() override |
127 | - { |
128 | - stop_server(); |
129 | - } |
130 | -}; |
131 | - |
132 | -struct ClientLibrary : HeadlessInProcessServer |
133 | +struct ClientLibrary : mtf::HeadlessInProcessServer |
134 | { |
135 | mtf::UsingStubClientPlatform using_stub_client_platform; |
136 | |
137 | |
138 | === modified file 'tests/acceptance-tests/test_prompt_session_client_api.cpp' |
139 | --- tests/acceptance-tests/test_prompt_session_client_api.cpp 2014-10-21 16:21:14 +0000 |
140 | +++ tests/acceptance-tests/test_prompt_session_client_api.cpp 2014-10-24 18:38:25 +0000 |
141 | @@ -21,13 +21,14 @@ |
142 | #include "mir/scene/prompt_session.h" |
143 | #include "mir/scene/prompt_session_manager.h" |
144 | #include "mir/scene/session.h" |
145 | +#include "mir/shell/session_coordinator_wrapper.h" |
146 | #include "mir/frontend/session_credentials.h" |
147 | #include "mir/frontend/shell.h" |
148 | +#include "mir/cached_ptr.h" |
149 | #include "mir/fd.h" |
150 | |
151 | #include "mir_test_doubles/stub_session_authorizer.h" |
152 | -#include "mir_test_framework/stubbed_server_configuration.h" |
153 | -#include "mir_test_framework/in_process_server.h" |
154 | +#include "mir_test_framework/headless_in_process_server.h" |
155 | #include "mir_test_framework/using_stub_client_platform.h" |
156 | #include "mir_test/popen.h" |
157 | |
158 | @@ -40,6 +41,7 @@ |
159 | namespace mtd = mir::test::doubles; |
160 | namespace mtf = mir_test_framework; |
161 | namespace ms = mir::scene; |
162 | +namespace msh = mir::shell; |
163 | namespace mf = mir::frontend; |
164 | |
165 | using namespace testing; |
166 | @@ -48,20 +50,8 @@ |
167 | { |
168 | struct MockPromptSessionListener : ms::PromptSessionListener |
169 | { |
170 | - MockPromptSessionListener(std::shared_ptr<ms::PromptSessionListener> const& wrapped) : |
171 | - wrapped(wrapped) |
172 | + MockPromptSessionListener() |
173 | { |
174 | - ON_CALL(*this, starting(_)).WillByDefault(Invoke( |
175 | - wrapped.get(), &ms::PromptSessionListener::starting)); |
176 | - |
177 | - ON_CALL(*this, stopping(_)).WillByDefault(Invoke( |
178 | - wrapped.get(), &ms::PromptSessionListener::stopping)); |
179 | - |
180 | - ON_CALL(*this, prompt_provider_added(_, _)).WillByDefault(Invoke( |
181 | - wrapped.get(), &ms::PromptSessionListener::prompt_provider_added)); |
182 | - |
183 | - ON_CALL(*this, prompt_provider_removed(_, _)).WillByDefault(Invoke( |
184 | - wrapped.get(), &ms::PromptSessionListener::prompt_provider_removed)); |
185 | } |
186 | |
187 | MOCK_METHOD1(starting, void(std::shared_ptr<ms::PromptSession> const& prompt_session)); |
188 | @@ -72,8 +62,6 @@ |
189 | |
190 | MOCK_METHOD2(prompt_provider_removed, |
191 | void(ms::PromptSession const& session, std::shared_ptr<ms::Session> const& provider)); |
192 | - |
193 | - std::shared_ptr<ms::PromptSessionListener> const wrapped; |
194 | }; |
195 | |
196 | struct MockSessionAuthorizer : public mtd::StubSessionAuthorizer |
197 | @@ -88,110 +76,136 @@ |
198 | MOCK_METHOD1(prompt_session_is_allowed, bool(mf::SessionCredentials const&)); |
199 | }; |
200 | |
201 | -struct PromptSessionTestConfiguration : mtf::StubbedServerConfiguration |
202 | +// We need to fake the client_pid for the as that is used to identify sessions |
203 | +class HookSessionCoordinator : public msh::SessionCoordinatorWrapper |
204 | { |
205 | - std::shared_ptr<ms::PromptSessionListener> the_prompt_session_listener() override |
206 | - { |
207 | - return prompt_session_listener([this]() |
208 | - ->std::shared_ptr<ms::PromptSessionListener> |
209 | - { |
210 | - return the_mock_prompt_session_listener(); |
211 | - }); |
212 | - } |
213 | - |
214 | - std::shared_ptr<MockPromptSessionListener> the_mock_prompt_session_listener() |
215 | - { |
216 | - return mock_prompt_session_listener([this] |
217 | - { |
218 | - return std::make_shared<NiceMock<MockPromptSessionListener>>( |
219 | - mtf::StubbedServerConfiguration::the_prompt_session_listener()); |
220 | - }); |
221 | - } |
222 | - |
223 | - std::shared_ptr<mf::SessionAuthorizer> the_session_authorizer() override |
224 | - { |
225 | - return session_authorizer([this]() |
226 | - ->std::shared_ptr<mf::SessionAuthorizer> |
227 | - { |
228 | - return the_mock_session_authorizer(); |
229 | - }); |
230 | - } |
231 | - |
232 | - std::shared_ptr<MockSessionAuthorizer> the_mock_session_authorizer() |
233 | - { |
234 | - return mock_prompt_session_authorizer([this] |
235 | - { |
236 | - return std::make_shared<NiceMock<MockSessionAuthorizer>>(); |
237 | - }); |
238 | - } |
239 | - |
240 | - mir::CachedPtr<MockPromptSessionListener> mock_prompt_session_listener; |
241 | - mir::CachedPtr<MockSessionAuthorizer> mock_prompt_session_authorizer; |
242 | +public: |
243 | + HookSessionCoordinator( |
244 | + std::shared_ptr<ms::SessionCoordinator> const& wrapped, |
245 | + std::vector<pid_t> const& pids) : |
246 | + msh::SessionCoordinatorWrapper(wrapped), |
247 | + pids(pids) |
248 | + { |
249 | + } |
250 | + |
251 | + auto open_session( |
252 | + pid_t client_pid, |
253 | + std::string const& name, |
254 | + std::shared_ptr<mf::EventSink> const& sink) |
255 | + -> std::shared_ptr<mf::Session> override |
256 | + { |
257 | + auto const override_pid = (next != pids.end()) ? *next++ : client_pid; |
258 | + |
259 | + return wrapped->open_session(override_pid, name, sink); |
260 | + } |
261 | + |
262 | +private: |
263 | + std::vector<pid_t> const pids; |
264 | + std::vector<pid_t>::const_iterator next{pids.begin()}; |
265 | }; |
266 | |
267 | -struct PromptSessionClientAPI : mtf::InProcessServer |
268 | +struct PromptSessionClientAPI : mtf::HeadlessInProcessServer |
269 | { |
270 | - PromptSessionTestConfiguration server_configuration; |
271 | - |
272 | - mir::DefaultServerConfiguration& server_config() override |
273 | - { return server_configuration; } |
274 | - |
275 | MirConnection* connection = nullptr; |
276 | |
277 | static constexpr pid_t application_session_pid = __LINE__; |
278 | std::shared_ptr<mf::Session> application_session; |
279 | + MirConnection* application_connection{nullptr}; |
280 | |
281 | std::shared_ptr<ms::PromptSession> server_prompt_session; |
282 | mtf::UsingStubClientPlatform using_stub_client_platform; |
283 | |
284 | + mir::CachedPtr<MockPromptSessionListener> mock_prompt_session_listener; |
285 | + mir::CachedPtr<MockSessionAuthorizer> mock_prompt_session_authorizer; |
286 | + |
287 | + std::shared_ptr<MockSessionAuthorizer> the_mock_session_authorizer() |
288 | + { |
289 | + return mock_prompt_session_authorizer([this] |
290 | + { |
291 | + return std::make_shared<NiceMock<MockSessionAuthorizer>>(); |
292 | + }); |
293 | + } |
294 | + |
295 | + std::shared_ptr<MockPromptSessionListener> the_mock_prompt_session_listener() |
296 | + { |
297 | + return mock_prompt_session_listener([] |
298 | + { |
299 | + return std::make_shared<NiceMock<MockPromptSessionListener>>(); |
300 | + }); |
301 | + } |
302 | + |
303 | + auto new_prompt_connection() -> std::string |
304 | + { |
305 | + auto const prompt_fd = server.open_prompt_socket(); |
306 | + return HeadlessInProcessServer::connection(prompt_fd); |
307 | + } |
308 | + |
309 | + void start_application_session() |
310 | + { |
311 | + std::mutex application_session_mutex; |
312 | + std::condition_variable application_session_cv; |
313 | + |
314 | + auto connect_handler = [&](std::shared_ptr<mf::Session> const& session) |
315 | + { |
316 | + std::lock_guard<std::mutex> lock(application_session_mutex); |
317 | + application_session = session; |
318 | + application_session_cv.notify_one(); |
319 | + }; |
320 | + |
321 | + auto const fd = server.open_client_socket(connect_handler); |
322 | + |
323 | + application_connection = mir_connect_sync(HeadlessInProcessServer::connection(fd).c_str(), __PRETTY_FUNCTION__); |
324 | + |
325 | + std::unique_lock<std::mutex> lock(application_session_mutex); |
326 | + application_session_cv.wait(lock, [&] { return !!application_session; }); |
327 | + } |
328 | + |
329 | void SetUp() override |
330 | { |
331 | - mtf::InProcessServer::SetUp(); |
332 | - |
333 | - std::shared_ptr<mf::EventSink> dummy_event_sink; |
334 | - auto const the_frontend_shell = server_config().the_frontend_shell(); |
335 | - |
336 | - application_session = the_frontend_shell->open_session( |
337 | - application_session_pid, __PRETTY_FUNCTION__, dummy_event_sink); |
338 | + auto session_coordinator_wrapper = [&](std::shared_ptr<ms::SessionCoordinator> const& wrapped) |
339 | + -> std::shared_ptr<ms::SessionCoordinator> |
340 | + { |
341 | + std::vector<pid_t> fake_pids; |
342 | + fake_pids.push_back(application_session_pid); |
343 | + |
344 | + return std::make_shared<HookSessionCoordinator>(wrapped, fake_pids); |
345 | + }; |
346 | + |
347 | + server.override_the_session_authorizer([this]() |
348 | + ->std::shared_ptr<mf::SessionAuthorizer> |
349 | + { |
350 | + return the_mock_session_authorizer(); |
351 | + }); |
352 | + |
353 | + server.override_the_prompt_session_listener([this] |
354 | + { |
355 | + return the_mock_prompt_session_listener(); |
356 | + }); |
357 | + |
358 | + server.wrap_session_coordinator(session_coordinator_wrapper); |
359 | + |
360 | + mtf::HeadlessInProcessServer::SetUp(); |
361 | + |
362 | + start_application_session(); |
363 | } |
364 | |
365 | void capture_server_prompt_session() |
366 | { |
367 | EXPECT_CALL(*the_mock_prompt_session_listener(), starting(_)). |
368 | - WillOnce(DoAll( |
369 | - Invoke( |
370 | - the_mock_prompt_session_listener()->wrapped.get(), |
371 | - &ms::PromptSessionListener::starting), |
372 | - SaveArg<0>(&server_prompt_session))); |
373 | + WillOnce(SaveArg<0>(&server_prompt_session)); |
374 | } |
375 | |
376 | void TearDown() override |
377 | { |
378 | - // TODO It really shouldn't be necessary to close these sessions. |
379 | - // TODO But the MediatingDisplayChanger id destroyed without deregistering |
380 | - // TODO callbacks from the BroadcastingSessionEventSink which gets called in |
381 | - // TODO SessionManager::~SessionManager() in code that the comments claim |
382 | - // TODO works around broken ownership. |
383 | - auto const the_frontend_shell = server_config().the_frontend_shell(); |
384 | - the_frontend_shell->close_session(application_session); |
385 | - |
386 | + application_session.reset(); |
387 | + if (application_connection) mir_connection_release(application_connection); |
388 | if (connection) mir_connection_release(connection); |
389 | - mtf::InProcessServer::TearDown(); |
390 | - } |
391 | - |
392 | - MockPromptSessionListener* the_mock_prompt_session_listener() |
393 | - { |
394 | - return server_configuration.the_mock_prompt_session_listener().get(); |
395 | - } |
396 | - |
397 | - MockSessionAuthorizer& the_mock_session_authorizer() |
398 | - { |
399 | - return *server_configuration.the_mock_session_authorizer(); |
400 | + mtf::HeadlessInProcessServer::TearDown(); |
401 | } |
402 | |
403 | std::shared_ptr<ms::PromptSessionManager> the_prompt_session_manager() |
404 | { |
405 | - return server_config().the_prompt_session_manager(); |
406 | + return server.the_prompt_session_manager(); |
407 | } |
408 | |
409 | MOCK_METHOD2(prompt_session_state_change, |
410 | @@ -240,6 +254,8 @@ |
411 | }; |
412 | }; |
413 | |
414 | +constexpr pid_t PromptSessionClientAPI::application_session_pid; |
415 | + |
416 | mir_prompt_session_state_change_callback const null_state_change_callback{nullptr}; |
417 | constexpr char const* const PromptSessionClientAPI::provider_name[]; |
418 | |
419 | @@ -417,7 +433,7 @@ |
420 | the_prompt_session_manager()->stop_prompt_session(server_prompt_session); |
421 | |
422 | // Verify we have got the "stopped" notification before we go on and release the session |
423 | - Mock::VerifyAndClearExpectations(the_mock_prompt_session_listener()); |
424 | + Mock::VerifyAndClearExpectations(the_mock_prompt_session_listener().get()); |
425 | |
426 | mir_prompt_session_release_sync(prompt_session); |
427 | } |
428 | @@ -493,7 +509,7 @@ |
429 | |
430 | TEST_F(PromptSessionClientAPI, cannot_start_a_prompt_session_without_authorization) |
431 | { |
432 | - EXPECT_CALL(the_mock_session_authorizer(), prompt_session_is_allowed(_)) |
433 | + EXPECT_CALL(*the_mock_session_authorizer(), prompt_session_is_allowed(_)) |
434 | .WillOnce(Return(false)); |
435 | |
436 | connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); |
437 | @@ -513,9 +529,9 @@ |
438 | TEST_F(PromptSessionClientAPI, |
439 | can_start_a_prompt_session_without_authorization_on_prompt_connection) |
440 | { |
441 | - ON_CALL(the_mock_session_authorizer(), prompt_session_is_allowed(_)) |
442 | + ON_CALL(*the_mock_session_authorizer(), prompt_session_is_allowed(_)) |
443 | .WillByDefault(Return(false)); |
444 | - EXPECT_CALL(the_mock_session_authorizer(), prompt_session_is_allowed(_)).Times(0); |
445 | + EXPECT_CALL(*the_mock_session_authorizer(), prompt_session_is_allowed(_)).Times(0); |
446 | |
447 | connection = mir_connect_sync(new_prompt_connection().c_str(), __PRETTY_FUNCTION__); |
448 | |
449 | @@ -539,7 +555,7 @@ |
450 | { |
451 | connection = mir_connect_sync(new_prompt_connection().c_str(), __PRETTY_FUNCTION__); |
452 | |
453 | - EXPECT_CALL(the_mock_session_authorizer(), connection_is_allowed(_)).Times(0); |
454 | + EXPECT_CALL(*the_mock_session_authorizer(), connection_is_allowed(_)).Times(0); |
455 | |
456 | MirPromptSession* prompt_session = mir_connection_create_prompt_session_sync( |
457 | connection, application_session_pid, null_state_change_callback, this); |
458 | |
459 | === added file 'tests/include/mir_test_framework/headless_in_process_server.h' |
460 | --- tests/include/mir_test_framework/headless_in_process_server.h 1970-01-01 00:00:00 +0000 |
461 | +++ tests/include/mir_test_framework/headless_in_process_server.h 2014-10-24 18:38:25 +0000 |
462 | @@ -0,0 +1,36 @@ |
463 | +/* |
464 | + * Copyright © 2014 Canonical Ltd. |
465 | + * |
466 | + * This program is free software: you can redistribute it and/or modify it |
467 | + * under the terms of the GNU General Public License version 3, |
468 | + * as published by the Free Software Foundation. |
469 | + * |
470 | + * This program is distributed in the hope that it will be useful, |
471 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
472 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
473 | + * GNU General Public License for more details. |
474 | + * |
475 | + * You should have received a copy of the GNU General Public License |
476 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
477 | + * |
478 | + * Authored By: Alan Griffiths <alan@octopull.co.uk> |
479 | + */ |
480 | + |
481 | +#ifndef MIR_TEST_FRAMEWORK_HEADLESS_IN_PROCESS_SERVER_H_ |
482 | +#define MIR_TEST_FRAMEWORK_HEADLESS_IN_PROCESS_SERVER_H_ |
483 | + |
484 | +#include "mir_test_framework/headless_test.h" |
485 | + |
486 | +namespace mir_test_framework |
487 | +{ |
488 | +struct HeadlessInProcessServer : HeadlessTest |
489 | +{ |
490 | + HeadlessInProcessServer(); |
491 | + |
492 | + void SetUp() override; |
493 | + |
494 | + void TearDown() override; |
495 | +}; |
496 | +} |
497 | + |
498 | +#endif /* MIR_TEST_FRAMEWORK_HEADLESS_IN_PROCESS_SERVER_H_ */ |
499 | |
500 | === modified file 'tests/include/mir_test_framework/headless_test.h' |
501 | --- tests/include/mir_test_framework/headless_test.h 2014-10-24 18:38:24 +0000 |
502 | +++ tests/include/mir_test_framework/headless_test.h 2014-10-24 18:38:25 +0000 |
503 | @@ -54,6 +54,9 @@ |
504 | /// \return a connection string for a new client to connect to the server |
505 | auto new_connection() -> std::string; |
506 | |
507 | + /// \return a connection string for a client to connect to the server |
508 | + auto connection(int fd) -> std::string; |
509 | + |
510 | mir::Server server; |
511 | |
512 | private: |
513 | |
514 | === modified file 'tests/mir_test_framework/CMakeLists.txt' |
515 | --- tests/mir_test_framework/CMakeLists.txt 2014-10-24 18:38:24 +0000 |
516 | +++ tests/mir_test_framework/CMakeLists.txt 2014-10-24 18:38:25 +0000 |
517 | @@ -15,6 +15,7 @@ |
518 | executable_path.cpp |
519 | command_line_server_configuration.cpp |
520 | cross_process_sync.cpp |
521 | + headless_in_process_server.cpp |
522 | headless_test.cpp |
523 | server_runner.cpp |
524 | temporary_environment_value.cpp |
525 | |
526 | === added file 'tests/mir_test_framework/headless_in_process_server.cpp' |
527 | --- tests/mir_test_framework/headless_in_process_server.cpp 1970-01-01 00:00:00 +0000 |
528 | +++ tests/mir_test_framework/headless_in_process_server.cpp 2014-10-24 18:38:25 +0000 |
529 | @@ -0,0 +1,36 @@ |
530 | +/* |
531 | + * Copyright © 2014 Canonical Ltd. |
532 | + * |
533 | + * This program is free software: you can redistribute it and/or modify it |
534 | + * under the terms of the GNU General Public License version 3, |
535 | + * as published by the Free Software Foundation. |
536 | + * |
537 | + * This program is distributed in the hope that it will be useful, |
538 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
539 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
540 | + * GNU General Public License for more details. |
541 | + * |
542 | + * You should have received a copy of the GNU General Public License |
543 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
544 | + * |
545 | + * Authored By: Alan Griffiths <alan@octopull.co.uk> |
546 | + */ |
547 | + |
548 | +#include "mir_test_framework/headless_in_process_server.h" |
549 | + |
550 | +namespace mtf = mir_test_framework; |
551 | + |
552 | +mtf::HeadlessInProcessServer::HeadlessInProcessServer() |
553 | +{ |
554 | + add_to_environment("MIR_SERVER_NO_FILE", ""); |
555 | +} |
556 | + |
557 | +void mtf::HeadlessInProcessServer::SetUp() |
558 | +{ |
559 | + start_server(); |
560 | +} |
561 | + |
562 | +void mtf::HeadlessInProcessServer::TearDown() |
563 | +{ |
564 | + stop_server(); |
565 | +} |
566 | |
567 | === modified file 'tests/mir_test_framework/headless_test.cpp' |
568 | --- tests/mir_test_framework/headless_test.cpp 2014-10-24 18:38:24 +0000 |
569 | +++ tests/mir_test_framework/headless_test.cpp 2014-10-24 18:38:25 +0000 |
570 | @@ -103,7 +103,12 @@ |
571 | |
572 | auto mtf::HeadlessTest::new_connection() -> std::string |
573 | { |
574 | + return connection(server.open_client_socket()); |
575 | +} |
576 | + |
577 | +auto mtf::HeadlessTest::connection(int fd) -> std::string |
578 | +{ |
579 | char connect_string[64] = {0}; |
580 | - sprintf(connect_string, "fd://%d", server.open_client_socket()); |
581 | + sprintf(connect_string, "fd://%d", fd); |
582 | return connect_string; |
583 | } |