diff options
author | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2018-06-06 13:50:11 +0200 |
---|---|---|
committer | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2018-06-07 09:39:10 +0200 |
commit | 4e386c883aae2b25c50e9da52e4da1cff51a6e66 (patch) | |
tree | 070fc611f08b634328b207d724d98ca26ab36ffa | |
parent | 7e72a9328365fbecc366e75a600d12ef8b8f3c4c (diff) | |
download | efl-4e386c883aae2b25c50e9da52e4da1cff51a6e66.tar.gz |
eo: add testcase for basic eventing and lifetime checking
checks if a object is really freed, even under error conditions.
The test suite now has the following timing:
TC TIME Eo general: 0.035713
SUITE TIME(8227) Eo: 0.036046
Differential Revision: https://phab.enlightenment.org/D6253
-rw-r--r-- | src/Makefile_Eo.am | 3 | ||||
-rw-r--r-- | src/tests/eo/suite/eo_suite.c | 1 | ||||
-rw-r--r-- | src/tests/eo/suite/eo_suite.h | 2 | ||||
-rw-r--r-- | src/tests/eo/suite/eo_test_lifecycle.c | 168 |
4 files changed, 172 insertions, 2 deletions
diff --git a/src/Makefile_Eo.am b/src/Makefile_Eo.am index 4874e5a90a..7d318d2a5d 100644 --- a/src/Makefile_Eo.am +++ b/src/Makefile_Eo.am @@ -148,7 +148,8 @@ tests/eo/suite/eo_test_general.c \ tests/eo/suite/eo_test_value.c \ tests/eo/suite/eo_test_event.c \ tests/eo/suite/eo_test_threaded_calls.c \ -tests/eo/suite/eo_test_init.c +tests/eo/suite/eo_test_init.c \ +tests/eo/suite/eo_test_lifecycle.c tests_eo_eo_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ -DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/eo\" \ diff --git a/src/tests/eo/suite/eo_suite.c b/src/tests/eo/suite/eo_suite.c index 58b01ac706..06e0d4ec0e 100644 --- a/src/tests/eo/suite/eo_suite.c +++ b/src/tests/eo/suite/eo_suite.c @@ -15,6 +15,7 @@ static const Efl_Test_Case etc[] = { { "Eo eina value", eo_test_value }, { "Eo threaded eo calls", eo_test_threaded_calls }, { "Eo event calls", eo_test_event}, + { "Eo lifecycle", eo_test_lifecycle}, { NULL, NULL } }; diff --git a/src/tests/eo/suite/eo_suite.h b/src/tests/eo/suite/eo_suite.h index 8895168248..700325c465 100644 --- a/src/tests/eo/suite/eo_suite.h +++ b/src/tests/eo/suite/eo_suite.h @@ -11,5 +11,5 @@ void eo_test_call_errors(TCase *tc); void eo_test_value(TCase *tc); void eo_test_threaded_calls(TCase *tc); void eo_test_event(TCase *tc); - +void eo_test_lifecycle(TCase *tc); #endif /* _EO_SUITE_H */ diff --git a/src/tests/eo/suite/eo_test_lifecycle.c b/src/tests/eo/suite/eo_test_lifecycle.c new file mode 100644 index 0000000000..a576ca6dda --- /dev/null +++ b/src/tests/eo/suite/eo_test_lifecycle.c @@ -0,0 +1,168 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <stdio.h> + +#include <Eo.h> + +#include "eo_suite.h" +#include "eo_test_class_simple.h" + +EFL_START_TEST(eo_test_base_del) +{ + Eo *par = efl_add_ref(SIMPLE_CLASS, NULL); + Eo *obj = efl_add(SIMPLE_CLASS, par); + + efl_del(obj); + + ck_assert_ptr_eq(efl_class_name_get(obj), NULL); + +} +EFL_END_TEST + +EFL_START_TEST(eo_test_base_unref) +{ + Eo *obj = efl_add_ref(SIMPLE_CLASS, NULL); + + efl_unref(obj); + + ck_assert_ptr_eq(efl_class_name_get(obj), NULL); + +} +EFL_END_TEST + +typedef struct { + unsigned int time, del_time, invalidate_time, noref_time, destruct_time; +} Helper; + +static void +_invalidate(void *data, const Efl_Event *ev) +{ + Helper *help = data; + + ck_assert_ptr_ne(efl_parent_get(ev->object), NULL); + + help->invalidate_time = help->time; + help->time ++; +} + +static void +_noref(void *data, const Efl_Event *ev EINA_UNUSED) +{ + Helper *help = data; + + help->noref_time = help->time; + help->time ++; +} + +static void +_del(void *data, const Efl_Event *ev) +{ + Helper *help = data; + + ck_assert_ptr_eq(efl_parent_get(ev->object), NULL); + + help->del_time = help->time; + help->time ++; +} + +static void +_destruct(void *data, const Efl_Event *ev EINA_UNUSED) +{ + Helper *help = data; + + help->destruct_time = help->time; + help->time ++; +} + +EFL_START_TEST(eo_test_shutdown_eventting) +{ + Eo *par = efl_add_ref(SIMPLE_CLASS, NULL); + Eo *obj = efl_add(SIMPLE_CLASS, par); + Helper data; + + data.time = 1; + data.del_time = 0; + data.invalidate_time = 0; + data.noref_time = 0; + data.destruct_time = 0; + + efl_event_callback_add(obj, EFL_EVENT_DEL, _del, &data); + efl_event_callback_add(obj, EFL_EVENT_INVALIDATE, _invalidate, &data); + efl_event_callback_add(obj, EFL_EVENT_NOREF, _noref, &data); + efl_event_callback_add(obj, EFL_EVENT_DESTRUCT, _destruct, &data); + + efl_del(obj); + + //documented assertions: + ck_assert_int_ne(data.del_time, 0); + ck_assert_int_ne(data.invalidate_time, 0); + ck_assert_int_ne(data.noref_time, 0); + ck_assert_int_ne(data.destruct_time, 0); + + //everything happened before destruct + ck_assert_int_lt(data.del_time, data.destruct_time); + ck_assert_int_lt(data.invalidate_time, data.destruct_time); + ck_assert_int_lt(data.noref_time, data.destruct_time); + + //invalidate has to happen before the destructor + ck_assert_int_lt(data.invalidate_time, data.destruct_time); + + ck_assert_ptr_eq(efl_class_name_get(obj), NULL); + +} +EFL_END_TEST + +static void +_noref2(void *data EINA_UNUSED, const Efl_Event *ev) +{ + //correctly delete this + efl_del(ev->object); + //error unref + efl_unref(ev->object); +} + +EFL_START_TEST(eo_test_del_in_noref) +{ + Eo *par = efl_add_ref(SIMPLE_CLASS, NULL); + Eo *obj = efl_add(SIMPLE_CLASS, par); + + efl_event_callback_add(obj, EFL_EVENT_NOREF, _noref2, NULL); + + efl_ref(obj); + efl_unref(obj); //this fires noref + + ck_assert_ptr_eq(efl_class_name_get(obj), NULL); + +} +EFL_END_TEST + +static void +_noref3(void *data EINA_UNUSED, const Efl_Event *ev) +{ + //this is a wrong fixme + efl_unref(ev->object); +} + +EFL_START_TEST(eo_test_unref_noref) +{ + Eo *obj = efl_add_ref(SIMPLE_CLASS, NULL); + + efl_event_callback_add(obj, EFL_EVENT_NOREF, _noref3, NULL); + + efl_unref(obj); + + ck_assert_ptr_eq(efl_class_name_get(obj), NULL); + +} +EFL_END_TEST + +void eo_test_lifecycle(TCase *tc) +{ + tcase_add_test(tc, eo_test_base_del); + tcase_add_test(tc, eo_test_base_unref); + tcase_add_test(tc, eo_test_shutdown_eventting); + tcase_add_test(tc, eo_test_del_in_noref); + tcase_add_test(tc, eo_test_unref_noref); +} |