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