summaryrefslogtreecommitdiff
path: root/src/tests/eo
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2018-06-06 13:50:11 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2018-06-07 09:39:10 +0200
commit4e386c883aae2b25c50e9da52e4da1cff51a6e66 (patch)
tree070fc611f08b634328b207d724d98ca26ab36ffa /src/tests/eo
parent7e72a9328365fbecc366e75a600d12ef8b8f3c4c (diff)
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
Diffstat (limited to 'src/tests/eo')
-rw-r--r--src/tests/eo/suite/eo_suite.c1
-rw-r--r--src/tests/eo/suite/eo_suite.h2
-rw-r--r--src/tests/eo/suite/eo_test_lifecycle.c168
3 files changed, 170 insertions, 1 deletions
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[] = {
15 { "Eo eina value", eo_test_value }, 15 { "Eo eina value", eo_test_value },
16 { "Eo threaded eo calls", eo_test_threaded_calls }, 16 { "Eo threaded eo calls", eo_test_threaded_calls },
17 { "Eo event calls", eo_test_event}, 17 { "Eo event calls", eo_test_event},
18 { "Eo lifecycle", eo_test_lifecycle},
18 { NULL, NULL } 19 { NULL, NULL }
19}; 20};
20 21
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);
11void eo_test_value(TCase *tc); 11void eo_test_value(TCase *tc);
12void eo_test_threaded_calls(TCase *tc); 12void eo_test_threaded_calls(TCase *tc);
13void eo_test_event(TCase *tc); 13void eo_test_event(TCase *tc);
14 14void eo_test_lifecycle(TCase *tc);
15#endif /* _EO_SUITE_H */ 15#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 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <stdio.h>
6
7#include <Eo.h>
8
9#include "eo_suite.h"
10#include "eo_test_class_simple.h"
11
12EFL_START_TEST(eo_test_base_del)
13{
14 Eo *par = efl_add_ref(SIMPLE_CLASS, NULL);
15 Eo *obj = efl_add(SIMPLE_CLASS, par);
16
17 efl_del(obj);
18
19 ck_assert_ptr_eq(efl_class_name_get(obj), NULL);
20
21}
22EFL_END_TEST
23
24EFL_START_TEST(eo_test_base_unref)
25{
26 Eo *obj = efl_add_ref(SIMPLE_CLASS, NULL);
27
28 efl_unref(obj);
29
30 ck_assert_ptr_eq(efl_class_name_get(obj), NULL);
31
32}
33EFL_END_TEST
34
35typedef struct {
36 unsigned int time, del_time, invalidate_time, noref_time, destruct_time;
37} Helper;
38
39static void
40_invalidate(void *data, const Efl_Event *ev)
41{
42 Helper *help = data;
43
44 ck_assert_ptr_ne(efl_parent_get(ev->object), NULL);
45
46 help->invalidate_time = help->time;
47 help->time ++;
48}
49
50static void
51_noref(void *data, const Efl_Event *ev EINA_UNUSED)
52{
53 Helper *help = data;
54
55 help->noref_time = help->time;
56 help->time ++;
57}
58
59static void
60_del(void *data, const Efl_Event *ev)
61{
62 Helper *help = data;
63
64 ck_assert_ptr_eq(efl_parent_get(ev->object), NULL);
65
66 help->del_time = help->time;
67 help->time ++;
68}
69
70static void
71_destruct(void *data, const Efl_Event *ev EINA_UNUSED)
72{
73 Helper *help = data;
74
75 help->destruct_time = help->time;
76 help->time ++;
77}
78
79EFL_START_TEST(eo_test_shutdown_eventting)
80{
81 Eo *par = efl_add_ref(SIMPLE_CLASS, NULL);
82 Eo *obj = efl_add(SIMPLE_CLASS, par);
83 Helper data;
84
85 data.time = 1;
86 data.del_time = 0;
87 data.invalidate_time = 0;
88 data.noref_time = 0;
89 data.destruct_time = 0;
90
91 efl_event_callback_add(obj, EFL_EVENT_DEL, _del, &data);
92 efl_event_callback_add(obj, EFL_EVENT_INVALIDATE, _invalidate, &data);
93 efl_event_callback_add(obj, EFL_EVENT_NOREF, _noref, &data);
94 efl_event_callback_add(obj, EFL_EVENT_DESTRUCT, _destruct, &data);
95
96 efl_del(obj);
97
98 //documented assertions:
99 ck_assert_int_ne(data.del_time, 0);
100 ck_assert_int_ne(data.invalidate_time, 0);
101 ck_assert_int_ne(data.noref_time, 0);
102 ck_assert_int_ne(data.destruct_time, 0);
103
104 //everything happened before destruct
105 ck_assert_int_lt(data.del_time, data.destruct_time);
106 ck_assert_int_lt(data.invalidate_time, data.destruct_time);
107 ck_assert_int_lt(data.noref_time, data.destruct_time);
108
109 //invalidate has to happen before the destructor
110 ck_assert_int_lt(data.invalidate_time, data.destruct_time);
111
112 ck_assert_ptr_eq(efl_class_name_get(obj), NULL);
113
114}
115EFL_END_TEST
116
117static void
118_noref2(void *data EINA_UNUSED, const Efl_Event *ev)
119{
120 //correctly delete this
121 efl_del(ev->object);
122 //error unref
123 efl_unref(ev->object);
124}
125
126EFL_START_TEST(eo_test_del_in_noref)
127{
128 Eo *par = efl_add_ref(SIMPLE_CLASS, NULL);
129 Eo *obj = efl_add(SIMPLE_CLASS, par);
130
131 efl_event_callback_add(obj, EFL_EVENT_NOREF, _noref2, NULL);
132
133 efl_ref(obj);
134 efl_unref(obj); //this fires noref
135
136 ck_assert_ptr_eq(efl_class_name_get(obj), NULL);
137
138}
139EFL_END_TEST
140
141static void
142_noref3(void *data EINA_UNUSED, const Efl_Event *ev)
143{
144 //this is a wrong fixme
145 efl_unref(ev->object);
146}
147
148EFL_START_TEST(eo_test_unref_noref)
149{
150 Eo *obj = efl_add_ref(SIMPLE_CLASS, NULL);
151
152 efl_event_callback_add(obj, EFL_EVENT_NOREF, _noref3, NULL);
153
154 efl_unref(obj);
155
156 ck_assert_ptr_eq(efl_class_name_get(obj), NULL);
157
158}
159EFL_END_TEST
160
161void eo_test_lifecycle(TCase *tc)
162{
163 tcase_add_test(tc, eo_test_base_del);
164 tcase_add_test(tc, eo_test_base_unref);
165 tcase_add_test(tc, eo_test_shutdown_eventting);
166 tcase_add_test(tc, eo_test_del_in_noref);
167 tcase_add_test(tc, eo_test_unref_noref);
168}