hotkey_equal.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. lib/widget - tests for hotkey comparison
  3. Copyright (C) 2019-2025
  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 <https://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. static const struct test_hotkey_equal_ds
  38. {
  39. const hotkey_t hotkey1;
  40. const hotkey_t hotkey2;
  41. gboolean expected_result;
  42. } test_hotkey_equal_ds[] = {
  43. {
  44. // 0
  45. { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  46. { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  47. TRUE,
  48. },
  49. {
  50. // 1
  51. { .start = C (""), .hotkey = C (""), .end = C ("") },
  52. { .start = C (""), .hotkey = C (""), .end = C ("") },
  53. TRUE,
  54. },
  55. {
  56. // 2
  57. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  58. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  59. TRUE,
  60. },
  61. {
  62. // 3
  63. { .start = C ("abc"), .hotkey = NULL, .end = C ("efg") },
  64. { .start = C ("abc"), .hotkey = NULL, .end = C ("efg") },
  65. TRUE,
  66. },
  67. {
  68. // 4
  69. { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  70. { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  71. TRUE,
  72. },
  73. {
  74. // 5
  75. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  76. { .start = C ("_bc"), .hotkey = C ("d"), .end = C ("efg") },
  77. FALSE,
  78. },
  79. {
  80. // 6
  81. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  82. { .start = C ("abc"), .hotkey = C ("_"), .end = C ("efg") },
  83. FALSE,
  84. },
  85. {
  86. // 7
  87. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  88. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("_fg") },
  89. FALSE,
  90. },
  91. {
  92. // 8
  93. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  94. { .start = C ("adc"), .hotkey = NULL, .end = C ("efg") },
  95. FALSE,
  96. },
  97. {
  98. // 9
  99. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  100. { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  101. FALSE,
  102. },
  103. {
  104. // 10
  105. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  106. { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  107. FALSE,
  108. },
  109. };
  110. /* @Test(dataSource = "test_hotkey_equal_ds") */
  111. START_PARAMETRIZED_TEST (test_hotkey_equal, test_hotkey_equal_ds)
  112. {
  113. // given
  114. gboolean result;
  115. // when
  116. result = hotkey_equal (data->hotkey1, data->hotkey2);
  117. // then
  118. ck_assert_int_eq (result, data->expected_result);
  119. }
  120. END_PARAMETRIZED_TEST
  121. /* --------------------------------------------------------------------------------------------- */
  122. int
  123. main (void)
  124. {
  125. TCase *tc_core;
  126. tc_core = tcase_create ("Core");
  127. tcase_add_checked_fixture (tc_core, setup, teardown);
  128. // Add new tests here: ***************
  129. mctest_add_parameterized_test (tc_core, test_hotkey_equal, test_hotkey_equal_ds);
  130. // ***********************************
  131. return mctest_run_all (tc_core);
  132. }
  133. /* --------------------------------------------------------------------------------------------- */