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