Mir

Merge lp:~robertcarr/mir/delete-some-test-code into lp:mir

Proposed by Robert Carr
Status: Merged
Approved by: Robert Carr
Approved revision: no longer in the source branch.
Merged at revision: 1209
Proposed branch: lp:~robertcarr/mir/delete-some-test-code
Merge into: lp:mir
Diff against target: 418 lines (+53/-228)
4 files modified
tests/acceptance-tests/test_client_authorization.cpp (+9/-57)
tests/acceptance-tests/test_client_focus_notification.cpp (+13/-46)
tests/acceptance-tests/test_client_input.cpp (+24/-74)
tests/acceptance-tests/test_focus_selection.cpp (+7/-51)
To merge this branch: bzr merge lp:~robertcarr/mir/delete-some-test-code
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alan Griffiths Approve
Daniel van Vugt Approve
Review via email: mp+194393@code.launchpad.net

This proposal supersedes a proposal from 2013-11-07.

Commit message

Factor out a bunch of "ClientConfigCommon".

Description of the change

Factor out a bunch of "ClientConfigCommon".

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) :
review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

OK

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
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/acceptance-tests/test_client_authorization.cpp'
2--- tests/acceptance-tests/test_client_authorization.cpp 2013-09-25 19:27:16 +0000
3+++ tests/acceptance-tests/test_client_authorization.cpp 2013-11-07 18:01:35 +0000
4@@ -43,62 +43,15 @@
5
6 namespace
7 {
8-
9-struct ClientConfigCommon : TestingClientConfiguration
10-{
11- ClientConfigCommon() :
12- connection(0),
13- surface(0)
14- {
15- }
16-
17- static void connection_callback(MirConnection* connection, void* context)
18- {
19- ClientConfigCommon* config = reinterpret_cast<ClientConfigCommon *>(context);
20- config->connection = connection;
21- }
22-
23- static void create_surface_callback(MirSurface* surface, void* context)
24- {
25- ClientConfigCommon* config = reinterpret_cast<ClientConfigCommon *>(context);
26- config->surface_created(surface);
27- }
28-
29- static void release_surface_callback(MirSurface* surface, void* context)
30- {
31- ClientConfigCommon* config = reinterpret_cast<ClientConfigCommon *>(context);
32- config->surface_released(surface);
33- }
34-
35- virtual void connected(MirConnection* new_connection)
36- {
37- connection = new_connection;
38- }
39-
40- virtual void surface_created(MirSurface* new_surface)
41- {
42- surface = new_surface;
43- }
44-
45- virtual void surface_released(MirSurface* /*released_surface*/)
46- {
47- surface = NULL;
48- }
49-
50- MirConnection* connection;
51- MirSurface* surface;
52-};
53-
54-struct ConnectingClient : ClientConfigCommon
55-{
56+struct ConnectingClient : TestingClientConfiguration
57+{
58+ MirConnection *connection;
59 void exec()
60 {
61- mir_wait_for(mir_connect(
62+ connection = mir_connect_sync(
63 mir_test_socket,
64- __PRETTY_FUNCTION__,
65- connection_callback,
66- this));
67- mir_connection_release(connection);
68+ __PRETTY_FUNCTION__);
69+ mir_connection_release(connection);
70 }
71 };
72
73@@ -235,11 +188,10 @@
74 pid_t client_pid = getpid();
75 shared_region->post_client_process_pid(client_pid);
76
77- mir_wait_for(mir_connect(
78+ connection = mir_connect_sync(
79 mir_test_socket,
80- __PRETTY_FUNCTION__,
81- connection_callback,
82- this));
83+ __PRETTY_FUNCTION__);
84+
85 MirSurfaceParameters const parameters =
86 {
87 __PRETTY_FUNCTION__,
88
89=== modified file 'tests/acceptance-tests/test_client_focus_notification.cpp'
90--- tests/acceptance-tests/test_client_focus_notification.cpp 2013-09-25 18:39:57 +0000
91+++ tests/acceptance-tests/test_client_focus_notification.cpp 2013-11-07 18:01:35 +0000
92@@ -37,50 +37,12 @@
93
94 namespace
95 {
96-struct ClientConfigCommon : TestingClientConfiguration
97-{
98- ClientConfigCommon() :
99- connection(0),
100- surface(0)
101- {
102- }
103- static void connection_callback(MirConnection* connection, void* context)
104- {
105- ClientConfigCommon* config = reinterpret_cast<ClientConfigCommon *>(context);
106- config->connection = connection;
107- }
108- static void create_surface_callback(MirSurface* surface, void* context)
109- {
110- ClientConfigCommon* config = reinterpret_cast<ClientConfigCommon *>(context);
111- config->surface_created(surface);
112- }
113- static void release_surface_callback(MirSurface* surface, void* context)
114- {
115- ClientConfigCommon* config = reinterpret_cast<ClientConfigCommon *>(context);
116- config->surface_released(surface);
117- }
118- virtual void connected(MirConnection* new_connection)
119- {
120- connection = new_connection;
121- }
122- virtual void surface_created(MirSurface* new_surface)
123- {
124- surface = new_surface;
125- }
126- virtual void surface_released(MirSurface* /* released_surface */)
127- {
128- surface = nullptr;
129- }
130- MirConnection* connection;
131- MirSurface* surface;
132-};
133-
134 struct MockEventObserver
135 {
136 MOCK_METHOD1(see, void(MirEvent const*));
137 };
138
139-struct EventObservingClient : ClientConfigCommon
140+struct EventObservingClient : mtf::TestingClientConfiguration
141 {
142 EventObservingClient()
143 : observer(std::make_shared<MockEventObserver>())
144@@ -95,26 +57,28 @@
145
146 virtual void expect_events(mt::WaitCondition* /* all_events_received */) = 0;
147
148- void surface_created(MirSurface *surface_) override
149+ static void surface_created(MirSurface *surface_, void *ctx)
150 {
151+ auto client = static_cast<EventObservingClient*>(ctx);
152+
153+ client->surface = surface_;
154 // We need to set the event delegate from the surface_created
155 // callback so we can block the reading of new events
156 // until we are ready
157 MirEventDelegate const event_delegate =
158 {
159 handle_event,
160- this
161+ client
162 };
163- surface = surface_;
164- mir_surface_set_event_handler(surface, &event_delegate);
165+ mir_surface_set_event_handler(surface_, &event_delegate);
166 }
167
168 void exec()
169 {
170 mt::WaitCondition all_events_received;
171 expect_events(&all_events_received);
172- mir_wait_for(mir_connect(mir_test_socket,
173- __PRETTY_FUNCTION__, connection_callback, this));
174+ connection = mir_connect_sync(mir_test_socket,
175+ __PRETTY_FUNCTION__);
176 ASSERT_TRUE(connection != NULL);
177 MirSurfaceParameters const request_params =
178 {
179@@ -124,7 +88,7 @@
180 mir_buffer_usage_hardware,
181 mir_display_output_id_invalid
182 };
183- mir_wait_for(mir_connection_create_surface(connection, &request_params, create_surface_callback, this));
184+ mir_wait_for(mir_connection_create_surface(connection, &request_params, surface_created, this));
185 all_events_received.wait_for_at_most_seconds(60);
186 mir_surface_release_sync(surface);
187 mir_connection_release(connection);
188@@ -136,6 +100,9 @@
189 std::shared_ptr<MockEventObserver> observer;
190 static int const surface_width = 100;
191 static int const surface_height = 100;
192+
193+ MirConnection *connection;
194+ MirSurface *surface;
195 };
196
197 }
198
199=== modified file 'tests/acceptance-tests/test_client_input.cpp'
200--- tests/acceptance-tests/test_client_input.cpp 2013-10-28 21:41:27 +0000
201+++ tests/acceptance-tests/test_client_input.cpp 2013-11-07 18:01:35 +0000
202@@ -71,57 +71,12 @@
203 namespace
204 {
205
206-struct ClientConfig : mtf::TestingClientConfiguration
207-{
208- ClientConfig() :
209- connection(0),
210- surface(0)
211- {
212- }
213-
214- static void connection_callback(MirConnection* connection, void* context)
215- {
216- ClientConfig* config = reinterpret_cast<ClientConfig *>(context);
217- config->connection = connection;
218- }
219-
220- static void create_surface_callback(MirSurface* surface, void* context)
221- {
222- ClientConfig* config = reinterpret_cast<ClientConfig *>(context);
223- config->surface_created(surface);
224- }
225-
226- static void release_surface_callback(MirSurface* surface, void* context)
227- {
228- ClientConfig* config = reinterpret_cast<ClientConfig *>(context);
229- config->surface_released(surface);
230- }
231-
232- virtual void connected(MirConnection* new_connection)
233- {
234- connection = new_connection;
235- }
236-
237- virtual void surface_created(MirSurface* new_surface)
238- {
239- surface = new_surface;
240- }
241-
242- virtual void surface_released(MirSurface* /* released_surface */)
243- {
244- surface = NULL;
245- }
246-
247- MirConnection* connection;
248- MirSurface* surface;
249-};
250-
251 struct MockInputHandler
252 {
253 MOCK_METHOD1(handle_input, void(MirEvent const*));
254 };
255
256-struct InputClient : ClientConfig
257+struct InputClient : mtf::TestingClientConfiguration
258 {
259 InputClient(const mtf::CrossProcessSync& input_cb_setup_fence, std::string const& client_name)
260 : input_cb_setup_fence(input_cb_setup_fence),
261@@ -129,29 +84,6 @@
262 {
263 }
264
265- virtual void surface_created(MirSurface* new_surface) override
266- {
267- ClientConfig::surface_created(new_surface);
268-
269- MirEventDelegate const event_delegate =
270- {
271- handle_input,
272- this
273- };
274-
275- // Set this in the callback, not main thread to avoid missing test events
276- mir_surface_set_event_handler(surface, &event_delegate);
277-
278- try
279- {
280- input_cb_setup_fence.try_signal_ready_for();
281- } catch (const std::runtime_error& e)
282- {
283- std::cout << e.what() << std::endl;
284- }
285-
286- }
287-
288 static void handle_input(MirSurface* /* surface */, MirEvent const* ev, void* context)
289 {
290 if (ev->type == mir_event_type_surface)
291@@ -182,15 +114,30 @@
292
293 expect_input(events_received);
294
295- mir_wait_for(mir_connect(
296+ connection = mir_connect_sync(
297 mir_test_socket,
298- client_name.c_str(),
299- connection_callback,
300- this));
301+ client_name.c_str());
302 ASSERT_TRUE(connection != NULL);
303
304 auto request_params = parameters();
305- mir_wait_for(mir_connection_create_surface(connection, &request_params, create_surface_callback, this));
306+ surface = mir_connection_create_surface_sync(connection, &request_params);
307+
308+ MirEventDelegate const event_delegate =
309+ {
310+ handle_input,
311+ this
312+ };
313+ // Set this in the callback, not main thread to avoid missing test events
314+ mir_surface_set_event_handler(surface, &event_delegate);
315+
316+ try
317+ {
318+ input_cb_setup_fence.try_signal_ready_for();
319+ }
320+ catch (const std::runtime_error& e)
321+ {
322+ std::cout << e.what() << std::endl;
323+ }
324
325 events_received.wait_for_at_most_seconds(60);
326
327@@ -211,6 +158,9 @@
328
329 static int const surface_width = 100;
330 static int const surface_height = 100;
331+
332+ MirConnection* connection;
333+ MirSurface* surface;
334 };
335
336 MATCHER(KeyDownEvent, "")
337
338=== modified file 'tests/acceptance-tests/test_focus_selection.cpp'
339--- tests/acceptance-tests/test_focus_selection.cpp 2013-11-04 05:59:29 +0000
340+++ tests/acceptance-tests/test_focus_selection.cpp 2013-11-07 18:01:35 +0000
341@@ -49,60 +49,13 @@
342 namespace
343 {
344
345-struct ClientConfigCommon : TestingClientConfiguration
346-{
347- ClientConfigCommon() :
348- connection(0),
349- surface(0)
350- {
351- }
352-
353- static void connection_callback(MirConnection* connection, void* context)
354- {
355- ClientConfigCommon* config = reinterpret_cast<ClientConfigCommon *>(context);
356- config->connection = connection;
357- }
358-
359- static void create_surface_callback(MirSurface* surface, void* context)
360- {
361- ClientConfigCommon* config = reinterpret_cast<ClientConfigCommon *>(context);
362- config->surface_created(surface);
363- }
364-
365- static void release_surface_callback(MirSurface* surface, void* context)
366- {
367- ClientConfigCommon* config = reinterpret_cast<ClientConfigCommon *>(context);
368- config->surface_released(surface);
369- }
370-
371- virtual void connected(MirConnection* new_connection)
372- {
373- connection = new_connection;
374- }
375-
376- virtual void surface_created(MirSurface* new_surface)
377- {
378- surface = new_surface;
379- }
380-
381- virtual void surface_released(MirSurface* /*released_surface*/)
382- {
383- surface = NULL;
384- }
385-
386- MirConnection* connection;
387- MirSurface* surface;
388-};
389-
390-struct SurfaceCreatingClient : ClientConfigCommon
391+struct SurfaceCreatingClient : mtf::TestingClientConfiguration
392 {
393 void exec()
394 {
395- mir_wait_for(mir_connect(
396+ connection = mir_connect_sync(
397 mir_test_socket,
398- __PRETTY_FUNCTION__,
399- connection_callback,
400- this));
401+ __PRETTY_FUNCTION__);
402 ASSERT_TRUE(connection != NULL);
403 MirSurfaceParameters const request_params =
404 {
405@@ -112,9 +65,12 @@
406 mir_buffer_usage_hardware,
407 mir_display_output_id_invalid
408 };
409- mir_wait_for(mir_connection_create_surface(connection, &request_params, create_surface_callback, this));
410+ surface = mir_connection_create_surface_sync(connection, &request_params);
411 mir_connection_release(connection);
412 }
413+
414+ MirConnection* connection;
415+ MirSurface* surface;
416 };
417
418 }

Subscribers

People subscribed via source and target branches