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 40static ClientRec client_request; 41 42static void 43reply_ChangeDeviceControl(ClientPtr client, int len, char *data, void *userdata) 44{ 45 xChangeDeviceControlReply *rep = (xChangeDeviceControlReply *) data; 46 47 if (client->swapped) { 48 swapl(&rep->length); 49 swaps(&rep->sequenceNumber); 50 } 51 52 reply_check_defaults(rep, len, ChangeDeviceControl); 53 54 /* XXX: check status code in reply */ 55} 56 57static void 58request_ChangeDeviceControl(ClientPtr client, xChangeDeviceControlReq * req, 59 xDeviceCtl *ctl, int error) 60{ 61 int rc; 62 63 client_request.req_len = req->length; 64 rc = ProcXChangeDeviceControl(&client_request); 65 assert(rc == error); 66 67 /* XXX: ChangeDeviceControl doesn't seem to fill in errorValue to check */ 68 69 client_request.swapped = TRUE; 70 swaps(&req->length); 71 swaps(&req->control); 72 swaps(&ctl->length); 73 swaps(&ctl->control); 74 /* XXX: swap other contents of ctl, depending on type */ 75 rc = SProcXChangeDeviceControl(&client_request); 76 assert(rc == error); 77} 78 79static unsigned char *data[4096]; /* the request buffer */ 80 81static void 82test_ChangeDeviceControl(void) 83{ 84 xChangeDeviceControlReq *request = (xChangeDeviceControlReq *) data; 85 xDeviceCtl *control = (xDeviceCtl *) (&request[1]); 86 87 request_init(request, ChangeDeviceControl); 88 89 reply_handler = reply_ChangeDeviceControl; 90 91 client_request = init_client(request->length, request); 92 93 printf("Testing invalid lengths:\n"); 94 printf(" -- no control struct\n"); 95 request_ChangeDeviceControl(&client_request, request, control, BadLength); 96 97 printf(" -- xDeviceResolutionCtl\n"); 98 request_init(request, ChangeDeviceControl); 99 request->control = DEVICE_RESOLUTION; 100 control->length = (sizeof(xDeviceResolutionCtl) >> 2); 101 request->length += control->length - 2; 102 request_ChangeDeviceControl(&client_request, request, control, BadLength); 103 104 printf(" -- xDeviceEnableCtl\n"); 105 request_init(request, ChangeDeviceControl); 106 request->control = DEVICE_ENABLE; 107 control->length = (sizeof(xDeviceEnableCtl) >> 2); 108 request->length += control->length - 2; 109 request_ChangeDeviceControl(&client_request, request, control, BadLength); 110 111 /* XXX: Test functionality! */ 112} 113 114int 115main(int argc, char **argv) 116{ 117 init_simple(); 118 119 test_ChangeDeviceControl(); 120 121 return 0; 122} 123