/trunk/Examples/test-suite/java/java_director_runme.java
Java | 92 lines | 65 code | 20 blank | 7 comment | 8 complexity | 762ea3de993f503a7701df9c296ee432 MD5 | raw file
1// Mainly tests that directors are finalized correctly 2 3import java_director.*; 4 5public class java_director_runme { 6 7 static { 8 try { 9 System.loadLibrary("java_director"); 10 } catch (UnsatisfiedLinkError e) { 11 System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); 12 System.exit(1); 13 } 14 } 15 16 public static void main(String argv[]) { 17 QuuxContainer qc = createContainer(); 18 19 int instances = Quux.instances(); 20 if (instances != 4) 21 throw new RuntimeException("Quux instances should be 4, actually " + instances); 22 23 for (int i = 0; i < qc.size(); ++i) { 24 Quux q = qc.get(i); 25 26 if (!q.director_method().equals(qc.invoke(i))) { 27 throw new RuntimeException ( "q.director_method()/qv.invoke(" + i + ")"); 28 } 29 } 30 31 qc = null; 32 /* Watch qc get reaped, which causes the C++ object to delete 33 objects from the internal vector */ 34 System.gc(); 35 System.runFinalization(); 36 37 // Give the finalizers a chance to run 38 try { 39 Thread.sleep(50); 40 } catch (InterruptedException e) { 41 } 42 43 /* Watch the Quux objects formerly in the QuuxContainer object 44 get reaped */ 45 System.gc(); 46 System.runFinalization(); 47 48 instances = Quux.instances(); 49 if (instances != 0) 50 throw new RuntimeException("Quux instances should be 0, actually " + instances); 51 52 /* Test Quux1's director disconnect method rename */ 53 Quux1 quux1 = new Quux1("quux1"); 54 if (quux1.disconnectMethodCalled) 55 throw new RuntimeException("Oops"); 56 quux1.delete(); 57 if (!quux1.disconnectMethodCalled) 58 throw new RuntimeException("disconnect method not called"); 59 } 60 61 public static QuuxContainer createContainer() { 62 QuuxContainer qc = new QuuxContainer(); 63 64 qc.push(new Quux("element 1")); 65 qc.push(new java_director_MyQuux("element 2")); 66 qc.push(new java_director_MyQuux("element 3")); 67 qc.push(new Quux("element 4")); 68 69 return qc; 70 } 71} 72 73class java_director_MyQuux extends Quux { 74 public java_director_MyQuux(String arg) { 75 super(arg); 76 } 77 78 public String director_method() { 79 return "java_director_MyQuux:" + member(); 80 } 81} 82 83class java_director_JavaExceptionTest extends JavaExceptionTest { 84 public java_director_JavaExceptionTest() { 85 super(); 86 } 87 88 public void etest() throws Exception { 89 super.etest(); 90 } 91} 92