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