2 // MonoTests.Remoting.GenericTest.cs
5 // Robert Jordan <robertj@gmx.net>
11 using System
.Collections
;
12 using System
.Runtime
.Remoting
;
13 using System
.Runtime
.Remoting
.Channels
;
14 using System
.Runtime
.Remoting
.Channels
.Tcp
;
15 using System
.Runtime
.Remoting
.Channels
.Http
;
16 using System
.Runtime
.Remoting
.Channels
.Ipc
;
17 using System
.Threading
;
18 using NUnit
.Framework
;
20 namespace MonoTests
.Remoting
22 public interface INested
26 int Test (int a
, int b
);
28 V Test
<V
, T
> (V v
, T t
);
31 public interface ITest
34 int TestDirectIfaceImpl (int i
);
36 INested
GetNestedMbr ();
39 public class ServerBase
<T
> : MarshalByRefObject
, ITest
41 public virtual V TestVirt
<V
> (V v
)
46 public V TestIface
<V
> (V v
)
51 int ITest
.TestDirectIfaceImpl (int i
)
56 public int TestDirectIfaceImpl (int i
)
61 public INested
GetNested ()
66 public INested
GetNested (string s
)
71 public INested
GetNestedMbr ()
73 return new NestedMbr ();
77 public class Server
<T
> : ServerBase
<T
>
79 public override V TestVirt
<V
> (V v
)
86 public class Nested
: INested
98 public int Test (int i
)
103 int INested
.Test (int a
, int b
)
108 public V Test
<V
> (V v
)
113 V INested
.Test
<V
, T
> (V v
, T t
)
119 public class NestedMbr
: MarshalByRefObject
, INested
131 public int Test (int i
)
136 int INested
.Test (int a
, int b
)
141 public V Test
<V
> (V v
)
146 V INested
.Test
<V
, T
> (V v
, T t
)
154 public class GenericTest
156 // Under MS.NET, INested.Test<V>(V v) isn't supported over the
157 // xappdom channel anymore (as of .NET 3.5). The stacktrace
158 // looks like if INested.Test(int) is invoked in place of
159 // INested.Test<int>(int).
160 [Category("NotDotNet")]
162 public void TestCrossAppDomainChannel ()
164 RunTests (RegisterAndConnect
<Server
<object>> ());
168 public void TestTcpChannel ()
170 IDictionary props
= new Hashtable ();
171 props
["name"] = Guid
.NewGuid ().ToString("N");
172 props
["port"] = 18191;
173 TcpChannel chan
= new TcpChannel (props
, null, null);
174 ChannelServices
.RegisterChannel (chan
);
177 Register
<Server
<object>> ("gentcptest.rem");
178 RunTests (Connect
<Server
<object>> ("tcp://localhost:18191/gentcptest.rem"));
180 ChannelServices
.UnregisterChannel (chan
);
184 static T RegisterAndConnect
<T
> () where T
: MarshalByRefObject
186 AppDomain d
= BaseCallTest
.CreateDomain ("GenericTests");
187 return (T
) d
.CreateInstanceAndUnwrap (
188 typeof (T
).Assembly
.FullName
,
189 typeof (T
).FullName
);
192 static void Register
<T
> (string uri
) where T
: MarshalByRefObject
194 object obj
= Activator
.CreateInstance (typeof(T
));
195 RemotingServices
.Marshal ((MarshalByRefObject
)obj
, uri
);
198 static T Connect
<T
> (string uri
) where T
: MarshalByRefObject
200 return (T
) RemotingServices
.Connect (typeof (T
), uri
);
203 static void RunTests (ServerBase
<object> rem
)
205 Assert
.AreEqual (42, rem
.TestIface
<int>(42),
206 "#1 calling TestIface on object instance");
208 Assert
.AreEqual (42, rem
.TestVirt
<int>(42),
209 "#2 calling TestVirt");
212 Assert
.AreEqual (42, i
.TestIface
<int>(42),
213 "#3 calling TestIface on interface");
215 Assert
.AreEqual (42, i
.TestDirectIfaceImpl (42),
216 "#4 calling TestDirectIfaceImp");
218 INested cao
= rem
.GetNested ();
219 Assert
.AreEqual (42, cao
.Test (),
220 "#5a calling INested.Test ()");
222 Assert
.AreEqual (42 + 500, cao
.Test (42),
223 "#5 calling INested.Test (int)");
225 Assert
.AreEqual (42, cao
.Test (21, 21),
226 "#6 calling INested.Test (int, int)");
228 Assert
.AreEqual (42, cao
.Test
<int> (42),
229 "#7 calling INested.Test<V>");
231 Assert
.AreEqual (0, cao
.Test
<int, string> (42, "bar"),
232 "#8 calling INested.Test<V, T>");
234 cao
= rem
.GetNestedMbr ();
235 Assert
.AreEqual (42, cao
.Test (),
236 "#9a calling INested.Test ()");
238 Assert
.AreEqual (42 + 500, cao
.Test (42),
239 "#9 calling INested.Test (int)");
241 Assert
.AreEqual (42, cao
.Test (21, 21),
242 "#10 calling INested.Test (int, int)");
244 Assert
.AreEqual (42, cao
.Test
<int> (42),
245 "#11 calling INested.Test<V>");
247 Assert
.AreEqual (0, cao
.Test
<int, string> (42, "bar"),
248 "#12 calling INested.Test<V, T>");