[interp] Reduce computation under calc_section mutex
[mono-project.git] / mcs / tests / test-53.cs
blob6e921d8bfa5035378c8ac09957a4fa63983a0c9f
1 //
2 // Tests the using statement implementation
3 //
4 using System;
5 using System.IO;
7 class MyDispose : IDisposable {
8 public bool disposed;
10 public void Dispose ()
12 disposed = true;
16 class X {
17 public static int Main ()
19 MyDispose copy_a, copy_b, copy_c;
22 // Test whether the two `a' and `b' get disposed
24 using (MyDispose a = new MyDispose (), b = new MyDispose ()){
25 copy_a = a;
26 copy_b = b;
29 if (!copy_a.disposed)
30 return 1;
31 if (!copy_b.disposed)
32 return 2;
34 Console.WriteLine ("Nested using clause disposed");
37 // See if the variable `b' is disposed if there is
38 // an error thrown inside the using block.
40 copy_c = null;
41 try {
42 using (MyDispose c = new MyDispose ()){
43 copy_c = c;
44 throw new Exception ();
46 } catch {}
48 if (!copy_c.disposed)
49 return 3;
50 else
51 Console.WriteLine ("Disposal on finally block works");
54 // This should test if `a' is non-null before calling dispose
55 // implicitly
57 using (MyDispose d = null){
60 Console.WriteLine ("Null test passed");
62 MyDispose bb = new MyDispose ();
63 using (bb){
66 if (bb.disposed == false)
67 return 6;
69 Console.WriteLine ("All tests pass");
70 return 0;