summaryrefslogtreecommitdiff
path: root/Examples/test-suite/csharp/director_primitives_runme.cs
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2009-08-18 20:56:02 +0000
committerLorry <lorry@roadtrain.codethink.co.uk>2012-09-25 16:59:08 +0000
commit9f8a09ed743cedd9547bf0661d518647966ab114 (patch)
tree9c7803d3b27a8ec22e91792ac7f7932efa128b20 /Examples/test-suite/csharp/director_primitives_runme.cs
downloadswig-tarball-master.tar.gz
Imported from /srv/lorry/lorry-area/swig-tarball/swig-1.3.40.tar.gz.HEADswig-1.3.40master
Diffstat (limited to 'Examples/test-suite/csharp/director_primitives_runme.cs')
-rw-r--r--Examples/test-suite/csharp/director_primitives_runme.cs127
1 files changed, 127 insertions, 0 deletions
diff --git a/Examples/test-suite/csharp/director_primitives_runme.cs b/Examples/test-suite/csharp/director_primitives_runme.cs
new file mode 100644
index 0000000..0a8f705
--- /dev/null
+++ b/Examples/test-suite/csharp/director_primitives_runme.cs
@@ -0,0 +1,127 @@
+/*
+ This test program shows a C# class CSharpDerived inheriting from Base. Three types of classes are created
+ and the virtual methods called to demonstrate:
+ 1) Wide variety of primitive types
+ 2) Calling methods with zero, one or more parameters
+ 3) Director methods that are not overridden in C#
+ 4) Director classes that are not overridden at all in C#, ie non-director behaviour is as expected for director classes
+ 5) Inheritance hierarchy using director methods
+ 6) Return types working as well as parameters
+
+ The Caller class is a tester class, which calls the virtual functions from C++.
+*/
+
+using System;
+using director_primitivesNamespace;
+
+public class runme
+{
+ static void Main()
+ {
+ runme r = new runme();
+ r.run();
+ }
+
+ void run()
+ {
+ if (director_primitives.PrintDebug) Console.WriteLine("------------ Start ------------ ");
+
+ Caller myCaller = new Caller();
+
+ // test C++ base class
+ using (Base myBase = new Base(100.0))
+ {
+ makeCalls(myCaller, myBase);
+ }
+
+ if (director_primitives.PrintDebug) Console.WriteLine("--------------------------------");
+
+ // test vanilla C++ wrapped derived class
+ using (Base myBase = new Derived(200.0))
+ {
+ makeCalls(myCaller, myBase);
+ }
+
+ if (director_primitives.PrintDebug) Console.WriteLine("--------------------------------");
+
+ // test director / C# derived class
+ using (Base myBase = new CSharpDerived(300.0))
+ {
+ makeCalls(myCaller, myBase);
+ }
+
+ if (director_primitives.PrintDebug) Console.WriteLine("------------ Finish ------------ ");
+ }
+
+ void makeCalls(Caller myCaller, Base myBase)
+ {
+ myCaller.set(myBase);
+
+ myCaller.NoParmsMethodCall();
+ if (myCaller.BoolMethodCall(true) != true) throw new Exception("failed");
+ if (myCaller.BoolMethodCall(false) != false) throw new Exception("failed");
+ if (myCaller.IntMethodCall(-123) != -123) throw new Exception("failed");
+ if (myCaller.UIntMethodCall(123) != 123) throw new Exception("failed");
+ if (myCaller.FloatMethodCall((float)-123.456) != (float)-123.456) throw new Exception("failed");
+ if (myCaller.CharPtrMethodCall("test string") != "test string") throw new Exception("failed");
+ if (myCaller.ConstCharPtrMethodCall("another string") != "another string") throw new Exception("failed");
+ if (myCaller.EnumMethodCall(HShadowMode.HShadowHard) != HShadowMode.HShadowHard) throw new Exception("failed");
+ myCaller.ManyParmsMethodCall(true, -123, 123, (float)123.456, "test string", "another string", HShadowMode.HShadowHard);
+ myCaller.NotOverriddenMethodCall();
+
+ myCaller.reset();
+ }
+}
+
+public class CSharpDerived : Base
+{
+ public CSharpDerived(double dd)
+ : base(dd)
+ {
+ }
+
+ public override void NoParmsMethod()
+ {
+ if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - NoParmsMethod()");
+ }
+ public override bool BoolMethod(bool x)
+ {
+ if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - BoolMethod({0})", x);
+ return x;
+ }
+ public override int IntMethod(int x)
+ {
+ if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - IntMethod({0})", x);
+ return x;
+ }
+ public override uint UIntMethod(uint x)
+ {
+ if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - UIntMethod({0})", x);
+ return x;
+ }
+ public override float FloatMethod(float x)
+ {
+ if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - FloatMethod({0})", x);
+ return x;
+ }
+ public override string CharPtrMethod(string x)
+ {
+ if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - CharPtrMethod({0})", x);
+ return x;
+ }
+ public override string ConstCharPtrMethod(string x)
+ {
+ if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - ConstCharPtrMethod({0})", x);
+ return x;
+ }
+ public override HShadowMode EnumMethod(HShadowMode x)
+ {
+ if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - EnumMethod({0})", x);
+ return x;
+ }
+ public override void ManyParmsMethod(bool b, int i, uint u, float f, string c, string cc, HShadowMode h)
+ {
+ if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - ManyParmsMethod({0}, {1}, {2}, {3}, {4}, {5}, {6})", b, i, u, f, c, cc, h);
+ }
+}
+