2 // Tests for System.Windows.Threading.Dispatcher.cs
5 // Miguel de Icaza (miguel@novell.com)
9 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
34 using System.Globalization;
35 using System.Windows.Threading;
36 using System.Threading;
38 namespace MonoTests.System.Windows.Threading
41 delegate void Action ();
44 public class DispatcherTest {
45 EventWaitHandle wait, wait2;
46 DispatcherOperation op;
49 public void DispatcherSetup ()
51 wait = new EventWaitHandle (false, EventResetMode.AutoReset);
52 wait2 = new EventWaitHandle (false, EventResetMode.AutoReset);
56 // Tests that fields in a DispatcherOperation can be issued from
60 public void TestDispatcherOpOnThread ()
62 Thread t = new Thread (new ThreadStart (thread));
63 Dispatcher d = Dispatcher.CurrentDispatcher;
66 op = Dispatcher.CurrentDispatcher.BeginInvoke (DispatcherPriority.Normal, (Action) delegate {
67 Console.WriteLine ("Some methods");
76 op.Priority = DispatcherPriority.DataBind;
81 public void TestDispatcherOrder ()
83 Dispatcher d = Dispatcher.CurrentDispatcher;
85 DispatcherFrame frame = new DispatcherFrame ();
89 d.BeginInvoke (DispatcherPriority.Normal, (Action) delegate {
91 throw new Exception ("Expected state 3, got " + next.ToString ());
94 Console.WriteLine ("First");
96 d.BeginInvoke (DispatcherPriority.Normal, (Action) delegate {
98 throw new Exception ("Expected state 4, got " + next.ToString ());
101 Console.WriteLine ("Second");
103 d.BeginInvoke (DispatcherPriority.Send, (Action) delegate {
105 throw new Exception ("Expected state 1, got " + next.ToString ());
107 Console.WriteLine ("High Priority");
108 d.BeginInvoke (DispatcherPriority.Send, (Action) delegate {
110 throw new Exception ("Expected state 2, got " + next.ToString ());
113 Console.WriteLine ("INSERTED");
116 d.BeginInvoke (DispatcherPriority.SystemIdle, (Action) delegate {
118 throw new Exception ("Expected state 6, got " + next.ToString ());
120 Console.WriteLine ("Idle");
121 frame.Continue = false;
125 d.BeginInvoke (DispatcherPriority.Normal, (Action) delegate {
127 throw new Exception ("Expected state 5, got " + next.ToString ());
129 Console.WriteLine ("Last normal");
132 Dispatcher.PushFrame (frame);
135 throw new Exception ("Expected all states to run");