[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / corlib / Test / System.Runtime.Remoting / ContextTest.cs
blobdef91e42b8809b2dd072e2b2a59b9394eb6827a2
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 ContextTest
38 TestCbo cbo = new TestCbo ();
39 Context otherCtx;
40 LocalDataStoreSlot slot;
42 [Test]
43 public void TestDoCallback ()
45 otherCtx = cbo.GetContext ();
46 Assert.IsTrue (Thread.CurrentContext != otherCtx, "New context not created");
48 otherCtx.DoCallBack (new CrossContextDelegate (DelegateTarget));
51 void DelegateTarget ()
53 Assert.IsTrue (Thread.CurrentContext == otherCtx, "Wrong context");
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.IsTrue (Context.GetData (slot).Equals ("data"), "Wrong data 1");
72 Assert.IsTrue (Context.GetData (namedSlot1).Equals ("data1"), "Wrong data 2");
73 Assert.IsTrue (Context.GetData (namedSlot2).Equals ("data2"), "Wrong data 3");
75 try
77 namedSlot1 = Context.AllocateNamedDataSlot ("slot1");
78 Assert.Fail ("Exception expected");
80 catch {}
82 Context.FreeNamedDataSlot ("slot1");
83 Context.FreeNamedDataSlot ("slot2");
85 try
87 namedSlot1 = Context.AllocateNamedDataSlot ("slot1");
89 catch
91 Assert.Fail ("Exception not expected");
94 Context.FreeNamedDataSlot ("slot1");
97 void CheckOtherContextDatastore ()
99 LocalDataStoreSlot namedSlot1 = Context.GetNamedDataSlot ("slot1");
100 LocalDataStoreSlot namedSlot2 = Context.GetNamedDataSlot ("slot2");
102 Assert.IsTrue (Context.GetData (slot) == null, "Slot already has data");
103 Assert.IsTrue (Context.GetData (namedSlot1) == null, "Slot already has data");
104 Assert.IsTrue (Context.GetData (namedSlot2) == null, "Slot already has data");
106 Context.SetData (slot, "other data");
107 Context.SetData (namedSlot1, "other data1");
108 Context.SetData (namedSlot2, "other data2");