protocol-xigetclientpointer.c revision 6747b715
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 XIGetClientPointer 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 "xigetclientpointer.h" 39#include "exevents.h" 40 41#include "protocol-common.h" 42#include <glib.h> 43 44struct { 45 int cp_is_set; 46 DeviceIntPtr dev; 47 int win; 48} test_data; 49 50static ClientRec client_window; 51static ClientRec client_request; 52 53int __wrap_dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access) 54{ 55 if (rid == ROOT_WINDOW_ID) 56 return BadWindow; 57 58 if (rid == CLIENT_WINDOW_ID) 59 { 60 *pClient = &client_window; 61 return Success; 62 } 63 64 return __real_dixLookupClient(pClient, rid, client, access); 65} 66 67 68static void reply_XIGetClientPointer(ClientPtr client, int len, char *data, void *userdata) 69{ 70 xXIGetClientPointerReply *rep = (xXIGetClientPointerReply*)data; 71 72 if (client->swapped) 73 { 74 char n; 75 swapl(&rep->length, n); 76 swaps(&rep->sequenceNumber, n); 77 swaps(&rep->deviceid, n); 78 } 79 80 reply_check_defaults(rep, len, XIGetClientPointer); 81 82 g_assert(rep->set == test_data.cp_is_set); 83 if (rep->set) 84 g_assert(rep->deviceid == test_data.dev->id); 85} 86 87static void request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq* req, int error) 88{ 89 char n; 90 int rc; 91 92 test_data.win = req->win; 93 94 rc = ProcXIGetClientPointer(&client_request); 95 g_assert(rc == error); 96 97 if (rc == BadWindow) 98 g_assert(client_request.errorValue == req->win); 99 100 client_request.swapped = TRUE; 101 swapl(&req->win, n); 102 swaps(&req->length, n); 103 rc = SProcXIGetClientPointer(&client_request); 104 g_assert(rc == error); 105 106 if (rc == BadWindow) 107 g_assert(client_request.errorValue == req->win); 108 109} 110 111static void test_XIGetClientPointer(void) 112{ 113 xXIGetClientPointerReq request; 114 115 request_init(&request, XIGetClientPointer); 116 117 request.win = CLIENT_WINDOW_ID; 118 119 120 reply_handler = reply_XIGetClientPointer; 121 122 client_request = init_client(request.length, &request); 123 124 g_test_message("Testing invalid window"); 125 request.win = INVALID_WINDOW_ID; 126 request_XIGetClientPointer(&client_request, &request, BadWindow); 127 128 test_data.cp_is_set = FALSE; 129 130 g_test_message("Testing window None, unset ClientPointer."); 131 request.win = None; 132 request_XIGetClientPointer(&client_request, &request, Success); 133 134 g_test_message("Testing valid window, unset ClientPointer."); 135 request.win = CLIENT_WINDOW_ID; 136 request_XIGetClientPointer(&client_request, &request, Success); 137 138 g_test_message("Testing valid window, set ClientPointer."); 139 client_window.clientPtr = devices.vcp; 140 test_data.dev = devices.vcp; 141 test_data.cp_is_set = TRUE; 142 request.win = CLIENT_WINDOW_ID; 143 request_XIGetClientPointer(&client_request, &request, Success); 144 145 client_window.clientPtr = NULL; 146 147 g_test_message("Testing window None, set ClientPointer."); 148 client_request.clientPtr = devices.vcp; 149 test_data.dev = devices.vcp; 150 test_data.cp_is_set = TRUE; 151 request.win = None; 152 request_XIGetClientPointer(&client_request, &request, Success); 153} 154 155int main(int argc, char** argv) 156{ 157 g_test_init(&argc, &argv,NULL); 158 g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id="); 159 160 init_simple(); 161 client_window = init_client(0, NULL); 162 163 164 g_test_add_func("/xi2/protocol/XIGetClientPointer", test_XIGetClientPointer); 165 166 return g_test_run(); 167} 168