summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2014-03-15 23:39:37 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2014-03-16 00:44:30 +0000
commit87963d2e685bdd96a765ab9418f536055437045c (patch)
tree75f9f3ea81eb94f44269e810b9c68cd48f5feac4
parent785d93d9fb948bddf51ac22a8b2bd5cb82cb7ba9 (diff)
downloadswig-87963d2e685bdd96a765ab9418f536055437045c.tar.gz
Java/C# smart pointer tests: Give GC more time to collect objects
-rw-r--r--Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs35
-rw-r--r--Examples/test-suite/csharp/li_std_auto_ptr_runme.cs36
-rw-r--r--Examples/test-suite/java/java_director_runme.java39
-rw-r--r--Examples/test-suite/java/li_boost_intrusive_ptr_runme.java19
-rw-r--r--Examples/test-suite/java/li_boost_shared_ptr_runme.java37
-rw-r--r--Examples/test-suite/java/li_std_auto_ptr_runme.java38
6 files changed, 137 insertions, 67 deletions
diff --git a/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs b/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs
index 6ded989b5..625542751 100644
--- a/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs
+++ b/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs
@@ -6,6 +6,13 @@ public class runme
// Debugging flag
public static bool debug = false;
+ private static void WaitForGC()
+ {
+ System.GC.Collect();
+ System.GC.WaitForPendingFinalizers();
+ System.Threading.Thread.Sleep(10);
+ }
+
static void Main()
{
if (debug)
@@ -27,22 +34,24 @@ public class runme
if (debug)
Console.WriteLine("Nearly finished");
- int countdown = 100;
- while (true) {
- System.GC.Collect();
- System.GC.WaitForPendingFinalizers();
- System.Threading.Thread.Sleep(10);
- if (--countdown == 0)
- break;
- if (Klass.getTotal_count() == 1) // Expect 1 instance - the one global variable (GlobalValue)
- break;
- };
- if (Klass.getTotal_count() != 1)
- throw new ApplicationException("Klass.total_count=" + Klass.getTotal_count());
+ {
+ int countdown = 500;
+ int expectedCount = 1;
+ while (true) {
+ WaitForGC();
+ if (--countdown == 0)
+ break;
+ if (Klass.getTotal_count() == expectedCount) // Expect the one global variable (GlobalValue)
+ break;
+ }
+ int actualCount = Klass.getTotal_count();
+ if (actualCount != expectedCount)
+ throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount);
+ }
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING)
- if (wrapper_count != 1) // Expect 1 instance - the one global variable (GlobalSmartValue)
+ if (wrapper_count != 1) // Expect the one global variable (GlobalSmartValue)
throw new ApplicationException("shared_ptr wrapper count=" + wrapper_count);
if (debug)
diff --git a/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs b/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs
index bea92d2f4..387d50400 100644
--- a/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs
+++ b/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs
@@ -20,18 +20,38 @@ public class li_std_auto_ptr_runme {
throw new Exception("number of objects should be 2");
k1 = null;
- WaitForGC();
-
- if (Klass.getTotal_count() != 1)
- throw new Exception("number of objects should be 1");
+ {
+ int countdown = 500;
+ int expectedCount = 1;
+ while (true) {
+ WaitForGC();
+ if (--countdown == 0)
+ break;
+ if (Klass.getTotal_count() == expectedCount)
+ break;
+ };
+ int actualCount = Klass.getTotal_count();
+ if (actualCount != expectedCount)
+ throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount);
+ }
if (k2.getLabel() != "second")
throw new Exception("wrong object label");
k2 = null;
- WaitForGC();
-
- if (Klass.getTotal_count() != 0)
- throw new Exception("no objects should be left");
+ {
+ int countdown = 500;
+ int expectedCount = 0;
+ while (true) {
+ WaitForGC();
+ if (--countdown == 0)
+ break;
+ if (Klass.getTotal_count() == expectedCount)
+ break;
+ }
+ int actualCount = Klass.getTotal_count();
+ if (actualCount != expectedCount)
+ throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount);
+ }
}
}
diff --git a/Examples/test-suite/java/java_director_runme.java b/Examples/test-suite/java/java_director_runme.java
index 86c92d49a..812e791f4 100644
--- a/Examples/test-suite/java/java_director_runme.java
+++ b/Examples/test-suite/java/java_director_runme.java
@@ -13,6 +13,16 @@ public class java_director_runme {
}
}
+ private static void WaitForGC()
+ {
+ System.gc();
+ System.runFinalization();
+ try {
+ java.lang.Thread.sleep(10);
+ } catch (java.lang.InterruptedException e) {
+ }
+ }
+
public static void main(String argv[]) {
QuuxContainer qc = createContainer();
@@ -31,24 +41,21 @@ public class java_director_runme {
qc = null;
/* Watch qc get reaped, which causes the C++ object to delete
objects from the internal vector */
- System.gc();
- System.runFinalization();
-
- // Give the finalizers a chance to run
- try {
- Thread.sleep(50);
- } catch (InterruptedException e) {
+ {
+ int countdown = 500;
+ int expectedCount = 0;
+ while (true) {
+ WaitForGC();
+ if (--countdown == 0)
+ break;
+ if (Quux.instances() == expectedCount)
+ break;
+ };
+ int actualCount = Quux.instances();
+ if (actualCount != expectedCount)
+ throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
}
- /* Watch the Quux objects formerly in the QuuxContainer object
- get reaped */
- System.gc();
- System.runFinalization();
-
- instances = Quux.instances();
- if (instances != 0)
- throw new RuntimeException("Quux instances should be 0, actually " + instances);
-
/* Test Quux1's director disconnect method rename */
Quux1 quux1 = new Quux1("quux1");
if (quux1.disconnectMethodCalled)
diff --git a/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java b/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java
index 9b480e7e0..530008a87 100644
--- a/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java
+++ b/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java
@@ -13,6 +13,16 @@ public class li_boost_intrusive_ptr_runme {
// Debugging flag
public final static boolean debug = false;
+ private static void WaitForGC()
+ {
+ System.gc();
+ System.runFinalization();
+ try {
+ java.lang.Thread.sleep(10);
+ } catch (java.lang.InterruptedException e) {
+ }
+ }
+
public static void main(String argv[])
{
if (debug)
@@ -39,12 +49,7 @@ public class li_boost_intrusive_ptr_runme {
int countdown = 50;
while (true) {
- System.gc();
- System.runFinalization();
- try {
- java.lang.Thread.sleep(100);
- } catch (java.lang.InterruptedException e) {
- }
+ WaitForGC();
if (--countdown == 0)
break;
if (Klass.getTotal_count() == 1 && KlassWithoutRefCount.getTotal_count() == 0 &&
@@ -52,7 +57,7 @@ public class li_boost_intrusive_ptr_runme {
KlassDerived.getTotal_count() == 0 && KlassDerivedDerived.getTotal_count() == 1)
// Expect 1 Klass instance - the one global variable (GlobalValue)
break;
- };
+ }
if (Klass.getTotal_count() != 1)
throw new RuntimeException("Klass.total_count=" + Klass.getTotal_count());
if (KlassWithoutRefCount.getTotal_count() != 0)
diff --git a/Examples/test-suite/java/li_boost_shared_ptr_runme.java b/Examples/test-suite/java/li_boost_shared_ptr_runme.java
index 02d6d6502..aa355c86a 100644
--- a/Examples/test-suite/java/li_boost_shared_ptr_runme.java
+++ b/Examples/test-suite/java/li_boost_shared_ptr_runme.java
@@ -13,6 +13,16 @@ public class li_boost_shared_ptr_runme {
// Debugging flag
public final static boolean debug = false;
+ private static void WaitForGC()
+ {
+ System.gc();
+ System.runFinalization();
+ try {
+ java.lang.Thread.sleep(10);
+ } catch (java.lang.InterruptedException e) {
+ }
+ }
+
public static void main(String argv[])
{
if (debug)
@@ -37,21 +47,20 @@ public class li_boost_shared_ptr_runme {
if (debug)
System.out.println("Nearly finished");
- int countdown = 100;
- while (true) {
- System.gc();
- System.runFinalization();
- try {
- java.lang.Thread.sleep(10);
- } catch (java.lang.InterruptedException e) {
+ {
+ int countdown = 500;
+ int expectedCount = 1;
+ while (true) {
+ WaitForGC();
+ if (--countdown == 0)
+ break;
+ if (Klass.getTotal_count() == expectedCount) // Expect the one global variable (GlobalValue)
+ break;
}
- if (--countdown == 0)
- break;
- if (Klass.getTotal_count() == 1) // Expect 1 instance - the one global variable (GlobalValue)
- break;
- };
- if (Klass.getTotal_count() != 1)
- throw new RuntimeException("Klass.total_count=" + Klass.getTotal_count());
+ int actualCount = Klass.getTotal_count();
+ if (actualCount != expectedCount)
+ throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
+ }
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
if (wrapper_count != li_boost_shared_ptr.getNOT_COUNTING())
diff --git a/Examples/test-suite/java/li_std_auto_ptr_runme.java b/Examples/test-suite/java/li_std_auto_ptr_runme.java
index eac7cacfc..db34fb529 100644
--- a/Examples/test-suite/java/li_std_auto_ptr_runme.java
+++ b/Examples/test-suite/java/li_std_auto_ptr_runme.java
@@ -15,7 +15,7 @@ public class li_std_auto_ptr_runme {
System.gc();
System.runFinalization();
try {
- java.lang.Thread.sleep(1);
+ java.lang.Thread.sleep(10);
} catch (java.lang.InterruptedException e) {
}
}
@@ -31,18 +31,38 @@ public class li_std_auto_ptr_runme {
throw new RuntimeException("number of objects should be 2");
k1 = null;
- WaitForGC();
-
- if (Klass.getTotal_count() != 1)
- throw new RuntimeException("number of objects should be 1");
+ {
+ int countdown = 500;
+ int expectedCount = 1;
+ while (true) {
+ WaitForGC();
+ if (--countdown == 0)
+ break;
+ if (Klass.getTotal_count() == expectedCount)
+ break;
+ }
+ int actualCount = Klass.getTotal_count();
+ if (actualCount != expectedCount)
+ throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
+ }
if (!k2.getLabel().equals("second"))
throw new RuntimeException("wrong object label");
k2 = null;
- WaitForGC();
-
- if (Klass.getTotal_count() != 0)
- throw new RuntimeException("no objects should be left");
+ {
+ int countdown = 500;
+ int expectedCount = 0;
+ while (true) {
+ WaitForGC();
+ if (--countdown == 0)
+ break;
+ if (Klass.getTotal_count() == expectedCount)
+ break;
+ };
+ int actualCount = Klass.getTotal_count();
+ if (actualCount != expectedCount)
+ throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
+ }
}
}