Debian Codegraph @

test/xi2/protocol-xigetclientpointer.c

raw
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 /* Test relies on assert() */
25 #undef NDEBUG
26
27 #ifdef HAVE_DIX_CONFIG_H
28 #include <dix-config.h>
29 #endif
30
31 /*
32 * Protocol testing for XIGetClientPointer request.
33 */
34 #include <stdint.h>
35 #include <X11/X.h>
36 #include <X11/Xproto.h>
37 #include <X11/extensions/XI2proto.h>
38 #include "inputstr.h"
39 #include "windowstr.h"
40 #include "scrnintstr.h"
41 #include "xigetclientpointer.h"
42 #include "exevents.h"
43
44 #include "protocol-common.h"
45
46 DECLARE_WRAP_FUNCTION(WriteToClient, void, ClientPtr client, int len, void *data);
47
48 static struct {
49 int cp_is_set;
50 DeviceIntPtr dev;
51 int win;
52 } test_data;
53
54 extern ClientRec client_window;
55 static ClientRec client_request;
56
57 static void
58 reply_XIGetClientPointer(ClientPtr client, int len, void *data)
59 {
60 xXIGetClientPointerReply *reply = (xXIGetClientPointerReply *) data;
61 xXIGetClientPointerReply rep = *reply; /* copy so swapping doesn't touch the real reply */
62
63 assert(len < 0xffff); /* suspicious size, swapping bug */
64
65 if (client->swapped) {
66 swapl(&rep.length);
67 swaps(&rep.sequenceNumber);
68 swaps(&rep.deviceid);
69 }
70
71 reply_check_defaults(&rep, len, XIGetClientPointer);
72
73 assert(rep.set == test_data.cp_is_set);
74 if (rep.set)
75 assert(rep.deviceid == test_data.dev->id);
76 }
77
78 static void
79 request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq * req,
80 int error)
81 {
82 int rc;
83
84 test_data.win = req->win;
85
86 rc = ProcXIGetClientPointer(&client_request);
87 assert(rc == error);
88
89 if (rc == BadWindow)
90 assert(client_request.errorValue == req->win);
91
92 client_request.swapped = TRUE;
93 swapl(&req->win);
94 swaps(&req->length);
95 rc = SProcXIGetClientPointer(&client_request);
96 assert(rc == error);
97
98 if (rc == BadWindow)
99 assert(client_request.errorValue == req->win);
100
101 }
102
103 static void
104 test_XIGetClientPointer(void)
105 {
106 xXIGetClientPointerReq request;
107
108 init_simple();
109 client_window = init_client(0, NULL);
110
111 request_init(&request, XIGetClientPointer);
112
113 request.win = CLIENT_WINDOW_ID;
114
115 wrapped_WriteToClient = reply_XIGetClientPointer;
116
117 client_request = init_client(request.length, &request);
118
119 dbg("Testing invalid window\n");
120 request.win = INVALID_WINDOW_ID;
121 request_XIGetClientPointer(&client_request, &request, BadWindow);
122
123 dbg("Testing invalid length\n");
124 client_request.req_len -= 4;
125 request_XIGetClientPointer(&client_request, &request, BadLength);
126 client_request.req_len += 4;
127
128 test_data.cp_is_set = FALSE;
129
130 dbg("Testing window None, unset ClientPointer.\n");
131 request.win = None;
132 request_XIGetClientPointer(&client_request, &request, Success);
133
134 dbg("Testing valid window, unset ClientPointer.\n");
135 request.win = CLIENT_WINDOW_ID;
136 request_XIGetClientPointer(&client_request, &request, Success);
137
138 dbg("Testing valid window, set ClientPointer.\n");
139 client_window.clientPtr = devices.vcp;
140 test_data.dev = devices.vcp;
141 test_data.cp_is_set = TRUE;
142 request.win = CLIENT_WINDOW_ID;
143 request_XIGetClientPointer(&client_request, &request, Success);
144
145 client_window.clientPtr = NULL;
146
147 dbg("Testing window None, set ClientPointer.\n");
148 client_request.clientPtr = devices.vcp;
149 test_data.dev = devices.vcp;
150 test_data.cp_is_set = TRUE;
151 request.win = None;
152 request_XIGetClientPointer(&client_request, &request, Success);
153 }
154
155 const testfunc_t*
156 protocol_xigetclientpointer_test(void)
157 {
158 static const testfunc_t testfuncs[] = {
159 test_XIGetClientPointer,
160 NULL,
161 };
162
163 return testfuncs;
164 }