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