PageRenderTime 26ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/d/director_primitives_runme.1.d

#
D | 122 lines | 82 code | 22 blank | 18 comment | 29 complexity | 0a514228fc26c10c79c7105b0a403aa9 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /**
  2. * This test program shows a D class DDerived inheriting from Base.
  3. *
  4. * Three types of classes are created and the virtual methods called to
  5. * demonstrate:
  6. * - Wide variety of primitive types
  7. * - Calling methods with zero, one or more parameters
  8. * - Director methods that are not overridden in D
  9. * - Director classes that are not overridden at all in D, i.e. non-director
  10. * behaviour is as expected for director classes
  11. * - Inheritance hierarchy using director methods
  12. * - Return types working as well as parameters
  13. *
  14. * The Caller class is a tester class which calls the virtual functions from C++.
  15. */
  16. module director_primitives_runme;
  17. import tango.io.Stdout;
  18. import director_primitives.director_primitives;
  19. import director_primitives.Base;
  20. import director_primitives.Caller;
  21. import director_primitives.Derived;
  22. import director_primitives.HShadowMode;
  23. void main() {
  24. PrintDebug = false;
  25. if (PrintDebug) Stdout("------------ Start ------------ ").newline;
  26. Caller myCaller = new Caller();
  27. // Test C++ base class.
  28. {
  29. scope myBase = new Base(100.0);
  30. makeCalls(myCaller, myBase);
  31. }
  32. if (PrintDebug) Stdout("--------------------------------").newline;
  33. // Test vanilla C++ wrapped derived class.
  34. {
  35. scope Base myBase = new Derived(100.0);
  36. makeCalls(myCaller, myBase);
  37. }
  38. if (PrintDebug) Stdout("--------------------------------").newline;
  39. // Test director/D derived class.
  40. {
  41. scope Base myBase = new DDerived(300.0);
  42. makeCalls(myCaller, myBase);
  43. }
  44. if (PrintDebug) Stdout("------------ Finish ------------ ").newline;
  45. }
  46. void makeCalls(Caller myCaller, Base myBase) {
  47. myCaller.set(myBase);
  48. myCaller.NoParmsMethodCall();
  49. if (myCaller.BoolMethodCall(true) != true) throw new Exception("failed");
  50. if (myCaller.BoolMethodCall(false) != false) throw new Exception("failed");
  51. if (myCaller.IntMethodCall(-123) != -123) throw new Exception("failed");
  52. if (myCaller.UIntMethodCall(123) != 123) throw new Exception("failed");
  53. if (myCaller.FloatMethodCall(-123.456f) != -123.456f) throw new Exception("failed");
  54. if (myCaller.CharPtrMethodCall("test string") != "test string") throw new Exception("failed");
  55. if (myCaller.ConstCharPtrMethodCall("another string") != "another string") throw new Exception("failed");
  56. if (myCaller.EnumMethodCall(HShadowMode.HShadowHard) != HShadowMode.HShadowHard) throw new Exception("failed");
  57. myCaller.ManyParmsMethodCall(true, -123, 123, 123.456f, "test string", "another string", HShadowMode.HShadowHard);
  58. myCaller.NotOverriddenMethodCall();
  59. myCaller.reset();
  60. }
  61. class DDerived : Base {
  62. public:
  63. this(double dd) {
  64. super(dd);
  65. }
  66. override void NoParmsMethod() {
  67. if (PrintDebug) Stdout("DDerived - NoParmsMethod()").newline;
  68. }
  69. override bool BoolMethod(bool x) {
  70. if (PrintDebug) Stdout.formatln("DDerived - BoolMethod({0})", x);
  71. return x;
  72. }
  73. override int IntMethod(int x) {
  74. if (PrintDebug) Stdout.formatln("DDerived - IntMethod({0})", x);
  75. return x;
  76. }
  77. override uint UIntMethod(uint x) {
  78. if (PrintDebug) Stdout.formatln("DDerived - UIntMethod({0})", x);
  79. return x;
  80. }
  81. override float FloatMethod(float x) {
  82. if (PrintDebug) Stdout.formatln("DDerived - FloatMethod({0})", x);
  83. return x;
  84. }
  85. override char[] CharPtrMethod(char[] x) {
  86. if (PrintDebug) Stdout.formatln("DDerived - CharPtrMethod({0})", x);
  87. return x;
  88. }
  89. override char[] ConstCharPtrMethod(char[] x) {
  90. if (PrintDebug) Stdout.formatln("DDerived - ConstCharPtrMethod({0})", x);
  91. return x;
  92. }
  93. override HShadowMode EnumMethod(HShadowMode x) {
  94. if (PrintDebug) Stdout.formatln("DDerived - EnumMethod({0})", x);
  95. return x;
  96. }
  97. override void ManyParmsMethod(bool b, int i, uint u, float f, char[] c, char[] cc, HShadowMode h) {
  98. if (PrintDebug) Stdout.formatln("DDerived - ManyParmsMethod({0}, {1}, {2}, {3:d3}, {4}, {5}, {6})", b, i, u, f, c, cc, h);
  99. }
  100. }