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

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