PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C# | 143 lines | 116 code | 23 blank | 4 comment | 58 complexity | f8df7143b542df90bc1f4f4e2092098a MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. using System;
  2. using default_argsNamespace;
  3. public class runme
  4. {
  5. static void Main()
  6. {
  7. if (default_args.anonymous() != 7771)
  8. throw new Exception("anonymous (1) failed");
  9. if (default_args.anonymous(1234) != 1234)
  10. throw new Exception("anonymous (2) failed");
  11. if (default_args.booltest() != true)
  12. throw new Exception("booltest (1) failed");
  13. if (default_args.booltest(true) != true)
  14. throw new Exception("booltest (2) failed");
  15. if (default_args.booltest(false) != false)
  16. throw new Exception("booltest (3) failed");
  17. EnumClass ec = new EnumClass();
  18. if (ec.blah() != true)
  19. throw new Exception("EnumClass failed");
  20. if (default_args.casts1() != null)
  21. throw new Exception("casts1 failed");
  22. if (default_args.casts2() != "Hello")
  23. throw new Exception("casts2 failed");
  24. if (default_args.casts1("Ciao") != "Ciao")
  25. throw new Exception("casts1 not default failed");
  26. if (default_args.chartest1() != 'x')
  27. throw new Exception("chartest1 failed");
  28. if (default_args.chartest2() != '\0')
  29. throw new Exception("chartest2 failed");
  30. if (default_args.chartest1('y') != 'y')
  31. throw new Exception("chartest1 not default failed");
  32. if (default_args.chartest1('y') != 'y')
  33. throw new Exception("chartest1 not default failed");
  34. if (default_args.reftest1() != 42)
  35. throw new Exception("reftest1 failed");
  36. if (default_args.reftest1(400) != 400)
  37. throw new Exception("reftest1 not default failed");
  38. if (default_args.reftest2() != "hello")
  39. throw new Exception("reftest2 failed");
  40. // rename
  41. Foo foo = new Foo();
  42. foo.newname();
  43. foo.newname(10);
  44. foo.renamed3arg(10, 10.0);
  45. foo.renamed2arg(10);
  46. foo.renamed1arg();
  47. // exception specifications
  48. try {
  49. default_args.exceptionspec();
  50. throw new Exception("exceptionspec 1 failed");
  51. } catch (Exception) {
  52. }
  53. try {
  54. default_args.exceptionspec(-1);
  55. throw new Exception("exceptionspec 2 failed");
  56. } catch (Exception) {
  57. }
  58. try {
  59. default_args.exceptionspec(100);
  60. throw new Exception("exceptionspec 3 failed");
  61. } catch (Exception) {
  62. }
  63. Except ex = new Except(false);
  64. try {
  65. ex.exspec();
  66. throw new Exception("exspec 1 failed");
  67. } catch (Exception) {
  68. }
  69. try {
  70. ex.exspec(-1);
  71. throw new Exception("exspec 2 failed");
  72. } catch (Exception) {
  73. }
  74. try {
  75. ex.exspec(100);
  76. throw new Exception("exspec 3 failed");
  77. } catch (Exception) {
  78. }
  79. try {
  80. ex = new Except(true);
  81. throw new Exception("Except constructor 1 failed");
  82. } catch (Exception) {
  83. }
  84. try {
  85. ex = new Except(true, -2);
  86. throw new Exception("Except constructor 2 failed");
  87. } catch (Exception) {
  88. }
  89. // Default parameters in static class methods
  90. if (Statics.staticmethod() != 10+20+30)
  91. throw new Exception("staticmethod 1 failed");
  92. if (Statics.staticmethod(100) != 100+20+30)
  93. throw new Exception("staticmethod 2 failed");
  94. if (Statics.staticmethod(100,200,300) != 100+200+300)
  95. throw new Exception("staticmethod 3 failed");
  96. Tricky tricky = new Tricky();
  97. if (tricky.privatedefault() != 200)
  98. throw new Exception("privatedefault failed");
  99. if (tricky.protectedint() != 2000)
  100. throw new Exception("protectedint failed");
  101. if (tricky.protecteddouble() != 987.654)
  102. throw new Exception("protecteddouble failed");
  103. if (tricky.functiondefault() != 500)
  104. throw new Exception("functiondefault failed");
  105. if (tricky.contrived() != 'X')
  106. throw new Exception("contrived failed");
  107. if (default_args.constructorcall().val != -1)
  108. throw new Exception("constructorcall test 1 failed");
  109. if (default_args.constructorcall(new Klass(2222)).val != 2222)
  110. throw new Exception("constructorcall test 2 failed");
  111. if (default_args.constructorcall(new Klass()).val != -1)
  112. throw new Exception("constructorcall test 3 failed");
  113. // const methods
  114. ConstMethods cm = new ConstMethods();
  115. if (cm.coo() != 20)
  116. throw new Exception("coo test 1 failed");
  117. if (cm.coo(1.0) != 20)
  118. throw new Exception("coo test 2 failed");
  119. }
  120. }