blob: daa9aa779c22e196e3007640df91deb306a5f00d [file] [log] [blame]
Pekka Paalanenf5b74f72015-03-25 12:50:31 +02001/*
2 * Copyright © 2015 Collabora, Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#include "config.h"
24
25#include <stdio.h>
26#include <string.h>
27
28#include "weston-test-client-helper.h"
29#include "ivi-application-client-protocol.h"
30#include "ivi-test.h"
31
32struct runner {
33 struct client *client;
34 struct weston_test_runner *test_runner;
35 int done;
36};
37
38static void
39runner_finished_handler(void *data, struct weston_test_runner *test_runner)
40{
41 struct runner *runner = data;
42
43 runner->done = 1;
44}
45
46static const struct weston_test_runner_listener test_runner_listener = {
47 runner_finished_handler
48};
49
50static struct runner *
51client_create_runner(struct client *client)
52{
53 struct runner *runner;
54 struct global *g;
55 struct global *global_runner = NULL;
56
57 runner = xzalloc(sizeof(*runner));
58 runner->client = client;
59
60 wl_list_for_each(g, &client->global_list, link) {
61 if (strcmp(g->interface, "weston_test_runner"))
62 continue;
63
64 if (global_runner)
65 assert(0 && "multiple weston_test_runner objects");
66
67 global_runner = g;
68 }
69
70 assert(global_runner && "no weston_test_runner found");
71 assert(global_runner->version == 1);
72
73 runner->test_runner = wl_registry_bind(client->wl_registry,
74 global_runner->name,
75 &weston_test_runner_interface,
76 1);
77 assert(runner->test_runner);
78
79 weston_test_runner_add_listener(runner->test_runner,
80 &test_runner_listener, runner);
81
82 return runner;
83}
84
85static void
86runner_destroy(struct runner *runner)
87{
88 weston_test_runner_destroy(runner->test_runner);
89 client_roundtrip(runner->client);
90 free(runner);
91}
92
93static void
94runner_run(struct runner *runner, const char *test_name)
95{
96 fprintf(stderr, "weston_test_runner.run(\"%s\")\n", test_name);
97
98 runner->done = 0;
99 weston_test_runner_run(runner->test_runner, test_name);
100
101 while (!runner->done) {
102 if (wl_display_dispatch(runner->client->wl_display) < 0)
103 assert(0 && "runner wait");
104 }
105}
106
107static struct ivi_application *
108get_ivi_application(struct client *client)
109{
110 struct global *g;
111 struct global *global_iviapp = NULL;
112 static struct ivi_application *iviapp;
113
114 if (iviapp)
115 return iviapp;
116
117 wl_list_for_each(g, &client->global_list, link) {
118 if (strcmp(g->interface, "ivi_application"))
119 continue;
120
121 if (global_iviapp)
122 assert(0 && "multiple ivi_application objects");
123
124 global_iviapp = g;
125 }
126
127 assert(global_iviapp && "no ivi_application found");
128
129 assert(global_iviapp->version == 1);
130
131 iviapp = wl_registry_bind(client->wl_registry, global_iviapp->name,
132 &ivi_application_interface, 1);
133 assert(iviapp);
134
135 return iviapp;
136}
137
138struct ivi_window {
139 struct wl_surface *wl_surface;
140 struct ivi_surface *ivi_surface;
141 uint32_t ivi_id;
142};
143
144static struct ivi_window *
145client_create_ivi_window(struct client *client, uint32_t ivi_id)
146{
147 struct ivi_application *iviapp;
148 struct ivi_window *wnd;
149
150 iviapp = get_ivi_application(client);
151
152 wnd = xzalloc(sizeof(*wnd));
153 wnd->wl_surface = wl_compositor_create_surface(client->wl_compositor);
154 wnd->ivi_surface = ivi_application_surface_create(iviapp, ivi_id,
155 wnd->wl_surface);
156 wnd->ivi_id = ivi_id;
157
158 return wnd;
159}
160
161static void
162ivi_window_destroy(struct ivi_window *wnd)
163{
164 ivi_surface_destroy(wnd->ivi_surface);
165 wl_surface_destroy(wnd->wl_surface);
166 free(wnd);
167}
168
169/******************************** tests ********************************/
170
171/*
172 * This is a test program, launched by ivi_layout-test-plugin.c. Each TEST()
173 * is forked and exec'd as usual with the weston-test-runner framework.
174 *
175 * These tests make use of weston_test_runner global interface exposed by
176 * ivi_layout-test-plugin.c. This allows these tests to trigger compositor-side
177 * checks.
178 *
179 * See ivi_layout-test-plugin.c for further details.
180 */
181
182/**
183 * RUNNER_TEST() names are defined in ivi_layout-test-plugin.c.
184 * Each RUNNER_TEST name listed here uses the same simple initial client setup.
185 */
186const char * const basic_test_names[] = {
187 "surface_visibility",
188 "surface_opacity",
189};
190
191TEST_P(ivi_layout_runner, basic_test_names)
192{
193 /* an element from basic_test_names */
194 const char * const *test_name = data;
195 struct client *client;
196 struct runner *runner;
197 struct ivi_window *wnd;
198
199 client = create_client();
200 runner = client_create_runner(client);
201
202 wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
203
204 runner_run(runner, *test_name);
205
206 ivi_window_destroy(wnd);
207 runner_destroy(runner);
208}
209
210TEST(ivi_layout_surface_create)
211{
212 struct client *client;
213 struct runner *runner;
214 struct ivi_window *winds[2];
215
216 client = create_client();
217 runner = client_create_runner(client);
218
219 winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
220 winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1));
221
222 runner_run(runner, "surface_create_p1");
223
224 ivi_window_destroy(winds[0]);
225
226 runner_run(runner, "surface_create_p2");
227
228 ivi_window_destroy(winds[1]);
229 runner_destroy(runner);
230}