blob: 90dee296b8b49d95a2a766d6bcb13212fc45df55 [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
31#include "weston-test-client-helper.h"
32#include "ivi-application-client-protocol.h"
33#include "ivi-test.h"
34
35struct runner {
36 struct client *client;
37 struct weston_test_runner *test_runner;
38 int done;
39};
40
41static void
42runner_finished_handler(void *data, struct weston_test_runner *test_runner)
43{
44 struct runner *runner = data;
45
46 runner->done = 1;
47}
48
49static const struct weston_test_runner_listener test_runner_listener = {
50 runner_finished_handler
51};
52
53static struct runner *
54client_create_runner(struct client *client)
55{
56 struct runner *runner;
57 struct global *g;
58 struct global *global_runner = NULL;
59
60 runner = xzalloc(sizeof(*runner));
61 runner->client = client;
62
63 wl_list_for_each(g, &client->global_list, link) {
64 if (strcmp(g->interface, "weston_test_runner"))
65 continue;
66
67 if (global_runner)
68 assert(0 && "multiple weston_test_runner objects");
69
70 global_runner = g;
71 }
72
73 assert(global_runner && "no weston_test_runner found");
74 assert(global_runner->version == 1);
75
76 runner->test_runner = wl_registry_bind(client->wl_registry,
77 global_runner->name,
78 &weston_test_runner_interface,
79 1);
80 assert(runner->test_runner);
81
82 weston_test_runner_add_listener(runner->test_runner,
83 &test_runner_listener, runner);
84
85 return runner;
86}
87
88static void
89runner_destroy(struct runner *runner)
90{
91 weston_test_runner_destroy(runner->test_runner);
92 client_roundtrip(runner->client);
93 free(runner);
94}
95
96static void
97runner_run(struct runner *runner, const char *test_name)
98{
99 fprintf(stderr, "weston_test_runner.run(\"%s\")\n", test_name);
100
101 runner->done = 0;
102 weston_test_runner_run(runner->test_runner, test_name);
103
104 while (!runner->done) {
105 if (wl_display_dispatch(runner->client->wl_display) < 0)
106 assert(0 && "runner wait");
107 }
108}
109
110static struct ivi_application *
111get_ivi_application(struct client *client)
112{
113 struct global *g;
114 struct global *global_iviapp = NULL;
115 static struct ivi_application *iviapp;
116
117 if (iviapp)
118 return iviapp;
119
120 wl_list_for_each(g, &client->global_list, link) {
121 if (strcmp(g->interface, "ivi_application"))
122 continue;
123
124 if (global_iviapp)
125 assert(0 && "multiple ivi_application objects");
126
127 global_iviapp = g;
128 }
129
130 assert(global_iviapp && "no ivi_application found");
131
132 assert(global_iviapp->version == 1);
133
134 iviapp = wl_registry_bind(client->wl_registry, global_iviapp->name,
135 &ivi_application_interface, 1);
136 assert(iviapp);
137
138 return iviapp;
139}
140
141struct ivi_window {
142 struct wl_surface *wl_surface;
143 struct ivi_surface *ivi_surface;
144 uint32_t ivi_id;
145};
146
147static struct ivi_window *
148client_create_ivi_window(struct client *client, uint32_t ivi_id)
149{
150 struct ivi_application *iviapp;
151 struct ivi_window *wnd;
152
153 iviapp = get_ivi_application(client);
154
155 wnd = xzalloc(sizeof(*wnd));
156 wnd->wl_surface = wl_compositor_create_surface(client->wl_compositor);
157 wnd->ivi_surface = ivi_application_surface_create(iviapp, ivi_id,
158 wnd->wl_surface);
159 wnd->ivi_id = ivi_id;
160
161 return wnd;
162}
163
164static void
165ivi_window_destroy(struct ivi_window *wnd)
166{
167 ivi_surface_destroy(wnd->ivi_surface);
168 wl_surface_destroy(wnd->wl_surface);
169 free(wnd);
170}
171
172/******************************** tests ********************************/
173
174/*
175 * This is a test program, launched by ivi_layout-test-plugin.c. Each TEST()
176 * is forked and exec'd as usual with the weston-test-runner framework.
177 *
178 * These tests make use of weston_test_runner global interface exposed by
179 * ivi_layout-test-plugin.c. This allows these tests to trigger compositor-side
180 * checks.
181 *
182 * See ivi_layout-test-plugin.c for further details.
183 */
184
185/**
186 * RUNNER_TEST() names are defined in ivi_layout-test-plugin.c.
187 * Each RUNNER_TEST name listed here uses the same simple initial client setup.
188 */
189const char * const basic_test_names[] = {
190 "surface_visibility",
191 "surface_opacity",
192};
193
194TEST_P(ivi_layout_runner, basic_test_names)
195{
196 /* an element from basic_test_names */
197 const char * const *test_name = data;
198 struct client *client;
199 struct runner *runner;
200 struct ivi_window *wnd;
201
202 client = create_client();
203 runner = client_create_runner(client);
204
205 wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
206
207 runner_run(runner, *test_name);
208
209 ivi_window_destroy(wnd);
210 runner_destroy(runner);
211}
212
213TEST(ivi_layout_surface_create)
214{
215 struct client *client;
216 struct runner *runner;
217 struct ivi_window *winds[2];
218
219 client = create_client();
220 runner = client_create_runner(client);
221
222 winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
223 winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1));
224
225 runner_run(runner, "surface_create_p1");
226
227 ivi_window_destroy(winds[0]);
228
229 runner_run(runner, "surface_create_p2");
230
231 ivi_window_destroy(winds[1]);
232 runner_destroy(runner);
233}