root/tests/lib/widget/group_init_destroy.c

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

DEFINITIONS

This source file includes following definitions.
  1. widget_callback
  2. group_callback
  3. START_TEST
  4. main

   1 /*
   2    libmc - checks for initialization and deinitialization of WGroup widget
   3 
   4    Copyright (C) 2020
   5    The Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Andrew Borodin <aborodin@vmail.ru>, 2020
   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/group"
  27 
  28 #include <config.h>
  29 
  30 #include <check.h>
  31 
  32 #include "lib/widget.h"
  33 
  34 /* --------------------------------------------------------------------------------------------- */
  35 
  36 static int ref = 0;
  37 
  38 /* --------------------------------------------------------------------------------------------- */
  39 
  40 static cb_ret_t
  41 widget_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
  42 {
  43     switch (msg)
  44     {
  45     case MSG_INIT:
  46         ref++;
  47         return widget_default_callback (w, NULL, MSG_INIT, 0, NULL);
  48 
  49     case MSG_DESTROY:
  50         ref--;
  51         return widget_default_callback (w, NULL, MSG_DESTROY, 0, NULL);
  52 
  53     default:
  54         return widget_default_callback (w, sender, msg, parm, data);
  55     }
  56 }
  57 
  58 /* --------------------------------------------------------------------------------------------- */
  59 
  60 static cb_ret_t
  61 group_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
  62 {
  63     switch (msg)
  64     {
  65     case MSG_INIT:
  66         ref++;
  67         return group_default_callback (w, NULL, MSG_INIT, 0, NULL);
  68 
  69     case MSG_DESTROY:
  70         ref--;
  71         return group_default_callback (w, NULL, MSG_DESTROY, 0, NULL);
  72 
  73     default:
  74         return group_default_callback (w, sender, msg, parm, data);
  75     }
  76 }
  77 
  78 /* --------------------------------------------------------------------------------------------- */
  79 
  80 /* *INDENT-OFF* */
  81 START_TEST (test_group_init_deinit)
     /* [previous][next][first][last][top][bottom][index][help]  */
  82 /* *INDENT-ON* */
  83 {
  84     WGroup *g, *g0;
  85     Widget *w0;
  86 
  87     g = g_new0 (WGroup, 1);
  88     group_init (g, 0, 0, 20, 20, group_callback, NULL);
  89 
  90     g0 = g_new0 (WGroup, 1);
  91     group_init (g0, 0, 0, 10, 10, group_callback, NULL);
  92     group_add_widget (g, g0);
  93 
  94     w0 = g_new0 (Widget, 1);
  95     widget_init (w0, 0, 0, 5, 5, widget_callback, NULL);
  96     group_add_widget (g0, w0);
  97 
  98     w0 = g_new0 (Widget, 1);
  99     widget_init (w0, 5, 5, 5, 5, widget_callback, NULL);
 100     group_add_widget (g0, w0);
 101 
 102     g0 = g_new0 (WGroup, 1);
 103     group_init (g0, 10, 10, 10, 10, group_callback, NULL);
 104     group_add_widget (g, g0);
 105 
 106     w0 = g_new0 (Widget, 1);
 107     widget_init (w0, 10, 10, 5, 5, widget_callback, NULL);
 108     group_add_widget (g0, w0);
 109 
 110     w0 = g_new0 (Widget, 1);
 111     widget_init (w0, 15, 15, 5, 5, widget_callback, NULL);
 112     group_add_widget (g0, w0);
 113 
 114     w0 = g_new0 (Widget, 1);
 115     widget_init (w0, 5, 5, 10, 10, widget_callback, NULL);
 116     group_add_widget (g, w0);
 117 
 118     fail_unless (w0->id == 7, "last id (%d) != 7", ref);
 119 
 120     send_message (g, NULL, MSG_INIT, 0, NULL);
 121 
 122     fail_unless (ref == 8, "ref (%d) != 8", ref);
 123 
 124     widget_destroy (WIDGET (g));
 125 
 126     fail_unless (ref == 0, "ref (%d) != 0", ref);
 127 }
 128 /* *INDENT-OFF* */
 129 END_TEST
 130 /* *INDENT-ON* */
 131 
 132 /* --------------------------------------------------------------------------------------------- */
 133 
 134 int
 135 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 136 {
 137     int number_failed;
 138 
 139     Suite *s = suite_create (TEST_SUITE_NAME);
 140     TCase *tc_core = tcase_create ("Core");
 141     SRunner *sr;
 142 
 143     /* Add new tests here: *************** */
 144     tcase_add_test (tc_core, test_group_init_deinit);
 145     /* *********************************** */
 146 
 147     suite_add_tcase (s, tc_core);
 148     sr = srunner_create (s);
 149     srunner_set_log (sr, "group_init_deinit.log");
 150     srunner_run_all (sr, CK_NORMAL);
 151     number_failed = srunner_ntests_failed (sr);
 152     srunner_free (sr);
 153     return (number_failed == 0) ? 0 : 1;
 154 }
 155 
 156 /* --------------------------------------------------------------------------------------------- */

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