PageRenderTime 32ms CodeModel.GetById 19ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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