2 // AutoResetEventTest.cs - NUnit test cases for System.Threading.AutoResetEvent
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Gert Driesen <gert.driesen@telenet.be>
8 // Copyright 2005 Novell, Inc (http://www.novell.com)
9 // Copyright 2007 Gert Driesen
12 using NUnit
.Framework
;
14 using System
.Threading
;
16 using Microsoft
.Win32
.SafeHandles
;
19 namespace MonoTests
.System
.Threading
22 public class AutoResetEventTest
25 public void MultipleSet ()
27 AutoResetEvent evt
= new AutoResetEvent (true);
28 Assert
.IsTrue (evt
.WaitOne (1000, false), "#1");
31 Assert
.IsTrue (evt
.WaitOne (1000, false), "#2");
32 Assert
.IsFalse (evt
.WaitOne (1000, false), "#3");
37 public void SafeWaitHandle ()
39 AutoResetEvent are1
= new AutoResetEvent (false);
40 AutoResetEvent are2
= new AutoResetEvent (false);
41 SafeWaitHandle swh1
= are1
.SafeWaitHandle
;
42 SafeWaitHandle swh2
= are2
.SafeWaitHandle
;
43 are1
.SafeWaitHandle
= are2
.SafeWaitHandle
;
44 Assert
.AreSame (are1
.SafeWaitHandle
, are2
.SafeWaitHandle
, "#1");
45 Assert
.AreEqual (are1
.Handle
, are2
.Handle
, "#2");
46 Assert
.IsFalse (are1
.SafeWaitHandle
.IsInvalid
, "#3");
47 Assert
.IsFalse (are1
.SafeWaitHandle
.IsClosed
, "#4");
48 Assert
.IsFalse (swh1
.IsClosed
, "#5");
49 Assert
.IsFalse (swh1
.IsInvalid
, "#6");
55 public void SafeWaitHandle_Null ()
57 AutoResetEvent are1
= new AutoResetEvent (false);
58 SafeWaitHandle swh1
= are1
.SafeWaitHandle
;
59 are1
.SafeWaitHandle
= null;
60 Assert
.IsNotNull (are1
.SafeWaitHandle
, "#1");
61 Assert
.AreEqual (-1, (int) are1
.Handle
, "#2");
62 Assert
.IsTrue (are1
.SafeWaitHandle
.IsInvalid
, "#3");
63 Assert
.IsFalse (are1
.SafeWaitHandle
.IsClosed
, "#4");
64 Assert
.IsFalse (swh1
.IsClosed
, "#5");
65 Assert
.IsFalse (swh1
.IsInvalid
, "#6");
69 public void Handle_Valid ()
71 AutoResetEvent are1
= new AutoResetEvent (false);
72 SafeWaitHandle swh1
= are1
.SafeWaitHandle
;
73 Assert
.IsFalse (swh1
.IsClosed
, "#1");
74 Assert
.IsFalse (swh1
.IsInvalid
, "#2");
75 IntPtr dummyHandle
= (IntPtr
) 2;
76 are1
.Handle
= dummyHandle
;
77 Assert
.AreEqual (are1
.Handle
, dummyHandle
, "#3");
78 Assert
.IsFalse (swh1
.IsClosed
, "#4");
79 Assert
.IsFalse (swh1
.IsClosed
, "#5");
80 Assert
.IsFalse (swh1
.IsInvalid
, "#6");
81 Assert
.IsFalse (are1
.SafeWaitHandle
.IsClosed
, "#7");
82 Assert
.IsFalse (are1
.SafeWaitHandle
.IsInvalid
, "#8");
88 public void Handle_Invalid ()
90 AutoResetEvent are1
= new AutoResetEvent (false);
91 SafeWaitHandle swh1
= are1
.SafeWaitHandle
;
92 are1
.Handle
= (IntPtr
) (-1);
93 Assert
.IsTrue (swh1
!= are1
.SafeWaitHandle
, "#1");
94 Assert
.IsFalse (swh1
.IsClosed
, "#2");
95 Assert
.IsFalse (swh1
.IsInvalid
, "#3");
96 Assert
.IsFalse (are1
.SafeWaitHandle
.IsClosed
, "#4");
97 Assert
.IsTrue (are1
.SafeWaitHandle
.IsInvalid
, "#5");
103 public void Handle_ZeroPtr ()
105 AutoResetEvent are1
= new AutoResetEvent (false);
106 SafeWaitHandle swh1
= are1
.SafeWaitHandle
;
107 are1
.Handle
= IntPtr
.Zero
;
108 Assert
.IsTrue (swh1
!= are1
.SafeWaitHandle
, "#1");
109 Assert
.IsFalse (swh1
.IsClosed
, "#2");
110 Assert
.IsFalse (swh1
.IsInvalid
, "#3");
111 Assert
.IsFalse (are1
.SafeWaitHandle
.IsClosed
, "#4");
112 Assert
.IsTrue (are1
.SafeWaitHandle
.IsInvalid
, "#5");