| 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 | |
| 44 | static int expected_x = SPRITE_X; |
| 45 | static int expected_y = SPRITE_Y; |
| 46 | |
| 47 | /* dixLookupWindow requires a lot of setup not necessary for this test. |
| 48 | * Simple wrapper that returns either one of the fake root window or the |
| 49 | * fake client window. If the requested ID is neither of those wanted, |
| 50 | * return whatever the real dixLookupWindow does. |
| 51 | */ |
| 52 | int |
| 53 | __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access) |
| 54 | { |
| 55 | if (id == root.drawable.id) { |
| 56 | *win = &root; |
| 57 | return Success; |
| 58 | } |
| 59 | else if (id == window.drawable.id) { |
| 60 | *win = &window; |
| 61 | return Success; |
| 62 | } |
| 63 | |
| 64 | return __real_dixLookupWindow(win, id, client, access); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * This function overrides the one in the screen rec. |
| 69 | */ |
| 70 | static Bool |
| 71 | ScreenSetCursorPosition(DeviceIntPtr dev, ScreenPtr scr, |
| 72 | int x, int y, Bool generateEvent) |
| 73 | { |
| 74 | assert(x == expected_x); |
| 75 | assert(y == expected_y); |
| 76 | return TRUE; |
| 77 | } |
| 78 | |
| 79 | static void |
| 80 | request_XIWarpPointer(ClientPtr client, xXIWarpPointerReq * req, int error) |
| 81 | { |
| 82 | int rc; |
| 83 | |
| 84 | rc = ProcXIWarpPointer(client); |
| 85 | assert(rc == error); |
| 86 | |
| 87 | if (rc == BadDevice) |
| 88 | assert(client->errorValue == req->deviceid); |
| 89 | else if (rc == BadWindow) |
| 90 | assert(client->errorValue == req->dst_win || |
| 91 | client->errorValue == req->src_win); |
| 92 | |
| 93 | client->swapped = TRUE; |
| 94 | |
| 95 | swapl(&req->src_win); |
| 96 | swapl(&req->dst_win); |
| 97 | swapl(&req->src_x); |
| 98 | swapl(&req->src_y); |
| 99 | swapl(&req->dst_x); |
| 100 | swapl(&req->dst_y); |
| 101 | swaps(&req->src_width); |
| 102 | swaps(&req->src_height); |
| 103 | swaps(&req->deviceid); |
| 104 | |
| 105 | rc = SProcXIWarpPointer(client); |
| 106 | assert(rc == error); |
| 107 | |
| 108 | if (rc == BadDevice) |
| 109 | assert(client->errorValue == req->deviceid); |
| 110 | else if (rc == BadWindow) |
| 111 | assert(client->errorValue == req->dst_win || |
| 112 | client->errorValue == req->src_win); |
| 113 | |
| 114 | client->swapped = FALSE; |
| 115 | } |
| 116 | |
| 117 | static void |
| 118 | test_XIWarpPointer(void) |
| 119 | { |
| 120 | int i; |
| 121 | ClientRec client_request; |
| 122 | xXIWarpPointerReq request; |
| 123 | |
| 124 | memset(&request, 0, sizeof(request)); |
| 125 | |
| 126 | request_init(&request, XIWarpPointer); |
| 127 | |
| 128 | client_request = init_client(request.length, &request); |
| 129 | |
| 130 | request.deviceid = XIAllDevices; |
| 131 | request_XIWarpPointer(&client_request, &request, BadDevice); |
| 132 | |
| 133 | request.deviceid = XIAllMasterDevices; |
| 134 | request_XIWarpPointer(&client_request, &request, BadDevice); |
| 135 | |
| 136 | request.src_win = root.drawable.id; |
| 137 | request.dst_win = root.drawable.id; |
| 138 | request.deviceid = devices.vcp->id; |
| 139 | request_XIWarpPointer(&client_request, &request, Success); |
| 140 | request.deviceid = devices.vck->id; |
| 141 | request_XIWarpPointer(&client_request, &request, BadDevice); |
| 142 | request.deviceid = devices.mouse->id; |
| 143 | request_XIWarpPointer(&client_request, &request, BadDevice); |
| 144 | request.deviceid = devices.kbd->id; |
| 145 | request_XIWarpPointer(&client_request, &request, BadDevice); |
| 146 | |
| 147 | devices.mouse->master = NULL; /* Float, kind-of */ |
| 148 | request.deviceid = devices.mouse->id; |
| 149 | request_XIWarpPointer(&client_request, &request, Success); |
| 150 | |
| 151 | for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) { |
| 152 | request.deviceid = i; |
| 153 | request_XIWarpPointer(&client_request, &request, BadDevice); |
| 154 | } |
| 155 | |
| 156 | request.src_win = window.drawable.id; |
| 157 | request.deviceid = devices.vcp->id; |
| 158 | request_XIWarpPointer(&client_request, &request, Success); |
| 159 | |
| 160 | request.deviceid = devices.mouse->id; |
| 161 | request_XIWarpPointer(&client_request, &request, Success); |
| 162 | |
| 163 | request.src_win = root.drawable.id; |
| 164 | request.dst_win = 0xFFFF; /* invalid window */ |
| 165 | request_XIWarpPointer(&client_request, &request, BadWindow); |
| 166 | |
| 167 | request.src_win = 0xFFFF; /* invalid window */ |
| 168 | request.dst_win = root.drawable.id; |
| 169 | request_XIWarpPointer(&client_request, &request, BadWindow); |
| 170 | |
| 171 | request.src_win = None; |
| 172 | request.dst_win = None; |
| 173 | |
| 174 | request.dst_y = 0; |
| 175 | expected_y = SPRITE_Y; |
| 176 | |
| 177 | request.dst_x = 1 << 16; |
| 178 | expected_x = SPRITE_X + 1; |
| 179 | request.deviceid = devices.vcp->id; |
| 180 | request_XIWarpPointer(&client_request, &request, Success); |
| 181 | |
| 182 | request.dst_x = -1 << 16; |
| 183 | expected_x = SPRITE_X - 1; |
| 184 | request.deviceid = devices.vcp->id; |
| 185 | request_XIWarpPointer(&client_request, &request, Success); |
| 186 | |
| 187 | request.dst_x = 0; |
| 188 | expected_x = SPRITE_X; |
| 189 | |
| 190 | request.dst_y = 1 << 16; |
| 191 | expected_y = SPRITE_Y + 1; |
| 192 | request.deviceid = devices.vcp->id; |
| 193 | request_XIWarpPointer(&client_request, &request, Success); |
| 194 | |
| 195 | request.dst_y = -1 << 16; |
| 196 | expected_y = SPRITE_Y - 1; |
| 197 | request.deviceid = devices.vcp->id; |
| 198 | request_XIWarpPointer(&client_request, &request, Success); |
| 199 | |
| 200 | /* FIXME: src_x/y checks */ |
| 201 | } |
| 202 | |
| 203 | int |
| 204 | main(int argc, char **argv) |
| 205 | { |
| 206 | init_simple(); |
| 207 | screen.SetCursorPosition = ScreenSetCursorPosition; |
| 208 | |
| 209 | test_XIWarpPointer(); |
| 210 | |
| 211 | return 0; |
| 212 | } |