hotkey_equal.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. /* 0 */
  45. { { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  46. { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  47. TRUE },
  48. /* 1 */
  49. { { .start = C (""), .hotkey = C (""), .end = C ("") },
  50. { .start = C (""), .hotkey = C (""), .end = C ("") },
  51. TRUE },
  52. /* 2 */
  53. { { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  54. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  55. TRUE },
  56. /* 3 */
  57. { { .start = C ("abc"), .hotkey = NULL, .end = C ("efg") },
  58. { .start = C ("abc"), .hotkey = NULL, .end = C ("efg") },
  59. TRUE },
  60. /* 4 */
  61. { { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  62. { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  63. TRUE },
  64. /* 5 */
  65. { { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  66. { .start = C ("_bc"), .hotkey = C ("d"), .end = C ("efg") },
  67. FALSE },
  68. /* 6 */
  69. { { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  70. { .start = C ("abc"), .hotkey = C ("_"), .end = C ("efg") },
  71. FALSE },
  72. /* 7 */
  73. { { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  74. { .start = C ("abc"), .hotkey = C ("d"), .end = C ("_fg") },
  75. FALSE },
  76. /* 8 */
  77. { { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  78. { .start = C ("adc"), .hotkey = NULL, .end = C ("efg") },
  79. FALSE },
  80. /* 9 */
  81. { { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  82. { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  83. FALSE },
  84. /* 10 */
  85. { { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  86. { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  87. FALSE }
  88. };
  89. /* *INDENT-ON* */
  90. /* @Test(dataSource = "test_hotkey_equal_ds") */
  91. /* *INDENT-OFF* */
  92. START_PARAMETRIZED_TEST (test_hotkey_equal, test_hotkey_equal_ds)
  93. /* *INDENT-ON* */
  94. {
  95. /* given */
  96. gboolean result;
  97. /* when */
  98. result = hotkey_equal (data->hotkey1, data->hotkey2);
  99. /* then */
  100. ck_assert_int_eq (result, data->expected_result);
  101. }
  102. /* *INDENT-OFF* */
  103. END_PARAMETRIZED_TEST
  104. /* *INDENT-ON* */
  105. /* --------------------------------------------------------------------------------------------- */
  106. int
  107. main (void)
  108. {
  109. TCase *tc_core;
  110. tc_core = tcase_create ("Core");
  111. tcase_add_checked_fixture (tc_core, setup, teardown);
  112. /* Add new tests here: *************** */
  113. mctest_add_parameterized_test (tc_core, test_hotkey_equal, test_hotkey_equal_ds);
  114. /* *********************************** */
  115. return mctest_run_all (tc_core);
  116. }
  117. /* --------------------------------------------------------------------------------------------- */