xref: /OK3568_Linux_fs/external/xserver/test/xi2/protocol-xiquerypointer.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /**
2*4882a593Smuzhiyun  * Copyright © 2009 Red Hat, Inc.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *  Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun  *  copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun  *  to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun  *  and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun  *  Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  *  The above copyright notice and this permission notice (including the next
12*4882a593Smuzhiyun  *  paragraph) shall be included in all copies or substantial portions of the
13*4882a593Smuzhiyun  *  Software.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*4882a593Smuzhiyun  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*4882a593Smuzhiyun  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*4882a593Smuzhiyun  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*4882a593Smuzhiyun  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*4882a593Smuzhiyun  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*4882a593Smuzhiyun  *  DEALINGS IN THE SOFTWARE.
22*4882a593Smuzhiyun  */
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
25*4882a593Smuzhiyun #include <dix-config.h>
26*4882a593Smuzhiyun #endif
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun  * Protocol testing for XIQueryPointer request.
30*4882a593Smuzhiyun  */
31*4882a593Smuzhiyun #include <stdint.h>
32*4882a593Smuzhiyun #include <X11/X.h>
33*4882a593Smuzhiyun #include <X11/Xproto.h>
34*4882a593Smuzhiyun #include <X11/extensions/XI2proto.h>
35*4882a593Smuzhiyun #include "inputstr.h"
36*4882a593Smuzhiyun #include "windowstr.h"
37*4882a593Smuzhiyun #include "scrnintstr.h"
38*4882a593Smuzhiyun #include "xiquerypointer.h"
39*4882a593Smuzhiyun #include "exevents.h"
40*4882a593Smuzhiyun #include "exglobals.h"
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun #include "protocol-common.h"
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun extern ClientRec client_window;
45*4882a593Smuzhiyun static ClientRec client_request;
46*4882a593Smuzhiyun static void reply_XIQueryPointer_data(ClientPtr client, int len,
47*4882a593Smuzhiyun                                       char *data, void *closure);
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun static struct {
50*4882a593Smuzhiyun     DeviceIntPtr dev;
51*4882a593Smuzhiyun     WindowPtr win;
52*4882a593Smuzhiyun } test_data;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun static void
reply_XIQueryPointer(ClientPtr client,int len,char * data,void * closure)55*4882a593Smuzhiyun reply_XIQueryPointer(ClientPtr client, int len, char *data, void *closure)
56*4882a593Smuzhiyun {
57*4882a593Smuzhiyun     xXIQueryPointerReply *rep = (xXIQueryPointerReply *) data;
58*4882a593Smuzhiyun     SpritePtr sprite;
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun     if (!rep->repType)
61*4882a593Smuzhiyun         return;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun     if (client->swapped) {
64*4882a593Smuzhiyun         swapl(&rep->length);
65*4882a593Smuzhiyun         swaps(&rep->sequenceNumber);
66*4882a593Smuzhiyun         swapl(&rep->root);
67*4882a593Smuzhiyun         swapl(&rep->child);
68*4882a593Smuzhiyun         swapl(&rep->root_x);
69*4882a593Smuzhiyun         swapl(&rep->root_y);
70*4882a593Smuzhiyun         swapl(&rep->win_x);
71*4882a593Smuzhiyun         swapl(&rep->win_y);
72*4882a593Smuzhiyun         swaps(&rep->buttons_len);
73*4882a593Smuzhiyun     }
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun     reply_check_defaults(rep, len, XIQueryPointer);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun     assert(rep->root == root.drawable.id);
78*4882a593Smuzhiyun     assert(rep->same_screen == xTrue);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun     sprite = test_data.dev->spriteInfo->sprite;
81*4882a593Smuzhiyun     assert((rep->root_x >> 16) == sprite->hot.x);
82*4882a593Smuzhiyun     assert((rep->root_y >> 16) == sprite->hot.y);
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun     if (test_data.win == &root) {
85*4882a593Smuzhiyun         assert(rep->root_x == rep->win_x);
86*4882a593Smuzhiyun         assert(rep->root_y == rep->win_y);
87*4882a593Smuzhiyun         assert(rep->child == window.drawable.id);
88*4882a593Smuzhiyun     }
89*4882a593Smuzhiyun     else {
90*4882a593Smuzhiyun         int x, y;
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun         x = sprite->hot.x - window.drawable.x;
93*4882a593Smuzhiyun         y = sprite->hot.y - window.drawable.y;
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun         assert((rep->win_x >> 16) == x);
96*4882a593Smuzhiyun         assert((rep->win_y >> 16) == y);
97*4882a593Smuzhiyun         assert(rep->child == None);
98*4882a593Smuzhiyun     }
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun     assert(rep->same_screen == xTrue);
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun     reply_handler = reply_XIQueryPointer_data;
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun static void
reply_XIQueryPointer_data(ClientPtr client,int len,char * data,void * closure)106*4882a593Smuzhiyun reply_XIQueryPointer_data(ClientPtr client, int len, char *data, void *closure)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun     reply_handler = reply_XIQueryPointer;
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun static void
request_XIQueryPointer(ClientPtr client,xXIQueryPointerReq * req,int error)112*4882a593Smuzhiyun request_XIQueryPointer(ClientPtr client, xXIQueryPointerReq * req, int error)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun     int rc;
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun     rc = ProcXIQueryPointer(&client_request);
117*4882a593Smuzhiyun     assert(rc == error);
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun     if (rc == BadDevice)
120*4882a593Smuzhiyun         assert(client_request.errorValue == req->deviceid);
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun     client_request.swapped = TRUE;
123*4882a593Smuzhiyun     swaps(&req->deviceid);
124*4882a593Smuzhiyun     swapl(&req->win);
125*4882a593Smuzhiyun     swaps(&req->length);
126*4882a593Smuzhiyun     rc = SProcXIQueryPointer(&client_request);
127*4882a593Smuzhiyun     assert(rc == error);
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun     if (rc == BadDevice)
130*4882a593Smuzhiyun         assert(client_request.errorValue == req->deviceid);
131*4882a593Smuzhiyun }
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun static void
test_XIQueryPointer(void)134*4882a593Smuzhiyun test_XIQueryPointer(void)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun     int i;
137*4882a593Smuzhiyun     xXIQueryPointerReq request;
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun     memset(&request, 0, sizeof(request));
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun     request_init(&request, XIQueryPointer);
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun     reply_handler = reply_XIQueryPointer;
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun     client_request = init_client(request.length, &request);
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun     request.deviceid = XIAllDevices;
148*4882a593Smuzhiyun     request_XIQueryPointer(&client_request, &request, BadDevice);
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun     request.deviceid = XIAllMasterDevices;
151*4882a593Smuzhiyun     request_XIQueryPointer(&client_request, &request, BadDevice);
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun     request.win = root.drawable.id;
154*4882a593Smuzhiyun     test_data.win = &root;
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun     test_data.dev = devices.vcp;
157*4882a593Smuzhiyun     request.deviceid = devices.vcp->id;
158*4882a593Smuzhiyun     request_XIQueryPointer(&client_request, &request, Success);
159*4882a593Smuzhiyun     request.deviceid = devices.vck->id;
160*4882a593Smuzhiyun     request_XIQueryPointer(&client_request, &request, BadDevice);
161*4882a593Smuzhiyun     request.deviceid = devices.mouse->id;
162*4882a593Smuzhiyun     request_XIQueryPointer(&client_request, &request, BadDevice);
163*4882a593Smuzhiyun     request.deviceid = devices.kbd->id;
164*4882a593Smuzhiyun     request_XIQueryPointer(&client_request, &request, BadDevice);
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun     test_data.dev = devices.mouse;
167*4882a593Smuzhiyun     devices.mouse->master = NULL;       /* Float, kind-of */
168*4882a593Smuzhiyun     request.deviceid = devices.mouse->id;
169*4882a593Smuzhiyun     request_XIQueryPointer(&client_request, &request, Success);
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun     for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) {
172*4882a593Smuzhiyun         request.deviceid = i;
173*4882a593Smuzhiyun         request_XIQueryPointer(&client_request, &request, BadDevice);
174*4882a593Smuzhiyun     }
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun     request.win = window.drawable.id;
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun     test_data.dev = devices.vcp;
179*4882a593Smuzhiyun     test_data.win = &window;
180*4882a593Smuzhiyun     request.deviceid = devices.vcp->id;
181*4882a593Smuzhiyun     request_XIQueryPointer(&client_request, &request, Success);
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun     test_data.dev = devices.mouse;
184*4882a593Smuzhiyun     request.deviceid = devices.mouse->id;
185*4882a593Smuzhiyun     request_XIQueryPointer(&client_request, &request, Success);
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun     /* test REQUEST_SIZE_MATCH */
188*4882a593Smuzhiyun     client_request.req_len -= 4;
189*4882a593Smuzhiyun     request_XIQueryPointer(&client_request, &request, BadLength);
190*4882a593Smuzhiyun }
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun int
protocol_xiquerypointer_test(void)193*4882a593Smuzhiyun protocol_xiquerypointer_test(void)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun     init_simple();
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun     test_XIQueryPointer();
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun     return 0;
200*4882a593Smuzhiyun }
201