Imported Upstream version 1.15.1
[deb_xorg-server.git] / test / xi2 / protocol-xiquerypointer.c
CommitLineData
a09e091a
JB
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
44static ClientRec client_request;
45static void reply_XIQueryPointer_data(ClientPtr client, int len,
46 char *data, void *closure);
47
48static struct {
49 DeviceIntPtr dev;
50 WindowPtr win;
51} test_data;
52
53/* dixLookupWindow requires a lot of setup not necessary for this test.
54 * Simple wrapper that returns either one of the fake root window or the
55 * fake client window. If the requested ID is neither of those wanted,
56 * return whatever the real dixLookupWindow does.
57 */
58int
59__wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access)
60{
61 if (id == root.drawable.id) {
62 *win = &root;
63 return Success;
64 }
65 else if (id == window.drawable.id) {
66 *win = &window;
67 return Success;
68 }
69
70 return __real_dixLookupWindow(win, id, client, access);
71}
72
73static void
74reply_XIQueryPointer(ClientPtr client, int len, char *data, void *closure)
75{
76 xXIQueryPointerReply *rep = (xXIQueryPointerReply *) data;
77 SpritePtr sprite;
78
79 if (!rep->repType)
80 return;
81
82 if (client->swapped) {
83 swapl(&rep->length);
84 swaps(&rep->sequenceNumber);
85 swapl(&rep->root);
86 swapl(&rep->child);
87 swapl(&rep->root_x);
88 swapl(&rep->root_y);
89 swapl(&rep->win_x);
90 swapl(&rep->win_y);
91 swaps(&rep->buttons_len);
92 }
93
94 reply_check_defaults(rep, len, XIQueryPointer);
95
96 assert(rep->root == root.drawable.id);
97 assert(rep->same_screen == xTrue);
98
99 sprite = test_data.dev->spriteInfo->sprite;
100 assert((rep->root_x >> 16) == sprite->hot.x);
101 assert((rep->root_y >> 16) == sprite->hot.y);
102
103 if (test_data.win == &root) {
104 assert(rep->root_x == rep->win_x);
105 assert(rep->root_y == rep->win_y);
106 assert(rep->child == window.drawable.id);
107 }
108 else {
109 int x, y;
110
111 x = sprite->hot.x - window.drawable.x;
112 y = sprite->hot.y - window.drawable.y;
113
114 assert((rep->win_x >> 16) == x);
115 assert((rep->win_y >> 16) == y);
116 assert(rep->child == None);
117 }
118
119 assert(rep->same_screen == xTrue);
120
121 reply_handler = reply_XIQueryPointer_data;
122}
123
124static void
125reply_XIQueryPointer_data(ClientPtr client, int len, char *data, void *closure)
126{
127 reply_handler = reply_XIQueryPointer;
128}
129
130static void
131request_XIQueryPointer(ClientPtr client, xXIQueryPointerReq * req, int error)
132{
133 int rc;
134
135 rc = ProcXIQueryPointer(&client_request);
136 assert(rc == error);
137
138 if (rc == BadDevice)
139 assert(client_request.errorValue == req->deviceid);
140
141 client_request.swapped = TRUE;
142 swaps(&req->deviceid);
143 swaps(&req->length);
144 rc = SProcXIQueryPointer(&client_request);
145 assert(rc == error);
146
147 if (rc == BadDevice)
148 assert(client_request.errorValue == req->deviceid);
149}
150
151static void
152test_XIQueryPointer(void)
153{
154 int i;
155 xXIQueryPointerReq request;
156
157 memset(&request, 0, sizeof(request));
158
159 request_init(&request, XIQueryPointer);
160
161 reply_handler = reply_XIQueryPointer;
162
163 client_request = init_client(request.length, &request);
164
165 request.deviceid = XIAllDevices;
166 request_XIQueryPointer(&client_request, &request, BadDevice);
167
168 request.deviceid = XIAllMasterDevices;
169 request_XIQueryPointer(&client_request, &request, BadDevice);
170
171 request.win = root.drawable.id;
172 test_data.win = &root;
173
174 test_data.dev = devices.vcp;
175 request.deviceid = devices.vcp->id;
176 request_XIQueryPointer(&client_request, &request, Success);
177 request.deviceid = devices.vck->id;
178 request_XIQueryPointer(&client_request, &request, BadDevice);
179 request.deviceid = devices.mouse->id;
180 request_XIQueryPointer(&client_request, &request, BadDevice);
181 request.deviceid = devices.kbd->id;
182 request_XIQueryPointer(&client_request, &request, BadDevice);
183
184 test_data.dev = devices.mouse;
185 devices.mouse->master = NULL; /* Float, kind-of */
186 request.deviceid = devices.mouse->id;
187 request_XIQueryPointer(&client_request, &request, Success);
188
189 for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) {
190 request.deviceid = i;
191 request_XIQueryPointer(&client_request, &request, BadDevice);
192 }
193
194 request.win = window.drawable.id;
195
196 test_data.dev = devices.vcp;
197 test_data.win = &window;
198 request.deviceid = devices.vcp->id;
199 request_XIQueryPointer(&client_request, &request, Success);
200
201 test_data.dev = devices.mouse;
202 request.deviceid = devices.mouse->id;
203 request_XIQueryPointer(&client_request, &request, Success);
204}
205
206int
207main(int argc, char **argv)
208{
209 init_simple();
210
211 test_XIQueryPointer();
212
213 return 0;
214}