Kristian Høgsberg | 3018b44 | 2012-04-27 15:02:56 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 3 | * Copyright © 2013 Collabora, Ltd. |
Kristian Høgsberg | 3018b44 | 2012-04-27 15:02:56 -0400 | [diff] [blame] | 4 | * |
| 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 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 24 | #include "weston-test-client-helper.h" |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 25 | |
| 26 | static void |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 27 | check_pointer(struct client *client, int x, int y) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 28 | { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 29 | int sx, sy; |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 30 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 31 | /* check that the client got the global pointer update */ |
| 32 | assert(client->test->pointer_x == x); |
| 33 | assert(client->test->pointer_y == y); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 34 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 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); |
| 39 | |
| 40 | /* |
| 41 | * check that the local surface pointer maps |
| 42 | * to the global pointer. |
| 43 | */ |
| 44 | sx = client->input->pointer->x + client->surface->x; |
| 45 | sy = client->input->pointer->y + client->surface->y; |
| 46 | assert(sx == x); |
| 47 | assert(sy == y); |
| 48 | } else { |
| 49 | /* |
| 50 | * The global pointer does not map onto surface. So |
| 51 | * check that it doesn't have the pointer focus. |
| 52 | */ |
| 53 | assert(client->input->pointer->focus == NULL); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | static void |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 58 | check_pointer_move(struct client *client, int x, int y) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 59 | { |
Kristian Høgsberg | ba0cfdd | 2012-12-11 22:17:35 -0500 | [diff] [blame] | 60 | wl_test_move_pointer(client->test->wl_test, x, y); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 61 | client_roundtrip(client); |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 62 | check_pointer(client, x, y); |
| 63 | } |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 64 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 65 | TEST(test_pointer_top_left) |
| 66 | { |
| 67 | struct client *client; |
| 68 | int x, y; |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 69 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 70 | client = client_create(46, 76, 111, 134); |
| 71 | assert(client); |
| 72 | |
| 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); |
| 78 | |
| 79 | /* move pointer on top left */ |
| 80 | x += 1; y += 1; |
| 81 | assert(surface_contains(client->surface, x, y)); |
| 82 | check_pointer_move(client, x, y); |
| 83 | |
| 84 | /* move pointer outside top left */ |
| 85 | x -= 1; y -= 1; |
| 86 | assert(!surface_contains(client->surface, x, y)); |
| 87 | check_pointer_move(client, x, y); |
| 88 | } |
| 89 | |
| 90 | TEST(test_pointer_bottom_left) |
| 91 | { |
| 92 | struct client *client; |
| 93 | int x, y; |
| 94 | |
| 95 | client = client_create(99, 100, 100, 98); |
| 96 | assert(client); |
| 97 | |
| 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); |
| 103 | |
| 104 | /* move pointer on bottom left */ |
| 105 | x += 1; y -= 1; |
| 106 | assert(surface_contains(client->surface, x, y)); |
| 107 | check_pointer_move(client, x, y); |
| 108 | |
| 109 | /* move pointer outside bottom left */ |
| 110 | x -= 1; y += 1; |
| 111 | assert(!surface_contains(client->surface, x, y)); |
| 112 | check_pointer_move(client, x, y); |
| 113 | } |
| 114 | |
| 115 | TEST(test_pointer_top_right) |
| 116 | { |
| 117 | struct client *client; |
| 118 | int x, y; |
| 119 | |
| 120 | client = client_create(48, 100, 67, 100); |
| 121 | assert(client); |
| 122 | |
| 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); |
| 128 | |
| 129 | /* move pointer on top right */ |
| 130 | x -= 1; y += 1; |
| 131 | assert(surface_contains(client->surface, x, y)); |
| 132 | check_pointer_move(client, x, y); |
| 133 | |
| 134 | /* move pointer outside top right */ |
| 135 | x += 1; y -= 1; |
| 136 | assert(!surface_contains(client->surface, x, y)); |
| 137 | check_pointer_move(client, x, y); |
| 138 | } |
| 139 | |
| 140 | TEST(test_pointer_bottom_right) |
| 141 | { |
| 142 | struct client *client; |
| 143 | int x, y; |
| 144 | |
| 145 | client = client_create(100, 123, 100, 69); |
| 146 | assert(client); |
| 147 | |
| 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); |
| 153 | |
| 154 | /* move pointer on bottom right */ |
| 155 | x -= 1; y -= 1; |
| 156 | assert(surface_contains(client->surface, x, y)); |
| 157 | check_pointer_move(client, x, y); |
| 158 | |
| 159 | /* move pointer outside bottom right */ |
| 160 | x += 1; y += 1; |
| 161 | assert(!surface_contains(client->surface, x, y)); |
| 162 | check_pointer_move(client, x, y); |
| 163 | } |
| 164 | |
| 165 | TEST(test_pointer_top_center) |
| 166 | { |
| 167 | struct client *client; |
| 168 | int x, y; |
| 169 | |
| 170 | client = client_create(100, 201, 100, 50); |
| 171 | assert(client); |
| 172 | |
| 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); |
| 178 | |
| 179 | /* move pointer on top center */ |
| 180 | y += 1; |
| 181 | assert(surface_contains(client->surface, x, y)); |
| 182 | check_pointer_move(client, x, y); |
| 183 | |
| 184 | /* move pointer outside top center */ |
| 185 | y -= 1; |
| 186 | assert(!surface_contains(client->surface, x, y)); |
| 187 | check_pointer_move(client, x, y); |
| 188 | } |
| 189 | |
| 190 | TEST(test_pointer_bottom_center) |
| 191 | { |
| 192 | struct client *client; |
| 193 | int x, y; |
| 194 | |
| 195 | client = client_create(100, 45, 67, 100); |
| 196 | assert(client); |
| 197 | |
| 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); |
| 203 | |
| 204 | /* move pointer on bottom center */ |
| 205 | y -= 1; |
| 206 | assert(surface_contains(client->surface, x, y)); |
| 207 | check_pointer_move(client, x, y); |
| 208 | |
| 209 | /* move pointer outside bottom center */ |
| 210 | y += 1; |
| 211 | assert(!surface_contains(client->surface, x, y)); |
| 212 | check_pointer_move(client, x, y); |
| 213 | } |
| 214 | |
| 215 | TEST(test_pointer_left_center) |
| 216 | { |
| 217 | struct client *client; |
| 218 | int x, y; |
| 219 | |
| 220 | client = client_create(167, 45, 78, 100); |
| 221 | assert(client); |
| 222 | |
| 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); |
| 228 | |
| 229 | /* move pointer on left center */ |
| 230 | x += 1; |
| 231 | assert(surface_contains(client->surface, x, y)); |
| 232 | check_pointer_move(client, x, y); |
| 233 | |
| 234 | /* move pointer outside left center */ |
| 235 | x -= 1; |
| 236 | assert(!surface_contains(client->surface, x, y)); |
| 237 | check_pointer_move(client, x, y); |
| 238 | } |
| 239 | |
| 240 | TEST(test_pointer_right_center) |
| 241 | { |
| 242 | struct client *client; |
| 243 | int x, y; |
| 244 | |
| 245 | client = client_create(110, 37, 100, 46); |
| 246 | assert(client); |
| 247 | |
| 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); |
| 253 | |
| 254 | /* move pointer on right center */ |
| 255 | x -= 1; |
| 256 | assert(surface_contains(client->surface, x, y)); |
| 257 | check_pointer_move(client, x, y); |
| 258 | |
| 259 | /* move pointer outside right center */ |
| 260 | x += 1; |
| 261 | assert(!surface_contains(client->surface, x, y)); |
| 262 | check_pointer_move(client, x, y); |
| 263 | } |
| 264 | |
| 265 | TEST(test_pointer_surface_move) |
| 266 | { |
| 267 | struct client *client; |
| 268 | |
| 269 | client = client_create(100, 100, 100, 100); |
| 270 | assert(client); |
| 271 | |
| 272 | /* move pointer outside of client */ |
| 273 | assert(!surface_contains(client->surface, 50, 50)); |
| 274 | check_pointer_move(client, 50, 50); |
| 275 | |
| 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); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static int |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 283 | output_contains_client(struct client *client) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 284 | { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 285 | struct output *output = client->output; |
| 286 | struct surface *surface = client->surface; |
| 287 | |
| 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); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static void |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 295 | check_client_move(struct client *client, int x, int y) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 296 | { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 297 | move_client(client, x, y); |
| 298 | |
| 299 | if (output_contains_client(client)) { |
| 300 | assert(client->surface->output == client->output); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 301 | } else { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 302 | assert(client->surface->output == NULL); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 306 | TEST(test_surface_output) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 307 | { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 308 | struct client *client; |
| 309 | int x, y; |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 310 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 311 | client = client_create(100, 100, 100, 100); |
| 312 | assert(client); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 313 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 314 | assert(output_contains_client(client)); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 315 | |
| 316 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 317 | x = 0; |
| 318 | y = -client->surface->height; |
| 319 | check_client_move(client, x, y); |
| 320 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 321 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 322 | check_client_move(client, x, ++y); |
| 323 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 324 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 325 | x = -client->surface->width; |
| 326 | y = 0; |
| 327 | check_client_move(client, x, y); |
| 328 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 329 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 330 | check_client_move(client, ++x, y); |
| 331 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 332 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 333 | x = client->output->width; |
| 334 | y = 0; |
| 335 | check_client_move(client, x, y); |
| 336 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 337 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 338 | check_client_move(client, --x, y); |
| 339 | assert(output_contains_client(client)); |
| 340 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 341 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 342 | x = 0; |
| 343 | y = client->output->height; |
| 344 | check_client_move(client, x, y); |
| 345 | assert(!output_contains_client(client)); |
| 346 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 347 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 348 | check_client_move(client, x, --y); |
| 349 | assert(output_contains_client(client)); |
Kristian Høgsberg | 3018b44 | 2012-04-27 15:02:56 -0400 | [diff] [blame] | 350 | } |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 351 | |
| 352 | static void |
| 353 | buffer_release_handler(void *data, struct wl_buffer *buffer) |
| 354 | { |
| 355 | int *released = data; |
| 356 | |
| 357 | *released = 1; |
| 358 | } |
| 359 | |
| 360 | static struct wl_buffer_listener buffer_listener = { |
| 361 | buffer_release_handler |
| 362 | }; |
| 363 | |
| 364 | TEST(buffer_release) |
| 365 | { |
| 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; |
| 374 | int frame; |
| 375 | |
| 376 | client = client_create(100, 100, 100, 100); |
| 377 | assert(client); |
| 378 | surface = client->surface->wl_surface; |
| 379 | |
| 380 | buf1 = create_shm_buffer(client, 100, 100, NULL); |
| 381 | wl_buffer_add_listener(buf1, &buffer_listener, &buf1_released); |
| 382 | |
| 383 | buf2 = create_shm_buffer(client, 100, 100, NULL); |
| 384 | wl_buffer_add_listener(buf2, &buffer_listener, &buf2_released); |
| 385 | |
| 386 | buf3 = create_shm_buffer(client, 100, 100, NULL); |
| 387 | wl_buffer_add_listener(buf3, &buffer_listener, &buf3_released); |
| 388 | |
| 389 | /* |
| 390 | * buf1 must never be released, since it is replaced before |
| 391 | * it is committed, therefore it never becomes busy. |
| 392 | */ |
| 393 | |
| 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); |
| 402 | |
| 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 */ |
| 410 | |
| 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); |
| 418 | } |