Debian Codegraph @

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