PageRenderTime 31ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/csharp/director_primitives_runme.cs

#
C# | 127 lines | 96 code | 16 blank | 15 comment | 29 complexity | b5658131869d8645ac461d0f3b0cca7e MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  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. The Caller class is a tester class, which calls the virtual functions from C++.
  11. */
  12. using System;
  13. using director_primitivesNamespace;
  14. public class runme
  15. {
  16. static void Main()
  17. {
  18. runme r = new runme();
  19. r.run();
  20. }
  21. void run()
  22. {
  23. if (director_primitives.PrintDebug) Console.WriteLine("------------ Start ------------ ");
  24. Caller myCaller = new Caller();
  25. // test C++ base class
  26. using (Base myBase = new Base(100.0))
  27. {
  28. makeCalls(myCaller, myBase);
  29. }
  30. if (director_primitives.PrintDebug) Console.WriteLine("--------------------------------");
  31. // test vanilla C++ wrapped derived class
  32. using (Base myBase = new Derived(200.0))
  33. {
  34. makeCalls(myCaller, myBase);
  35. }
  36. if (director_primitives.PrintDebug) Console.WriteLine("--------------------------------");
  37. // test director / C# derived class
  38. using (Base myBase = new CSharpDerived(300.0))
  39. {
  40. makeCalls(myCaller, myBase);
  41. }
  42. if (director_primitives.PrintDebug) Console.WriteLine("------------ Finish ------------ ");
  43. }
  44. void makeCalls(Caller myCaller, Base myBase)
  45. {
  46. myCaller.set(myBase);
  47. myCaller.NoParmsMethodCall();
  48. if (myCaller.BoolMethodCall(true) != true) throw new Exception("failed");
  49. if (myCaller.BoolMethodCall(false) != false) throw new Exception("failed");
  50. if (myCaller.IntMethodCall(-123) != -123) throw new Exception("failed");
  51. if (myCaller.UIntMethodCall(123) != 123) throw new Exception("failed");
  52. if (myCaller.FloatMethodCall((float)-123.456) != (float)-123.456) throw new Exception("failed");
  53. if (myCaller.CharPtrMethodCall("test string") != "test string") throw new Exception("failed");
  54. if (myCaller.ConstCharPtrMethodCall("another string") != "another string") throw new Exception("failed");
  55. if (myCaller.EnumMethodCall(HShadowMode.HShadowHard) != HShadowMode.HShadowHard) throw new Exception("failed");
  56. myCaller.ManyParmsMethodCall(true, -123, 123, (float)123.456, "test string", "another string", HShadowMode.HShadowHard);
  57. myCaller.NotOverriddenMethodCall();
  58. myCaller.reset();
  59. }
  60. }
  61. public class CSharpDerived : Base
  62. {
  63. public CSharpDerived(double dd)
  64. : base(dd)
  65. {
  66. }
  67. public override void NoParmsMethod()
  68. {
  69. if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - NoParmsMethod()");
  70. }
  71. public override bool BoolMethod(bool x)
  72. {
  73. if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - BoolMethod({0})", x);
  74. return x;
  75. }
  76. public override int IntMethod(int x)
  77. {
  78. if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - IntMethod({0})", x);
  79. return x;
  80. }
  81. public override uint UIntMethod(uint x)
  82. {
  83. if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - UIntMethod({0})", x);
  84. return x;
  85. }
  86. public override float FloatMethod(float x)
  87. {
  88. if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - FloatMethod({0})", x);
  89. return x;
  90. }
  91. public override string CharPtrMethod(string x)
  92. {
  93. if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - CharPtrMethod({0})", x);
  94. return x;
  95. }
  96. public override string ConstCharPtrMethod(string x)
  97. {
  98. if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - ConstCharPtrMethod({0})", x);
  99. return x;
  100. }
  101. public override HShadowMode EnumMethod(HShadowMode x)
  102. {
  103. if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - EnumMethod({0})", x);
  104. return x;
  105. }
  106. public override void ManyParmsMethod(bool b, int i, uint u, float f, string c, string cc, HShadowMode h)
  107. {
  108. if (director_primitives.PrintDebug) Console.WriteLine("CSharpDerived - ManyParmsMethod({0}, {1}, {2}, {3}, {4}, {5}, {6})", b, i, u, f, c, cc, h);
  109. }
  110. }