/tags/rel-1-3-29/SWIG/Examples/test-suite/java/java_throws_runme.java
Java | 98 lines | 71 code | 18 blank | 9 comment | 6 complexity | b47870615388d59919c3fa2049129ae5 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1 2import java_throws.*; 3 4public class java_throws_runme { 5 6 static { 7 try { 8 System.loadLibrary("java_throws"); 9 } catch (UnsatisfiedLinkError e) { 10 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); 11 System.exit(1); 12 } 13 } 14 15 public static void main(String argv[]) 16 { 17 // Check the exception classes in the main typemaps 18 boolean pass = false; 19 20 // This won't compile unless all of these exceptions are in the throw clause 21 try { 22 short s = java_throws.full_of_exceptions(10); 23 } 24 catch (ClassNotFoundException e) {} 25 catch (NoSuchFieldException e) { pass = true; } 26 catch (InstantiationException e) {} 27 catch (CloneNotSupportedException e) {} 28 catch (IllegalAccessException e) {} 29 30 if (!pass) 31 throw new RuntimeException("Test 1 failed"); 32 33 // Check the exception class in the throw typemap 34 pass = false; 35 try { 36 java_throws.throw_spec_function(100); 37 } 38 catch (IllegalAccessException e) { pass = true; } 39 40 if (!pass) 41 throw new RuntimeException("Test 2 failed"); 42 43 // Check newfree typemap throws attribute 44 try { 45 TestClass tc = java_throws.makeTestClass(); 46 } 47 catch (NoSuchMethodException e) {} 48 49 // Check javaout typemap throws attribute 50 pass = false; 51 try { 52 int myInt = java_throws.ioTest(); 53 } 54 catch (java.io.IOException e) { pass = true; } 55 56 if (!pass) 57 throw new RuntimeException("Test 4 failed"); 58 59 // Check except feature throws attribute... 60 // Static method 61 pass = false; 62 try { 63 FeatureTest.staticMethod(); 64 } 65 catch (MyException e) { pass = true; } 66 67 if (!pass) 68 throw new RuntimeException("Test 5 failed"); 69 70 FeatureTest f = null; 71 try { 72 f = new FeatureTest(); 73 } 74 catch (MyException e) {} 75 76 // Instance method 77 pass = false; 78 try { 79 f.method(); 80 } 81 catch (MyException e) { pass = true; } 82 83 if (!pass) 84 throw new RuntimeException("Test 6 failed"); 85 86 // Global function 87 pass = false; 88 try { 89 java_throws.globalFunction(10); 90 } 91 catch (MyException e) { pass = true; } 92 catch (ClassNotFoundException e) {} 93 catch (NoSuchFieldException e) {} 94 95 if (!pass) 96 throw new RuntimeException("Test 7 failed"); 97 } 98}