xref: /OK3568_Linux_fs/external/xserver/test/xi2/protocol-xisetclientpointer.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 XISetClientPointer request.
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  * Tests include:
32*4882a593Smuzhiyun  * BadDevice of all devices except master pointers.
33*4882a593Smuzhiyun  * Success for a valid window.
34*4882a593Smuzhiyun  * Success for window None.
35*4882a593Smuzhiyun  * BadWindow for invalid windows.
36*4882a593Smuzhiyun  */
37*4882a593Smuzhiyun #include <stdint.h>
38*4882a593Smuzhiyun #include <X11/X.h>
39*4882a593Smuzhiyun #include <X11/Xproto.h>
40*4882a593Smuzhiyun #include <X11/extensions/XI2proto.h>
41*4882a593Smuzhiyun #include "inputstr.h"
42*4882a593Smuzhiyun #include "windowstr.h"
43*4882a593Smuzhiyun #include "extinit.h"            /* for XInputExtensionInit */
44*4882a593Smuzhiyun #include "scrnintstr.h"
45*4882a593Smuzhiyun #include "xisetclientpointer.h"
46*4882a593Smuzhiyun #include "exevents.h"
47*4882a593Smuzhiyun #include "exglobals.h"
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun #include "protocol-common.h"
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun extern ClientRec client_window;
52*4882a593Smuzhiyun static ClientRec client_request;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun static void
request_XISetClientPointer(xXISetClientPointerReq * req,int error)55*4882a593Smuzhiyun request_XISetClientPointer(xXISetClientPointerReq * req, int error)
56*4882a593Smuzhiyun {
57*4882a593Smuzhiyun     int rc;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun     client_request = init_client(req->length, req);
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun     rc = ProcXISetClientPointer(&client_request);
62*4882a593Smuzhiyun     assert(rc == error);
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun     if (rc == BadDevice)
65*4882a593Smuzhiyun         assert(client_request.errorValue == req->deviceid);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun     client_request.swapped = TRUE;
68*4882a593Smuzhiyun     swapl(&req->win);
69*4882a593Smuzhiyun     swaps(&req->length);
70*4882a593Smuzhiyun     swaps(&req->deviceid);
71*4882a593Smuzhiyun     rc = SProcXISetClientPointer(&client_request);
72*4882a593Smuzhiyun     assert(rc == error);
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun     if (rc == BadDevice)
75*4882a593Smuzhiyun         assert(client_request.errorValue == req->deviceid);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun static void
test_XISetClientPointer(void)80*4882a593Smuzhiyun test_XISetClientPointer(void)
81*4882a593Smuzhiyun {
82*4882a593Smuzhiyun     int i;
83*4882a593Smuzhiyun     xXISetClientPointerReq request;
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun     request_init(&request, XISetClientPointer);
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun     request.win = CLIENT_WINDOW_ID;
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun     printf("Testing BadDevice error for XIAllDevices and XIMasterDevices.\n");
90*4882a593Smuzhiyun     request.deviceid = XIAllDevices;
91*4882a593Smuzhiyun     request_XISetClientPointer(&request, BadDevice);
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun     request.deviceid = XIAllMasterDevices;
94*4882a593Smuzhiyun     request_XISetClientPointer(&request, BadDevice);
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun     printf("Testing Success for VCP and VCK.\n");
97*4882a593Smuzhiyun     request.deviceid = devices.vcp->id; /* 2 */
98*4882a593Smuzhiyun     request_XISetClientPointer(&request, Success);
99*4882a593Smuzhiyun     assert(client_window.clientPtr->id == 2);
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun     request.deviceid = devices.vck->id; /* 3 */
102*4882a593Smuzhiyun     request_XISetClientPointer(&request, Success);
103*4882a593Smuzhiyun     assert(client_window.clientPtr->id == 2);
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun     printf("Testing BadDevice error for all other devices.\n");
106*4882a593Smuzhiyun     for (i = 4; i <= 0xFFFF; i++) {
107*4882a593Smuzhiyun         request.deviceid = i;
108*4882a593Smuzhiyun         request_XISetClientPointer(&request, BadDevice);
109*4882a593Smuzhiyun     }
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun     printf("Testing window None\n");
112*4882a593Smuzhiyun     request.win = None;
113*4882a593Smuzhiyun     request.deviceid = devices.vcp->id; /* 2 */
114*4882a593Smuzhiyun     request_XISetClientPointer(&request, Success);
115*4882a593Smuzhiyun     assert(client_request.clientPtr->id == 2);
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun     printf("Testing invalid window\n");
118*4882a593Smuzhiyun     request.win = INVALID_WINDOW_ID;
119*4882a593Smuzhiyun     request.deviceid = devices.vcp->id;
120*4882a593Smuzhiyun     request_XISetClientPointer(&request, BadWindow);
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun int
protocol_xisetclientpointer_test(void)125*4882a593Smuzhiyun protocol_xisetclientpointer_test(void)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun     init_simple();
128*4882a593Smuzhiyun     client_window = init_client(0, NULL);
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun     test_XISetClientPointer();
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun     return 0;
133*4882a593Smuzhiyun }
134