ui.widget: add exception handling code and unit test of sub_object_add/del function

Add missing exception check code with unit test.

Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de>
Differential Revision: https://phab.enlightenment.org/D8282
This commit is contained in:
Yeongjong Lee 2019-03-11 00:59:07 +00:00 committed by Marcel Hollerbach
parent e2b63eae75
commit 0838c1af63
2 changed files with 20 additions and 0 deletions

View File

@ -1460,6 +1460,9 @@ _efl_ui_widget_widget_sub_object_add(Eo *obj, Elm_Widget_Smart_Data *sd, Evas_Ob
{
Efl_Ui_Widget *parent;
if (!sobj) return EINA_FALSE;
EINA_SAFETY_ON_TRUE_RETURN_VAL(obj == sobj, EINA_FALSE);
//first make sure that we unregister the sobj from the parent
if (elm_widget_is(sobj))
parent = efl_ui_widget_parent_get(sobj);

View File

@ -172,6 +172,22 @@ EFL_START_TEST(efl_ui_test_widget_sub_iterator)
}
EFL_END_TEST
EFL_START_TEST(efl_ui_test_widget_sub_object_add_del)
{
State s;
_small_ui(&s);
ck_assert(!efl_ui_widget_sub_object_add(s.btn1, s.btn1));
ck_assert(efl_ui_widget_sub_object_add(s.box, s.btn1));
ck_assert(!efl_ui_widget_sub_object_add(s.box, NULL));
ck_assert(!efl_ui_widget_sub_object_del(s.btn1, s.btn1));
ck_assert(!efl_ui_widget_sub_object_del(s.box, NULL));
ck_assert(!efl_ui_widget_sub_object_del(s.btn1, s.box));
ck_assert(efl_ui_widget_sub_object_del(s.box, s.btn1));
}
EFL_END_TEST
void efl_ui_test_widget(TCase *tc)
{
tcase_add_test(tc, efl_ui_test_widget_parent_iterator);
@ -179,4 +195,5 @@ void efl_ui_test_widget(TCase *tc)
tcase_add_test(tc, efl_ui_test_widget_widget_sub_iterator);
tcase_add_test(tc, efl_ui_test_widget_iterator);
tcase_add_test(tc, efl_ui_test_widget_sub_iterator);
tcase_add_test(tc, efl_ui_test_widget_sub_object_add_del);
}