Manual pages: mcmcdiffmceditmcview

root/tests/lib/widget/widget_find_by_id.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) 2020-2025
   5    The Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Andrew Borodin <aborodin@vmail.ru>, 2020-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_find_by_id)
     /* [previous][next][first][last][top][bottom][index][help]  */
  35 {
  36     WGroup *g, *g0;
  37     Widget *w0;
  38     WRect r;
  39 
  40     g = g_new0 (WGroup, 1);
  41     rect_init (&r, 0, 0, 20, 20);
  42     group_init (g, &r, NULL, NULL);  // ID = 0
  43 
  44     g0 = g_new0 (WGroup, 1);
  45     rect_init (&r, 0, 0, 10, 10);
  46     group_init (g0, &r, NULL, NULL);  // ID = 1
  47     group_add_widget (g, g0);
  48 
  49     w0 = g_new0 (Widget, 1);
  50     rect_init (&r, 0, 0, 5, 5);
  51     widget_init (w0, &r, widget_default_callback, NULL);  // ID = 2
  52     group_add_widget (g0, w0);
  53 
  54     w0 = g_new0 (Widget, 1);
  55     rect_init (&r, 5, 5, 5, 5);
  56     widget_init (w0, &r, widget_default_callback, NULL);  // ID = 3
  57     group_add_widget (g0, w0);
  58 
  59     g0 = g_new0 (WGroup, 1);
  60     rect_init (&r, 10, 10, 10, 10);
  61     group_init (g0, &r, NULL, NULL);  // ID = 4
  62     group_add_widget (g, g0);
  63 
  64     w0 = g_new0 (Widget, 1);
  65     rect_init (&r, 10, 10, 5, 5);
  66     widget_init (w0, &r, widget_default_callback, NULL);  // ID = 5
  67     group_add_widget (g0, w0);
  68 
  69     w0 = g_new0 (Widget, 1);
  70     rect_init (&r, 15, 15, 5, 5);
  71     widget_init (w0, &r, widget_default_callback, NULL);  // ID = 6
  72     group_add_widget (g0, w0);
  73 
  74     w0 = g_new0 (Widget, 1);
  75     rect_init (&r, 5, 5, 10, 10);
  76     widget_init (w0, &r, widget_default_callback, NULL);  // ID = 7
  77     group_add_widget (g, w0);
  78 
  79     w0 = WIDGET (g);
  80 
  81     ck_assert_msg (widget_find_by_id (w0, 0) != NULL, "Not found ID=0");
  82     ck_assert_msg (widget_find_by_id (w0, 1) != NULL, "Not found ID=1");
  83     ck_assert_msg (widget_find_by_id (w0, 2) != NULL, "Not found ID=2");
  84     ck_assert_msg (widget_find_by_id (w0, 3) != NULL, "Not found ID=3");
  85     ck_assert_msg (widget_find_by_id (w0, 4) != NULL, "Not found ID=4");
  86     ck_assert_msg (widget_find_by_id (w0, 5) != NULL, "Not found ID=5");
  87     ck_assert_msg (widget_find_by_id (w0, 6) != NULL, "Not found ID=6");
  88     ck_assert_msg (widget_find_by_id (w0, 7) != NULL, "Not found ID=7");
  89     ck_assert_msg (widget_find_by_id (w0, 8) == NULL, "Found ID=8");
  90 
  91     send_message (g, NULL, MSG_INIT, 0, NULL);
  92     widget_destroy (w0);
  93 }
  94 END_TEST
  95 
  96 /* --------------------------------------------------------------------------------------------- */
  97 
  98 int
  99 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 100 {
 101     TCase *tc_core;
 102 
 103     tc_core = tcase_create ("Core");
 104 
 105     // Add new tests here: ***************
 106     tcase_add_test (tc_core, test_widget_find_by_id);
 107     // ***********************************
 108 
 109     return mctest_run_all (tc_core);
 110 }
 111 
 112 /* --------------------------------------------------------------------------------------------- */

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