2016-09-28 14:34:08 +03:00
|
|
|
/*
|
|
|
|
libmc - checks for initialization and deinitialization of WGroup widget
|
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 2020-2024
|
2016-09-28 14:34:08 +03:00
|
|
|
The Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by:
|
2022-05-21 16:11:06 +03:00
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2020-2022
|
2016-09-28 14:34:08 +03:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
|
|
|
The Midnight Commander is free software: you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TEST_SUITE_NAME "lib/widget/group"
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <check.h>
|
|
|
|
|
|
|
|
#include "lib/widget.h"
|
|
|
|
|
2020-12-30 18:23:26 +03:00
|
|
|
#include "tests/mctest.h"
|
|
|
|
|
2016-09-28 14:34:08 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static int ref = 0;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static cb_ret_t
|
2024-06-01 21:12:14 +03:00
|
|
|
widget_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
|
2016-09-28 14:34:08 +03:00
|
|
|
{
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case MSG_INIT:
|
|
|
|
ref++;
|
|
|
|
return widget_default_callback (w, NULL, MSG_INIT, 0, NULL);
|
|
|
|
|
|
|
|
case MSG_DESTROY:
|
|
|
|
ref--;
|
|
|
|
return widget_default_callback (w, NULL, MSG_DESTROY, 0, NULL);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return widget_default_callback (w, sender, msg, parm, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static cb_ret_t
|
2024-06-01 21:12:14 +03:00
|
|
|
group_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
|
2016-09-28 14:34:08 +03:00
|
|
|
{
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case MSG_INIT:
|
|
|
|
ref++;
|
|
|
|
return group_default_callback (w, NULL, MSG_INIT, 0, NULL);
|
|
|
|
|
|
|
|
case MSG_DESTROY:
|
|
|
|
ref--;
|
|
|
|
return group_default_callback (w, NULL, MSG_DESTROY, 0, NULL);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return group_default_callback (w, sender, msg, parm, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
START_TEST (test_group_init_deinit)
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
{
|
|
|
|
WGroup *g, *g0;
|
|
|
|
Widget *w0;
|
2022-05-21 16:11:06 +03:00
|
|
|
WRect r;
|
2016-09-28 14:34:08 +03:00
|
|
|
|
|
|
|
g = g_new0 (WGroup, 1);
|
2022-05-21 19:30:17 +03:00
|
|
|
rect_init (&r, 0, 0, 20, 20);
|
|
|
|
group_init (g, &r, group_callback, NULL);
|
2016-09-28 14:34:08 +03:00
|
|
|
|
|
|
|
g0 = g_new0 (WGroup, 1);
|
2022-05-21 19:30:17 +03:00
|
|
|
rect_init (&r, 0, 0, 10, 10);
|
|
|
|
group_init (g0, &r, group_callback, NULL);
|
2016-09-28 14:34:08 +03:00
|
|
|
group_add_widget (g, g0);
|
|
|
|
|
|
|
|
w0 = g_new0 (Widget, 1);
|
2022-05-21 16:11:06 +03:00
|
|
|
rect_init (&r, 0, 0, 5, 5);
|
|
|
|
widget_init (w0, &r, widget_callback, NULL);
|
2016-09-28 14:34:08 +03:00
|
|
|
group_add_widget (g0, w0);
|
|
|
|
|
|
|
|
w0 = g_new0 (Widget, 1);
|
2022-05-21 16:11:06 +03:00
|
|
|
rect_init (&r, 5, 5, 5, 5);
|
|
|
|
widget_init (w0, &r, widget_callback, NULL);
|
2016-09-28 14:34:08 +03:00
|
|
|
group_add_widget (g0, w0);
|
|
|
|
|
|
|
|
g0 = g_new0 (WGroup, 1);
|
2022-05-21 19:30:17 +03:00
|
|
|
rect_init (&r, 10, 10, 10, 10);
|
|
|
|
group_init (g0, &r, group_callback, NULL);
|
2016-09-28 14:34:08 +03:00
|
|
|
group_add_widget (g, g0);
|
|
|
|
|
|
|
|
w0 = g_new0 (Widget, 1);
|
2022-05-21 16:11:06 +03:00
|
|
|
rect_init (&r, 10, 10, 5, 5);
|
|
|
|
widget_init (w0, &r, widget_callback, NULL);
|
2016-09-28 14:34:08 +03:00
|
|
|
group_add_widget (g0, w0);
|
|
|
|
|
|
|
|
w0 = g_new0 (Widget, 1);
|
2022-05-21 16:11:06 +03:00
|
|
|
rect_init (&r, 15, 15, 5, 5);
|
|
|
|
widget_init (w0, &r, widget_callback, NULL);
|
2016-09-28 14:34:08 +03:00
|
|
|
group_add_widget (g0, w0);
|
|
|
|
|
|
|
|
w0 = g_new0 (Widget, 1);
|
2022-05-21 16:11:06 +03:00
|
|
|
rect_init (&r, 5, 5, 10, 10);
|
|
|
|
widget_init (w0, &r, widget_callback, NULL);
|
2016-09-28 14:34:08 +03:00
|
|
|
group_add_widget (g, w0);
|
|
|
|
|
2020-12-28 19:52:04 +03:00
|
|
|
ck_assert_msg (w0->id == 7, "last id (%d) != 7", ref);
|
2016-09-28 14:34:08 +03:00
|
|
|
|
|
|
|
send_message (g, NULL, MSG_INIT, 0, NULL);
|
|
|
|
|
2020-12-28 19:52:04 +03:00
|
|
|
ck_assert_msg (ref == 8, "ref (%d) != 8", ref);
|
2016-09-28 14:34:08 +03:00
|
|
|
|
|
|
|
widget_destroy (WIDGET (g));
|
|
|
|
|
2020-12-28 19:52:04 +03:00
|
|
|
ck_assert_msg (ref == 0, "ref (%d) != 0", ref);
|
2016-09-28 14:34:08 +03:00
|
|
|
}
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
END_TEST
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2020-12-30 18:23:26 +03:00
|
|
|
TCase *tc_core;
|
2016-09-28 14:34:08 +03:00
|
|
|
|
2020-12-30 18:23:26 +03:00
|
|
|
tc_core = tcase_create ("Core");
|
2016-09-28 14:34:08 +03:00
|
|
|
|
|
|
|
/* Add new tests here: *************** */
|
|
|
|
tcase_add_test (tc_core, test_group_init_deinit);
|
|
|
|
/* *********************************** */
|
|
|
|
|
2020-12-30 18:23:26 +03:00
|
|
|
return mctest_run_all (tc_core);
|
2016-09-28 14:34:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|