blob: 66076687dcf9551bcab2891d35a75664deb007e5 [file] [log] [blame]
Kristian Høgsberg3018b442012-04-27 15:02:56 -04001/*
2 * Copyright © 2012 Intel Corporation
Pekka Paalanend1c426e2013-02-08 17:01:27 +02003 * Copyright © 2013 Collabora, Ltd.
Kristian Høgsberg3018b442012-04-27 15:02:56 -04004 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
Bryce Harrington12cc4052014-11-19 17:18:33 -080024#include "config.h"
25
U. Artie Eoff84f9db52012-12-07 13:50:33 -080026#include "weston-test-client-helper.h"
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070027
28static void
U. Artie Eoff84f9db52012-12-07 13:50:33 -080029check_pointer(struct client *client, int x, int y)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070030{
U. Artie Eoff84f9db52012-12-07 13:50:33 -080031 int sx, sy;
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070032
U. Artie Eoff84f9db52012-12-07 13:50:33 -080033 /* check that the client got the global pointer update */
34 assert(client->test->pointer_x == x);
35 assert(client->test->pointer_y == y);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070036
U. Artie Eoff84f9db52012-12-07 13:50:33 -080037 /* Does global pointer map onto the surface? */
38 if (surface_contains(client->surface, x, y)) {
39 /* check that the surface has the pointer focus */
40 assert(client->input->pointer->focus == client->surface);
41
42 /*
43 * check that the local surface pointer maps
44 * to the global pointer.
45 */
46 sx = client->input->pointer->x + client->surface->x;
47 sy = client->input->pointer->y + client->surface->y;
48 assert(sx == x);
49 assert(sy == y);
50 } else {
51 /*
52 * The global pointer does not map onto surface. So
53 * check that it doesn't have the pointer focus.
54 */
55 assert(client->input->pointer->focus == NULL);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070056 }
57}
58
59static void
U. Artie Eoff84f9db52012-12-07 13:50:33 -080060check_pointer_move(struct client *client, int x, int y)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070061{
Derek Foremanf6a65922015-02-24 09:32:14 -060062 weston_test_move_pointer(client->test->weston_test, x, y);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +020063 client_roundtrip(client);
U. Artie Eoff84f9db52012-12-07 13:50:33 -080064 check_pointer(client, x, y);
65}
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070066
U. Artie Eoff84f9db52012-12-07 13:50:33 -080067TEST(test_pointer_top_left)
68{
69 struct client *client;
70 int x, y;
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070071
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +020072 client = create_client_and_test_surface(46, 76, 111, 134);
U. Artie Eoff84f9db52012-12-07 13:50:33 -080073 assert(client);
74
75 /* move pointer outside top left */
76 x = client->surface->x - 1;
77 y = client->surface->y - 1;
78 assert(!surface_contains(client->surface, x, y));
79 check_pointer_move(client, x, y);
80
81 /* move pointer on top left */
82 x += 1; y += 1;
83 assert(surface_contains(client->surface, x, y));
84 check_pointer_move(client, x, y);
85
86 /* move pointer outside top left */
87 x -= 1; y -= 1;
88 assert(!surface_contains(client->surface, x, y));
89 check_pointer_move(client, x, y);
90}
91
92TEST(test_pointer_bottom_left)
93{
94 struct client *client;
95 int x, y;
96
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +020097 client = create_client_and_test_surface(99, 100, 100, 98);
U. Artie Eoff84f9db52012-12-07 13:50:33 -080098 assert(client);
99
100 /* move pointer outside bottom left */
101 x = client->surface->x - 1;
102 y = client->surface->y + client->surface->height;
103 assert(!surface_contains(client->surface, x, y));
104 check_pointer_move(client, x, y);
105
106 /* move pointer on bottom left */
107 x += 1; y -= 1;
108 assert(surface_contains(client->surface, x, y));
109 check_pointer_move(client, x, y);
110
111 /* move pointer outside bottom left */
112 x -= 1; y += 1;
113 assert(!surface_contains(client->surface, x, y));
114 check_pointer_move(client, x, y);
115}
116
117TEST(test_pointer_top_right)
118{
119 struct client *client;
120 int x, y;
121
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200122 client = create_client_and_test_surface(48, 100, 67, 100);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800123 assert(client);
124
125 /* move pointer outside top right */
126 x = client->surface->x + client->surface->width;
127 y = client->surface->y - 1;
128 assert(!surface_contains(client->surface, x, y));
129 check_pointer_move(client, x, y);
130
131 /* move pointer on top right */
132 x -= 1; y += 1;
133 assert(surface_contains(client->surface, x, y));
134 check_pointer_move(client, x, y);
135
136 /* move pointer outside top right */
137 x += 1; y -= 1;
138 assert(!surface_contains(client->surface, x, y));
139 check_pointer_move(client, x, y);
140}
141
142TEST(test_pointer_bottom_right)
143{
144 struct client *client;
145 int x, y;
146
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200147 client = create_client_and_test_surface(100, 123, 100, 69);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800148 assert(client);
149
150 /* move pointer outside bottom right */
151 x = client->surface->x + client->surface->width;
152 y = client->surface->y + client->surface->height;
153 assert(!surface_contains(client->surface, x, y));
154 check_pointer_move(client, x, y);
155
156 /* move pointer on bottom right */
157 x -= 1; y -= 1;
158 assert(surface_contains(client->surface, x, y));
159 check_pointer_move(client, x, y);
160
161 /* move pointer outside bottom right */
162 x += 1; y += 1;
163 assert(!surface_contains(client->surface, x, y));
164 check_pointer_move(client, x, y);
165}
166
167TEST(test_pointer_top_center)
168{
169 struct client *client;
170 int x, y;
171
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200172 client = create_client_and_test_surface(100, 201, 100, 50);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800173 assert(client);
174
175 /* move pointer outside top center */
176 x = client->surface->x + client->surface->width/2;
177 y = client->surface->y - 1;
178 assert(!surface_contains(client->surface, x, y));
179 check_pointer_move(client, x, y);
180
181 /* move pointer on top center */
182 y += 1;
183 assert(surface_contains(client->surface, x, y));
184 check_pointer_move(client, x, y);
185
186 /* move pointer outside top center */
187 y -= 1;
188 assert(!surface_contains(client->surface, x, y));
189 check_pointer_move(client, x, y);
190}
191
192TEST(test_pointer_bottom_center)
193{
194 struct client *client;
195 int x, y;
196
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200197 client = create_client_and_test_surface(100, 45, 67, 100);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800198 assert(client);
199
200 /* move pointer outside bottom center */
201 x = client->surface->x + client->surface->width/2;
202 y = client->surface->y + client->surface->height;
203 assert(!surface_contains(client->surface, x, y));
204 check_pointer_move(client, x, y);
205
206 /* move pointer on bottom center */
207 y -= 1;
208 assert(surface_contains(client->surface, x, y));
209 check_pointer_move(client, x, y);
210
211 /* move pointer outside bottom center */
212 y += 1;
213 assert(!surface_contains(client->surface, x, y));
214 check_pointer_move(client, x, y);
215}
216
217TEST(test_pointer_left_center)
218{
219 struct client *client;
220 int x, y;
221
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200222 client = create_client_and_test_surface(167, 45, 78, 100);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800223 assert(client);
224
225 /* move pointer outside left center */
226 x = client->surface->x - 1;
227 y = client->surface->y + client->surface->height/2;
228 assert(!surface_contains(client->surface, x, y));
229 check_pointer_move(client, x, y);
230
231 /* move pointer on left center */
232 x += 1;
233 assert(surface_contains(client->surface, x, y));
234 check_pointer_move(client, x, y);
235
236 /* move pointer outside left center */
237 x -= 1;
238 assert(!surface_contains(client->surface, x, y));
239 check_pointer_move(client, x, y);
240}
241
242TEST(test_pointer_right_center)
243{
244 struct client *client;
245 int x, y;
246
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200247 client = create_client_and_test_surface(110, 37, 100, 46);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800248 assert(client);
249
250 /* move pointer outside right center */
251 x = client->surface->x + client->surface->width;
252 y = client->surface->y + client->surface->height/2;
253 assert(!surface_contains(client->surface, x, y));
254 check_pointer_move(client, x, y);
255
256 /* move pointer on right center */
257 x -= 1;
258 assert(surface_contains(client->surface, x, y));
259 check_pointer_move(client, x, y);
260
261 /* move pointer outside right center */
262 x += 1;
263 assert(!surface_contains(client->surface, x, y));
264 check_pointer_move(client, x, y);
265}
266
267TEST(test_pointer_surface_move)
268{
269 struct client *client;
270
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200271 client = create_client_and_test_surface(100, 100, 100, 100);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800272 assert(client);
273
274 /* move pointer outside of client */
275 assert(!surface_contains(client->surface, 50, 50));
276 check_pointer_move(client, 50, 50);
277
278 /* move client center to pointer */
279 move_client(client, 0, 0);
280 assert(surface_contains(client->surface, 50, 50));
281 check_pointer(client, 50, 50);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700282}
283
284static int
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800285output_contains_client(struct client *client)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700286{
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800287 struct output *output = client->output;
288 struct surface *surface = client->surface;
289
290 return !(output->x >= surface->x + surface->width
291 || output->x + output->width <= surface->x
292 || output->y >= surface->y + surface->height
293 || output->y + output->height <= surface->y);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700294}
295
296static void
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800297check_client_move(struct client *client, int x, int y)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700298{
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800299 move_client(client, x, y);
300
301 if (output_contains_client(client)) {
302 assert(client->surface->output == client->output);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700303 } else {
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800304 assert(client->surface->output == NULL);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700305 }
306}
307
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800308TEST(test_surface_output)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700309{
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800310 struct client *client;
311 int x, y;
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700312
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200313 client = create_client_and_test_surface(100, 100, 100, 100);
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800314 assert(client);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700315
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800316 assert(output_contains_client(client));
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700317
318 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800319 x = 0;
320 y = -client->surface->height;
321 check_client_move(client, x, y);
322
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700323 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800324 check_client_move(client, x, ++y);
325
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700326 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800327 x = -client->surface->width;
328 y = 0;
329 check_client_move(client, x, y);
330
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700331 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800332 check_client_move(client, ++x, y);
333
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700334 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800335 x = client->output->width;
336 y = 0;
337 check_client_move(client, x, y);
338
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700339 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800340 check_client_move(client, --x, y);
341 assert(output_contains_client(client));
342
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700343 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800344 x = 0;
345 y = client->output->height;
346 check_client_move(client, x, y);
347 assert(!output_contains_client(client));
348
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700349 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800350 check_client_move(client, x, --y);
351 assert(output_contains_client(client));
Kristian Høgsberg3018b442012-04-27 15:02:56 -0400352}
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200353
354static void
355buffer_release_handler(void *data, struct wl_buffer *buffer)
356{
357 int *released = data;
358
359 *released = 1;
360}
361
362static struct wl_buffer_listener buffer_listener = {
363 buffer_release_handler
364};
365
366TEST(buffer_release)
367{
368 struct client *client;
369 struct wl_surface *surface;
370 struct wl_buffer *buf1;
371 struct wl_buffer *buf2;
372 struct wl_buffer *buf3;
373 int buf1_released = 0;
374 int buf2_released = 0;
375 int buf3_released = 0;
376 int frame;
377
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200378 client = create_client_and_test_surface(100, 100, 100, 100);
Pekka Paalanend1c426e2013-02-08 17:01:27 +0200379 assert(client);
380 surface = client->surface->wl_surface;
381
382 buf1 = create_shm_buffer(client, 100, 100, NULL);
383 wl_buffer_add_listener(buf1, &buffer_listener, &buf1_released);
384
385 buf2 = create_shm_buffer(client, 100, 100, NULL);
386 wl_buffer_add_listener(buf2, &buffer_listener, &buf2_released);
387
388 buf3 = create_shm_buffer(client, 100, 100, NULL);
389 wl_buffer_add_listener(buf3, &buffer_listener, &buf3_released);
390
391 /*
392 * buf1 must never be released, since it is replaced before
393 * it is committed, therefore it never becomes busy.
394 */
395
396 wl_surface_attach(surface, buf1, 0, 0);
397 wl_surface_attach(surface, buf2, 0, 0);
398 frame_callback_set(surface, &frame);
399 wl_surface_commit(surface);
400 frame_callback_wait(client, &frame);
401 assert(buf1_released == 0);
402 /* buf2 may or may not be released */
403 assert(buf3_released == 0);
404
405 wl_surface_attach(surface, buf3, 0, 0);
406 frame_callback_set(surface, &frame);
407 wl_surface_commit(surface);
408 frame_callback_wait(client, &frame);
409 assert(buf1_released == 0);
410 assert(buf2_released == 1);
411 /* buf3 may or may not be released */
412
413 wl_surface_attach(surface, client->surface->wl_buffer, 0, 0);
414 frame_callback_set(surface, &frame);
415 wl_surface_commit(surface);
416 frame_callback_wait(client, &frame);
417 assert(buf1_released == 0);
418 assert(buf2_released == 1);
419 assert(buf3_released == 1);
420}