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