1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
//
// AutoResetEventTest.cs - NUnit test cases for System.Threading.AutoResetEvent
//
// Author:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Gert Driesen <gert.driesen@telenet.be>
//
// Copyright 2005 Novell, Inc (http://www.novell.com)
// Copyright 2007 Gert Driesen
//
using NUnit.Framework;
using System;
using System.Threading;
using Microsoft.Win32.SafeHandles;
namespace MonoTests.System.Threading
{
[TestFixture]
public class AutoResetEventTest
{
[Test]
public void MultipleSet ()
{
AutoResetEvent evt = new AutoResetEvent (true);
Assert.IsTrue (evt.WaitOne (1000, false), "#1");
evt.Set ();
evt.Set ();
Assert.IsTrue (evt.WaitOne (1000, false), "#2");
Assert.IsFalse (evt.WaitOne (1000, false), "#3");
}
[Test] // bug #81529
public void SafeWaitHandle ()
{
AutoResetEvent are1 = new AutoResetEvent (false);
AutoResetEvent are2 = new AutoResetEvent (false);
SafeWaitHandle swh1 = are1.SafeWaitHandle;
SafeWaitHandle swh2 = are2.SafeWaitHandle;
are1.SafeWaitHandle = are2.SafeWaitHandle;
Assert.AreSame (are1.SafeWaitHandle, are2.SafeWaitHandle, "#1");
Assert.AreEqual (are1.Handle, are2.Handle, "#2");
Assert.IsFalse (are1.SafeWaitHandle.IsInvalid, "#3");
Assert.IsFalse (are1.SafeWaitHandle.IsClosed, "#4");
Assert.IsFalse (swh1.IsClosed, "#5");
Assert.IsFalse (swh1.IsInvalid, "#6");
swh1.Dispose ();
are1.Close ();
}
[Test] // bug #81529
public void SafeWaitHandle_Null ()
{
AutoResetEvent are1 = new AutoResetEvent (false);
SafeWaitHandle swh1 = are1.SafeWaitHandle;
are1.SafeWaitHandle = null;
Assert.IsNotNull (are1.SafeWaitHandle, "#1");
Assert.AreEqual (-1, (int) are1.Handle, "#2");
Assert.IsTrue (are1.SafeWaitHandle.IsInvalid, "#3");
Assert.IsFalse (are1.SafeWaitHandle.IsClosed, "#4");
Assert.IsFalse (swh1.IsClosed, "#5");
Assert.IsFalse (swh1.IsInvalid, "#6");
}
[Test] // bug #81529
// Causes a Attempting to unref unused handle 0x2 warning
[Category ("NotWorking")]
public void Handle_Valid ()
{
AutoResetEvent are1 = new AutoResetEvent (false);
SafeWaitHandle swh1 = are1.SafeWaitHandle;
Assert.IsFalse (swh1.IsClosed, "#1");
Assert.IsFalse (swh1.IsInvalid, "#2");
IntPtr dummyHandle = (IntPtr) 2;
are1.Handle = dummyHandle;
Assert.AreEqual (are1.Handle, dummyHandle, "#3");
Assert.IsFalse (swh1.IsClosed, "#4");
Assert.IsFalse (swh1.IsClosed, "#5");
Assert.IsFalse (swh1.IsInvalid, "#6");
Assert.IsFalse (are1.SafeWaitHandle.IsClosed, "#7");
Assert.IsFalse (are1.SafeWaitHandle.IsInvalid, "#8");
are1.Close ();
swh1.Dispose ();
}
[Test] // bug #81529
public void Handle_Invalid ()
{
AutoResetEvent are1 = new AutoResetEvent (false);
SafeWaitHandle swh1 = are1.SafeWaitHandle;
are1.Handle = (IntPtr) (-1);
Assert.IsTrue (swh1 != are1.SafeWaitHandle, "#1");
Assert.IsFalse (swh1.IsClosed, "#2");
Assert.IsFalse (swh1.IsInvalid, "#3");
Assert.IsFalse (are1.SafeWaitHandle.IsClosed, "#4");
Assert.IsTrue (are1.SafeWaitHandle.IsInvalid, "#5");
are1.Close ();
swh1.Dispose ();
}
[Test] // bug #81529
public void Handle_ZeroPtr ()
{
AutoResetEvent are1 = new AutoResetEvent (false);
SafeWaitHandle swh1 = are1.SafeWaitHandle;
are1.Handle = IntPtr.Zero;
Assert.IsTrue (swh1 != are1.SafeWaitHandle, "#1");
Assert.IsFalse (swh1.IsClosed, "#2");
Assert.IsFalse (swh1.IsInvalid, "#3");
Assert.IsFalse (are1.SafeWaitHandle.IsClosed, "#4");
Assert.IsTrue (are1.SafeWaitHandle.IsInvalid, "#5");
are1.Close ();
swh1.Dispose ();
}
}
}
|