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 XIWarpPointer request.
33 #include <X11/Xproto.h>
34 #include <X11/extensions/XI2proto.h>
36 #include "windowstr.h"
37 #include "scrnintstr.h"
38 #include "xiwarppointer.h"
40 #include "exglobals.h"
42 #include "protocol-common.h"
44 static int expected_x
= SPRITE_X
;
45 static int expected_y
= SPRITE_Y
;
47 /* dixLookupWindow requires a lot of setup not necessary for this test.
48 * Simple wrapper that returns either one of the fake root window or the
49 * fake client window. If the requested ID is neither of those wanted,
50 * return whatever the real dixLookupWindow does.
53 __wrap_dixLookupWindow(WindowPtr
*win
, XID id
, ClientPtr client
, Mask access
)
55 if (id
== root
.drawable
.id
) {
59 else if (id
== window
.drawable
.id
) {
64 return __real_dixLookupWindow(win
, id
, client
, access
);
68 * This function overrides the one in the screen rec.
71 ScreenSetCursorPosition(DeviceIntPtr dev
, ScreenPtr scr
,
72 int x
, int y
, Bool generateEvent
)
74 assert(x
== expected_x
);
75 assert(y
== expected_y
);
80 request_XIWarpPointer(ClientPtr client
, xXIWarpPointerReq
* req
, int error
)
84 rc
= ProcXIWarpPointer(client
);
88 assert(client
->errorValue
== req
->deviceid
);
89 else if (rc
== BadWindow
)
90 assert(client
->errorValue
== req
->dst_win
||
91 client
->errorValue
== req
->src_win
);
93 client
->swapped
= TRUE
;
101 swaps(&req
->src_width
);
102 swaps(&req
->src_height
);
103 swaps(&req
->deviceid
);
105 rc
= SProcXIWarpPointer(client
);
109 assert(client
->errorValue
== req
->deviceid
);
110 else if (rc
== BadWindow
)
111 assert(client
->errorValue
== req
->dst_win
||
112 client
->errorValue
== req
->src_win
);
114 client
->swapped
= FALSE
;
118 test_XIWarpPointer(void)
121 ClientRec client_request
;
122 xXIWarpPointerReq request
;
124 memset(&request
, 0, sizeof(request
));
126 request_init(&request
, XIWarpPointer
);
128 client_request
= init_client(request
.length
, &request
);
130 request
.deviceid
= XIAllDevices
;
131 request_XIWarpPointer(&client_request
, &request
, BadDevice
);
133 request
.deviceid
= XIAllMasterDevices
;
134 request_XIWarpPointer(&client_request
, &request
, BadDevice
);
136 request
.src_win
= root
.drawable
.id
;
137 request
.dst_win
= root
.drawable
.id
;
138 request
.deviceid
= devices
.vcp
->id
;
139 request_XIWarpPointer(&client_request
, &request
, Success
);
140 request
.deviceid
= devices
.vck
->id
;
141 request_XIWarpPointer(&client_request
, &request
, BadDevice
);
142 request
.deviceid
= devices
.mouse
->id
;
143 request_XIWarpPointer(&client_request
, &request
, BadDevice
);
144 request
.deviceid
= devices
.kbd
->id
;
145 request_XIWarpPointer(&client_request
, &request
, BadDevice
);
147 devices
.mouse
->master
= NULL
; /* Float, kind-of */
148 request
.deviceid
= devices
.mouse
->id
;
149 request_XIWarpPointer(&client_request
, &request
, Success
);
151 for (i
= devices
.kbd
->id
+ 1; i
<= 0xFFFF; i
++) {
152 request
.deviceid
= i
;
153 request_XIWarpPointer(&client_request
, &request
, BadDevice
);
156 request
.src_win
= window
.drawable
.id
;
157 request
.deviceid
= devices
.vcp
->id
;
158 request_XIWarpPointer(&client_request
, &request
, Success
);
160 request
.deviceid
= devices
.mouse
->id
;
161 request_XIWarpPointer(&client_request
, &request
, Success
);
163 request
.src_win
= root
.drawable
.id
;
164 request
.dst_win
= 0xFFFF; /* invalid window */
165 request_XIWarpPointer(&client_request
, &request
, BadWindow
);
167 request
.src_win
= 0xFFFF; /* invalid window */
168 request
.dst_win
= root
.drawable
.id
;
169 request_XIWarpPointer(&client_request
, &request
, BadWindow
);
171 request
.src_win
= None
;
172 request
.dst_win
= None
;
175 expected_y
= SPRITE_Y
;
177 request
.dst_x
= 1 << 16;
178 expected_x
= SPRITE_X
+ 1;
179 request
.deviceid
= devices
.vcp
->id
;
180 request_XIWarpPointer(&client_request
, &request
, Success
);
182 request
.dst_x
= -1 << 16;
183 expected_x
= SPRITE_X
- 1;
184 request
.deviceid
= devices
.vcp
->id
;
185 request_XIWarpPointer(&client_request
, &request
, Success
);
188 expected_x
= SPRITE_X
;
190 request
.dst_y
= 1 << 16;
191 expected_y
= SPRITE_Y
+ 1;
192 request
.deviceid
= devices
.vcp
->id
;
193 request_XIWarpPointer(&client_request
, &request
, Success
);
195 request
.dst_y
= -1 << 16;
196 expected_y
= SPRITE_Y
- 1;
197 request
.deviceid
= devices
.vcp
->id
;
198 request_XIWarpPointer(&client_request
, &request
, Success
);
200 /* FIXME: src_x/y checks */
204 main(int argc
, char **argv
)
207 screen
.SetCursorPosition
= ScreenSetCursorPosition
;
209 test_XIWarpPointer();