Manual pages: mcmcdiffmceditmcview

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

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