blob: ba22f3f9c749387928b84f9d63d1bb787a8542a7 [file] [log] [blame]
Kristian Høgsberg3018b442012-04-27 15:02:56 -04001/*
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 Eoff84f9db52012-12-07 13:50:33 -080023#include "weston-test-client-helper.h"
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070024
25static void
U. Artie Eoff84f9db52012-12-07 13:50:33 -080026check_pointer(struct client *client, int x, int y)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070027{
U. Artie Eoff84f9db52012-12-07 13:50:33 -080028 int sx, sy;
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070029
U. Artie Eoff84f9db52012-12-07 13:50:33 -080030 /* 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 Eoff1ae298f2012-09-28 06:39:30 -070033
U. Artie Eoff84f9db52012-12-07 13:50:33 -080034 /* 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 Eoff1ae298f2012-09-28 06:39:30 -070053 }
54}
55
56static void
U. Artie Eoff84f9db52012-12-07 13:50:33 -080057check_pointer_move(struct client *client, int x, int y)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070058{
Kristian Høgsbergba0cfdd2012-12-11 22:17:35 -050059 wl_test_move_pointer(client->test->wl_test, x, y);
60 wl_display_roundtrip(client->wl_display);
U. Artie Eoff84f9db52012-12-07 13:50:33 -080061 check_pointer(client, x, y);
62}
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070063
U. Artie Eoff84f9db52012-12-07 13:50:33 -080064TEST(test_pointer_top_left)
65{
66 struct client *client;
67 int x, y;
U. Artie Eoff1ae298f2012-09-28 06:39:30 -070068
U. Artie Eoff84f9db52012-12-07 13:50:33 -080069 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
89TEST(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
114TEST(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
139TEST(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
164TEST(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
189TEST(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
214TEST(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
239TEST(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
264TEST(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 Eoff1ae298f2012-09-28 06:39:30 -0700279}
280
281static int
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800282output_contains_client(struct client *client)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700283{
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800284 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 Eoff1ae298f2012-09-28 06:39:30 -0700291}
292
293static void
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800294check_client_move(struct client *client, int x, int y)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700295{
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800296 move_client(client, x, y);
297
298 if (output_contains_client(client)) {
299 assert(client->surface->output == client->output);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700300 } else {
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800301 assert(client->surface->output == NULL);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700302 }
303}
304
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800305TEST(test_surface_output)
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700306{
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800307 struct client *client;
308 int x, y;
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700309
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800310 client = client_create(100, 100, 100, 100);
311 assert(client);
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700312
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800313 assert(output_contains_client(client));
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700314
315 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800316 x = 0;
317 y = -client->surface->height;
318 check_client_move(client, x, y);
319
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700320 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800321 check_client_move(client, x, ++y);
322
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700323 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800324 x = -client->surface->width;
325 y = 0;
326 check_client_move(client, x, y);
327
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700328 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800329 check_client_move(client, ++x, y);
330
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700331 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800332 x = client->output->width;
333 y = 0;
334 check_client_move(client, x, y);
335
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700336 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800337 check_client_move(client, --x, y);
338 assert(output_contains_client(client));
339
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700340 /* not visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800341 x = 0;
342 y = client->output->height;
343 check_client_move(client, x, y);
344 assert(!output_contains_client(client));
345
U. Artie Eoff1ae298f2012-09-28 06:39:30 -0700346 /* visible */
U. Artie Eoff84f9db52012-12-07 13:50:33 -0800347 check_client_move(client, x, --y);
348 assert(output_contains_client(client));
Kristian Høgsberg3018b442012-04-27 15:02:56 -0400349}