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