PageRenderTime 51ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-26/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. 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 newfree typemap throws attribute
  35. try {
  36. TestClass tc = java_throws.makeTestClass();
  37. }
  38. catch (NoSuchMethodException e) {}
  39. // Check javaout typemap throws attribute
  40. pass = false;
  41. try {
  42. int myInt = java_throws.ioTest();
  43. }
  44. catch (java.io.IOException e) { pass = true; }
  45. if (!pass)
  46. throw new RuntimeException("Test 4 failed");
  47. // Check except feature throws attribute...
  48. // Static method
  49. pass = false;
  50. try {
  51. FeatureTest.staticMethod();
  52. }
  53. catch (MyException e) { pass = true; }
  54. if (!pass)
  55. throw new RuntimeException("Test 5 failed");
  56. FeatureTest f = null;
  57. try {
  58. f = new FeatureTest();
  59. }
  60. catch (MyException e) {}
  61. // Instance method
  62. pass = false;
  63. try {
  64. f.method();
  65. }
  66. catch (MyException e) { pass = true; }
  67. if (!pass)
  68. throw new RuntimeException("Test 6 failed");
  69. // Global function
  70. pass = false;
  71. try {
  72. java_throws.globalFunction(10);
  73. }
  74. catch (MyException e) { pass = true; }
  75. catch (ClassNotFoundException e) {}
  76. catch (NoSuchFieldException e) {}
  77. if (!pass)
  78. throw new RuntimeException("Test 7 failed");
  79. }
  80. }