root/tests/lib/widget/widget_make_global_local.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. START_TEST
  2. main

   1 /*
   2    libmc - checks for search widget with requested ID
   3 
   4    Copyright (C) 2021-2024
   5    The Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Andrew Borodin <aborodin@vmail.ru>, 2021-2022
   9 
  10    This file is part of the Midnight Commander.
  11 
  12    The Midnight Commander is free software: you can redistribute it
  13    and/or modify it under the terms of the GNU General Public License as
  14    published by the Free Software Foundation, either version 3 of the License,
  15    or (at your option) any later version.
  16 
  17    The Midnight Commander is distributed in the hope that it will be useful,
  18    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20    GNU General Public License for more details.
  21 
  22    You should have received a copy of the GNU General Public License
  23    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  24  */
  25 
  26 #define TEST_SUITE_NAME "lib/widget"
  27 
  28 #include <config.h>
  29 
  30 #include <check.h>
  31 
  32 #include "lib/widget.h"
  33 
  34 #include "tests/mctest.h"
  35 
  36 /* --------------------------------------------------------------------------------------------- */
  37 
  38 /* *INDENT-OFF* */
  39 START_TEST (test_widget_make_global_local)
     /* [previous][next][first][last][top][bottom][index][help]  */
  40 /* *INDENT-ON* */
  41 {
  42     WRect r;
  43     WGroup *g0, *g1, *g2;
  44     Widget *w0, *w1, *w2;
  45 
  46     /* top level group */
  47     g0 = g_new0 (WGroup, 1);
  48     rect_init (&r, 20, 20, 40, 40);
  49     group_init (g0, &r, NULL, NULL);
  50 
  51     /* g0 child */
  52     w0 = g_new0 (Widget, 1);
  53     rect_init (&r, 1, 1, 5, 5);
  54     widget_init (w0, &r, widget_default_callback, NULL);
  55     group_add_widget (g0, w0);
  56 
  57     /* g0 child */
  58     g1 = g_new0 (WGroup, 1);
  59     rect_init (&r, 5, 5, 30, 30);
  60     group_init (g1, &r, NULL, NULL);
  61 
  62     /* g1 child */
  63     w1 = g_new0 (Widget, 1);
  64     rect_init (&r, 5, 5, 10, 10);
  65     widget_init (w1, &r, widget_default_callback, NULL);
  66     group_add_widget (g1, w1);
  67 
  68     /* g1 child */
  69     g2 = g_new0 (WGroup, 1);
  70     rect_init (&r, 15, 15, 20, 20);
  71     group_init (g2, &r, NULL, NULL);
  72     group_add_widget (g1, g2);
  73 
  74     /* g2 child */
  75     w2 = g_new0 (Widget, 1);
  76     rect_init (&r, 15, 15, 5, 5);
  77     widget_init (w2, &r, widget_default_callback, NULL);
  78     group_add_widget (g2, w2);
  79 
  80     /* g0 child */
  81     group_add_widget (g0, g1);
  82 
  83     /* test global coordinates */
  84     /* w0 is a member of g0 */
  85     ck_assert_int_eq (w0->rect.y, 21);
  86     ck_assert_int_eq (w0->rect.x, 21);
  87     /* g1 is a member of g0 */
  88     ck_assert_int_eq (WIDGET (g1)->rect.y, 25);
  89     ck_assert_int_eq (WIDGET (g1)->rect.x, 25);
  90     /* w1 is a member of g1 */
  91     ck_assert_int_eq (w1->rect.y, 30);
  92     ck_assert_int_eq (w1->rect.x, 30);
  93     /* g2 is a member of g1 */
  94     ck_assert_int_eq (WIDGET (g2)->rect.y, 40);
  95     ck_assert_int_eq (WIDGET (g2)->rect.x, 40);
  96     /* w2 is a member of g2 */
  97     ck_assert_int_eq (w2->rect.y, 55);
  98     ck_assert_int_eq (w2->rect.x, 55);
  99 
 100     group_remove_widget (w0);
 101     group_remove_widget (g1);
 102 
 103     /* test local coordinates */
 104     /* w0 is not a member of g0 */
 105     ck_assert_int_eq (w0->rect.y, 1);
 106     ck_assert_int_eq (w0->rect.x, 1);
 107 
 108     /* g1 is not a member of g0 */
 109     ck_assert_int_eq (WIDGET (g1)->rect.y, 5);
 110     ck_assert_int_eq (WIDGET (g1)->rect.x, 5);
 111     /* w1 is a member of g1 */
 112     ck_assert_int_eq (w1->rect.y, 10);
 113     ck_assert_int_eq (w1->rect.x, 10);
 114     /* g2 is not a member of g1 */
 115     ck_assert_int_eq (WIDGET (g2)->rect.y, 20);
 116     ck_assert_int_eq (WIDGET (g2)->rect.x, 20);
 117     /* w2 is a member of g2 */
 118     ck_assert_int_eq (w2->rect.y, 35);
 119     ck_assert_int_eq (w2->rect.x, 35);
 120 
 121     widget_destroy (w0);
 122     widget_destroy (WIDGET (g1));
 123     widget_destroy (WIDGET (g0));
 124 }
 125 /* *INDENT-OFF* */
 126 END_TEST
 127 /* *INDENT-ON* */
 128 
 129 /* --------------------------------------------------------------------------------------------- */
 130 
 131 int
 132 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 133 {
 134     TCase *tc_core;
 135 
 136     tc_core = tcase_create ("Core");
 137 
 138     /* Add new tests here: *************** */
 139     tcase_add_test (tc_core, test_widget_make_global_local);
 140     /* *********************************** */
 141 
 142     return mctest_run_all (tc_core);
 143 }
 144 
 145 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */