PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 138 lines | 105 code | 18 blank | 15 comment | 27 complexity | 8517853de2525e2531131182b78fdd48 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /*
  2. This test program shows a C# class JavaDerived inheriting from Base. Three types of classes are created
  3. and the virtual methods called to demonstrate:
  4. 1) Wide variety of primitive types
  5. 2) Calling methods with zero, one or more parameters
  6. 3) Director methods that are not overridden in C#
  7. 4) Director classes that are not overridden at all in C#, ie non-director behaviour is as expected for director classes
  8. 5) Inheritance hierarchy using director methods
  9. 6) Return types working as well as parameters
  10. The Caller class is a tester class, which calls the virtual functions from C++.
  11. */
  12. import director_primitives.*;
  13. public class director_primitives_runme {
  14. static {
  15. try {
  16. System.loadLibrary("director_primitives");
  17. } catch (UnsatisfiedLinkError e) {
  18. 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);
  19. System.exit(1);
  20. }
  21. }
  22. public static void main(String argv[]) throws Throwable
  23. {
  24. director_primitives_runme r = new director_primitives_runme();
  25. r.run();
  26. }
  27. void run()
  28. {
  29. if (director_primitives.getPrintDebug()) System.out.println("------------ Start ------------ ");
  30. Caller myCaller = new Caller();
  31. // test C++ base class
  32. {
  33. Base myBase = new Base(100.0);
  34. makeCalls(myCaller, myBase);
  35. myBase.delete();
  36. }
  37. if (director_primitives.getPrintDebug()) System.out.println("--------------------------------");
  38. // test vanilla C++ wrapped derived class
  39. {
  40. Base myBase = new Derived(200.0);
  41. makeCalls(myCaller, myBase);
  42. myBase.delete();
  43. }
  44. if (director_primitives.getPrintDebug()) System.out.println("--------------------------------");
  45. // test director / C# derived class
  46. {
  47. Base myBase = new JavaDerived(300.0);
  48. makeCalls(myCaller, myBase);
  49. myBase.delete();
  50. }
  51. if (director_primitives.getPrintDebug()) System.out.println("------------ Finish ------------ ");
  52. }
  53. void makeCalls(Caller myCaller, Base myBase)
  54. {
  55. myCaller.set(myBase);
  56. myCaller.NoParmsMethodCall();
  57. if (myCaller.BoolMethodCall(true) != true) throw new RuntimeException("failed");
  58. if (myCaller.BoolMethodCall(false) != false) throw new RuntimeException("failed");
  59. if (myCaller.IntMethodCall(-123) != -123) throw new RuntimeException("failed");
  60. if (myCaller.UIntMethodCall(123) != 123) throw new RuntimeException("failed");
  61. if (myCaller.FloatMethodCall((float)-123.456) != (float)-123.456) throw new RuntimeException("failed");
  62. if (!myCaller.CharPtrMethodCall("test string").equals("test string")) throw new RuntimeException("failed");
  63. if (!myCaller.ConstCharPtrMethodCall("another string").equals("another string")) throw new RuntimeException("failed");
  64. if (myCaller.EnumMethodCall(HShadowMode.HShadowHard) != HShadowMode.HShadowHard) throw new RuntimeException("failed");
  65. myCaller.ManyParmsMethodCall(true, -123, 123, (float)123.456, "test string", "another string", HShadowMode.HShadowHard);
  66. myCaller.NotOverriddenMethodCall();
  67. myCaller.reset();
  68. }
  69. }
  70. class JavaDerived extends Base
  71. {
  72. public JavaDerived(double dd)
  73. {
  74. super(dd);
  75. }
  76. public void NoParmsMethod()
  77. {
  78. if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - NoParmsMethod()");
  79. }
  80. public boolean BoolMethod(boolean x)
  81. {
  82. if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - BoolMethod(" + x + ")");
  83. return x;
  84. }
  85. public int IntMethod(int x)
  86. {
  87. if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - IntMethod(" + x + ")");
  88. return x;
  89. }
  90. public long UIntMethod(long x)
  91. {
  92. if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - UIntMethod(" + x + ")");
  93. return x;
  94. }
  95. public float FloatMethod(float x)
  96. {
  97. if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - FloatMethod(" + x + ")");
  98. return x;
  99. }
  100. public String CharPtrMethod(String x)
  101. {
  102. if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - CharPtrMethod(" + x + ")");
  103. return x;
  104. }
  105. public String ConstCharPtrMethod(String x)
  106. {
  107. if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - ConstCharPtrMethod(" + x + ")");
  108. return x;
  109. }
  110. public HShadowMode EnumMethod(HShadowMode x)
  111. {
  112. if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - EnumMethod(" + x + ")");
  113. return x;
  114. }
  115. public void ManyParmsMethod(boolean b, int i, long u, float f, String c, String cc, HShadowMode h)
  116. {
  117. if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - ManyParmsMethod(" + b + ", " + i + ", " + u + ", " + f + ", " + c + ", " + cc + ", " + h);
  118. }
  119. }