Debian Codegraph @

test/xi2/protocol-xiwarppointer.c

raw
1 /**
2 * Copyright © 2009 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 /* Test relies on assert() */
25 #undef NDEBUG
26
27 #ifdef HAVE_DIX_CONFIG_H
28 #include <dix-config.h>
29 #endif
30
31 /*
32 * Protocol testing for XIWarpPointer request.
33 */
34 #include <stdint.h>
35 #include <X11/X.h>
36 #include <X11/Xproto.h>
37 #include <X11/extensions/XI2proto.h>
38 #include "inputstr.h"
39 #include "windowstr.h"
40 #include "scrnintstr.h"
41 #include "xiwarppointer.h"
42 #include "exevents.h"
43 #include "exglobals.h"
44
45 #include "protocol-common.h"
46
47 static int expected_x = SPRITE_X;
48 static int expected_y = SPRITE_Y;
49
50 extern ClientRec client_window;
51
52 /**
53 * This function overrides the one in the screen rec.
54 */
55 static Bool
56 ScreenSetCursorPosition(DeviceIntPtr dev, ScreenPtr scr,
57 int x, int y, Bool generateEvent)
58 {
59 assert(x == expected_x);
60 assert(y == expected_y);
61 return TRUE;
62 }
63
64 static void
65 request_XIWarpPointer(ClientPtr client, xXIWarpPointerReq * req, int error)
66 {
67 int rc;
68
69 rc = ProcXIWarpPointer(client);
70 assert(rc == error);
71
72 if (rc == BadDevice)
73 assert(client->errorValue == req->deviceid);
74 else if (rc == BadWindow)
75 assert(client->errorValue == req->dst_win ||
76 client->errorValue == req->src_win);
77
78 client->swapped = TRUE;
79
80 swapl(&req->src_win);
81 swapl(&req->dst_win);
82 swapl(&req->src_x);
83 swapl(&req->src_y);
84 swapl(&req->dst_x);
85 swapl(&req->dst_y);
86 swaps(&req->src_width);
87 swaps(&req->src_height);
88 swaps(&req->deviceid);
89
90 rc = SProcXIWarpPointer(client);
91 assert(rc == error);
92
93 if (rc == BadDevice)
94 assert(client->errorValue == req->deviceid);
95 else if (rc == BadWindow)
96 assert(client->errorValue == req->dst_win ||
97 client->errorValue == req->src_win);
98
99 client->swapped = FALSE;
100 }
101
102 static void
103 test_XIWarpPointer(void)
104 {
105 int i;
106 ClientRec client_request;
107 xXIWarpPointerReq request;
108
109 init_simple();
110 screen.SetCursorPosition = ScreenSetCursorPosition;
111
112 memset(&request, 0, sizeof(request));
113
114 request_init(&request, XIWarpPointer);
115
116 client_request = init_client(request.length, &request);
117
118 request.deviceid = XIAllDevices;
119 request_XIWarpPointer(&client_request, &request, BadDevice);
120
121 request.deviceid = XIAllMasterDevices;
122 request_XIWarpPointer(&client_request, &request, BadDevice);
123
124 request.src_win = root.drawable.id;
125 request.dst_win = root.drawable.id;
126 request.deviceid = devices.vcp->id;
127 request_XIWarpPointer(&client_request, &request, Success);
128 request.deviceid = devices.vck->id;
129 request_XIWarpPointer(&client_request, &request, BadDevice);
130 request.deviceid = devices.mouse->id;
131 request_XIWarpPointer(&client_request, &request, BadDevice);
132 request.deviceid = devices.kbd->id;
133 request_XIWarpPointer(&client_request, &request, BadDevice);
134
135 devices.mouse->master = NULL; /* Float, kind-of */
136 request.deviceid = devices.mouse->id;
137 request_XIWarpPointer(&client_request, &request, Success);
138
139 for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) {
140 request.deviceid = i;
141 request_XIWarpPointer(&client_request, &request, BadDevice);
142 }
143
144 request.src_win = window.drawable.id;
145 request.deviceid = devices.vcp->id;
146 request_XIWarpPointer(&client_request, &request, Success);
147
148 request.deviceid = devices.mouse->id;
149 request_XIWarpPointer(&client_request, &request, Success);
150
151 request.src_win = root.drawable.id;
152 request.dst_win = 0xFFFF; /* invalid window */
153 request_XIWarpPointer(&client_request, &request, BadWindow);
154
155 request.src_win = 0xFFFF; /* invalid window */
156 request.dst_win = root.drawable.id;
157 request_XIWarpPointer(&client_request, &request, BadWindow);
158
159 request.src_win = None;
160 request.dst_win = None;
161
162 request.dst_y = 0;
163 expected_y = SPRITE_Y;
164
165 request.dst_x = 1 << 16;
166 expected_x = SPRITE_X + 1;
167 request.deviceid = devices.vcp->id;
168 request_XIWarpPointer(&client_request, &request, Success);
169
170 request.dst_x = -1 << 16;
171 expected_x = SPRITE_X - 1;
172 request.deviceid = devices.vcp->id;
173 request_XIWarpPointer(&client_request, &request, Success);
174
175 request.dst_x = 0;
176 expected_x = SPRITE_X;
177
178 request.dst_y = 1 << 16;
179 expected_y = SPRITE_Y + 1;
180 request.deviceid = devices.vcp->id;
181 request_XIWarpPointer(&client_request, &request, Success);
182
183 request.dst_y = -1 << 16;
184 expected_y = SPRITE_Y - 1;
185 request.deviceid = devices.vcp->id;
186 request_XIWarpPointer(&client_request, &request, Success);
187
188 /* FIXME: src_x/y checks */
189
190 client_request.req_len -= 2; /* invalid length */
191 request_XIWarpPointer(&client_request, &request, BadLength);
192 }
193
194 const testfunc_t*
195 protocol_xiwarppointer_test(void)
196 {
197 static const testfunc_t testfuncs[] = {
198 test_XIWarpPointer,
199 NULL,
200 };
201 return testfuncs;
202 }