PageRenderTime 551ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 81 lines | 50 code | 18 blank | 13 comment | 1 complexity | 7730ff7da3d677089c6c076ca626ac17 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // This is the java_typemaps_proxy runtime testcase. Contrived example checks that the pure Java code from the Java typemaps compiles.
  2. import java_typemaps_proxy.*;
  3. import java.lang.reflect.*;
  4. public class java_typemaps_proxy_runme {
  5. static {
  6. try {
  7. System.loadLibrary("java_typemaps_proxy");
  8. } catch (UnsatisfiedLinkError e) {
  9. 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);
  10. System.exit(1);
  11. }
  12. }
  13. public static void main(String argv[]) {
  14. Greeting greet = new Greeting();
  15. Farewell bye = new Farewell();
  16. // Check that pure Java methods have been added
  17. greet.sayhello();
  18. bye.saybye(new java.math.BigDecimal(java.math.BigInteger.ONE));
  19. // No finalize method so may as well delete manually
  20. bye.delete();
  21. // Check that Greeting is derived from Exception
  22. try {
  23. throw new Greeting();
  24. } catch (Greeting g) {
  25. String msg = g.getMessage();
  26. }
  27. // Check that Greeting has implemented the EventListener interface
  28. Greeting.cheerio(greet);
  29. // The default getCPtr() call in each method will through an exception if null is passed.
  30. // Make sure the modified version works with and without null objects.
  31. Greeting.ciao(null);
  32. Greeting.ciao(greet);
  33. // Create a NULL pointer for Farewell using the constructor with changed modifiers
  34. Farewell nullFarewell = new Farewell(0, false);
  35. // Test typemaps are being found for templated classes
  36. AdieuIntPtrPtr.adieu();
  37. // Check the %javamethodmodifiers feature
  38. try {
  39. Method methodmodifiertest = nullFarewell.getClass().getDeclaredMethod("methodmodifiertest", (java.lang.Class[])null);
  40. if ( !Modifier.isPrivate(methodmodifiertest.getModifiers()) )
  41. throw new RuntimeException("NS::Farewell::methodmodifiertest not private" );
  42. } catch (NoSuchMethodException n) {
  43. throw new RuntimeException("NoSuchmethodException caught. Test failed.");
  44. } catch (SecurityException s) {
  45. throw new RuntimeException("SecurityException caught. Test failed.");
  46. }
  47. // Check the premature garbage collection prevention parameter
  48. // Check it is normally present
  49. long nullPtr = 0;
  50. With with = new With(null);
  51. java_typemaps_proxyJNI.new_With(nullPtr, with);
  52. java_typemaps_proxyJNI.With_static_method(nullPtr, with);
  53. java_typemaps_proxyJNI.With_member_method(nullPtr, with, nullPtr, with);
  54. java_typemaps_proxyJNI.delete_With(nullPtr);
  55. java_typemaps_proxyJNI.global_method_with(nullPtr, with);
  56. // Check that it can be turned off
  57. java_typemaps_proxyJNI.new_Without(nullPtr);
  58. java_typemaps_proxyJNI.Without_static_method(nullPtr);
  59. java_typemaps_proxyJNI.Without_member_method(nullPtr, nullPtr);
  60. java_typemaps_proxyJNI.delete_Without(nullPtr);
  61. java_typemaps_proxyJNI.global_method_without(nullPtr);
  62. }
  63. }