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

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

#
D | 123 lines | 83 code | 22 blank | 18 comment | 21 complexity | dd34e6656ba0afec62c91101003f274d 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 std.exception;
  18. import std.stdio;
  19. import director_primitives.director_primitives;
  20. import director_primitives.Base;
  21. import director_primitives.Caller;
  22. import director_primitives.Derived;
  23. import director_primitives.HShadowMode;
  24. void main() {
  25. PrintDebug = false;
  26. if (PrintDebug) writeln("------------ Start ------------ ");
  27. auto myCaller = new Caller();
  28. // Test C++ base class.
  29. {
  30. scope myBase = new Base(100.0);
  31. makeCalls(myCaller, myBase);
  32. }
  33. if (PrintDebug) writeln("--------------------------------");
  34. // Test vanilla C++ wrapped derived class.
  35. {
  36. scope Base myBase = new Derived(100.0);
  37. makeCalls(myCaller, myBase);
  38. }
  39. if (PrintDebug) writeln("--------------------------------");
  40. // Test director/D derived class.
  41. {
  42. scope Base myBase = new DDerived(300.0);
  43. makeCalls(myCaller, myBase);
  44. }
  45. if (PrintDebug) writeln("------------ Finish ------------ ");
  46. }
  47. void makeCalls(Caller myCaller, Base myBase) {
  48. myCaller.set(myBase);
  49. myCaller.NoParmsMethodCall();
  50. enforce(myCaller.BoolMethodCall(true) == true, "failed");
  51. enforce(myCaller.BoolMethodCall(false) == false, "failed");
  52. enforce(myCaller.IntMethodCall(-123) == -123, "failed");
  53. enforce(myCaller.UIntMethodCall(123) == 123, "failed");
  54. enforce(myCaller.FloatMethodCall(-123.456f) == -123.456f, "failed");
  55. enforce(myCaller.CharPtrMethodCall("test string") == "test string", "failed");
  56. enforce(myCaller.ConstCharPtrMethodCall("another string") == "another string", "failed");
  57. enforce(myCaller.EnumMethodCall(HShadowMode.HShadowHard) == HShadowMode.HShadowHard, "failed");
  58. myCaller.ManyParmsMethodCall(true, -123, 123, 123.456f, "test string", "another string", HShadowMode.HShadowHard);
  59. myCaller.NotOverriddenMethodCall();
  60. myCaller.reset();
  61. }
  62. class DDerived : Base {
  63. public:
  64. this(double dd) {
  65. super(dd);
  66. }
  67. override void NoParmsMethod() {
  68. if (PrintDebug) writeln("DDerived - NoParmsMethod()");
  69. }
  70. override bool BoolMethod(bool x) {
  71. if (PrintDebug) writefln("DDerived - BoolMethod(%s)", x);
  72. return x;
  73. }
  74. override int IntMethod(int x) {
  75. if (PrintDebug) writefln("DDerived - IntMethod(%s)", x);
  76. return x;
  77. }
  78. override uint UIntMethod(uint x) {
  79. if (PrintDebug) writefln("DDerived - UIntMethod(%s)", x);
  80. return x;
  81. }
  82. override float FloatMethod(float x) {
  83. if (PrintDebug) writefln("DDerived - FloatMethod(%s)", x);
  84. return x;
  85. }
  86. override string CharPtrMethod(string x) {
  87. if (PrintDebug) writefln("DDerived - CharPtrMethod(%s)", x);
  88. return x;
  89. }
  90. override string ConstCharPtrMethod(string x) {
  91. if (PrintDebug) writefln("DDerived - ConstCharPtrMethod(%s)", x);
  92. return x;
  93. }
  94. override HShadowMode EnumMethod(HShadowMode x) {
  95. if (PrintDebug) writefln("DDerived - EnumMethod(%s)", x);
  96. return x;
  97. }
  98. override void ManyParmsMethod(bool b, int i, uint u, float f, string c, string cc, HShadowMode h) {
  99. if (PrintDebug) writefln("DDerived - ManyParmsMethod(%s, %s, %s, %s, %s, %s, %s)", b, i, u, f, c, cc, h);
  100. }
  101. }