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 #ifdef HAVE_DIX_CONFIG_H
25 #include <dix-config.h>
26 #endif
27
28 /*
29 * Protocol testing for XIQueryPointer request.
30 */
31 #include <stdint.h>
32 #include <X11/X.h>
33 #include <X11/Xproto.h>
34 #include <X11/extensions/XI2proto.h>
35 #include "inputstr.h"
36 #include "windowstr.h"
37 #include "scrnintstr.h"
38 #include "xiquerypointer.h"
39 #include "exevents.h"
40 #include "exglobals.h"
41
42 #include "protocol-common.h"
43
44 extern ClientRec client_window;
45 static ClientRec client_request;
46 static void reply_XIQueryPointer_data(ClientPtr client, int len,
47 char *data, void *closure);
48
49 static struct {
50 DeviceIntPtr dev;
51 WindowPtr win;
52 } test_data;
53
54 static void
reply_XIQueryPointer(ClientPtr client,int len,char * data,void * closure)55 reply_XIQueryPointer(ClientPtr client, int len, char *data, void *closure)
56 {
57 xXIQueryPointerReply *rep = (xXIQueryPointerReply *) data;
58 SpritePtr sprite;
59
60 if (!rep->repType)
61 return;
62
63 if (client->swapped) {
64 swapl(&rep->length);
65 swaps(&rep->sequenceNumber);
66 swapl(&rep->root);
67 swapl(&rep->child);
68 swapl(&rep->root_x);
69 swapl(&rep->root_y);
70 swapl(&rep->win_x);
71 swapl(&rep->win_y);
72 swaps(&rep->buttons_len);
73 }
74
75 reply_check_defaults(rep, len, XIQueryPointer);
76
77 assert(rep->root == root.drawable.id);
78 assert(rep->same_screen == xTrue);
79
80 sprite = test_data.dev->spriteInfo->sprite;
81 assert((rep->root_x >> 16) == sprite->hot.x);
82 assert((rep->root_y >> 16) == sprite->hot.y);
83
84 if (test_data.win == &root) {
85 assert(rep->root_x == rep->win_x);
86 assert(rep->root_y == rep->win_y);
87 assert(rep->child == window.drawable.id);
88 }
89 else {
90 int x, y;
91
92 x = sprite->hot.x - window.drawable.x;
93 y = sprite->hot.y - window.drawable.y;
94
95 assert((rep->win_x >> 16) == x);
96 assert((rep->win_y >> 16) == y);
97 assert(rep->child == None);
98 }
99
100 assert(rep->same_screen == xTrue);
101
102 reply_handler = reply_XIQueryPointer_data;
103 }
104
105 static void
reply_XIQueryPointer_data(ClientPtr client,int len,char * data,void * closure)106 reply_XIQueryPointer_data(ClientPtr client, int len, char *data, void *closure)
107 {
108 reply_handler = reply_XIQueryPointer;
109 }
110
111 static void
request_XIQueryPointer(ClientPtr client,xXIQueryPointerReq * req,int error)112 request_XIQueryPointer(ClientPtr client, xXIQueryPointerReq * req, int error)
113 {
114 int rc;
115
116 rc = ProcXIQueryPointer(&client_request);
117 assert(rc == error);
118
119 if (rc == BadDevice)
120 assert(client_request.errorValue == req->deviceid);
121
122 client_request.swapped = TRUE;
123 swaps(&req->deviceid);
124 swapl(&req->win);
125 swaps(&req->length);
126 rc = SProcXIQueryPointer(&client_request);
127 assert(rc == error);
128
129 if (rc == BadDevice)
130 assert(client_request.errorValue == req->deviceid);
131 }
132
133 static void
test_XIQueryPointer(void)134 test_XIQueryPointer(void)
135 {
136 int i;
137 xXIQueryPointerReq request;
138
139 memset(&request, 0, sizeof(request));
140
141 request_init(&request, XIQueryPointer);
142
143 reply_handler = reply_XIQueryPointer;
144
145 client_request = init_client(request.length, &request);
146
147 request.deviceid = XIAllDevices;
148 request_XIQueryPointer(&client_request, &request, BadDevice);
149
150 request.deviceid = XIAllMasterDevices;
151 request_XIQueryPointer(&client_request, &request, BadDevice);
152
153 request.win = root.drawable.id;
154 test_data.win = &root;
155
156 test_data.dev = devices.vcp;
157 request.deviceid = devices.vcp->id;
158 request_XIQueryPointer(&client_request, &request, Success);
159 request.deviceid = devices.vck->id;
160 request_XIQueryPointer(&client_request, &request, BadDevice);
161 request.deviceid = devices.mouse->id;
162 request_XIQueryPointer(&client_request, &request, BadDevice);
163 request.deviceid = devices.kbd->id;
164 request_XIQueryPointer(&client_request, &request, BadDevice);
165
166 test_data.dev = devices.mouse;
167 devices.mouse->master = NULL; /* Float, kind-of */
168 request.deviceid = devices.mouse->id;
169 request_XIQueryPointer(&client_request, &request, Success);
170
171 for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) {
172 request.deviceid = i;
173 request_XIQueryPointer(&client_request, &request, BadDevice);
174 }
175
176 request.win = window.drawable.id;
177
178 test_data.dev = devices.vcp;
179 test_data.win = &window;
180 request.deviceid = devices.vcp->id;
181 request_XIQueryPointer(&client_request, &request, Success);
182
183 test_data.dev = devices.mouse;
184 request.deviceid = devices.mouse->id;
185 request_XIQueryPointer(&client_request, &request, Success);
186
187 /* test REQUEST_SIZE_MATCH */
188 client_request.req_len -= 4;
189 request_XIQueryPointer(&client_request, &request, BadLength);
190 }
191
192 int
protocol_xiquerypointer_test(void)193 protocol_xiquerypointer_test(void)
194 {
195 init_simple();
196
197 test_XIQueryPointer();
198
199 return 0;
200 }
201