blob: 1dc1457b6624ff7a09f5b8577cb48c6b816e4147 [file] [log] [blame]
Pekka Paalanenf5b74f72015-03-25 12:50:31 +02001/*
2 * Copyright © 2015 Collabora, Ltd.
3 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07004 * 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:
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020011 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070012 * 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.
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020024 */
25
26#include "config.h"
27
28#include <stdio.h>
29#include <string.h>
30
Jon Cruz35b2eaa2015-06-15 15:37:08 -070031#include "shared/helpers.h"
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020032#include "weston-test-client-helper.h"
33#include "ivi-application-client-protocol.h"
34#include "ivi-test.h"
35
36struct runner {
37 struct client *client;
38 struct weston_test_runner *test_runner;
39 int done;
40};
41
42static void
43runner_finished_handler(void *data, struct weston_test_runner *test_runner)
44{
45 struct runner *runner = data;
46
47 runner->done = 1;
48}
49
50static const struct weston_test_runner_listener test_runner_listener = {
51 runner_finished_handler
52};
53
54static struct runner *
55client_create_runner(struct client *client)
56{
57 struct runner *runner;
58 struct global *g;
59 struct global *global_runner = NULL;
60
61 runner = xzalloc(sizeof(*runner));
62 runner->client = client;
63
64 wl_list_for_each(g, &client->global_list, link) {
65 if (strcmp(g->interface, "weston_test_runner"))
66 continue;
67
68 if (global_runner)
69 assert(0 && "multiple weston_test_runner objects");
70
71 global_runner = g;
72 }
73
74 assert(global_runner && "no weston_test_runner found");
75 assert(global_runner->version == 1);
76
77 runner->test_runner = wl_registry_bind(client->wl_registry,
78 global_runner->name,
79 &weston_test_runner_interface,
80 1);
81 assert(runner->test_runner);
82
83 weston_test_runner_add_listener(runner->test_runner,
84 &test_runner_listener, runner);
85
86 return runner;
87}
88
89static void
90runner_destroy(struct runner *runner)
91{
92 weston_test_runner_destroy(runner->test_runner);
93 client_roundtrip(runner->client);
94 free(runner);
95}
96
97static void
98runner_run(struct runner *runner, const char *test_name)
99{
100 fprintf(stderr, "weston_test_runner.run(\"%s\")\n", test_name);
101
102 runner->done = 0;
103 weston_test_runner_run(runner->test_runner, test_name);
104
105 while (!runner->done) {
106 if (wl_display_dispatch(runner->client->wl_display) < 0)
107 assert(0 && "runner wait");
108 }
109}
110
111static struct ivi_application *
112get_ivi_application(struct client *client)
113{
114 struct global *g;
115 struct global *global_iviapp = NULL;
116 static struct ivi_application *iviapp;
117
118 if (iviapp)
119 return iviapp;
120
121 wl_list_for_each(g, &client->global_list, link) {
122 if (strcmp(g->interface, "ivi_application"))
123 continue;
124
125 if (global_iviapp)
126 assert(0 && "multiple ivi_application objects");
127
128 global_iviapp = g;
129 }
130
131 assert(global_iviapp && "no ivi_application found");
132
133 assert(global_iviapp->version == 1);
134
135 iviapp = wl_registry_bind(client->wl_registry, global_iviapp->name,
136 &ivi_application_interface, 1);
137 assert(iviapp);
138
139 return iviapp;
140}
141
142struct ivi_window {
143 struct wl_surface *wl_surface;
144 struct ivi_surface *ivi_surface;
145 uint32_t ivi_id;
146};
147
148static struct ivi_window *
149client_create_ivi_window(struct client *client, uint32_t ivi_id)
150{
151 struct ivi_application *iviapp;
152 struct ivi_window *wnd;
153
154 iviapp = get_ivi_application(client);
155
156 wnd = xzalloc(sizeof(*wnd));
157 wnd->wl_surface = wl_compositor_create_surface(client->wl_compositor);
158 wnd->ivi_surface = ivi_application_surface_create(iviapp, ivi_id,
159 wnd->wl_surface);
160 wnd->ivi_id = ivi_id;
161
162 return wnd;
163}
164
165static void
166ivi_window_destroy(struct ivi_window *wnd)
167{
168 ivi_surface_destroy(wnd->ivi_surface);
169 wl_surface_destroy(wnd->wl_surface);
170 free(wnd);
171}
172
173/******************************** tests ********************************/
174
175/*
176 * This is a test program, launched by ivi_layout-test-plugin.c. Each TEST()
177 * is forked and exec'd as usual with the weston-test-runner framework.
178 *
179 * These tests make use of weston_test_runner global interface exposed by
180 * ivi_layout-test-plugin.c. This allows these tests to trigger compositor-side
181 * checks.
182 *
183 * See ivi_layout-test-plugin.c for further details.
184 */
185
186/**
187 * RUNNER_TEST() names are defined in ivi_layout-test-plugin.c.
188 * Each RUNNER_TEST name listed here uses the same simple initial client setup.
189 */
190const char * const basic_test_names[] = {
191 "surface_visibility",
192 "surface_opacity",
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900193 "surface_orientation",
194 "surface_dimension",
195 "surface_position",
196 "surface_destination_rectangle",
197 "surface_source_rectangle",
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900198 "surface_bad_opacity",
199};
200
201const char * const surface_property_commit_changes_test_names[] = {
202 "commit_changes_after_visibility_set_surface_destroy",
203 "commit_changes_after_opacity_set_surface_destroy",
204 "commit_changes_after_orientation_set_surface_destroy",
205 "commit_changes_after_dimension_set_surface_destroy",
206 "commit_changes_after_position_set_surface_destroy",
207 "commit_changes_after_source_rectangle_set_surface_destroy",
208 "commit_changes_after_destination_rectangle_set_surface_destroy",
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200209};
210
211TEST_P(ivi_layout_runner, basic_test_names)
212{
213 /* an element from basic_test_names */
214 const char * const *test_name = data;
215 struct client *client;
216 struct runner *runner;
217 struct ivi_window *wnd;
218
219 client = create_client();
220 runner = client_create_runner(client);
221
222 wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
223
224 runner_run(runner, *test_name);
225
226 ivi_window_destroy(wnd);
227 runner_destroy(runner);
228}
229
230TEST(ivi_layout_surface_create)
231{
232 struct client *client;
233 struct runner *runner;
234 struct ivi_window *winds[2];
235
236 client = create_client();
237 runner = client_create_runner(client);
238
239 winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
240 winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1));
241
242 runner_run(runner, "surface_create_p1");
243
244 ivi_window_destroy(winds[0]);
245
246 runner_run(runner, "surface_create_p2");
247
248 ivi_window_destroy(winds[1]);
249 runner_destroy(runner);
250}
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900251
252TEST_P(commit_changes_after_properties_set_surface_destroy, surface_property_commit_changes_test_names)
253{
254 /* an element from surface_property_commit_changes_test_names */
255 const char * const *test_name = data;
256 struct client *client;
257 struct runner *runner;
258 struct ivi_window *wnd;
259
260 client = create_client();
261 runner = client_create_runner(client);
262
263 wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
264
265 runner_run(runner, *test_name);
266
267 ivi_window_destroy(wnd);
268
269 runner_run(runner, "ivi_layout_commit_changes");
270
271 runner_destroy(runner);
272}
273
274TEST(get_surface_after_destroy_ivi_surface)
275{
276 struct client *client;
277 struct runner *runner;
278 struct ivi_window *wnd;
279
280 client = create_client();
281 runner = client_create_runner(client);
282
283 wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
284
285 ivi_surface_destroy(wnd->ivi_surface);
286
287 runner_run(runner, "get_surface_after_destroy_surface");
288
289 wl_surface_destroy(wnd->wl_surface);
290 free(wnd);
291 runner_destroy(runner);
292}
293
294TEST(get_surface_after_destroy_wl_surface)
295{
296 struct client *client;
297 struct runner *runner;
298 struct ivi_window *wnd;
299
300 client = create_client();
301 runner = client_create_runner(client);
302
303 wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
304
305 wl_surface_destroy(wnd->wl_surface);
306
307 runner_run(runner, "get_surface_after_destroy_surface");
308
309 ivi_surface_destroy(wnd->ivi_surface);
310 free(wnd);
311 runner_destroy(runner);
312}