misc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * Copyright © 2011 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. #include <stdint.h>
  27. #include "misc.h"
  28. #include "scrnintstr.h"
  29. #include "dix.h"
  30. #include "dixstruct.h"
  31. ScreenInfo screenInfo;
  32. static void
  33. dix_version_compare(void)
  34. {
  35. int rc;
  36. rc = version_compare(0, 0, 1, 0);
  37. assert(rc < 0);
  38. rc = version_compare(1, 0, 0, 0);
  39. assert(rc > 0);
  40. rc = version_compare(0, 0, 0, 0);
  41. assert(rc == 0);
  42. rc = version_compare(1, 0, 1, 0);
  43. assert(rc == 0);
  44. rc = version_compare(1, 0, 0, 9);
  45. assert(rc > 0);
  46. rc = version_compare(0, 9, 1, 0);
  47. assert(rc < 0);
  48. rc = version_compare(1, 0, 1, 9);
  49. assert(rc < 0);
  50. rc = version_compare(1, 9, 1, 0);
  51. assert(rc > 0);
  52. rc = version_compare(2, 0, 1, 9);
  53. assert(rc > 0);
  54. rc = version_compare(1, 9, 2, 0);
  55. assert(rc < 0);
  56. }
  57. static void
  58. dix_update_desktop_dimensions(void)
  59. {
  60. int i;
  61. int x, y, w, h;
  62. int w2, h2;
  63. ScreenRec screens[MAXSCREENS];
  64. for (i = 0; i < MAXSCREENS; i++)
  65. screenInfo.screens[i] = &screens[i];
  66. x = 0;
  67. y = 0;
  68. w = 10;
  69. h = 5;
  70. w2 = 35;
  71. h2 = 25;
  72. #define assert_dimensions(_x, _y, _w, _h) \
  73. update_desktop_dimensions(); \
  74. assert(screenInfo.x == _x); \
  75. assert(screenInfo.y == _y); \
  76. assert(screenInfo.width == _w); \
  77. assert(screenInfo.height == _h);
  78. #define set_screen(idx, _x, _y, _w, _h) \
  79. screenInfo.screens[idx]->x = _x; \
  80. screenInfo.screens[idx]->y = _y; \
  81. screenInfo.screens[idx]->width = _w; \
  82. screenInfo.screens[idx]->height = _h; \
  83. /* single screen */
  84. screenInfo.numScreens = 1;
  85. set_screen(0, x, y, w, h);
  86. assert_dimensions(x, y, w, h);
  87. /* dualhead rightof */
  88. screenInfo.numScreens = 2;
  89. set_screen(1, w, 0, w2, h2);
  90. assert_dimensions(x, y, w + w2, h2);
  91. /* dualhead belowof */
  92. screenInfo.numScreens = 2;
  93. set_screen(1, 0, h, w2, h2);
  94. assert_dimensions(x, y, w2, h + h2);
  95. /* triplehead L shape */
  96. screenInfo.numScreens = 3;
  97. set_screen(1, 0, h, w2, h2);
  98. set_screen(2, w2, h2, w, h);
  99. assert_dimensions(x, y, w + w2, h + h2);
  100. /* quadhead 2x2 */
  101. screenInfo.numScreens = 4;
  102. set_screen(1, 0, h, w, h);
  103. set_screen(2, w, h, w, h2);
  104. set_screen(3, w, 0, w2, h);
  105. assert_dimensions(x, y, w + w2, h + h2);
  106. /* quadhead horiz line */
  107. screenInfo.numScreens = 4;
  108. set_screen(1, w, 0, w, h);
  109. set_screen(2, 2 * w, 0, w, h);
  110. set_screen(3, 3 * w, 0, w, h);
  111. assert_dimensions(x, y, 4 * w, h);
  112. /* quadhead vert line */
  113. screenInfo.numScreens = 4;
  114. set_screen(1, 0, h, w, h);
  115. set_screen(2, 0, 2 * h, w, h);
  116. set_screen(3, 0, 3 * h, w, h);
  117. assert_dimensions(x, y, w, 4 * h);
  118. /* x overlap */
  119. screenInfo.numScreens = 2;
  120. set_screen(0, 0, 0, w2, h2);
  121. set_screen(1, w, 0, w2, h2);
  122. assert_dimensions(x, y, w2 + w, h2);
  123. /* y overlap */
  124. screenInfo.numScreens = 2;
  125. set_screen(0, 0, 0, w2, h2);
  126. set_screen(1, 0, h, w2, h2);
  127. assert_dimensions(x, y, w2, h2 + h);
  128. /* negative origin */
  129. screenInfo.numScreens = 1;
  130. set_screen(0, -w2, -h2, w, h);
  131. assert_dimensions(-w2, -h2, w, h);
  132. /* dualhead negative origin, overlap */
  133. screenInfo.numScreens = 2;
  134. set_screen(0, -w2, -h2, w2, h2);
  135. set_screen(1, -w, -h, w, h);
  136. assert_dimensions(-w2, -h2, w2, h2);
  137. }
  138. static int
  139. dix_request_fixed_size_overflow(ClientRec *client)
  140. {
  141. xReq req = { 0 };
  142. client->req_len = req.length = 1;
  143. REQUEST_FIXED_SIZE(req, SIZE_MAX);
  144. return Success;
  145. }
  146. static int
  147. dix_request_fixed_size_match(ClientRec *client)
  148. {
  149. xReq req = { 0 };
  150. client->req_len = req.length = 9;
  151. REQUEST_FIXED_SIZE(req, 30);
  152. return Success;
  153. }
  154. static void
  155. dix_request_size_checks(void)
  156. {
  157. ClientRec client = { 0 };
  158. int rc;
  159. rc = dix_request_fixed_size_overflow(&client);
  160. assert(rc == BadLength);
  161. rc = dix_request_fixed_size_match(&client);
  162. assert(rc == Success);
  163. }
  164. int
  165. main(int argc, char **argv)
  166. {
  167. dix_version_compare();
  168. dix_update_desktop_dimensions();
  169. dix_request_size_checks();
  170. return 0;
  171. }