Merge remote branch 'upstream/master'
[mono.git] / nacl / test / hw.cs
1 using System;
2 using System.Runtime.CompilerServices;
3 using System.Runtime.InteropServices;
4 using System.Collections;
5 using System.Text;
6 using System.Threading;
7
8 namespace Test {
9
10         public class c_code {
11
12                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
13                 public extern static void my_c_func(int x, string s, double d);
14                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
15                 public extern static void my_c_pass(int x);
16         }
17
18         public class HelloWorld
19         {
20                 static public void Main ()
21                 {
22                 }
23
24                 static public void Foobar (int x, string s)
25                 {
26                         // first line is a simple test
27                         // 1. call back into c code 2. use mscorlib Math.Sqrt()
28                         c_code.my_c_func(x, s, Math.Sqrt(3.1415 * 3.1415));
29
30                         // second part of this test:
31                         // attempt a try/catch, generate exception w/ throw
32                         try {
33                                 c_code.my_c_pass(0);
34                                 // attempt an invalid cast
35                                 throw new InvalidCastException();
36                                 c_code.my_c_pass(1);
37                         }
38                         catch (InvalidCastException e) {
39                                 c_code.my_c_pass(2);
40                         }
41                         c_code.my_c_pass(3);
42
43                         // third part of this test:
44                         // attempt an invalid cast again, this time generating
45                         // exception instead of using explicit throw.
46                         try {
47                                 c_code.my_c_pass(0);
48                                 StringBuilder reference1 = new StringBuilder();
49                                 object reference2 = reference1;
50                                 // attempt invalid cast
51                                 int reference3 = (int)reference2;
52                                 c_code.my_c_pass(4);
53                         }
54                         catch (InvalidCastException e) {
55                                 c_code.my_c_pass(5);
56                         }
57                         c_code.my_c_pass(3);
58                 }
59         } 
60 }