widget_make_global_local.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. libmc - checks for search widget with requested ID
  3. Copyright (C) 2021-2025
  4. The Free Software Foundation, Inc.
  5. Written by:
  6. Andrew Borodin <aborodin@vmail.ru>, 2021-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 <https://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. START_TEST (test_widget_make_global_local)
  26. {
  27. WRect r;
  28. WGroup *g0, *g1, *g2;
  29. Widget *w0, *w1, *w2;
  30. // top level group
  31. g0 = g_new0 (WGroup, 1);
  32. rect_init (&r, 20, 20, 40, 40);
  33. group_init (g0, &r, NULL, NULL);
  34. // g0 child
  35. w0 = g_new0 (Widget, 1);
  36. rect_init (&r, 1, 1, 5, 5);
  37. widget_init (w0, &r, widget_default_callback, NULL);
  38. group_add_widget (g0, w0);
  39. // g0 child
  40. g1 = g_new0 (WGroup, 1);
  41. rect_init (&r, 5, 5, 30, 30);
  42. group_init (g1, &r, NULL, NULL);
  43. // g1 child
  44. w1 = g_new0 (Widget, 1);
  45. rect_init (&r, 5, 5, 10, 10);
  46. widget_init (w1, &r, widget_default_callback, NULL);
  47. group_add_widget (g1, w1);
  48. // g1 child
  49. g2 = g_new0 (WGroup, 1);
  50. rect_init (&r, 15, 15, 20, 20);
  51. group_init (g2, &r, NULL, NULL);
  52. group_add_widget (g1, g2);
  53. // g2 child
  54. w2 = g_new0 (Widget, 1);
  55. rect_init (&r, 15, 15, 5, 5);
  56. widget_init (w2, &r, widget_default_callback, NULL);
  57. group_add_widget (g2, w2);
  58. // g0 child
  59. group_add_widget (g0, g1);
  60. // test global coordinates
  61. // w0 is a member of g0
  62. ck_assert_int_eq (w0->rect.y, 21);
  63. ck_assert_int_eq (w0->rect.x, 21);
  64. // g1 is a member of g0
  65. ck_assert_int_eq (WIDGET (g1)->rect.y, 25);
  66. ck_assert_int_eq (WIDGET (g1)->rect.x, 25);
  67. // w1 is a member of g1
  68. ck_assert_int_eq (w1->rect.y, 30);
  69. ck_assert_int_eq (w1->rect.x, 30);
  70. // g2 is a member of g1
  71. ck_assert_int_eq (WIDGET (g2)->rect.y, 40);
  72. ck_assert_int_eq (WIDGET (g2)->rect.x, 40);
  73. // w2 is a member of g2
  74. ck_assert_int_eq (w2->rect.y, 55);
  75. ck_assert_int_eq (w2->rect.x, 55);
  76. group_remove_widget (w0);
  77. group_remove_widget (g1);
  78. // test local coordinates
  79. // w0 is not a member of g0
  80. ck_assert_int_eq (w0->rect.y, 1);
  81. ck_assert_int_eq (w0->rect.x, 1);
  82. // g1 is not a member of g0
  83. ck_assert_int_eq (WIDGET (g1)->rect.y, 5);
  84. ck_assert_int_eq (WIDGET (g1)->rect.x, 5);
  85. // w1 is a member of g1
  86. ck_assert_int_eq (w1->rect.y, 10);
  87. ck_assert_int_eq (w1->rect.x, 10);
  88. // g2 is not a member of g1
  89. ck_assert_int_eq (WIDGET (g2)->rect.y, 20);
  90. ck_assert_int_eq (WIDGET (g2)->rect.x, 20);
  91. // w2 is a member of g2
  92. ck_assert_int_eq (w2->rect.y, 35);
  93. ck_assert_int_eq (w2->rect.x, 35);
  94. widget_destroy (w0);
  95. widget_destroy (WIDGET (g1));
  96. widget_destroy (WIDGET (g0));
  97. }
  98. END_TEST
  99. /* --------------------------------------------------------------------------------------------- */
  100. int
  101. main (void)
  102. {
  103. TCase *tc_core;
  104. tc_core = tcase_create ("Core");
  105. // Add new tests here: ***************
  106. tcase_add_test (tc_core, test_widget_make_global_local);
  107. // ***********************************
  108. return mctest_run_all (tc_core);
  109. }
  110. /* --------------------------------------------------------------------------------------------- */