hotkey_equal.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. lib/widget - tests for hotkey comparison
  3. Copyright (C) 2019-2024
  4. Free Software Foundation, Inc.
  5. Written by:
  6. Andrew Borodin <aborodin@vmail.ru>, 2019
  7. This file is part of the Midnight Commander.
  8. The Midnight Commander is free software: you can redistribute it
  9. and/or modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation, either version 3 of the License,
  11. or (at your option) any later version.
  12. The Midnight Commander is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define TEST_SUITE_NAME "/lib/widget"
  20. #include "tests/mctest.h"
  21. #include "lib/widget.h"
  22. #define C(x) ((char *) x)
  23. /* --------------------------------------------------------------------------------------------- */
  24. /* @Before */
  25. static void
  26. setup (void)
  27. {
  28. }
  29. /* --------------------------------------------------------------------------------------------- */
  30. /* @After */
  31. static void
  32. teardown (void)
  33. {
  34. }
  35. /* --------------------------------------------------------------------------------------------- */
  36. /* @DataSource("test_hotkey_equal_ds") */
  37. /* *INDENT-OFF* */
  38. static const struct test_hotkey_equal_ds
  39. {
  40. const hotkey_t hotkey1;
  41. const hotkey_t hotkey2;
  42. gboolean expected_result;
  43. } test_hotkey_equal_ds[] =
  44. {
  45. /* 0 */
  46. {
  47. { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  48. { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  49. TRUE
  50. },
  51. /* 1 */
  52. {
  53. { .start = C (""), .hotkey = C (""), .end = C ("") },
  54. { .start = C (""), .hotkey = C (""), .end = C ("") },
  55. TRUE
  56. },
  57. /* 2 */
  58. {
  59. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  60. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  61. TRUE
  62. },
  63. /* 3 */
  64. {
  65. { .start = C ("abc"), .hotkey = NULL, .end = C ("efg") },
  66. { .start = C ("abc"), .hotkey = NULL, .end = C ("efg") },
  67. TRUE
  68. },
  69. /* 4 */
  70. {
  71. { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  72. { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  73. TRUE
  74. },
  75. /* 5 */
  76. {
  77. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  78. { .start = C ("_bc"), .hotkey = C ("d"), .end = C ("efg") },
  79. FALSE
  80. },
  81. /* 6 */
  82. {
  83. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  84. { .start = C ("abc"), .hotkey = C ("_"), .end = C ("efg") },
  85. FALSE
  86. },
  87. /* 7 */
  88. {
  89. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  90. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("_fg") },
  91. FALSE
  92. },
  93. /* 8 */
  94. {
  95. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  96. { .start = C ("adc"), .hotkey = NULL, .end = C ("efg") },
  97. FALSE
  98. },
  99. /* 9 */
  100. {
  101. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  102. { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  103. FALSE
  104. },
  105. /* 10 */
  106. {
  107. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  108. { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  109. FALSE
  110. }
  111. };
  112. /* *INDENT-ON* */
  113. /* @Test(dataSource = "test_hotkey_equal_ds") */
  114. /* *INDENT-OFF* */
  115. START_PARAMETRIZED_TEST (test_hotkey_equal,
  116. test_hotkey_equal_ds)
  117. /* *INDENT-ON* */
  118. {
  119. /* given */
  120. gboolean result;
  121. /* when */
  122. result = hotkey_equal (data->hotkey1, data->hotkey2);
  123. /* then */
  124. ck_assert_int_eq (result, data->expected_result);
  125. }
  126. /* *INDENT-OFF* */
  127. END_PARAMETRIZED_TEST
  128. /* *INDENT-ON* */
  129. /* --------------------------------------------------------------------------------------------- */
  130. int
  131. main (void)
  132. {
  133. TCase *tc_core;
  134. tc_core = tcase_create ("Core");
  135. tcase_add_checked_fixture (tc_core, setup, teardown);
  136. /* Add new tests here: *************** */
  137. mctest_add_parameterized_test (tc_core, test_hotkey_equal, test_hotkey_equal_ds);
  138. /* *********************************** */
  139. return mctest_run_all (tc_core);
  140. }
  141. /* --------------------------------------------------------------------------------------------- */