| 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 XISetClientPointer request. |
| 33 |
* |
| 34 |
* Tests include: |
| 35 |
* BadDevice of all devices except master pointers. |
| 36 |
* Success for a valid window. |
| 37 |
* Success for window None. |
| 38 |
* BadWindow for invalid windows. |
| 39 |
*/ |
| 40 |
#include <stdint.h> |
| 41 |
#include <X11/X.h> |
| 42 |
#include <X11/Xproto.h> |
| 43 |
#include <X11/extensions/XI2proto.h> |
| 44 |
#include "inputstr.h" |
| 45 |
#include "windowstr.h" |
| 46 |
#include "extinit.h" /* for XInputExtensionInit */ |
| 47 |
#include "scrnintstr.h" |
| 48 |
#include "xisetclientpointer.h" |
| 49 |
#include "exevents.h" |
| 50 |
#include "exglobals.h" |
| 51 |
|
| 52 |
#include "protocol-common.h" |
| 53 |
|
| 54 |
extern ClientRec client_window; |
| 55 |
static ClientRec client_request; |
| 56 |
|
| 57 |
static void |
| 58 |
request_XISetClientPointer(xXISetClientPointerReq * req, int error) |
| 59 |
{ |
| 60 |
int rc; |
| 61 |
|
| 62 |
client_request = init_client(req->length, req); |
| 63 |
|
| 64 |
rc = ProcXISetClientPointer(&client_request); |
| 65 |
assert(rc == error); |
| 66 |
|
| 67 |
if (rc == BadDevice) |
| 68 |
assert(client_request.errorValue == req->deviceid); |
| 69 |
|
| 70 |
client_request.swapped = TRUE; |
| 71 |
swapl(&req->win); |
| 72 |
swaps(&req->length); |
| 73 |
swaps(&req->deviceid); |
| 74 |
rc = SProcXISetClientPointer(&client_request); |
| 75 |
assert(rc == error); |
| 76 |
|
| 77 |
if (rc == BadDevice) |
| 78 |
assert(client_request.errorValue == req->deviceid); |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
static void |
| 83 |
test_XISetClientPointer(void) |
| 84 |
{ |
| 85 |
int i; |
| 86 |
xXISetClientPointerReq request; |
| 87 |
|
| 88 |
init_simple(); |
| 89 |
client_window = init_client(0, NULL); |
| 90 |
|
| 91 |
request_init(&request, XISetClientPointer); |
| 92 |
|
| 93 |
request.win = CLIENT_WINDOW_ID; |
| 94 |
|
| 95 |
dbg("Testing BadDevice error for XIAllDevices and XIMasterDevices.\n"); |
| 96 |
request.deviceid = XIAllDevices; |
| 97 |
request_XISetClientPointer(&request, BadDevice); |
| 98 |
|
| 99 |
request.deviceid = XIAllMasterDevices; |
| 100 |
request_XISetClientPointer(&request, BadDevice); |
| 101 |
|
| 102 |
dbg("Testing Success for VCP and VCK.\n"); |
| 103 |
request.deviceid = devices.vcp->id; /* 2 */ |
| 104 |
request_XISetClientPointer(&request, Success); |
| 105 |
assert(client_window.clientPtr->id == 2); |
| 106 |
|
| 107 |
request.deviceid = devices.vck->id; /* 3 */ |
| 108 |
request_XISetClientPointer(&request, Success); |
| 109 |
assert(client_window.clientPtr->id == 2); |
| 110 |
|
| 111 |
dbg("Testing BadDevice error for all other devices.\n"); |
| 112 |
for (i = 4; i <= 0xFFFF; i++) { |
| 113 |
request.deviceid = i; |
| 114 |
request_XISetClientPointer(&request, BadDevice); |
| 115 |
} |
| 116 |
|
| 117 |
dbg("Testing window None\n"); |
| 118 |
request.win = None; |
| 119 |
request.deviceid = devices.vcp->id; /* 2 */ |
| 120 |
request_XISetClientPointer(&request, Success); |
| 121 |
assert(client_request.clientPtr->id == 2); |
| 122 |
|
| 123 |
dbg("Testing invalid window\n"); |
| 124 |
request.win = INVALID_WINDOW_ID; |
| 125 |
request.deviceid = devices.vcp->id; |
| 126 |
request_XISetClientPointer(&request, BadWindow); |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
const testfunc_t* |
| 131 |
protocol_xisetclientpointer_test(void) |
| 132 |
{ |
| 133 |
static const testfunc_t testfuncs[] = { |
| 134 |
test_XISetClientPointer, |
| 135 |
NULL, |
| 136 |
}; |
| 137 |
|
| 138 |
return testfuncs; |
| 139 |
} |