protocol-xigetclientpointer.c revision f7df2e56
1/** 2 * Copyright © 2009 Red Hat, Inc. 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 XIGetClientPointer request. 30 */ 31#include <stdint.h> 32#include <X11/X.h> 33#include <X11/Xproto.h> 34#include <X11/extensions/XI2proto.h> 35#include "inputstr.h" 36#include "windowstr.h" 37#include "scrnintstr.h" 38#include "xigetclientpointer.h" 39#include "exevents.h" 40 41#include "protocol-common.h" 42 43struct { 44 int cp_is_set; 45 DeviceIntPtr dev; 46 int win; 47} test_data; 48 49static ClientRec client_window; 50static ClientRec client_request; 51 52int 53__wrap_dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, 54 Mask access) 55{ 56 if (rid == ROOT_WINDOW_ID) 57 return BadWindow; 58 59 if (rid == CLIENT_WINDOW_ID) { 60 *pClient = &client_window; 61 return Success; 62 } 63 64 return __real_dixLookupClient(pClient, rid, client, access); 65} 66 67static void 68reply_XIGetClientPointer(ClientPtr client, int len, char *data, void *userdata) 69{ 70 xXIGetClientPointerReply *rep = (xXIGetClientPointerReply *) data; 71 72 if (client->swapped) { 73 swapl(&rep->length); 74 swaps(&rep->sequenceNumber); 75 swaps(&rep->deviceid); 76 } 77 78 reply_check_defaults(rep, len, XIGetClientPointer); 79 80 assert(rep->set == test_data.cp_is_set); 81 if (rep->set) 82 assert(rep->deviceid == test_data.dev->id); 83} 84 85static void 86request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq * req, 87 int error) 88{ 89 int rc; 90 91 test_data.win = req->win; 92 93 rc = ProcXIGetClientPointer(&client_request); 94 assert(rc == error); 95 96 if (rc == BadWindow) 97 assert(client_request.errorValue == req->win); 98 99 client_request.swapped = TRUE; 100 swapl(&req->win); 101 swaps(&req->length); 102 rc = SProcXIGetClientPointer(&client_request); 103 assert(rc == error); 104 105 if (rc == BadWindow) 106 assert(client_request.errorValue == req->win); 107 108} 109 110static void 111test_XIGetClientPointer(void) 112{ 113 xXIGetClientPointerReq request; 114 115 request_init(&request, XIGetClientPointer); 116 117 request.win = CLIENT_WINDOW_ID; 118 119 reply_handler = reply_XIGetClientPointer; 120 121 client_request = init_client(request.length, &request); 122 123 printf("Testing invalid window\n"); 124 request.win = INVALID_WINDOW_ID; 125 request_XIGetClientPointer(&client_request, &request, BadWindow); 126 127 printf("Testing invalid length\n"); 128 client_request.req_len -= 4; 129 request_XIGetClientPointer(&client_request, &request, BadLength); 130 client_request.req_len += 4; 131 132 test_data.cp_is_set = FALSE; 133 134 printf("Testing window None, unset ClientPointer.\n"); 135 request.win = None; 136 request_XIGetClientPointer(&client_request, &request, Success); 137 138 printf("Testing valid window, unset ClientPointer.\n"); 139 request.win = CLIENT_WINDOW_ID; 140 request_XIGetClientPointer(&client_request, &request, Success); 141 142 printf("Testing valid window, set ClientPointer.\n"); 143 client_window.clientPtr = devices.vcp; 144 test_data.dev = devices.vcp; 145 test_data.cp_is_set = TRUE; 146 request.win = CLIENT_WINDOW_ID; 147 request_XIGetClientPointer(&client_request, &request, Success); 148 149 client_window.clientPtr = NULL; 150 151 printf("Testing window None, set ClientPointer.\n"); 152 client_request.clientPtr = devices.vcp; 153 test_data.dev = devices.vcp; 154 test_data.cp_is_set = TRUE; 155 request.win = None; 156 request_XIGetClientPointer(&client_request, &request, Success); 157} 158 159int 160main(int argc, char **argv) 161{ 162 init_simple(); 163 client_window = init_client(0, NULL); 164 165 test_XIGetClientPointer(); 166 167 return 0; 168} 169