tests: add test_seat_release() for symmetry
[platform/upstream/weston.git] / tests / ivi_layout-test.c
1 /*
2  * Copyright © 2015 Collabora, Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial
14  * portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25
26 #include "config.h"
27
28 #include <stdint.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #include "shared/helpers.h"
33 #include "shared/xalloc.h"
34 #include "weston-test-client-helper.h"
35 #include "ivi-application-client-protocol.h"
36 #include "ivi-test.h"
37
38 struct runner {
39         struct client *client;
40         struct weston_test_runner *test_runner;
41         int done;
42 };
43
44 static void
45 runner_finished_handler(void *data, struct weston_test_runner *test_runner)
46 {
47         struct runner *runner = data;
48
49         runner->done = 1;
50 }
51
52 static const struct weston_test_runner_listener test_runner_listener = {
53         runner_finished_handler
54 };
55
56 static struct runner *
57 client_create_runner(struct client *client)
58 {
59         struct runner *runner;
60         struct global *g;
61         struct global *global_runner = NULL;
62
63         runner = xzalloc(sizeof(*runner));
64         runner->client = client;
65
66         wl_list_for_each(g, &client->global_list, link) {
67                 if (strcmp(g->interface, "weston_test_runner"))
68                         continue;
69
70                 if (global_runner)
71                         assert(0 && "multiple weston_test_runner objects");
72
73                 global_runner = g;
74         }
75
76         assert(global_runner && "no weston_test_runner found");
77         assert(global_runner->version == 1);
78
79         runner->test_runner = wl_registry_bind(client->wl_registry,
80                                                global_runner->name,
81                                                &weston_test_runner_interface,
82                                                1);
83         assert(runner->test_runner);
84
85         weston_test_runner_add_listener(runner->test_runner,
86                                         &test_runner_listener, runner);
87
88         return runner;
89 }
90
91 static void
92 runner_destroy(struct runner *runner)
93 {
94         weston_test_runner_destroy(runner->test_runner);
95         client_roundtrip(runner->client);
96         free(runner);
97 }
98
99 static void
100 runner_run(struct runner *runner, const char *test_name)
101 {
102         fprintf(stderr, "weston_test_runner.run(\"%s\")\n", test_name);
103
104         runner->done = 0;
105         weston_test_runner_run(runner->test_runner, test_name);
106
107         while (!runner->done) {
108                 if (wl_display_dispatch(runner->client->wl_display) < 0)
109                         assert(0 && "runner wait");
110         }
111 }
112
113 static struct ivi_application *
114 get_ivi_application(struct client *client)
115 {
116         struct global *g;
117         struct global *global_iviapp = NULL;
118         static struct ivi_application *iviapp;
119
120         if (iviapp)
121                 return iviapp;
122
123         wl_list_for_each(g, &client->global_list, link) {
124                 if (strcmp(g->interface, "ivi_application"))
125                         continue;
126
127                 if (global_iviapp)
128                         assert(0 && "multiple ivi_application objects");
129
130                 global_iviapp = g;
131         }
132
133         assert(global_iviapp && "no ivi_application found");
134
135         assert(global_iviapp->version == 1);
136
137         iviapp = wl_registry_bind(client->wl_registry, global_iviapp->name,
138                                   &ivi_application_interface, 1);
139         assert(iviapp);
140
141         return iviapp;
142 }
143
144 struct ivi_window {
145         struct wl_surface *wl_surface;
146         struct ivi_surface *ivi_surface;
147         uint32_t ivi_id;
148 };
149
150 static struct ivi_window *
151 client_create_ivi_window(struct client *client, uint32_t ivi_id)
152 {
153         struct ivi_application *iviapp;
154         struct ivi_window *wnd;
155
156         iviapp = get_ivi_application(client);
157
158         wnd = xzalloc(sizeof(*wnd));
159         wnd->wl_surface = wl_compositor_create_surface(client->wl_compositor);
160         wnd->ivi_surface = ivi_application_surface_create(iviapp, ivi_id,
161                                                           wnd->wl_surface);
162         wnd->ivi_id = ivi_id;
163
164         return wnd;
165 }
166
167 static void
168 ivi_window_destroy(struct ivi_window *wnd)
169 {
170         ivi_surface_destroy(wnd->ivi_surface);
171         wl_surface_destroy(wnd->wl_surface);
172         free(wnd);
173 }
174
175 /******************************** tests ********************************/
176
177 /*
178  * This is a test program, launched by ivi_layout-test-plugin.c. Each TEST()
179  * is forked and exec'd as usual with the weston-test-runner framework.
180  *
181  * These tests make use of weston_test_runner global interface exposed by
182  * ivi_layout-test-plugin.c. This allows these tests to trigger compositor-side
183  * checks.
184  *
185  * See ivi_layout-test-plugin.c for further details.
186  */
187
188 /**
189  * RUNNER_TEST() names are defined in ivi_layout-test-plugin.c.
190  * Each RUNNER_TEST name listed here uses the same simple initial client setup.
191  */
192 const char * const basic_test_names[] = {
193         "surface_visibility",
194         "surface_opacity",
195         "surface_dimension",
196         "surface_position",
197         "surface_destination_rectangle",
198         "surface_source_rectangle",
199         "surface_bad_opacity",
200         "surface_properties_changed_notification",
201         "surface_bad_properties_changed_notification",
202         "surface_on_many_layer",
203 };
204
205 const char * const surface_property_commit_changes_test_names[] = {
206         "commit_changes_after_visibility_set_surface_destroy",
207         "commit_changes_after_opacity_set_surface_destroy",
208         "commit_changes_after_source_rectangle_set_surface_destroy",
209         "commit_changes_after_destination_rectangle_set_surface_destroy",
210 };
211
212 const char * const render_order_test_names[] = {
213         "layer_render_order",
214         "layer_bad_render_order",
215         "layer_add_surfaces",
216 };
217
218 TEST_P(ivi_layout_runner, basic_test_names)
219 {
220         /* an element from basic_test_names */
221         const char * const *test_name = data;
222         struct client *client;
223         struct runner *runner;
224         struct ivi_window *wnd;
225
226         client = create_client();
227         runner = client_create_runner(client);
228
229         wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
230
231         runner_run(runner, *test_name);
232
233         ivi_window_destroy(wnd);
234         runner_destroy(runner);
235 }
236
237 TEST(ivi_layout_surface_create)
238 {
239         struct client *client;
240         struct runner *runner;
241         struct ivi_window *winds[2];
242
243         client = create_client();
244         runner = client_create_runner(client);
245
246         winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
247         winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1));
248
249         runner_run(runner, "surface_create_p1");
250
251         ivi_window_destroy(winds[0]);
252
253         runner_run(runner, "surface_create_p2");
254
255         ivi_window_destroy(winds[1]);
256         runner_destroy(runner);
257 }
258
259 TEST_P(commit_changes_after_properties_set_surface_destroy, surface_property_commit_changes_test_names)
260 {
261         /* an element from surface_property_commit_changes_test_names */
262         const char * const *test_name = data;
263         struct client *client;
264         struct runner *runner;
265         struct ivi_window *wnd;
266
267         client = create_client();
268         runner = client_create_runner(client);
269
270         wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
271
272         runner_run(runner, *test_name);
273
274         ivi_window_destroy(wnd);
275
276         runner_run(runner, "ivi_layout_commit_changes");
277
278         runner_destroy(runner);
279 }
280
281 TEST(get_surface_after_destroy_ivi_surface)
282 {
283         struct client *client;
284         struct runner *runner;
285         struct ivi_window *wnd;
286
287         client = create_client();
288         runner = client_create_runner(client);
289
290         wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
291
292         ivi_surface_destroy(wnd->ivi_surface);
293
294         runner_run(runner, "get_surface_after_destroy_surface");
295
296         wl_surface_destroy(wnd->wl_surface);
297         free(wnd);
298         runner_destroy(runner);
299 }
300
301 TEST(get_surface_after_destroy_wl_surface)
302 {
303         struct client *client;
304         struct runner *runner;
305         struct ivi_window *wnd;
306
307         client = create_client();
308         runner = client_create_runner(client);
309
310         wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
311
312         wl_surface_destroy(wnd->wl_surface);
313
314         runner_run(runner, "get_surface_after_destroy_surface");
315
316         ivi_surface_destroy(wnd->ivi_surface);
317         free(wnd);
318         runner_destroy(runner);
319 }
320
321 TEST_P(ivi_layout_layer_render_order_runner, render_order_test_names)
322 {
323         /* an element from render_order_test_names */
324         const char * const *test_name = data;
325         struct client *client;
326         struct runner *runner;
327         struct ivi_window *winds[3];
328
329         client = create_client();
330         runner = client_create_runner(client);
331
332         winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
333         winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1));
334         winds[2] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(2));
335
336         runner_run(runner, *test_name);
337
338         ivi_window_destroy(winds[0]);
339         ivi_window_destroy(winds[1]);
340         ivi_window_destroy(winds[2]);
341         runner_destroy(runner);
342 }
343
344 TEST(destroy_surface_after_layer_render_order)
345 {
346         struct client *client;
347         struct runner *runner;
348         struct ivi_window *winds[3];
349
350         client = create_client();
351         runner = client_create_runner(client);
352
353         winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
354         winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1));
355         winds[2] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(2));
356
357         runner_run(runner, "test_layer_render_order_destroy_one_surface_p1");
358
359         ivi_window_destroy(winds[1]);
360
361         runner_run(runner, "test_layer_render_order_destroy_one_surface_p2");
362
363         ivi_window_destroy(winds[0]);
364         ivi_window_destroy(winds[2]);
365         runner_destroy(runner);
366 }
367
368 TEST(commit_changes_after_render_order_set_surface_destroy)
369 {
370         struct client *client;
371         struct runner *runner;
372         struct ivi_window *winds[3];
373
374         client = create_client();
375         runner = client_create_runner(client);
376
377         winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
378         winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1));
379         winds[2] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(2));
380
381         runner_run(runner, "commit_changes_after_render_order_set_surface_destroy");
382
383         ivi_window_destroy(winds[1]);
384
385         runner_run(runner, "ivi_layout_commit_changes");
386         runner_run(runner, "cleanup_layer");
387
388         ivi_window_destroy(winds[0]);
389         ivi_window_destroy(winds[2]);
390         runner_destroy(runner);
391 }
392
393 TEST(ivi_layout_surface_configure_notification)
394 {
395         struct client *client;
396         struct runner *runner;
397         struct ivi_window *wind;
398         struct buffer *buffer;
399
400         client = create_client();
401         runner = client_create_runner(client);
402
403         runner_run(runner, "surface_configure_notification_p1");
404
405         wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
406
407         buffer = create_shm_buffer_a8r8g8b8(client, 200, 300);
408
409         wl_surface_attach(wind->wl_surface, buffer->proxy, 0, 0);
410         wl_surface_damage(wind->wl_surface, 0, 0, 20, 30);
411         wl_surface_commit(wind->wl_surface);
412
413         runner_run(runner, "surface_configure_notification_p2");
414
415         wl_surface_attach(wind->wl_surface, buffer->proxy, 0, 0);
416         wl_surface_damage(wind->wl_surface, 0, 0, 40, 50);
417         wl_surface_commit(wind->wl_surface);
418
419         runner_run(runner, "surface_configure_notification_p3");
420
421         buffer_destroy(buffer);
422         ivi_window_destroy(wind);
423         runner_destroy(runner);
424 }
425
426 TEST(ivi_layout_surface_create_notification)
427 {
428         struct client *client;
429         struct runner *runner;
430         struct ivi_window *wind;
431
432         client = create_client();
433         runner = client_create_runner(client);
434
435         runner_run(runner, "surface_create_notification_p1");
436
437         wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
438
439         runner_run(runner, "surface_create_notification_p2");
440
441         ivi_window_destroy(wind);
442         wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
443         runner_run(runner, "surface_create_notification_p3");
444
445         ivi_window_destroy(wind);
446         runner_destroy(runner);
447 }
448
449 TEST(ivi_layout_surface_remove_notification)
450 {
451         struct client *client;
452         struct runner *runner;
453         struct ivi_window *wind;
454
455         client = create_client();
456         runner = client_create_runner(client);
457
458         wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
459         runner_run(runner, "surface_remove_notification_p1");
460         ivi_window_destroy(wind);
461
462         runner_run(runner, "surface_remove_notification_p2");
463
464         wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
465         ivi_window_destroy(wind);
466         runner_run(runner, "surface_remove_notification_p3");
467
468         runner_destroy(runner);
469 }