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