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-2025
   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 <https://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 START_TEST (test_widget_make_global_local)
     /* [previous][next][first][last][top][bottom][index][help]  */
  39 {
  40     WRect r;
  41     WGroup *g0, *g1, *g2;
  42     Widget *w0, *w1, *w2;
  43 
  44     // top level group
  45     g0 = g_new0 (WGroup, 1);
  46     rect_init (&r, 20, 20, 40, 40);
  47     group_init (g0, &r, NULL, NULL);
  48 
  49     // g0 child
  50     w0 = g_new0 (Widget, 1);
  51     rect_init (&r, 1, 1, 5, 5);
  52     widget_init (w0, &r, widget_default_callback, NULL);
  53     group_add_widget (g0, w0);
  54 
  55     // g0 child
  56     g1 = g_new0 (WGroup, 1);
  57     rect_init (&r, 5, 5, 30, 30);
  58     group_init (g1, &r, NULL, NULL);
  59 
  60     // g1 child
  61     w1 = g_new0 (Widget, 1);
  62     rect_init (&r, 5, 5, 10, 10);
  63     widget_init (w1, &r, widget_default_callback, NULL);
  64     group_add_widget (g1, w1);
  65 
  66     // g1 child
  67     g2 = g_new0 (WGroup, 1);
  68     rect_init (&r, 15, 15, 20, 20);
  69     group_init (g2, &r, NULL, NULL);
  70     group_add_widget (g1, g2);
  71 
  72     // g2 child
  73     w2 = g_new0 (Widget, 1);
  74     rect_init (&r, 15, 15, 5, 5);
  75     widget_init (w2, &r, widget_default_callback, NULL);
  76     group_add_widget (g2, w2);
  77 
  78     // g0 child
  79     group_add_widget (g0, g1);
  80 
  81     // test global coordinates
  82     // w0 is a member of g0
  83     ck_assert_int_eq (w0->rect.y, 21);
  84     ck_assert_int_eq (w0->rect.x, 21);
  85     // g1 is a member of g0
  86     ck_assert_int_eq (WIDGET (g1)->rect.y, 25);
  87     ck_assert_int_eq (WIDGET (g1)->rect.x, 25);
  88     // w1 is a member of g1
  89     ck_assert_int_eq (w1->rect.y, 30);
  90     ck_assert_int_eq (w1->rect.x, 30);
  91     // g2 is a member of g1
  92     ck_assert_int_eq (WIDGET (g2)->rect.y, 40);
  93     ck_assert_int_eq (WIDGET (g2)->rect.x, 40);
  94     // w2 is a member of g2
  95     ck_assert_int_eq (w2->rect.y, 55);
  96     ck_assert_int_eq (w2->rect.x, 55);
  97 
  98     group_remove_widget (w0);
  99     group_remove_widget (g1);
 100 
 101     // test local coordinates
 102     // w0 is not a member of g0
 103     ck_assert_int_eq (w0->rect.y, 1);
 104     ck_assert_int_eq (w0->rect.x, 1);
 105 
 106     // g1 is not a member of g0
 107     ck_assert_int_eq (WIDGET (g1)->rect.y, 5);
 108     ck_assert_int_eq (WIDGET (g1)->rect.x, 5);
 109     // w1 is a member of g1
 110     ck_assert_int_eq (w1->rect.y, 10);
 111     ck_assert_int_eq (w1->rect.x, 10);
 112     // g2 is not a member of g1
 113     ck_assert_int_eq (WIDGET (g2)->rect.y, 20);
 114     ck_assert_int_eq (WIDGET (g2)->rect.x, 20);
 115     // w2 is a member of g2
 116     ck_assert_int_eq (w2->rect.y, 35);
 117     ck_assert_int_eq (w2->rect.x, 35);
 118 
 119     widget_destroy (w0);
 120     widget_destroy (WIDGET (g1));
 121     widget_destroy (WIDGET (g0));
 122 }
 123 END_TEST
 124 
 125 /* --------------------------------------------------------------------------------------------- */
 126 
 127 int
 128 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 129 {
 130     TCase *tc_core;
 131 
 132     tc_core = tcase_create ("Core");
 133 
 134     // Add new tests here: ***************
 135     tcase_add_test (tc_core, test_widget_make_global_local);
 136     // ***********************************
 137 
 138     return mctest_run_all (tc_core);
 139 }
 140 
 141 /* --------------------------------------------------------------------------------------------- */

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