protocol-xchangedevicecontrol.c revision 706f2543
1706f2543Smrg/**
2706f2543Smrg * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3706f2543Smrg *
4706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5706f2543Smrg * copy of this software and associated documentation files (the "Software"),
6706f2543Smrg * to deal in the Software without restriction, including without limitation
7706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the
9706f2543Smrg * Software is furnished to do so, subject to the following conditions:
10706f2543Smrg *
11706f2543Smrg * The above copyright notice and this permission notice (including the next
12706f2543Smrg * paragraph) shall be included in all copies or substantial portions of the
13706f2543Smrg * Software.
14706f2543Smrg *
15706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18706f2543Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19706f2543Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20706f2543Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21706f2543Smrg * DEALINGS IN THE SOFTWARE.
22706f2543Smrg */
23706f2543Smrg
24706f2543Smrg#ifdef HAVE_DIX_CONFIG_H
25706f2543Smrg#include <dix-config.h>
26706f2543Smrg#endif
27706f2543Smrg
28706f2543Smrg/*
29706f2543Smrg * Protocol testing for ChangeDeviceControl request.
30706f2543Smrg */
31706f2543Smrg#include <stdint.h>
32706f2543Smrg#include <X11/X.h>
33706f2543Smrg#include <X11/Xproto.h>
34706f2543Smrg#include <X11/extensions/XIproto.h>
35706f2543Smrg#include "inputstr.h"
36706f2543Smrg#include "chgdctl.h"
37706f2543Smrg
38706f2543Smrg#include "protocol-common.h"
39706f2543Smrg
40706f2543Smrgstatic ClientRec client_request;
41706f2543Smrg
42706f2543Smrgstatic void
43706f2543Smrgreply_ChangeDeviceControl(ClientPtr client, int len, char *data, void *userdata)
44706f2543Smrg{
45706f2543Smrg    xChangeDeviceControlReply *rep = (xChangeDeviceControlReply *) data;
46706f2543Smrg
47706f2543Smrg    if (client->swapped) {
48706f2543Smrg        swapl(&rep->length);
49706f2543Smrg        swaps(&rep->sequenceNumber);
50706f2543Smrg    }
51706f2543Smrg
52706f2543Smrg    reply_check_defaults(rep, len, ChangeDeviceControl);
53706f2543Smrg
54706f2543Smrg    /* XXX: check status code in reply */
55706f2543Smrg}
56706f2543Smrg
57706f2543Smrgstatic void
58706f2543Smrgrequest_ChangeDeviceControl(ClientPtr client, xChangeDeviceControlReq * req,
59706f2543Smrg                            xDeviceCtl *ctl, int error)
60706f2543Smrg{
61706f2543Smrg    int rc;
62706f2543Smrg
63706f2543Smrg    client_request.req_len = req->length;
64706f2543Smrg    rc = ProcXChangeDeviceControl(&client_request);
65706f2543Smrg    assert(rc == error);
66706f2543Smrg
67706f2543Smrg    /* XXX: ChangeDeviceControl doesn't seem to fill in errorValue to check */
68706f2543Smrg
69706f2543Smrg    client_request.swapped = TRUE;
70706f2543Smrg    swaps(&req->length);
71706f2543Smrg    swaps(&req->control);
72706f2543Smrg    swaps(&ctl->length);
73706f2543Smrg    swaps(&ctl->control);
74706f2543Smrg    /* XXX: swap other contents of ctl, depending on type */
75706f2543Smrg    rc = SProcXChangeDeviceControl(&client_request);
76706f2543Smrg    assert(rc == error);
77706f2543Smrg}
78706f2543Smrg
79706f2543Smrgstatic unsigned char *data[4096];       /* the request buffer */
80706f2543Smrg
81706f2543Smrgstatic void
82706f2543Smrgtest_ChangeDeviceControl(void)
83706f2543Smrg{
84706f2543Smrg    xChangeDeviceControlReq *request = (xChangeDeviceControlReq *) data;
85706f2543Smrg    xDeviceCtl *control = (xDeviceCtl *) (&request[1]);
86706f2543Smrg
87706f2543Smrg    request_init(request, ChangeDeviceControl);
88706f2543Smrg
89706f2543Smrg    reply_handler = reply_ChangeDeviceControl;
90706f2543Smrg
91706f2543Smrg    client_request = init_client(request->length, request);
92706f2543Smrg
93706f2543Smrg    printf("Testing invalid lengths:\n");
94706f2543Smrg    printf(" -- no control struct\n");
95706f2543Smrg    request_ChangeDeviceControl(&client_request, request, control, BadLength);
96706f2543Smrg
97706f2543Smrg    printf(" -- xDeviceResolutionCtl\n");
98706f2543Smrg    request_init(request, ChangeDeviceControl);
99706f2543Smrg    request->control = DEVICE_RESOLUTION;
100706f2543Smrg    control->length = (sizeof(xDeviceResolutionCtl) >> 2);
101706f2543Smrg    request->length += control->length - 2;
102706f2543Smrg    request_ChangeDeviceControl(&client_request, request, control, BadLength);
103706f2543Smrg
104706f2543Smrg    printf(" -- xDeviceEnableCtl\n");
105706f2543Smrg    request_init(request, ChangeDeviceControl);
106706f2543Smrg    request->control = DEVICE_ENABLE;
107706f2543Smrg    control->length = (sizeof(xDeviceEnableCtl) >> 2);
108706f2543Smrg    request->length += control->length - 2;
109706f2543Smrg    request_ChangeDeviceControl(&client_request, request, control, BadLength);
110706f2543Smrg
111706f2543Smrg    /* XXX: Test functionality! */
112706f2543Smrg}
113706f2543Smrg
114706f2543Smrgint
115706f2543Smrgmain(int argc, char **argv)
116706f2543Smrg{
117706f2543Smrg    init_simple();
118706f2543Smrg
119706f2543Smrg    test_ChangeDeviceControl();
120706f2543Smrg
121706f2543Smrg    return 0;
122706f2543Smrg}
123