(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / Test / System.Runtime.Remoting / ContextTest.cs
blob6560d1b7336ae302ec1993d8b2db6671203c9123
1 //
2 // MonoTests.System.Runtime.Remoting.BaseCalls.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
5 //
6 // 2003 (C) Copyright, Novell, Inc.
7 //
9 using System;
10 using System.Threading;
11 using System.Collections;
12 using System.Runtime.Remoting;
13 using System.Runtime.Remoting.Activation;
14 using System.Runtime.Remoting.Contexts;
15 using NUnit.Framework;
17 namespace MonoTests.System.Runtime.Remoting
20 public class NeedsContextAttribute: Attribute, IContextAttribute
22 public void GetPropertiesForNewContext (IConstructionCallMessage msg) {}
23 public bool IsContextOK (Context ctx, IConstructionCallMessage msg) { return false; }
26 [NeedsContextAttribute]
27 public class TestCbo: ContextBoundObject
29 public Context GetContext ()
31 return Thread.CurrentContext;
35 [TestFixture]
36 public class ContextText: Assertion
38 TestCbo cbo = new TestCbo ();
39 Context otherCtx;
40 LocalDataStoreSlot slot;
42 [Test]
43 public void TestDoCallback ()
45 otherCtx = cbo.GetContext ();
46 Assert ("New context not created", Thread.CurrentContext != otherCtx);
48 otherCtx.DoCallBack (new CrossContextDelegate (DelegateTarget));
51 void DelegateTarget ()
53 Assert ("Wrong context", Thread.CurrentContext == otherCtx);
56 [Test]
57 public void TestDatastore ()
59 otherCtx = cbo.GetContext ();
61 slot = Context.AllocateDataSlot ();
62 LocalDataStoreSlot namedSlot1 = Context.AllocateNamedDataSlot ("slot1");
63 LocalDataStoreSlot namedSlot2 = Context.GetNamedDataSlot ("slot2");
65 Context.SetData (slot, "data");
66 Context.SetData (namedSlot1, "data1");
67 Context.SetData (namedSlot2, "data2");
69 otherCtx.DoCallBack (new CrossContextDelegate (CheckOtherContextDatastore));
71 Assert ("Wrong data 1", Context.GetData (slot).Equals ("data"));
72 Assert ("Wrong data 2", Context.GetData (namedSlot1).Equals ("data1"));
73 Assert ("Wrong data 3", Context.GetData (namedSlot2).Equals ("data2"));
75 try
77 namedSlot1 = Context.AllocateNamedDataSlot ("slot1");
78 Assert ("Exception expected",false);
80 catch {}
82 Context.FreeNamedDataSlot ("slot1");
83 Context.FreeNamedDataSlot ("slot2");
85 try
87 namedSlot1 = Context.AllocateNamedDataSlot ("slot1");
89 catch
91 Assert ("Exception not expected",false);
94 Context.FreeNamedDataSlot ("slot1");
97 void CheckOtherContextDatastore ()
99 LocalDataStoreSlot namedSlot1 = Context.GetNamedDataSlot ("slot1");
100 LocalDataStoreSlot namedSlot2 = Context.GetNamedDataSlot ("slot2");
102 Assert ("Slot already has data", Context.GetData (slot) == null);
103 Assert ("Slot already has data", Context.GetData (namedSlot1) == null);
104 Assert ("Slot already has data", Context.GetData (namedSlot2) == null);
106 Context.SetData (slot, "other data");
107 Context.SetData (namedSlot1, "other data1");
108 Context.SetData (namedSlot2, "other data2");