X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Ftests%2Fsynchronized.cs;h=9d56cd8c365a121503d886399b40ec3d2a5c5081;hb=c5054e44a62c7212ec81e813793b224bf7ea245a;hp=58eda9a209ef36fe813fce6392778fefb2db047b;hpb=75df74a96c33af7a99e16e4281272f1b67334a48;p=mono.git diff --git a/mono/tests/synchronized.cs b/mono/tests/synchronized.cs index 58eda9a209e..9d56cd8c365 100644 --- a/mono/tests/synchronized.cs +++ b/mono/tests/synchronized.cs @@ -8,19 +8,20 @@ using System; using System.Threading; using System.Runtime.CompilerServices; -class Test { +class Tests { + + // We use Monitor.Pulse to test that the object is synchronized [MethodImplAttribute(MethodImplOptions.Synchronized)] public int test () { - Monitor.Exit (this); - Monitor.Enter (this); + Monitor.Pulse (this); + //Monitor.Enter (this); return 2 + 2; } [MethodImplAttribute(MethodImplOptions.Synchronized)] public static int test_static () { - Monitor.Exit (typeof (Test)); - Monitor.Enter (typeof (Test)); + Monitor.Pulse (typeof (Tests)); return 2 + 2; } @@ -32,46 +33,80 @@ class Test { [MethodImplAttribute(MethodImplOptions.Synchronized)] public virtual int test_virtual () { - Monitor.Exit (this); - Monitor.Enter (this); + Monitor.Pulse (this); return 2 + 2; } + public static bool is_synchronized (object o) { + try { + Monitor.Pulse (o); + } + catch (SynchronizationLockException ex) { + return false; + } + return true; + } + + class Gen + { + [MethodImpl(MethodImplOptions.Synchronized)] + public static void Run () + { + } + } + public delegate int Delegate1 (); static public int Main (String[] args) { - Test b = new Test (); - int res; + Tests b = new Tests (); + int res, err; Console.WriteLine ("Test1..."); b.test (); + if (is_synchronized (b)) + return 1; + Console.WriteLine ("Test2..."); test_static (); + if (is_synchronized (typeof (Tests))) + return 1; + Console.WriteLine ("Test3..."); try { b.test_exception (); } catch (SynchronizationLockException ex) { - return 1; + // OK } catch (Exception ex) { - // OK + // The other exception should be overwritten by the lock one + return 1; } + if (is_synchronized (b)) + return 1; Console.WriteLine ("Test4..."); b.test_virtual (); + if (is_synchronized (b)) + return 1; Console.WriteLine ("Test5..."); Delegate1 d = new Delegate1 (b.test); res = d (); + if (is_synchronized (b)) + return 1; Console.WriteLine ("Test6..."); d = new Delegate1 (test_static); res = d (); + if (is_synchronized (typeof (Tests))) + return 1; Console.WriteLine ("Test7..."); d = new Delegate1 (b.test_virtual); res = d (); + if (is_synchronized (b)) + return 1; Console.WriteLine ("Test8..."); d = new Delegate1 (b.test_exception); @@ -79,11 +114,22 @@ class Test { d (); } catch (SynchronizationLockException ex) { - return 2; + // OK } catch (Exception ex) { - // OK + return 2; } + if (is_synchronized (b)) + return 1; + + Monitor.Enter (typeof (Gen<>)); + Thread t = new Thread (() => + { + Gen.Run (); + }); + t.Start (); + t.Join (); + Monitor.Exit (typeof (Gen<>)); return 0; }