summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-05-31 17:34:59 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-05-31 17:41:14 -0300
commit937da0b12c5b2b07a173199078856c35becdb0e0 (patch)
tree78d05f2bc299be847ab790db6ec2bbcd88ce363d
parent37941b757d75dc4847c081197e16689b5fe8eb1f (diff)
csharp: Add some tests
Summary: - Wrappers losing C# ref while alive in Eo - Inherited instances being collected Also cleanup GC and loop queue before each test Reviewers: vitor.sousa Reviewed By: vitor.sousa Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9063
-rw-r--r--src/Makefile_Efl_Mono.am10
-rw-r--r--src/tests/efl_mono/Eo.cs14
-rw-r--r--src/tests/efl_mono/Events.cs53
-rw-r--r--src/tests/efl_mono/Main.cs3
-rw-r--r--src/tests/efl_mono/TestUtils.cs14
-rw-r--r--src/tests/efl_mono/dummy_event_manager.c55
-rw-r--r--src/tests/efl_mono/dummy_event_manager.eo29
-rw-r--r--src/tests/efl_mono/libefl_mono_native_test.h1
-rw-r--r--src/tests/efl_mono/meson.build12
9 files changed, 189 insertions, 2 deletions
diff --git a/src/Makefile_Efl_Mono.am b/src/Makefile_Efl_Mono.am
index 10ceb5040d..8caf083e05 100644
--- a/src/Makefile_Efl_Mono.am
+++ b/src/Makefile_Efl_Mono.am
@@ -69,7 +69,8 @@ efl_mono_test_eolian_files = \
69 tests/efl_mono/dummy_inherit_helper.eo \ 69 tests/efl_mono/dummy_inherit_helper.eo \
70 tests/efl_mono/dummy_child.eo \ 70 tests/efl_mono/dummy_child.eo \
71 tests/efl_mono/dummy_part_holder.eo \ 71 tests/efl_mono/dummy_part_holder.eo \
72 tests/efl_mono/dummy_numberwrapper.eo 72 tests/efl_mono/dummy_numberwrapper.eo \
73 tests/efl_mono/dummy_event_manager.eo
73 74
74efl_mono_test_files = \ 75efl_mono_test_files = \
75 $(efl_mono_test_eolian_files) \ 76 $(efl_mono_test_eolian_files) \
@@ -395,6 +396,7 @@ check_LTLIBRARIES += tests/efl_mono/libefl_mono_native_test.la
395 396
396tests_efl_mono_libefl_mono_native_test_la_SOURCES = \ 397tests_efl_mono_libefl_mono_native_test_la_SOURCES = \
397 tests/efl_mono/dummy_child.c \ 398 tests/efl_mono/dummy_child.c \
399 tests/efl_mono/dummy_event_manager.c \
398 tests/efl_mono/dummy_inherit_helper.c \ 400 tests/efl_mono/dummy_inherit_helper.c \
399 tests/efl_mono/dummy_interfaces.c \ 401 tests/efl_mono/dummy_interfaces.c \
400 tests/efl_mono/dummy_numberwrapper.c \ 402 tests/efl_mono/dummy_numberwrapper.c \
@@ -418,6 +420,11 @@ tests/efl_mono/dummy_child.c: \
418 $(efl_mono_test_eolian_h) \ 420 $(efl_mono_test_eolian_h) \
419 tests/efl_mono/libefl_mono_native_test.h 421 tests/efl_mono/libefl_mono_native_test.h
420 422
423tests/efl_mono/dummy_event_manager.c: \
424 $(efl_mono_test_eolian_c) \
425 $(efl_mono_test_eolian_h) \
426 tests/efl_mono/libefl_mono_native_test.h
427
421tests/efl_mono/dummy_inherit_helper.c: \ 428tests/efl_mono/dummy_inherit_helper.c: \
422 $(efl_mono_test_eolian_c) \ 429 $(efl_mono_test_eolian_c) \
423 $(efl_mono_test_eolian_h) \ 430 $(efl_mono_test_eolian_h) \
@@ -447,6 +454,7 @@ tests/efl_mono/dummy_test_object.c: \
447efl_mono_test_eolian_mono_files = tests/efl_mono/dummy_test_object.eo.cs \ 454efl_mono_test_eolian_mono_files = tests/efl_mono/dummy_test_object.eo.cs \
448tests/efl_mono/dummy_test_iface.eo.cs \ 455tests/efl_mono/dummy_test_iface.eo.cs \
449tests/efl_mono/dummy_child.eo.cs \ 456tests/efl_mono/dummy_child.eo.cs \
457tests/efl_mono/dummy_event_manager.eo.cs \
450tests/efl_mono/dummy_part_holder.eo.cs \ 458tests/efl_mono/dummy_part_holder.eo.cs \
451tests/efl_mono/dummy_numberwrapper.eo.cs \ 459tests/efl_mono/dummy_numberwrapper.eo.cs \
452tests/efl_mono/dummy_inherit_iface.eo.cs \ 460tests/efl_mono/dummy_inherit_iface.eo.cs \
diff --git a/src/tests/efl_mono/Eo.cs b/src/tests/efl_mono/Eo.cs
index e77fd7bbc7..95b6b6395e 100644
--- a/src/tests/efl_mono/Eo.cs
+++ b/src/tests/efl_mono/Eo.cs
@@ -110,6 +110,20 @@ class TestEoInherit
110 Efl.Object loop = new MyObject(); 110 Efl.Object loop = new MyObject();
111 Test.Assert(loop.NativeHandle != System.IntPtr.Zero); 111 Test.Assert(loop.NativeHandle != System.IntPtr.Zero);
112 } 112 }
113
114 private static WeakReference CreateCollectableInherited()
115 {
116 var obj = new MyObject();
117 return new WeakReference(obj);
118 }
119
120 public static void inherited_collected()
121 {
122 var wref = CreateCollectableInherited();
123 Test.CollectAndIterate();
124
125 Test.AssertNull(wref.Target);
126 }
113} 127}
114 128
115class TestEoNames 129class TestEoNames
diff --git a/src/tests/efl_mono/Events.cs b/src/tests/efl_mono/Events.cs
index 70a49bff7e..b664e2bbbd 100644
--- a/src/tests/efl_mono/Events.cs
+++ b/src/tests/efl_mono/Events.cs
@@ -274,4 +274,57 @@ class TestEventNaming
274 274
275 } 275 }
276} 276}
277
278class TestEventWithDeadWrappers
279{
280
281 private static WeakReference AttachToManager(Dummy.EventManager manager,
282 EventHandler<Dummy.TestObjectEvtWithIntEvt_Args> cb)
283 {
284 var obj = new Dummy.TestObject();
285 manager.Emitter = obj;
286
287 obj.EvtWithIntEvt += cb;
288 return new WeakReference(obj);
289 }
290
291 public static void test_event_from_c_owned_wrapper()
292 {
293 // Set upon object instantiation
294 WeakReference wref = null;
295
296 // Checks in the callback called
297 bool callbackCalled = false;
298 int received = -1;
299
300 // attach to evt with int
301 EventHandler<Dummy.TestObjectEvtWithIntEvt_Args> cb = (object sender, Dummy.TestObjectEvtWithIntEvt_Args args) => {
302 callbackCalled = true;
303 received = args.arg;
304 Test.Assert(Object.ReferenceEquals(sender, wref.Target));
305 };
306
307 Dummy.EventManager manager = new Dummy.EventManager();
308 wref = AttachToManager(manager, cb);
309
310 Test.CollectAndIterate();
311
312 manager.EmitWithInt(42);
313
314 Test.CollectAndIterate();
315
316 Test.Assert(callbackCalled, "Callback must have been called.");
317 Test.AssertEquals(42, received, "Wrong value received.");
318
319 // Cleanup checks
320 manager.Release();
321
322 // Make sure the released wrapper is collected and release the Eo object
323 Test.CollectAndIterate();
324
325 Test.AssertNull(wref.Target);
326 }
327
328}
329
277} 330}
diff --git a/src/tests/efl_mono/Main.cs b/src/tests/efl_mono/Main.cs
index a5700ff180..f154f935eb 100644
--- a/src/tests/efl_mono/Main.cs
+++ b/src/tests/efl_mono/Main.cs
@@ -42,6 +42,9 @@ class TestMain
42 if (localTestCase == setUp || localTestCase == tearDown) 42 if (localTestCase == setUp || localTestCase == tearDown)
43 continue; 43 continue;
44 44
45 // Cleanup garbage collector and job queue
46 Test.CollectAndIterate(1);
47
45 Console.WriteLine("[ RUN ] " + testCase.Name + "." + localTestCase.Name); 48 Console.WriteLine("[ RUN ] " + testCase.Name + "." + localTestCase.Name);
46 bool caseResult = true; 49 bool caseResult = true;
47 50
diff --git a/src/tests/efl_mono/TestUtils.cs b/src/tests/efl_mono/TestUtils.cs
index e7daf0559d..657bdb0300 100644
--- a/src/tests/efl_mono/TestUtils.cs
+++ b/src/tests/efl_mono/TestUtils.cs
@@ -196,6 +196,20 @@ public static class Test
196 if (reference == null) 196 if (reference == null)
197 throw new AssertionException($"Assertion failed: {file}:{line} ({member}) {msg}"); 197 throw new AssertionException($"Assertion failed: {file}:{line} ({member}) {msg}");
198 } 198 }
199
200 /// <summary>Runs a number of garbage collections and iterate the main loop.
201 /// The iteration is needed to make sure objects collected in the GC thread
202 /// are efl_unref'd in the main thread.</summary>
203 public static void CollectAndIterate(int iterations=1000)
204 {
205 for (int i = 0; i < iterations; i++)
206 {
207 System.GC.Collect();
208 }
209 System.GC.WaitForPendingFinalizers();
210 Efl.App.AppMain.Iterate();
211 }
212
199} 213}
200 214
201 215
diff --git a/src/tests/efl_mono/dummy_event_manager.c b/src/tests/efl_mono/dummy_event_manager.c
new file mode 100644
index 0000000000..416877dbfd
--- /dev/null
+++ b/src/tests/efl_mono/dummy_event_manager.c
@@ -0,0 +1,55 @@
1#include "libefl_mono_native_test.h"
2
3typedef struct Dummy_Event_Manager_Data
4{
5 Eo* emitter;
6} Dummy_Event_Manager_Data;
7
8static Efl_Object*
9_dummy_event_manager_efl_object_constructor(Eo *obj, EINA_UNUSED Dummy_Event_Manager_Data *pd)
10{
11 efl_constructor(efl_super(obj, DUMMY_EVENT_MANAGER_CLASS));
12
13 return obj;
14}
15
16static void
17_dummy_event_manager_efl_object_destructor(Eo *obj, Dummy_Event_Manager_Data *pd)
18{
19 if (pd->emitter != 0)
20 efl_unref(pd->emitter);
21
22 efl_destructor(efl_super(obj, DUMMY_EVENT_MANAGER_CLASS));
23}
24
25static void
26_dummy_event_manager_emitter_set(EINA_UNUSED Eo *obj, Dummy_Event_Manager_Data *pd, Eo *emitter)
27{
28 pd->emitter = emitter;
29}
30
31static Eina_Bool
32_dummy_event_manager_emit_with_int(EINA_UNUSED Eo *obj, Dummy_Event_Manager_Data *pd, int data)
33{
34 if (pd->emitter)
35 efl_event_callback_call(pd->emitter, DUMMY_TEST_OBJECT_EVENT_EVT_WITH_INT, &data);
36 else
37 {
38 EINA_LOG_ERR("Trying to emit event without an emitter.");
39 return EINA_FALSE;
40 }
41
42 return EINA_TRUE;
43}
44
45static void
46_dummy_event_manager_release(EINA_UNUSED Eo *obj, Dummy_Event_Manager_Data *pd)
47{
48 if (!pd->emitter)
49 return;
50
51 efl_unref(pd->emitter);
52}
53
54
55#include "dummy_event_manager.eo.c"
diff --git a/src/tests/efl_mono/dummy_event_manager.eo b/src/tests/efl_mono/dummy_event_manager.eo
new file mode 100644
index 0000000000..78b9dec8df
--- /dev/null
+++ b/src/tests/efl_mono/dummy_event_manager.eo
@@ -0,0 +1,29 @@
1import eina_types;
2
3class @beta Dummy.Event_Manager extends Efl.Object {
4
5 methods {
6 @property emitter {
7 set {
8 }
9 values {
10 emitter: Efl.Object @owned;
11 }
12 }
13
14 emit_with_int {
15 params {
16 data: int;
17 }
18 return: bool;
19 }
20
21 release {
22 }
23 }
24
25 implements {
26 Efl.Object.constructor;
27 Efl.Object.destructor;
28 }
29}
diff --git a/src/tests/efl_mono/libefl_mono_native_test.h b/src/tests/efl_mono/libefl_mono_native_test.h
index 672f249e27..9251118fc6 100644
--- a/src/tests/efl_mono/libefl_mono_native_test.h
+++ b/src/tests/efl_mono/libefl_mono_native_test.h
@@ -54,6 +54,7 @@
54#include "dummy_child.eo.h" 54#include "dummy_child.eo.h"
55#include "dummy_inherit_helper.eo.h" 55#include "dummy_inherit_helper.eo.h"
56#include "dummy_part_holder.eo.h" 56#include "dummy_part_holder.eo.h"
57#include "dummy_event_manager.eo.h"
57 58
58#include <interfaces/efl_part.eo.h> 59#include <interfaces/efl_part.eo.h>
59 60
diff --git a/src/tests/efl_mono/meson.build b/src/tests/efl_mono/meson.build
index 84a0c22515..f75a5b8bb9 100644
--- a/src/tests/efl_mono/meson.build
+++ b/src/tests/efl_mono/meson.build
@@ -1,4 +1,13 @@
1eo_files = ['dummy_child.eo', 'dummy_numberwrapper.eo', 'dummy_test_object.eo', 'dummy_test_iface.eo', 'dummy_inherit_helper.eo', 'dummy_inherit_iface.eo', 'dummy_part_holder.eo'] 1eo_files = [
2 'dummy_child.eo',
3 'dummy_numberwrapper.eo',
4 'dummy_test_object.eo',
5 'dummy_test_iface.eo',
6 'dummy_inherit_helper.eo',
7 'dummy_inherit_iface.eo',
8 'dummy_part_holder.eo',
9 'dummy_event_manager.eo',
10]
2 11
3eo_file_targets = [] 12eo_file_targets = []
4 13
@@ -23,6 +32,7 @@ efl_mono_native_test = library('efl_mono_native_test',
23 'dummy_numberwrapper.c', 32 'dummy_numberwrapper.c',
24 'dummy_part_holder.c', 33 'dummy_part_holder.c',
25 'dummy_test_object.c', 34 'dummy_test_object.c',
35 'dummy_event_manager.c',
26 ], 36 ],
27 dependencies : [ecore, eo, efl], 37 dependencies : [ecore, eo, efl],
28) 38)