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