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 XIGetClientPointer 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 "xigetclientpointer.h" | |
39 | #include "exevents.h" | |
40 | ||
41 | #include "protocol-common.h" | |
42 | ||
43 | struct { | |
44 | int cp_is_set; | |
45 | DeviceIntPtr dev; | |
46 | int win; | |
47 | } test_data; | |
48 | ||
49 | static ClientRec client_window; | |
50 | static ClientRec client_request; | |
51 | ||
52 | int | |
53 | __wrap_dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, | |
54 | Mask access) | |
55 | { | |
56 | if (rid == ROOT_WINDOW_ID) | |
57 | return BadWindow; | |
58 | ||
59 | if (rid == CLIENT_WINDOW_ID) { | |
60 | *pClient = &client_window; | |
61 | return Success; | |
62 | } | |
63 | ||
64 | return __real_dixLookupClient(pClient, rid, client, access); | |
65 | } | |
66 | ||
67 | static void | |
68 | reply_XIGetClientPointer(ClientPtr client, int len, char *data, void *userdata) | |
69 | { | |
70 | xXIGetClientPointerReply *rep = (xXIGetClientPointerReply *) data; | |
71 | ||
72 | if (client->swapped) { | |
73 | swapl(&rep->length); | |
74 | swaps(&rep->sequenceNumber); | |
75 | swaps(&rep->deviceid); | |
76 | } | |
77 | ||
78 | reply_check_defaults(rep, len, XIGetClientPointer); | |
79 | ||
80 | assert(rep->set == test_data.cp_is_set); | |
81 | if (rep->set) | |
82 | assert(rep->deviceid == test_data.dev->id); | |
83 | } | |
84 | ||
85 | static void | |
86 | request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq * req, | |
87 | int error) | |
88 | { | |
89 | int rc; | |
90 | ||
91 | test_data.win = req->win; | |
92 | ||
93 | rc = ProcXIGetClientPointer(&client_request); | |
94 | assert(rc == error); | |
95 | ||
96 | if (rc == BadWindow) | |
97 | assert(client_request.errorValue == req->win); | |
98 | ||
99 | client_request.swapped = TRUE; | |
100 | swapl(&req->win); | |
101 | swaps(&req->length); | |
102 | rc = SProcXIGetClientPointer(&client_request); | |
103 | assert(rc == error); | |
104 | ||
105 | if (rc == BadWindow) | |
106 | assert(client_request.errorValue == req->win); | |
107 | ||
108 | } | |
109 | ||
110 | static void | |
111 | test_XIGetClientPointer(void) | |
112 | { | |
113 | xXIGetClientPointerReq request; | |
114 | ||
115 | request_init(&request, XIGetClientPointer); | |
116 | ||
117 | request.win = CLIENT_WINDOW_ID; | |
118 | ||
119 | reply_handler = reply_XIGetClientPointer; | |
120 | ||
121 | client_request = init_client(request.length, &request); | |
122 | ||
123 | printf("Testing invalid window\n"); | |
124 | request.win = INVALID_WINDOW_ID; | |
125 | request_XIGetClientPointer(&client_request, &request, BadWindow); | |
126 | ||
127 | test_data.cp_is_set = FALSE; | |
128 | ||
129 | printf("Testing window None, unset ClientPointer.\n"); | |
130 | request.win = None; | |
131 | request_XIGetClientPointer(&client_request, &request, Success); | |
132 | ||
133 | printf("Testing valid window, unset ClientPointer.\n"); | |
134 | request.win = CLIENT_WINDOW_ID; | |
135 | request_XIGetClientPointer(&client_request, &request, Success); | |
136 | ||
137 | printf("Testing valid window, set ClientPointer.\n"); | |
138 | client_window.clientPtr = devices.vcp; | |
139 | test_data.dev = devices.vcp; | |
140 | test_data.cp_is_set = TRUE; | |
141 | request.win = CLIENT_WINDOW_ID; | |
142 | request_XIGetClientPointer(&client_request, &request, Success); | |
143 | ||
144 | client_window.clientPtr = NULL; | |
145 | ||
146 | printf("Testing window None, set ClientPointer.\n"); | |
147 | client_request.clientPtr = devices.vcp; | |
148 | test_data.dev = devices.vcp; | |
149 | test_data.cp_is_set = TRUE; | |
150 | request.win = None; | |
151 | request_XIGetClientPointer(&client_request, &request, Success); | |
152 | } | |
153 | ||
154 | int | |
155 | main(int argc, char **argv) | |
156 | { | |
157 | init_simple(); | |
158 | client_window = init_client(0, NULL); | |
159 | ||
160 | test_XIGetClientPointer(); | |
161 | ||
162 | return 0; | |
163 | } |