PageRenderTime 27ms CodeModel.GetById 15ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/test-suite/java/java_throws_runme.java

#
Java | 123 lines | 88 code | 24 blank | 11 comment | 8 complexity | d718245d53916751d4b6b665ee148c1f MD5 | raw file
  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 the exception class is used with %catches
 44      pass = false;
 45      try {
 46        java_throws.catches_function(100);
 47      }
 48      catch (IllegalAccessException e) { pass = true; }
 49
 50      if (!pass)
 51        throw new RuntimeException("Test 3 failed");
 52
 53      // Check newfree typemap throws attribute
 54      try {
 55        TestClass tc = java_throws.makeTestClass();
 56      }
 57      catch (NoSuchMethodException e) {}
 58
 59      // Check javaout typemap throws attribute
 60      pass = false;
 61      try {
 62        int myInt = java_throws.ioTest();
 63      }
 64      catch (java.io.IOException e) { pass = true; }
 65
 66      if (!pass)
 67        throw new RuntimeException("Test 4 failed");
 68
 69      // Check except feature throws attribute...
 70      // Static method
 71      pass = false;
 72      try {
 73        FeatureTest.staticMethod();
 74      }
 75      catch (MyException e) { pass = true; }
 76      
 77      if (!pass)
 78        throw new RuntimeException("Test 5 failed");
 79
 80      FeatureTest f = null;
 81      try {
 82        f = new FeatureTest();
 83      }
 84      catch (MyException e) {}
 85
 86      // Instance method
 87      pass = false;
 88      try {
 89        f.method();
 90      }
 91      catch (MyException e) { pass = true; }
 92
 93      if (!pass)
 94        throw new RuntimeException("Test 6 failed");
 95
 96      // Global function
 97      pass = false;
 98      try {
 99        java_throws.globalFunction(10);
100      }
101      catch (MyException e) { pass = true; }
102      catch (ClassNotFoundException e) {}
103      catch (NoSuchFieldException e) {}
104
105      if (!pass)
106        throw new RuntimeException("Test 7 failed");
107
108      // Test %nojavaexception
109      NoExceptTest net = new NoExceptTest();
110
111      pass = false;
112      try {
113        net.exceptionPlease();
114	pass = true;
115      }
116      catch (MyException e) {}
117
118      if (!pass)
119        throw new RuntimeException("Test 8 failed");
120
121      net.noExceptionPlease();
122  }
123}