Kristian Høgsberg | 3018b44 | 2012-04-27 15:02:56 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 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 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 23 | #include "weston-test-client-helper.h" |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 24 | |
| 25 | static void |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 26 | check_pointer(struct client *client, int x, int y) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 27 | { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 28 | int sx, sy; |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 29 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 30 | /* check that the client got the global pointer update */ |
| 31 | assert(client->test->pointer_x == x); |
| 32 | assert(client->test->pointer_y == y); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 33 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 34 | /* Does global pointer map onto the surface? */ |
| 35 | if (surface_contains(client->surface, x, y)) { |
| 36 | /* check that the surface has the pointer focus */ |
| 37 | assert(client->input->pointer->focus == client->surface); |
| 38 | |
| 39 | /* |
| 40 | * check that the local surface pointer maps |
| 41 | * to the global pointer. |
| 42 | */ |
| 43 | sx = client->input->pointer->x + client->surface->x; |
| 44 | sy = client->input->pointer->y + client->surface->y; |
| 45 | assert(sx == x); |
| 46 | assert(sy == y); |
| 47 | } else { |
| 48 | /* |
| 49 | * The global pointer does not map onto surface. So |
| 50 | * check that it doesn't have the pointer focus. |
| 51 | */ |
| 52 | assert(client->input->pointer->focus == NULL); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
| 56 | static void |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 57 | check_pointer_move(struct client *client, int x, int y) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 58 | { |
Kristian Høgsberg | ba0cfdd | 2012-12-11 22:17:35 -0500 | [diff] [blame^] | 59 | wl_test_move_pointer(client->test->wl_test, x, y); |
| 60 | wl_display_roundtrip(client->wl_display); |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 61 | check_pointer(client, x, y); |
| 62 | } |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 63 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 64 | TEST(test_pointer_top_left) |
| 65 | { |
| 66 | struct client *client; |
| 67 | int x, y; |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 68 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 69 | client = client_create(46, 76, 111, 134); |
| 70 | assert(client); |
| 71 | |
| 72 | /* move pointer outside top left */ |
| 73 | x = client->surface->x - 1; |
| 74 | y = client->surface->y - 1; |
| 75 | assert(!surface_contains(client->surface, x, y)); |
| 76 | check_pointer_move(client, x, y); |
| 77 | |
| 78 | /* move pointer on top left */ |
| 79 | x += 1; y += 1; |
| 80 | assert(surface_contains(client->surface, x, y)); |
| 81 | check_pointer_move(client, x, y); |
| 82 | |
| 83 | /* move pointer outside top left */ |
| 84 | x -= 1; y -= 1; |
| 85 | assert(!surface_contains(client->surface, x, y)); |
| 86 | check_pointer_move(client, x, y); |
| 87 | } |
| 88 | |
| 89 | TEST(test_pointer_bottom_left) |
| 90 | { |
| 91 | struct client *client; |
| 92 | int x, y; |
| 93 | |
| 94 | client = client_create(99, 100, 100, 98); |
| 95 | assert(client); |
| 96 | |
| 97 | /* move pointer outside bottom left */ |
| 98 | x = client->surface->x - 1; |
| 99 | y = client->surface->y + client->surface->height; |
| 100 | assert(!surface_contains(client->surface, x, y)); |
| 101 | check_pointer_move(client, x, y); |
| 102 | |
| 103 | /* move pointer on bottom left */ |
| 104 | x += 1; y -= 1; |
| 105 | assert(surface_contains(client->surface, x, y)); |
| 106 | check_pointer_move(client, x, y); |
| 107 | |
| 108 | /* move pointer outside bottom left */ |
| 109 | x -= 1; y += 1; |
| 110 | assert(!surface_contains(client->surface, x, y)); |
| 111 | check_pointer_move(client, x, y); |
| 112 | } |
| 113 | |
| 114 | TEST(test_pointer_top_right) |
| 115 | { |
| 116 | struct client *client; |
| 117 | int x, y; |
| 118 | |
| 119 | client = client_create(48, 100, 67, 100); |
| 120 | assert(client); |
| 121 | |
| 122 | /* move pointer outside top right */ |
| 123 | x = client->surface->x + client->surface->width; |
| 124 | y = client->surface->y - 1; |
| 125 | assert(!surface_contains(client->surface, x, y)); |
| 126 | check_pointer_move(client, x, y); |
| 127 | |
| 128 | /* move pointer on top right */ |
| 129 | x -= 1; y += 1; |
| 130 | assert(surface_contains(client->surface, x, y)); |
| 131 | check_pointer_move(client, x, y); |
| 132 | |
| 133 | /* move pointer outside top right */ |
| 134 | x += 1; y -= 1; |
| 135 | assert(!surface_contains(client->surface, x, y)); |
| 136 | check_pointer_move(client, x, y); |
| 137 | } |
| 138 | |
| 139 | TEST(test_pointer_bottom_right) |
| 140 | { |
| 141 | struct client *client; |
| 142 | int x, y; |
| 143 | |
| 144 | client = client_create(100, 123, 100, 69); |
| 145 | assert(client); |
| 146 | |
| 147 | /* move pointer outside bottom right */ |
| 148 | x = client->surface->x + client->surface->width; |
| 149 | y = client->surface->y + client->surface->height; |
| 150 | assert(!surface_contains(client->surface, x, y)); |
| 151 | check_pointer_move(client, x, y); |
| 152 | |
| 153 | /* move pointer on bottom right */ |
| 154 | x -= 1; y -= 1; |
| 155 | assert(surface_contains(client->surface, x, y)); |
| 156 | check_pointer_move(client, x, y); |
| 157 | |
| 158 | /* move pointer outside bottom right */ |
| 159 | x += 1; y += 1; |
| 160 | assert(!surface_contains(client->surface, x, y)); |
| 161 | check_pointer_move(client, x, y); |
| 162 | } |
| 163 | |
| 164 | TEST(test_pointer_top_center) |
| 165 | { |
| 166 | struct client *client; |
| 167 | int x, y; |
| 168 | |
| 169 | client = client_create(100, 201, 100, 50); |
| 170 | assert(client); |
| 171 | |
| 172 | /* move pointer outside top center */ |
| 173 | x = client->surface->x + client->surface->width/2; |
| 174 | y = client->surface->y - 1; |
| 175 | assert(!surface_contains(client->surface, x, y)); |
| 176 | check_pointer_move(client, x, y); |
| 177 | |
| 178 | /* move pointer on top center */ |
| 179 | y += 1; |
| 180 | assert(surface_contains(client->surface, x, y)); |
| 181 | check_pointer_move(client, x, y); |
| 182 | |
| 183 | /* move pointer outside top center */ |
| 184 | y -= 1; |
| 185 | assert(!surface_contains(client->surface, x, y)); |
| 186 | check_pointer_move(client, x, y); |
| 187 | } |
| 188 | |
| 189 | TEST(test_pointer_bottom_center) |
| 190 | { |
| 191 | struct client *client; |
| 192 | int x, y; |
| 193 | |
| 194 | client = client_create(100, 45, 67, 100); |
| 195 | assert(client); |
| 196 | |
| 197 | /* move pointer outside bottom center */ |
| 198 | x = client->surface->x + client->surface->width/2; |
| 199 | y = client->surface->y + client->surface->height; |
| 200 | assert(!surface_contains(client->surface, x, y)); |
| 201 | check_pointer_move(client, x, y); |
| 202 | |
| 203 | /* move pointer on bottom center */ |
| 204 | y -= 1; |
| 205 | assert(surface_contains(client->surface, x, y)); |
| 206 | check_pointer_move(client, x, y); |
| 207 | |
| 208 | /* move pointer outside bottom center */ |
| 209 | y += 1; |
| 210 | assert(!surface_contains(client->surface, x, y)); |
| 211 | check_pointer_move(client, x, y); |
| 212 | } |
| 213 | |
| 214 | TEST(test_pointer_left_center) |
| 215 | { |
| 216 | struct client *client; |
| 217 | int x, y; |
| 218 | |
| 219 | client = client_create(167, 45, 78, 100); |
| 220 | assert(client); |
| 221 | |
| 222 | /* move pointer outside left center */ |
| 223 | x = client->surface->x - 1; |
| 224 | y = client->surface->y + client->surface->height/2; |
| 225 | assert(!surface_contains(client->surface, x, y)); |
| 226 | check_pointer_move(client, x, y); |
| 227 | |
| 228 | /* move pointer on left center */ |
| 229 | x += 1; |
| 230 | assert(surface_contains(client->surface, x, y)); |
| 231 | check_pointer_move(client, x, y); |
| 232 | |
| 233 | /* move pointer outside left center */ |
| 234 | x -= 1; |
| 235 | assert(!surface_contains(client->surface, x, y)); |
| 236 | check_pointer_move(client, x, y); |
| 237 | } |
| 238 | |
| 239 | TEST(test_pointer_right_center) |
| 240 | { |
| 241 | struct client *client; |
| 242 | int x, y; |
| 243 | |
| 244 | client = client_create(110, 37, 100, 46); |
| 245 | assert(client); |
| 246 | |
| 247 | /* move pointer outside right center */ |
| 248 | x = client->surface->x + client->surface->width; |
| 249 | y = client->surface->y + client->surface->height/2; |
| 250 | assert(!surface_contains(client->surface, x, y)); |
| 251 | check_pointer_move(client, x, y); |
| 252 | |
| 253 | /* move pointer on right center */ |
| 254 | x -= 1; |
| 255 | assert(surface_contains(client->surface, x, y)); |
| 256 | check_pointer_move(client, x, y); |
| 257 | |
| 258 | /* move pointer outside right center */ |
| 259 | x += 1; |
| 260 | assert(!surface_contains(client->surface, x, y)); |
| 261 | check_pointer_move(client, x, y); |
| 262 | } |
| 263 | |
| 264 | TEST(test_pointer_surface_move) |
| 265 | { |
| 266 | struct client *client; |
| 267 | |
| 268 | client = client_create(100, 100, 100, 100); |
| 269 | assert(client); |
| 270 | |
| 271 | /* move pointer outside of client */ |
| 272 | assert(!surface_contains(client->surface, 50, 50)); |
| 273 | check_pointer_move(client, 50, 50); |
| 274 | |
| 275 | /* move client center to pointer */ |
| 276 | move_client(client, 0, 0); |
| 277 | assert(surface_contains(client->surface, 50, 50)); |
| 278 | check_pointer(client, 50, 50); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static int |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 282 | output_contains_client(struct client *client) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 283 | { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 284 | struct output *output = client->output; |
| 285 | struct surface *surface = client->surface; |
| 286 | |
| 287 | return !(output->x >= surface->x + surface->width |
| 288 | || output->x + output->width <= surface->x |
| 289 | || output->y >= surface->y + surface->height |
| 290 | || output->y + output->height <= surface->y); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static void |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 294 | check_client_move(struct client *client, int x, int y) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 295 | { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 296 | move_client(client, x, y); |
| 297 | |
| 298 | if (output_contains_client(client)) { |
| 299 | assert(client->surface->output == client->output); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 300 | } else { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 301 | assert(client->surface->output == NULL); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 305 | TEST(test_surface_output) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 306 | { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 307 | struct client *client; |
| 308 | int x, y; |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 309 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 310 | client = client_create(100, 100, 100, 100); |
| 311 | assert(client); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 312 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 313 | assert(output_contains_client(client)); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 314 | |
| 315 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 316 | x = 0; |
| 317 | y = -client->surface->height; |
| 318 | check_client_move(client, x, y); |
| 319 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 320 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 321 | check_client_move(client, x, ++y); |
| 322 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 323 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 324 | x = -client->surface->width; |
| 325 | y = 0; |
| 326 | check_client_move(client, x, y); |
| 327 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 328 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 329 | check_client_move(client, ++x, y); |
| 330 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 331 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 332 | x = client->output->width; |
| 333 | y = 0; |
| 334 | check_client_move(client, x, y); |
| 335 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 336 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 337 | check_client_move(client, --x, y); |
| 338 | assert(output_contains_client(client)); |
| 339 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 340 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 341 | x = 0; |
| 342 | y = client->output->height; |
| 343 | check_client_move(client, x, y); |
| 344 | assert(!output_contains_client(client)); |
| 345 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 346 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 347 | check_client_move(client, x, --y); |
| 348 | assert(output_contains_client(client)); |
Kristian Høgsberg | 3018b44 | 2012-04-27 15:02:56 -0400 | [diff] [blame] | 349 | } |