widget_find_by_id.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. libmc - checks for search widget with requested ID
  3. Copyright (C) 2020-2024
  4. The Free Software Foundation, Inc.
  5. Written by:
  6. Andrew Borodin <aborodin@vmail.ru>, 2020-2022
  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 <config.h>
  21. #include <check.h>
  22. #include "lib/widget.h"
  23. #include "tests/mctest.h"
  24. /* --------------------------------------------------------------------------------------------- */
  25. /* *INDENT-OFF* */
  26. START_TEST (test_widget_find_by_id)
  27. /* *INDENT-ON* */
  28. {
  29. WGroup *g, *g0;
  30. Widget *w0;
  31. WRect r;
  32. g = g_new0 (WGroup, 1);
  33. rect_init (&r, 0, 0, 20, 20);
  34. group_init (g, &r, NULL, NULL); /* ID = 0 */
  35. g0 = g_new0 (WGroup, 1);
  36. rect_init (&r, 0, 0, 10, 10);
  37. group_init (g0, &r, NULL, NULL); /* ID = 1 */
  38. group_add_widget (g, g0);
  39. w0 = g_new0 (Widget, 1);
  40. rect_init (&r, 0, 0, 5, 5);
  41. widget_init (w0, &r, widget_default_callback, NULL); /* ID = 2 */
  42. group_add_widget (g0, w0);
  43. w0 = g_new0 (Widget, 1);
  44. rect_init (&r, 5, 5, 5, 5);
  45. widget_init (w0, &r, widget_default_callback, NULL); /* ID = 3 */
  46. group_add_widget (g0, w0);
  47. g0 = g_new0 (WGroup, 1);
  48. rect_init (&r, 10, 10, 10, 10);
  49. group_init (g0, &r, NULL, NULL); /* ID = 4 */
  50. group_add_widget (g, g0);
  51. w0 = g_new0 (Widget, 1);
  52. rect_init (&r, 10, 10, 5, 5);
  53. widget_init (w0, &r, widget_default_callback, NULL); /* ID = 5 */
  54. group_add_widget (g0, w0);
  55. w0 = g_new0 (Widget, 1);
  56. rect_init (&r, 15, 15, 5, 5);
  57. widget_init (w0, &r, widget_default_callback, NULL); /* ID = 6 */
  58. group_add_widget (g0, w0);
  59. w0 = g_new0 (Widget, 1);
  60. rect_init (&r, 5, 5, 10, 10);
  61. widget_init (w0, &r, widget_default_callback, NULL); /* ID = 7 */
  62. group_add_widget (g, w0);
  63. w0 = WIDGET (g);
  64. ck_assert_msg (widget_find_by_id (w0, 0) != NULL, "Not found ID=0");
  65. ck_assert_msg (widget_find_by_id (w0, 1) != NULL, "Not found ID=1");
  66. ck_assert_msg (widget_find_by_id (w0, 2) != NULL, "Not found ID=2");
  67. ck_assert_msg (widget_find_by_id (w0, 3) != NULL, "Not found ID=3");
  68. ck_assert_msg (widget_find_by_id (w0, 4) != NULL, "Not found ID=4");
  69. ck_assert_msg (widget_find_by_id (w0, 5) != NULL, "Not found ID=5");
  70. ck_assert_msg (widget_find_by_id (w0, 6) != NULL, "Not found ID=6");
  71. ck_assert_msg (widget_find_by_id (w0, 7) != NULL, "Not found ID=7");
  72. ck_assert_msg (widget_find_by_id (w0, 8) == NULL, "Found ID=8");
  73. send_message (g, NULL, MSG_INIT, 0, NULL);
  74. widget_destroy (w0);
  75. }
  76. /* *INDENT-OFF* */
  77. END_TEST
  78. /* *INDENT-ON* */
  79. /* --------------------------------------------------------------------------------------------- */
  80. int
  81. main (void)
  82. {
  83. TCase *tc_core;
  84. tc_core = tcase_create ("Core");
  85. /* Add new tests here: *************** */
  86. tcase_add_test (tc_core, test_widget_find_by_id);
  87. /* *********************************** */
  88. return mctest_run_all (tc_core);
  89. }
  90. /* --------------------------------------------------------------------------------------------- */