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