2 * Copyright © 2012 Intel Corporation
3 * Copyright © 2013 Collabora, Ltd.
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.
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.
24 #include "weston-test-client-helper.h"
27 check_pointer(struct client *client, int x, int y)
31 /* check that the client got the global pointer update */
32 assert(client->test->pointer_x == x);
33 assert(client->test->pointer_y == y);
35 /* Does global pointer map onto the surface? */
36 if (surface_contains(client->surface, x, y)) {
37 /* check that the surface has the pointer focus */
38 assert(client->input->pointer->focus == client->surface);
41 * check that the local surface pointer maps
42 * to the global pointer.
44 sx = client->input->pointer->x + client->surface->x;
45 sy = client->input->pointer->y + client->surface->y;
50 * The global pointer does not map onto surface. So
51 * check that it doesn't have the pointer focus.
53 assert(client->input->pointer->focus == NULL);
58 check_pointer_move(struct client *client, int x, int y)
60 wl_test_move_pointer(client->test->wl_test, x, y);
61 client_roundtrip(client);
62 check_pointer(client, x, y);
65 TEST(test_pointer_top_left)
67 struct client *client;
70 client = client_create(46, 76, 111, 134);
73 /* move pointer outside top left */
74 x = client->surface->x - 1;
75 y = client->surface->y - 1;
76 assert(!surface_contains(client->surface, x, y));
77 check_pointer_move(client, x, y);
79 /* move pointer on top left */
81 assert(surface_contains(client->surface, x, y));
82 check_pointer_move(client, x, y);
84 /* move pointer outside top left */
86 assert(!surface_contains(client->surface, x, y));
87 check_pointer_move(client, x, y);
90 TEST(test_pointer_bottom_left)
92 struct client *client;
95 client = client_create(99, 100, 100, 98);
98 /* move pointer outside bottom left */
99 x = client->surface->x - 1;
100 y = client->surface->y + client->surface->height;
101 assert(!surface_contains(client->surface, x, y));
102 check_pointer_move(client, x, y);
104 /* move pointer on bottom left */
106 assert(surface_contains(client->surface, x, y));
107 check_pointer_move(client, x, y);
109 /* move pointer outside bottom left */
111 assert(!surface_contains(client->surface, x, y));
112 check_pointer_move(client, x, y);
115 TEST(test_pointer_top_right)
117 struct client *client;
120 client = client_create(48, 100, 67, 100);
123 /* move pointer outside top right */
124 x = client->surface->x + client->surface->width;
125 y = client->surface->y - 1;
126 assert(!surface_contains(client->surface, x, y));
127 check_pointer_move(client, x, y);
129 /* move pointer on top right */
131 assert(surface_contains(client->surface, x, y));
132 check_pointer_move(client, x, y);
134 /* move pointer outside top right */
136 assert(!surface_contains(client->surface, x, y));
137 check_pointer_move(client, x, y);
140 TEST(test_pointer_bottom_right)
142 struct client *client;
145 client = client_create(100, 123, 100, 69);
148 /* move pointer outside bottom right */
149 x = client->surface->x + client->surface->width;
150 y = client->surface->y + client->surface->height;
151 assert(!surface_contains(client->surface, x, y));
152 check_pointer_move(client, x, y);
154 /* move pointer on bottom right */
156 assert(surface_contains(client->surface, x, y));
157 check_pointer_move(client, x, y);
159 /* move pointer outside bottom right */
161 assert(!surface_contains(client->surface, x, y));
162 check_pointer_move(client, x, y);
165 TEST(test_pointer_top_center)
167 struct client *client;
170 client = client_create(100, 201, 100, 50);
173 /* move pointer outside top center */
174 x = client->surface->x + client->surface->width/2;
175 y = client->surface->y - 1;
176 assert(!surface_contains(client->surface, x, y));
177 check_pointer_move(client, x, y);
179 /* move pointer on top center */
181 assert(surface_contains(client->surface, x, y));
182 check_pointer_move(client, x, y);
184 /* move pointer outside top center */
186 assert(!surface_contains(client->surface, x, y));
187 check_pointer_move(client, x, y);
190 TEST(test_pointer_bottom_center)
192 struct client *client;
195 client = client_create(100, 45, 67, 100);
198 /* move pointer outside bottom center */
199 x = client->surface->x + client->surface->width/2;
200 y = client->surface->y + client->surface->height;
201 assert(!surface_contains(client->surface, x, y));
202 check_pointer_move(client, x, y);
204 /* move pointer on bottom center */
206 assert(surface_contains(client->surface, x, y));
207 check_pointer_move(client, x, y);
209 /* move pointer outside bottom center */
211 assert(!surface_contains(client->surface, x, y));
212 check_pointer_move(client, x, y);
215 TEST(test_pointer_left_center)
217 struct client *client;
220 client = client_create(167, 45, 78, 100);
223 /* move pointer outside left center */
224 x = client->surface->x - 1;
225 y = client->surface->y + client->surface->height/2;
226 assert(!surface_contains(client->surface, x, y));
227 check_pointer_move(client, x, y);
229 /* move pointer on left center */
231 assert(surface_contains(client->surface, x, y));
232 check_pointer_move(client, x, y);
234 /* move pointer outside left center */
236 assert(!surface_contains(client->surface, x, y));
237 check_pointer_move(client, x, y);
240 TEST(test_pointer_right_center)
242 struct client *client;
245 client = client_create(110, 37, 100, 46);
248 /* move pointer outside right center */
249 x = client->surface->x + client->surface->width;
250 y = client->surface->y + client->surface->height/2;
251 assert(!surface_contains(client->surface, x, y));
252 check_pointer_move(client, x, y);
254 /* move pointer on right center */
256 assert(surface_contains(client->surface, x, y));
257 check_pointer_move(client, x, y);
259 /* move pointer outside right center */
261 assert(!surface_contains(client->surface, x, y));
262 check_pointer_move(client, x, y);
265 TEST(test_pointer_surface_move)
267 struct client *client;
269 client = client_create(100, 100, 100, 100);
272 /* move pointer outside of client */
273 assert(!surface_contains(client->surface, 50, 50));
274 check_pointer_move(client, 50, 50);
276 /* move client center to pointer */
277 move_client(client, 0, 0);
278 assert(surface_contains(client->surface, 50, 50));
279 check_pointer(client, 50, 50);
283 output_contains_client(struct client *client)
285 struct output *output = client->output;
286 struct surface *surface = client->surface;
288 return !(output->x >= surface->x + surface->width
289 || output->x + output->width <= surface->x
290 || output->y >= surface->y + surface->height
291 || output->y + output->height <= surface->y);
295 check_client_move(struct client *client, int x, int y)
297 move_client(client, x, y);
299 if (output_contains_client(client)) {
300 assert(client->surface->output == client->output);
302 assert(client->surface->output == NULL);
306 TEST(test_surface_output)
308 struct client *client;
311 client = client_create(100, 100, 100, 100);
314 assert(output_contains_client(client));
318 y = -client->surface->height;
319 check_client_move(client, x, y);
322 check_client_move(client, x, ++y);
325 x = -client->surface->width;
327 check_client_move(client, x, y);
330 check_client_move(client, ++x, y);
333 x = client->output->width;
335 check_client_move(client, x, y);
338 check_client_move(client, --x, y);
339 assert(output_contains_client(client));
343 y = client->output->height;
344 check_client_move(client, x, y);
345 assert(!output_contains_client(client));
348 check_client_move(client, x, --y);
349 assert(output_contains_client(client));
353 buffer_release_handler(void *data, struct wl_buffer *buffer)
355 int *released = data;
360 static struct wl_buffer_listener buffer_listener = {
361 buffer_release_handler
366 struct client *client;
367 struct wl_surface *surface;
368 struct wl_buffer *buf1;
369 struct wl_buffer *buf2;
370 struct wl_buffer *buf3;
371 int buf1_released = 0;
372 int buf2_released = 0;
373 int buf3_released = 0;
376 client = client_create(100, 100, 100, 100);
378 surface = client->surface->wl_surface;
380 buf1 = create_shm_buffer(client, 100, 100, NULL);
381 wl_buffer_add_listener(buf1, &buffer_listener, &buf1_released);
383 buf2 = create_shm_buffer(client, 100, 100, NULL);
384 wl_buffer_add_listener(buf2, &buffer_listener, &buf2_released);
386 buf3 = create_shm_buffer(client, 100, 100, NULL);
387 wl_buffer_add_listener(buf3, &buffer_listener, &buf3_released);
390 * buf1 must never be released, since it is replaced before
391 * it is committed, therefore it never becomes busy.
394 wl_surface_attach(surface, buf1, 0, 0);
395 wl_surface_attach(surface, buf2, 0, 0);
396 frame_callback_set(surface, &frame);
397 wl_surface_commit(surface);
398 frame_callback_wait(client, &frame);
399 assert(buf1_released == 0);
400 /* buf2 may or may not be released */
401 assert(buf3_released == 0);
403 wl_surface_attach(surface, buf3, 0, 0);
404 frame_callback_set(surface, &frame);
405 wl_surface_commit(surface);
406 frame_callback_wait(client, &frame);
407 assert(buf1_released == 0);
408 assert(buf2_released == 1);
409 /* buf3 may or may not be released */
411 wl_surface_attach(surface, client->surface->wl_buffer, 0, 0);
412 frame_callback_set(surface, &frame);
413 wl_surface_commit(surface);
414 frame_callback_wait(client, &frame);
415 assert(buf1_released == 0);
416 assert(buf2_released == 1);
417 assert(buf3_released == 1);