widget_make_global_local.c 4.1 KB

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