summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-07-12 17:09:41 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-07-12 17:15:37 -0300
commitc3c81263fd4504c8558ea47a48d0e764997b21d0 (patch)
tree8c3fad3b56466d9a319e2deaab38d29500e7948b
parentb799ba1a10b0f4906a5487474ba9f14db465caeb (diff)
csharp: fix some unit tests that rely on garbage collection
Summary: Fix unit tests `TestEoInherit.inherited_collected` and `TestFunctionPointers.set_callback_inherited_called_from_c`. Iterate through garbage collection and EFL main loop more times to ensure that allocated objects are really collected. Also expand the test utility method `CollectAndIterate` to receive the number of times to call the whole cleaning iteration process (not only the garbage collection). Test Plan: `meson test` Reviewers: lauromoura Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9271
-rw-r--r--src/tests/efl_mono/Eo.cs2
-rw-r--r--src/tests/efl_mono/FunctionPointers.cs4
-rw-r--r--src/tests/efl_mono/TestUtils.cs13
3 files changed, 10 insertions, 9 deletions
diff --git a/src/tests/efl_mono/Eo.cs b/src/tests/efl_mono/Eo.cs
index be66f0842c..aa3565dd76 100644
--- a/src/tests/efl_mono/Eo.cs
+++ b/src/tests/efl_mono/Eo.cs
@@ -120,7 +120,7 @@ class TestEoInherit
120 public static void inherited_collected() 120 public static void inherited_collected()
121 { 121 {
122 var wref = CreateCollectableInherited(); 122 var wref = CreateCollectableInherited();
123 Test.CollectAndIterate(); 123 Test.CollectAndIterate(300, 10);
124 124
125 Test.AssertNull(wref.Target); 125 Test.AssertNull(wref.Target);
126 } 126 }
diff --git a/src/tests/efl_mono/FunctionPointers.cs b/src/tests/efl_mono/FunctionPointers.cs
index 4536704389..911e20ea38 100644
--- a/src/tests/efl_mono/FunctionPointers.cs
+++ b/src/tests/efl_mono/FunctionPointers.cs
@@ -171,9 +171,7 @@ class TestFunctionPointers
171 // Should release the handle to the wrapper allocated when calling set_callback from C. 171 // Should release the handle to the wrapper allocated when calling set_callback from C.
172 obj.SetCallback(twice); 172 obj.SetCallback(twice);
173 173
174 GC.Collect(); 174 Test.CollectAndIterate(300, 10);
175 GC.WaitForPendingFinalizers();
176 Efl.App.AppMain.Iterate();
177 175
178 Test.Assert(obj.set_called, "set_callback override must have been called"); 176 Test.Assert(obj.set_called, "set_callback override must have been called");
179 Test.Assert(!obj.invoke_called, "invoke_callback must not have been called"); 177 Test.Assert(!obj.invoke_called, "invoke_callback must not have been called");
diff --git a/src/tests/efl_mono/TestUtils.cs b/src/tests/efl_mono/TestUtils.cs
index 21b8ec7794..bbc37b5e65 100644
--- a/src/tests/efl_mono/TestUtils.cs
+++ b/src/tests/efl_mono/TestUtils.cs
@@ -200,14 +200,17 @@ public static class Test
200 /// <summary>Runs a number of garbage collections and iterate the main loop. 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 201 /// The iteration is needed to make sure objects collected in the GC thread
202 /// are efl_unref'd in the main thread.</summary> 202 /// are efl_unref'd in the main thread.</summary>
203 public static void CollectAndIterate(int iterations=1000) 203 public static void CollectAndIterate(int iterations=1000, int global_iterations=1)
204 { 204 {
205 for (int i = 0; i < iterations; i++) 205 for (int g = 0; g < global_iterations; ++g)
206 { 206 {
207 System.GC.Collect(); 207 for (int i = 0; i < iterations; ++i)
208 {
209 System.GC.Collect();
210 }
211 System.GC.WaitForPendingFinalizers();
212 Efl.App.AppMain.Iterate();
208 } 213 }
209 System.GC.WaitForPendingFinalizers();
210 Efl.App.AppMain.Iterate();
211 } 214 }
212 215
213} 216}