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