PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 80 lines | 56 code | 12 blank | 12 comment | 20 complexity | 4b595f1fe1268bf6b61a4830ccfac5ac MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // This tests changes the package name from nspace to nspacePackage as javac can't seem to resolve classes and packages having the same name
  2. public class nspace_runme {
  3. static {
  4. try {
  5. System.loadLibrary("nspace");
  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. // constructors and destructors
  13. nspacePackage.Outer.Inner1.Color color1 = new nspacePackage.Outer.Inner1.Color();
  14. nspacePackage.Outer.Inner1.Color color = new nspacePackage.Outer.Inner1.Color(color1);
  15. color1.delete();
  16. color1 = null;
  17. // class methods
  18. color.colorInstanceMethod(20.0);
  19. nspacePackage.Outer.Inner1.Color.colorStaticMethod(20.0);
  20. nspacePackage.Outer.Inner1.Color created = nspacePackage.Outer.Inner1.Color.create();
  21. // class enums
  22. nspacePackage.Outer.SomeClass someClass = new nspacePackage.Outer.SomeClass();
  23. nspacePackage.Outer.Inner1.Color.Channel channel = someClass.GetInner1ColorChannel();
  24. if (channel != nspacePackage.Outer.Inner1.Color.Channel.Transmission)
  25. throw new RuntimeException("Transmission wrong");
  26. // class anonymous enums
  27. int val1 = nspacePackage.Outer.Inner1.Color.ColorEnumVal1;
  28. int val2 = nspacePackage.Outer.Inner1.Color.ColorEnumVal2;
  29. if (val1 != 0 || val2 != 0x22)
  30. throw new RuntimeException("ColorEnumVal wrong");
  31. // instance member variables
  32. color.setInstanceMemberVariable(123);
  33. if (color.getInstanceMemberVariable() != 123)
  34. throw new RuntimeException("instance member variable failed");
  35. // static member variables
  36. nspacePackage.Outer.Inner1.Color.setStaticMemberVariable(789);
  37. if (nspacePackage.Outer.Inner1.Color.getStaticMemberVariable() != 789)
  38. throw new RuntimeException("static member variable failed");
  39. if (nspacePackage.Outer.Inner1.Color.staticConstMemberVariable != 222)
  40. throw new RuntimeException("static const member variable failed");
  41. if (nspacePackage.Outer.Inner1.Color.staticConstEnumMemberVariable != nspacePackage.Outer.Inner1.Color.Channel.Transmission)
  42. throw new RuntimeException("static const enum member variable failed");
  43. // Same class different namespaces
  44. nspacePackage.Outer.Inner1.Color col1 = new nspacePackage.Outer.Inner1.Color();
  45. nspacePackage.Outer.Inner2.Color col2 = nspacePackage.Outer.Inner2.Color.create();
  46. col2.colors(col1, col1, col2, col2, col2);
  47. // check globals in a namespace don't get mangled with the nspacePackage option
  48. nspacePackage.nspace.namespaceFunction(color);
  49. nspacePackage.nspace.setNamespaceVar(111);
  50. if (nspacePackage.nspace.getNamespaceVar() != 111)
  51. throw new RuntimeException("global var failed");
  52. // global enums
  53. nspacePackage.Outer.Inner1.Channel outerChannel1 = someClass.GetInner1Channel();
  54. if (outerChannel1 != nspacePackage.Outer.Inner1.Channel.Transmission1)
  55. throw new RuntimeException("Transmission1 wrong");
  56. nspacePackage.Outer.Inner2.Channel outerChannel2 = someClass.GetInner2Channel();
  57. if (outerChannel2 != nspacePackage.Outer.Inner2.Channel.Transmission2)
  58. throw new RuntimeException("Transmission2 wrong");
  59. // turn feature off / ignoring
  60. nspacePackage.Outer.namespce ns = new nspacePackage.Outer.namespce();
  61. nspacePackage.NoNSpacePlease nons = new nspacePackage.NoNSpacePlease();
  62. // Derived class
  63. nspacePackage.Outer.Inner3.Blue blue3 = new nspacePackage.Outer.Inner3.Blue();
  64. blue3.blueInstanceMethod();
  65. nspacePackage.Outer.Inner4.Blue blue4 = new nspacePackage.Outer.Inner4.Blue();
  66. blue4.blueInstanceMethod();
  67. }
  68. }