2 * Copyright © 2009 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 XIGetSelectedEvents request.
32 * BadWindow on wrong window.
33 * Zero-length masks if no masks are set.
34 * Valid masks for valid devices.
35 * Masks set on non-existent devices are not returned.
37 * Note that this test is not connected to the XISelectEvents request.
41 #include <X11/Xproto.h>
42 #include <X11/extensions/XI2proto.h>
44 #include "windowstr.h"
45 #include "extinit.h" /* for XInputExtensionInit */
46 #include "scrnintstr.h"
47 #include "xiselectev.h"
50 #include "protocol-common.h"
52 static void reply_XIGetSelectedEvents(ClientPtr client
, int len
, char *data
,
54 static void reply_XIGetSelectedEvents_data(ClientPtr client
, int len
,
55 char *data
, void *userdata
);
58 int num_masks_expected
;
59 unsigned char mask
[MAXDEVICES
][XI2LASTEVENT
]; /* intentionally bigger */
63 /* dixLookupWindow requires a lot of setup not necessary for this test.
64 * Simple wrapper that returns either one of the fake root window or the
65 * fake client window. If the requested ID is neither of those wanted,
66 * return whatever the real dixLookupWindow does.
69 __wrap_dixLookupWindow(WindowPtr
*win
, XID id
, ClientPtr client
, Mask access
)
71 if (id
== root
.drawable
.id
) {
75 else if (id
== window
.drawable
.id
) {
80 return __real_dixLookupWindow(win
, id
, client
, access
);
83 /* AddResource is called from XISetSEventMask, we don't need this */
85 __wrap_AddResource(XID id
, RESTYPE type
, pointer value
)
91 reply_XIGetSelectedEvents(ClientPtr client
, int len
, char *data
, void *userdata
)
93 xXIGetSelectedEventsReply
*rep
= (xXIGetSelectedEventsReply
*) data
;
95 if (client
->swapped
) {
97 swaps(&rep
->sequenceNumber
);
98 swaps(&rep
->num_masks
);
101 reply_check_defaults(rep
, len
, XIGetSelectedEvents
);
103 assert(rep
->num_masks
== test_data
.num_masks_expected
);
105 reply_handler
= reply_XIGetSelectedEvents_data
;
109 reply_XIGetSelectedEvents_data(ClientPtr client
, int len
, char *data
,
114 unsigned char *bitmask
;
116 mask
= (xXIEventMask
*) data
;
117 for (i
= 0; i
< test_data
.num_masks_expected
; i
++) {
118 if (client
->swapped
) {
119 swaps(&mask
->deviceid
);
120 swaps(&mask
->mask_len
);
123 assert(mask
->deviceid
< 6);
124 assert(mask
->mask_len
<= (((XI2LASTEVENT
+ 8) / 8) + 3) / 4);
126 bitmask
= (unsigned char *) &mask
[1];
127 assert(memcmp(bitmask
,
128 test_data
.mask
[mask
->deviceid
], mask
->mask_len
* 4) == 0);
131 (xXIEventMask
*) ((char *) mask
+ mask
->mask_len
* 4 +
132 sizeof(xXIEventMask
));
138 request_XIGetSelectedEvents(xXIGetSelectedEventsReq
* req
, int error
)
143 client
= init_client(req
->length
, req
);
145 reply_handler
= reply_XIGetSelectedEvents
;
147 rc
= ProcXIGetSelectedEvents(&client
);
150 reply_handler
= reply_XIGetSelectedEvents
;
151 client
.swapped
= TRUE
;
154 rc
= SProcXIGetSelectedEvents(&client
);
159 test_XIGetSelectedEvents(void)
162 xXIGetSelectedEventsReq request
;
163 ClientRec client
= init_client(0, NULL
);
167 request_init(&request
, XIGetSelectedEvents
);
169 printf("Testing for BadWindow on invalid window.\n");
171 request_XIGetSelectedEvents(&request
, BadWindow
);
173 printf("Testing for zero-length (unset) masks.\n");
174 /* No masks set yet */
175 test_data
.num_masks_expected
= 0;
176 request
.win
= ROOT_WINDOW_ID
;
177 request_XIGetSelectedEvents(&request
, Success
);
179 request
.win
= CLIENT_WINDOW_ID
;
180 request_XIGetSelectedEvents(&request
, Success
);
182 memset(test_data
.mask
, 0, sizeof(test_data
.mask
));
184 printf("Testing for valid masks\n");
185 memset(&dev
, 0, sizeof(dev
)); /* dev->id is enough for XISetEventMask */
186 request
.win
= ROOT_WINDOW_ID
;
188 /* devices 6 - MAXDEVICES don't exist, they mustn't be included in the
189 * reply even if a mask is set */
190 for (j
= 0; j
< MAXDEVICES
; j
++) {
191 test_data
.num_masks_expected
= min(j
+ 1, devices
.num_devices
+ 2);
193 mask
= test_data
.mask
[j
];
194 /* bits one-by-one */
195 for (i
= 0; i
< XI2LASTEVENT
; i
++) {
197 XISetEventMask(&dev
, &root
, &client
, (i
+ 8) / 8, mask
);
198 request_XIGetSelectedEvents(&request
, Success
);
202 /* all valid mask bits */
203 for (i
= 0; i
< XI2LASTEVENT
; i
++) {
205 XISetEventMask(&dev
, &root
, &client
, (i
+ 8) / 8, mask
);
206 request_XIGetSelectedEvents(&request
, Success
);
210 printf("Testing removing all masks\n");
211 /* Unset all masks one-by-one */
212 for (j
= MAXDEVICES
- 1; j
>= 0; j
--) {
213 if (j
< devices
.num_devices
+ 2)
214 test_data
.num_masks_expected
--;
216 mask
= test_data
.mask
[j
];
217 memset(mask
, 0, XI2LASTEVENT
);
220 XISetEventMask(&dev
, &root
, &client
, 0, NULL
);
222 request_XIGetSelectedEvents(&request
, Success
);
227 main(int argc
, char **argv
)
231 test_XIGetSelectedEvents();