protocol-xiquerypointer.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. #ifdef HAVE_DIX_CONFIG_H
  24. #include <dix-config.h>
  25. #endif
  26. /*
  27. * Protocol testing for XIQueryPointer request.
  28. */
  29. #include <stdint.h>
  30. #include <X11/X.h>
  31. #include <X11/Xproto.h>
  32. #include <X11/extensions/XI2proto.h>
  33. #include "inputstr.h"
  34. #include "windowstr.h"
  35. #include "scrnintstr.h"
  36. #include "xiquerypointer.h"
  37. #include "exevents.h"
  38. #include "exglobals.h"
  39. #include "protocol-common.h"
  40. static ClientRec client_request;
  41. static void reply_XIQueryPointer_data(ClientPtr client, int len,
  42. char *data, void *closure);
  43. static struct {
  44. DeviceIntPtr dev;
  45. WindowPtr win;
  46. } test_data;
  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. return __real_dixLookupWindow(win, id, client, access);
  64. }
  65. static void
  66. reply_XIQueryPointer(ClientPtr client, int len, char *data, void *closure)
  67. {
  68. xXIQueryPointerReply *rep = (xXIQueryPointerReply *) data;
  69. SpritePtr sprite;
  70. if (!rep->repType)
  71. return;
  72. if (client->swapped) {
  73. swapl(&rep->length);
  74. swaps(&rep->sequenceNumber);
  75. swapl(&rep->root);
  76. swapl(&rep->child);
  77. swapl(&rep->root_x);
  78. swapl(&rep->root_y);
  79. swapl(&rep->win_x);
  80. swapl(&rep->win_y);
  81. swaps(&rep->buttons_len);
  82. }
  83. reply_check_defaults(rep, len, XIQueryPointer);
  84. assert(rep->root == root.drawable.id);
  85. assert(rep->same_screen == xTrue);
  86. sprite = test_data.dev->spriteInfo->sprite;
  87. assert((rep->root_x >> 16) == sprite->hot.x);
  88. assert((rep->root_y >> 16) == sprite->hot.y);
  89. if (test_data.win == &root) {
  90. assert(rep->root_x == rep->win_x);
  91. assert(rep->root_y == rep->win_y);
  92. assert(rep->child == window.drawable.id);
  93. }
  94. else {
  95. int x, y;
  96. x = sprite->hot.x - window.drawable.x;
  97. y = sprite->hot.y - window.drawable.y;
  98. assert((rep->win_x >> 16) == x);
  99. assert((rep->win_y >> 16) == y);
  100. assert(rep->child == None);
  101. }
  102. assert(rep->same_screen == xTrue);
  103. reply_handler = reply_XIQueryPointer_data;
  104. }
  105. static void
  106. reply_XIQueryPointer_data(ClientPtr client, int len, char *data, void *closure)
  107. {
  108. reply_handler = reply_XIQueryPointer;
  109. }
  110. static void
  111. request_XIQueryPointer(ClientPtr client, xXIQueryPointerReq * req, int error)
  112. {
  113. int rc;
  114. rc = ProcXIQueryPointer(&client_request);
  115. assert(rc == error);
  116. if (rc == BadDevice)
  117. assert(client_request.errorValue == req->deviceid);
  118. client_request.swapped = TRUE;
  119. swaps(&req->deviceid);
  120. swaps(&req->length);
  121. rc = SProcXIQueryPointer(&client_request);
  122. assert(rc == error);
  123. if (rc == BadDevice)
  124. assert(client_request.errorValue == req->deviceid);
  125. }
  126. static void
  127. test_XIQueryPointer(void)
  128. {
  129. int i;
  130. xXIQueryPointerReq request;
  131. memset(&request, 0, sizeof(request));
  132. request_init(&request, XIQueryPointer);
  133. reply_handler = reply_XIQueryPointer;
  134. client_request = init_client(request.length, &request);
  135. request.deviceid = XIAllDevices;
  136. request_XIQueryPointer(&client_request, &request, BadDevice);
  137. request.deviceid = XIAllMasterDevices;
  138. request_XIQueryPointer(&client_request, &request, BadDevice);
  139. request.win = root.drawable.id;
  140. test_data.win = &root;
  141. test_data.dev = devices.vcp;
  142. request.deviceid = devices.vcp->id;
  143. request_XIQueryPointer(&client_request, &request, Success);
  144. request.deviceid = devices.vck->id;
  145. request_XIQueryPointer(&client_request, &request, BadDevice);
  146. request.deviceid = devices.mouse->id;
  147. request_XIQueryPointer(&client_request, &request, BadDevice);
  148. request.deviceid = devices.kbd->id;
  149. request_XIQueryPointer(&client_request, &request, BadDevice);
  150. test_data.dev = devices.mouse;
  151. devices.mouse->master = NULL; /* Float, kind-of */
  152. request.deviceid = devices.mouse->id;
  153. request_XIQueryPointer(&client_request, &request, Success);
  154. for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) {
  155. request.deviceid = i;
  156. request_XIQueryPointer(&client_request, &request, BadDevice);
  157. }
  158. request.win = window.drawable.id;
  159. test_data.dev = devices.vcp;
  160. test_data.win = &window;
  161. request.deviceid = devices.vcp->id;
  162. request_XIQueryPointer(&client_request, &request, Success);
  163. test_data.dev = devices.mouse;
  164. request.deviceid = devices.mouse->id;
  165. request_XIQueryPointer(&client_request, &request, Success);
  166. /* test REQUEST_SIZE_MATCH */
  167. client_request.req_len -= 4;
  168. request_XIQueryPointer(&client_request, &request, BadLength);
  169. }
  170. int
  171. main(int argc, char **argv)
  172. {
  173. init_simple();
  174. test_XIQueryPointer();
  175. return 0;
  176. }