protocol-xisetclientpointer.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 XISetClientPointer request.
  28. *
  29. * Tests include:
  30. * BadDevice of all devices except master pointers.
  31. * Success for a valid window.
  32. * Success for window None.
  33. * BadWindow for invalid windows.
  34. */
  35. #include <stdint.h>
  36. #include <X11/X.h>
  37. #include <X11/Xproto.h>
  38. #include <X11/extensions/XI2proto.h>
  39. #include "inputstr.h"
  40. #include "windowstr.h"
  41. #include "extinit.h" /* for XInputExtensionInit */
  42. #include "scrnintstr.h"
  43. #include "xisetclientpointer.h"
  44. #include "exevents.h"
  45. #include "exglobals.h"
  46. #include "protocol-common.h"
  47. static ClientRec client_window;
  48. static ClientRec client_request;
  49. int
  50. __wrap_dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client,
  51. Mask access)
  52. {
  53. if (rid == ROOT_WINDOW_ID)
  54. return BadWindow;
  55. if (rid == CLIENT_WINDOW_ID) {
  56. *pClient = &client_window;
  57. return Success;
  58. }
  59. return __real_dixLookupClient(pClient, rid, client, access);
  60. }
  61. static void
  62. request_XISetClientPointer(xXISetClientPointerReq * req, int error)
  63. {
  64. int rc;
  65. client_request = init_client(req->length, req);
  66. rc = ProcXISetClientPointer(&client_request);
  67. assert(rc == error);
  68. if (rc == BadDevice)
  69. assert(client_request.errorValue == req->deviceid);
  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. if (rc == BadDevice)
  77. assert(client_request.errorValue == req->deviceid);
  78. }
  79. static void
  80. test_XISetClientPointer(void)
  81. {
  82. int i;
  83. xXISetClientPointerReq request;
  84. request_init(&request, XISetClientPointer);
  85. request.win = CLIENT_WINDOW_ID;
  86. printf("Testing BadDevice error for XIAllDevices and XIMasterDevices.\n");
  87. request.deviceid = XIAllDevices;
  88. request_XISetClientPointer(&request, BadDevice);
  89. request.deviceid = XIAllMasterDevices;
  90. request_XISetClientPointer(&request, BadDevice);
  91. printf("Testing Success for VCP and VCK.\n");
  92. request.deviceid = devices.vcp->id; /* 2 */
  93. request_XISetClientPointer(&request, Success);
  94. assert(client_window.clientPtr->id == 2);
  95. request.deviceid = devices.vck->id; /* 3 */
  96. request_XISetClientPointer(&request, Success);
  97. assert(client_window.clientPtr->id == 2);
  98. printf("Testing BadDevice error for all other devices.\n");
  99. for (i = 4; i <= 0xFFFF; i++) {
  100. request.deviceid = i;
  101. request_XISetClientPointer(&request, BadDevice);
  102. }
  103. printf("Testing window None\n");
  104. request.win = None;
  105. request.deviceid = devices.vcp->id; /* 2 */
  106. request_XISetClientPointer(&request, Success);
  107. assert(client_request.clientPtr->id == 2);
  108. printf("Testing invalid window\n");
  109. request.win = INVALID_WINDOW_ID;
  110. request.deviceid = devices.vcp->id;
  111. request_XISetClientPointer(&request, BadWindow);
  112. }
  113. int
  114. main(int argc, char **argv)
  115. {
  116. init_simple();
  117. client_window = init_client(0, NULL);
  118. test_XISetClientPointer();
  119. return 0;
  120. }