Debian Codegraph @

test/xi1/protocol-xchangedevicecontrol.c

raw
1 /**
2 * Copyright (c) 2014, Oracle and/or its affiliates.
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 ChangeDeviceControl request.
33 */
34 #include <stdint.h>
35 #include <X11/X.h>
36 #include <X11/Xproto.h>
37 #include <X11/extensions/XIproto.h>
38 #include "inputstr.h"
39 #include "chgdctl.h"
40
41 #include "protocol-common.h"
42
43 DECLARE_WRAP_FUNCTION(WriteToClient, void, ClientPtr client, int len, void *data);
44
45 extern ClientRec client_window;
46 static ClientRec client_request;
47
48 static void
49 reply_ChangeDeviceControl(ClientPtr client, int len, void *data)
50 {
51 xChangeDeviceControlReply *rep = (xChangeDeviceControlReply *) data;
52
53 if (client->swapped) {
54 swapl(&rep->length);
55 swaps(&rep->sequenceNumber);
56 }
57
58 reply_check_defaults(rep, len, ChangeDeviceControl);
59
60 /* XXX: check status code in reply */
61 }
62
63 static void
64 request_ChangeDeviceControl(ClientPtr client, xChangeDeviceControlReq * req,
65 xDeviceCtl *ctl, int error)
66 {
67 int rc;
68
69 client_request.req_len = req->length;
70 rc = ProcXChangeDeviceControl(&client_request);
71 assert(rc == error);
72
73 /* XXX: ChangeDeviceControl doesn't seem to fill in errorValue to check */
74
75 client_request.swapped = TRUE;
76 swaps(&req->length);
77 swaps(&req->control);
78 swaps(&ctl->length);
79 swaps(&ctl->control);
80 /* XXX: swap other contents of ctl, depending on type */
81 rc = SProcXChangeDeviceControl(&client_request);
82 assert(rc == error);
83 }
84
85 static unsigned char *data[4096]; /* the request buffer */
86
87 static void
88 test_ChangeDeviceControl(void)
89 {
90 init_simple();
91
92 xChangeDeviceControlReq *request = (xChangeDeviceControlReq *) data;
93 xDeviceCtl *control = (xDeviceCtl *) (&request[1]);
94
95 request_init(request, ChangeDeviceControl);
96
97 wrapped_WriteToClient = reply_ChangeDeviceControl;
98
99 client_request = init_client(request->length, request);
100
101 dbg("Testing invalid lengths:\n");
102 dbg(" -- no control struct\n");
103 request_ChangeDeviceControl(&client_request, request, control, BadLength);
104
105 dbg(" -- xDeviceResolutionCtl\n");
106 request_init(request, ChangeDeviceControl);
107 request->control = DEVICE_RESOLUTION;
108 control->length = (sizeof(xDeviceResolutionCtl) >> 2);
109 request->length += control->length - 2;
110 request_ChangeDeviceControl(&client_request, request, control, BadLength);
111
112 dbg(" -- xDeviceEnableCtl\n");
113 request_init(request, ChangeDeviceControl);
114 request->control = DEVICE_ENABLE;
115 control->length = (sizeof(xDeviceEnableCtl) >> 2);
116 request->length += control->length - 2;
117 request_ChangeDeviceControl(&client_request, request, control, BadLength);
118
119 /* XXX: Test functionality! */
120 }
121
122 const testfunc_t*
123 protocol_xchangedevicecontrol_test(void)
124 {
125 static const testfunc_t testfuncs[] = {
126 test_ChangeDeviceControl,
127 NULL,
128 };
129 return testfuncs;
130 }