protocol-xiwarppointer.c revision 7e31ba66
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 XIWarpPointer 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 "xiwarppointer.h" 39#include "exevents.h" 40#include "exglobals.h" 41 42#include "protocol-common.h" 43 44static int expected_x = SPRITE_X; 45static int expected_y = SPRITE_Y; 46 47ClientRec client_window; 48 49/** 50 * This function overrides the one in the screen rec. 51 */ 52static Bool 53ScreenSetCursorPosition(DeviceIntPtr dev, ScreenPtr scr, 54 int x, int y, Bool generateEvent) 55{ 56 assert(x == expected_x); 57 assert(y == expected_y); 58 return TRUE; 59} 60 61static void 62request_XIWarpPointer(ClientPtr client, xXIWarpPointerReq * req, int error) 63{ 64 int rc; 65 66 rc = ProcXIWarpPointer(client); 67 assert(rc == error); 68 69 if (rc == BadDevice) 70 assert(client->errorValue == req->deviceid); 71 else if (rc == BadWindow) 72 assert(client->errorValue == req->dst_win || 73 client->errorValue == req->src_win); 74 75 client->swapped = TRUE; 76 77 swapl(&req->src_win); 78 swapl(&req->dst_win); 79 swapl(&req->src_x); 80 swapl(&req->src_y); 81 swapl(&req->dst_x); 82 swapl(&req->dst_y); 83 swaps(&req->src_width); 84 swaps(&req->src_height); 85 swaps(&req->deviceid); 86 87 rc = SProcXIWarpPointer(client); 88 assert(rc == error); 89 90 if (rc == BadDevice) 91 assert(client->errorValue == req->deviceid); 92 else if (rc == BadWindow) 93 assert(client->errorValue == req->dst_win || 94 client->errorValue == req->src_win); 95 96 client->swapped = FALSE; 97} 98 99static void 100test_XIWarpPointer(void) 101{ 102 int i; 103 ClientRec client_request; 104 xXIWarpPointerReq request; 105 106 memset(&request, 0, sizeof(request)); 107 108 request_init(&request, XIWarpPointer); 109 110 client_request = init_client(request.length, &request); 111 112 request.deviceid = XIAllDevices; 113 request_XIWarpPointer(&client_request, &request, BadDevice); 114 115 request.deviceid = XIAllMasterDevices; 116 request_XIWarpPointer(&client_request, &request, BadDevice); 117 118 request.src_win = root.drawable.id; 119 request.dst_win = root.drawable.id; 120 request.deviceid = devices.vcp->id; 121 request_XIWarpPointer(&client_request, &request, Success); 122 request.deviceid = devices.vck->id; 123 request_XIWarpPointer(&client_request, &request, BadDevice); 124 request.deviceid = devices.mouse->id; 125 request_XIWarpPointer(&client_request, &request, BadDevice); 126 request.deviceid = devices.kbd->id; 127 request_XIWarpPointer(&client_request, &request, BadDevice); 128 129 devices.mouse->master = NULL; /* Float, kind-of */ 130 request.deviceid = devices.mouse->id; 131 request_XIWarpPointer(&client_request, &request, Success); 132 133 for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) { 134 request.deviceid = i; 135 request_XIWarpPointer(&client_request, &request, BadDevice); 136 } 137 138 request.src_win = window.drawable.id; 139 request.deviceid = devices.vcp->id; 140 request_XIWarpPointer(&client_request, &request, Success); 141 142 request.deviceid = devices.mouse->id; 143 request_XIWarpPointer(&client_request, &request, Success); 144 145 request.src_win = root.drawable.id; 146 request.dst_win = 0xFFFF; /* invalid window */ 147 request_XIWarpPointer(&client_request, &request, BadWindow); 148 149 request.src_win = 0xFFFF; /* invalid window */ 150 request.dst_win = root.drawable.id; 151 request_XIWarpPointer(&client_request, &request, BadWindow); 152 153 request.src_win = None; 154 request.dst_win = None; 155 156 request.dst_y = 0; 157 expected_y = SPRITE_Y; 158 159 request.dst_x = 1 << 16; 160 expected_x = SPRITE_X + 1; 161 request.deviceid = devices.vcp->id; 162 request_XIWarpPointer(&client_request, &request, Success); 163 164 request.dst_x = -1 << 16; 165 expected_x = SPRITE_X - 1; 166 request.deviceid = devices.vcp->id; 167 request_XIWarpPointer(&client_request, &request, Success); 168 169 request.dst_x = 0; 170 expected_x = SPRITE_X; 171 172 request.dst_y = 1 << 16; 173 expected_y = SPRITE_Y + 1; 174 request.deviceid = devices.vcp->id; 175 request_XIWarpPointer(&client_request, &request, Success); 176 177 request.dst_y = -1 << 16; 178 expected_y = SPRITE_Y - 1; 179 request.deviceid = devices.vcp->id; 180 request_XIWarpPointer(&client_request, &request, Success); 181 182 /* FIXME: src_x/y checks */ 183 184 client_request.req_len -= 2; /* invalid length */ 185 request_XIWarpPointer(&client_request, &request, BadLength); 186} 187 188int 189protocol_xiwarppointer_test(void) 190{ 191 init_simple(); 192 screen.SetCursorPosition = ScreenSetCursorPosition; 193 194 test_XIWarpPointer(); 195 196 return 0; 197} 198