2 * Copyright © 2011 Red Hat, Inc.
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:
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
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.
24 #ifdef HAVE_DIX_CONFIG_H
25 #include <dix-config.h>
29 * Protocol testing for XIPassiveGrab request.
33 #include <X11/Xproto.h>
34 #include <X11/extensions/XI2proto.h>
36 #include "windowstr.h"
37 #include "scrnintstr.h"
38 #include "xipassivegrab.h"
40 #include "exglobals.h"
42 #include "protocol-common.h"
44 static ClientRec client_request
;
47 static uint32_t modifiers
[N_MODS
] = { 1, 2, 3, 4, 5, 6, 7 };
53 int __wrap_GrabButton(ClientPtr client
, DeviceIntPtr dev
,
54 DeviceIntPtr modifier_device
, int button
,
55 GrabParameters
*param
, enum InputLevel grabtype
,
57 static void reply_XIPassiveGrabDevice_data(ClientPtr client
, int len
,
58 char *data
, void *closure
);
61 __wrap_dixLookupWindow(WindowPtr
*win
, XID id
, ClientPtr client
, Mask access
)
63 if (id
== root
.drawable
.id
) {
67 else if (id
== window
.drawable
.id
) {
72 return __real_dixLookupWindow(win
, id
, client
, access
);
76 __wrap_GrabButton(ClientPtr client
, DeviceIntPtr dev
,
77 DeviceIntPtr modifier_device
, int button
,
78 GrabParameters
*param
, enum InputLevel grabtype
,
81 /* Fail every odd modifier */
82 if (param
->modifiers
% 2)
89 reply_XIPassiveGrabDevice(ClientPtr client
, int len
, char *data
, void *closure
)
91 xXIPassiveGrabDeviceReply
*rep
= (xXIPassiveGrabDeviceReply
*) data
;
93 if (client
->swapped
) {
94 swaps(&rep
->sequenceNumber
);
96 swaps(&rep
->num_modifiers
);
98 testdata
.num_modifiers
= rep
->num_modifiers
;
101 reply_check_defaults(rep
, len
, XIPassiveGrabDevice
);
103 /* ProcXIPassiveGrabDevice sends the data in two batches, let the second
104 * handler handle the modifier data */
105 if (rep
->num_modifiers
> 0)
106 reply_handler
= reply_XIPassiveGrabDevice_data
;
110 reply_XIPassiveGrabDevice_data(ClientPtr client
, int len
, char *data
,
115 xXIGrabModifierInfo
*mods
= (xXIGrabModifierInfo
*) data
;
117 for (i
= 0; i
< testdata
.num_modifiers
; i
++, mods
++) {
119 swapl(&mods
->modifiers
);
121 /* 1 - 7 is the range we use for the global modifiers array
123 assert(mods
->modifiers
> 0);
124 assert(mods
->modifiers
<= 7);
125 assert(mods
->modifiers
% 2 == 1); /* because we fail odd ones */
126 assert(mods
->status
!= Success
);
127 assert(mods
->pad0
== 0);
128 assert(mods
->pad1
== 0);
131 reply_handler
= reply_XIPassiveGrabDevice
;
135 request_XIPassiveGrabDevice(ClientPtr client
, xXIPassiveGrabDeviceReq
* req
,
136 int error
, int errval
)
142 rc
= ProcXIPassiveGrabDevice(&client_request
);
146 assert(client_request
.errorValue
== errval
);
148 client_request
.swapped
= TRUE
;
151 swapl(&req
->grab_window
);
154 swaps(&req
->deviceid
);
155 modifiers
= req
->num_modifiers
;
156 swaps(&req
->num_modifiers
);
157 mask_len
= req
->mask_len
;
158 swaps(&req
->mask_len
);
160 while (modifiers
--) {
161 CARD32
*mod
= ((CARD32
*) (req
+ 1)) + mask_len
+ modifiers
;
166 rc
= SProcXIPassiveGrabDevice(&client_request
);
170 assert(client_request
.errorValue
== errval
);
173 static unsigned char *data
[4096]; /* the request buffer */
175 test_XIPassiveGrabDevice(void)
178 xXIPassiveGrabDeviceReq
*request
= (xXIPassiveGrabDeviceReq
*) data
;
181 request_init(request
, XIPassiveGrabDevice
);
183 request
->grab_window
= CLIENT_WINDOW_ID
;
185 reply_handler
= reply_XIPassiveGrabDevice
;
186 client_request
= init_client(request
->length
, request
);
188 printf("Testing invalid device\n");
189 request
->deviceid
= 12;
190 request_XIPassiveGrabDevice(&client_request
, request
, BadDevice
,
193 request
->deviceid
= XIAllMasterDevices
;
195 printf("Testing invalid grab types\n");
196 for (i
= XIGrabtypeTouchBegin
+ 1; i
< 0xFF; i
++) {
197 request
->grab_type
= i
;
198 request_XIPassiveGrabDevice(&client_request
, request
, BadValue
,
202 printf("Testing invalid grab type + detail combinations\n");
203 request
->grab_type
= XIGrabtypeEnter
;
205 request_XIPassiveGrabDevice(&client_request
, request
, BadValue
,
208 request
->grab_type
= XIGrabtypeFocusIn
;
209 request_XIPassiveGrabDevice(&client_request
, request
, BadValue
,
214 printf("Testing invalid masks\n");
215 mask
= (unsigned char *) &request
[1];
217 request
->mask_len
= bytes_to_int32(XI2LASTEVENT
+ 1);
218 request
->length
+= request
->mask_len
;
219 SetBit(mask
, XI2LASTEVENT
+ 1);
220 request_XIPassiveGrabDevice(&client_request
, request
, BadValue
,
223 ClearBit(mask
, XI2LASTEVENT
+ 1);
225 /* tested all special cases now, test a few valid cases */
228 request
->deviceid
= XIAllDevices
;
229 request
->grab_type
= XIGrabtypeButton
;
230 request
->detail
= XIAnyButton
;
231 request_XIPassiveGrabDevice(&client_request
, request
, Success
, 0);
233 /* Set a few random masks to make sure we handle modifiers correctly */
234 SetBit(mask
, XI_ButtonPress
);
235 SetBit(mask
, XI_KeyPress
);
236 SetBit(mask
, XI_Enter
);
239 request
->num_modifiers
= N_MODS
;
240 request
->length
+= N_MODS
;
241 memcpy((uint32_t *) (request
+ 1) + request
->mask_len
, modifiers
,
243 request_XIPassiveGrabDevice(&client_request
, request
, Success
, 0);
247 main(int argc
, char **argv
)
251 test_XIPassiveGrabDevice();