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