blob: d6401c4db5fa9605b127508c124956fa28974154 [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",
193};
194
195TEST_P(ivi_layout_runner, basic_test_names)
196{
197 /* an element from basic_test_names */
198 const char * const *test_name = data;
199 struct client *client;
200 struct runner *runner;
201 struct ivi_window *wnd;
202
203 client = create_client();
204 runner = client_create_runner(client);
205
206 wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
207
208 runner_run(runner, *test_name);
209
210 ivi_window_destroy(wnd);
211 runner_destroy(runner);
212}
213
214TEST(ivi_layout_surface_create)
215{
216 struct client *client;
217 struct runner *runner;
218 struct ivi_window *winds[2];
219
220 client = create_client();
221 runner = client_create_runner(client);
222
223 winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
224 winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1));
225
226 runner_run(runner, "surface_create_p1");
227
228 ivi_window_destroy(winds[0]);
229
230 runner_run(runner, "surface_create_p2");
231
232 ivi_window_destroy(winds[1]);
233 runner_destroy(runner);
234}