/tags/rel-1-3-29/SWIG/Examples/test-suite/java/java_director_runme.java
Java | 75 lines | 53 code | 16 blank | 6 comment | 8 complexity | 998b364a97c25b09880fb159adb63cd8 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
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 /* Watch the Quux objects formerly in the QuuxContainer object 38 get reaped */ 39 System.gc(); 40 System.runFinalization(); 41 42 instances = Quux.instances(); 43 if (instances != 0) 44 throw new RuntimeException("Quux instances should be 0, actually " + instances); 45 46 /* Test Quux1's director disconnect method rename */ 47 Quux1 quux1 = new Quux1("quux1"); 48 if (quux1.disconnectMethodCalled) 49 throw new RuntimeException("Oops"); 50 quux1.delete(); 51 if (!quux1.disconnectMethodCalled) 52 throw new RuntimeException("disconnect method not called"); 53 } 54 55 public static QuuxContainer createContainer() { 56 QuuxContainer qc = new QuuxContainer(); 57 58 qc.push(new Quux("element 1")); 59 qc.push(new java_director_MyQuux("element 2")); 60 qc.push(new java_director_MyQuux("element 3")); 61 qc.push(new Quux("element 4")); 62 63 return qc; 64 } 65} 66 67class java_director_MyQuux extends Quux { 68 public java_director_MyQuux(String arg) { 69 super(arg); 70 } 71 72 public String director_method() { 73 return "java_director_MyQuux:" + member(); 74 } 75}