message-test.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright © 2014 Jonas Ådahl
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the
  13. * next paragraph) shall be included in all copies or substantial
  14. * portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. */
  25. #include <assert.h>
  26. #include "wayland-client.h"
  27. #include "wayland-private.h"
  28. #include "wayland-server.h"
  29. #include "test-runner.h"
  30. TEST(message_version)
  31. {
  32. unsigned int i;
  33. const struct {
  34. const struct wl_message *message;
  35. int expected_version;
  36. } messages[] = {
  37. { &wl_pointer_interface.events[WL_POINTER_ENTER], 1 },
  38. { &wl_surface_interface.events[WL_SURFACE_ENTER], 1 },
  39. { &wl_pointer_interface.methods[WL_POINTER_SET_CURSOR], 1 },
  40. { &wl_pointer_interface.methods[WL_POINTER_RELEASE], 3 },
  41. { &wl_surface_interface.methods[WL_SURFACE_DESTROY], 1 },
  42. { &wl_surface_interface.methods[WL_SURFACE_SET_BUFFER_TRANSFORM], 2 },
  43. { &wl_surface_interface.methods[WL_SURFACE_SET_BUFFER_SCALE], 3 },
  44. };
  45. for (i = 0; i < ARRAY_LENGTH(messages); ++i) {
  46. assert(wl_message_get_since(messages[i].message) ==
  47. messages[i].expected_version);
  48. }
  49. }
  50. TEST(message_count_arrays)
  51. {
  52. unsigned int i;
  53. struct wl_message fake_messages[] = {
  54. { "empty", "", NULL },
  55. { "non_present", "iufsonh", NULL },
  56. { "leading", "aiufsonh", NULL},
  57. { "trailing", "iufsonha", NULL },
  58. { "middle", "iufasonh", NULL },
  59. { "multiple", "aaiufaasonhaa", NULL },
  60. { "leading_version", "2aaiufaasonhaa", NULL },
  61. { "among_nullables", "iufsa?oa?sah", NULL },
  62. { "all_mixed", "2aiufas?oa?sa", NULL },
  63. };
  64. const struct {
  65. const struct wl_message *message;
  66. int expected_array_count;
  67. } messages[] = {
  68. { &wl_pointer_interface.events[WL_POINTER_ENTER], 0 },
  69. { &wl_keyboard_interface.events[WL_KEYBOARD_ENTER], 1 },
  70. { &fake_messages[0], 0 },
  71. { &fake_messages[1], 0 },
  72. { &fake_messages[2], 1 },
  73. { &fake_messages[3], 1 },
  74. { &fake_messages[4], 1 },
  75. { &fake_messages[5], 6 },
  76. { &fake_messages[6], 6 },
  77. { &fake_messages[7], 3 },
  78. { &fake_messages[8], 4 },
  79. };
  80. for (i = 0; i < ARRAY_LENGTH(messages); ++i) {
  81. assert(wl_message_count_arrays(messages[i].message) ==
  82. messages[i].expected_array_count);
  83. }
  84. }