Merge pull request #1617 from keneanung/OdbcCommandExceptionOnNoData
[mono.git] / mono / tests / shared-generic-synchronized.2.cs
1 //
2 //  shared-generic-synchronized.2.cs:
3 //
4 //    Tests for the 'synchronized' method attribute in shared generic methods
5 //
6
7 using System;
8 using System.Threading;
9 using System.Runtime.CompilerServices;
10
11 public class Test<T> {
12
13         [MethodImplAttribute(MethodImplOptions.Synchronized)]
14         public int test () {
15                 Monitor.Exit (this);
16                 Monitor.Enter (this);
17                 return 2 + 2;
18         }
19
20         [MethodImplAttribute(MethodImplOptions.Synchronized)]
21         public static int test_static () {
22                 Monitor.Exit (typeof (Test<T>));
23                 Monitor.Enter (typeof (Test<T>));
24                 return 2 + 2;
25         }
26
27         [MethodImplAttribute(MethodImplOptions.Synchronized)]
28         public int test_exception () {
29                 Monitor.Exit (this);
30                 throw new Exception ("A");
31         }
32
33         [MethodImplAttribute(MethodImplOptions.Synchronized)]
34         public virtual int test_virtual () {
35                 Monitor.Exit (this);
36                 Monitor.Enter (this);
37                 return 2 + 2;
38         }
39 }
40
41 class main {
42         public delegate int Delegate1 ();
43
44         static public int Main (String[] args) {
45                 Test<string> b = new Test<string> ();
46                 int res;
47
48                 Console.WriteLine ("Test1...");
49                 b.test ();
50                 Console.WriteLine ("Test2...");
51                 Test<string>.test_static ();
52                 Console.WriteLine ("Test3...");
53                 try {
54                         b.test_exception ();
55                 }
56                 catch (SynchronizationLockException ex) {
57                         return 1;
58                 }
59                 catch (Exception ex) {
60                         // OK
61                 }
62
63                 Console.WriteLine ("Test4...");
64                 b.test_virtual ();
65
66                 Console.WriteLine ("Test5...");
67                 Delegate1 d = new Delegate1 (b.test);
68                 res = d ();
69
70                 Console.WriteLine ("Test6...");
71                 d = new Delegate1 (Test<string>.test_static);
72                 res = d ();
73
74                 Console.WriteLine ("Test7...");
75                 d = new Delegate1 (b.test_virtual);
76                 res = d ();
77
78                 Console.WriteLine ("Test8...");
79                 d = new Delegate1 (b.test_exception);
80                 try {
81                         d ();
82                 }
83                 catch (SynchronizationLockException ex) {
84                         return 2;
85                 }
86                 catch (Exception ex) {
87                         // OK
88                 }
89
90                 return 0;
91         }
92 }