Author: robertj
Date: 2007-09-08 19:16:34 -0400 (Sat, 08 Sep 2007)
New Revision: 85527
Modified:
trunk/mcs/class/System.Runtime.Remoting/Test/ChangeLog
trunk/mcs/class/System.Runtime.Remoting/Test/GenericTest.cs
Log:
2007-09-09 Robert Jordan <[EMAIL PROTECTED]>
* GenericTest.cs: Add tests for bug #78882, #81554.
Modified: trunk/mcs/class/System.Runtime.Remoting/Test/ChangeLog
===================================================================
--- trunk/mcs/class/System.Runtime.Remoting/Test/ChangeLog 2007-09-08
22:36:32 UTC (rev 85526)
+++ trunk/mcs/class/System.Runtime.Remoting/Test/ChangeLog 2007-09-08
23:16:34 UTC (rev 85527)
@@ -1,3 +1,7 @@
+2007-09-09 Robert Jordan <[EMAIL PROTECTED]>
+
+ * GenericTest.cs: Add tests for bug #78882, #81554.
+
2007-06-05 Robert Jordan <[EMAIL PROTECTED]>
* RemotingServicesTest.cs: Add test for bug #81811.
Modified: trunk/mcs/class/System.Runtime.Remoting/Test/GenericTest.cs
===================================================================
--- trunk/mcs/class/System.Runtime.Remoting/Test/GenericTest.cs 2007-09-08
22:36:32 UTC (rev 85526)
+++ trunk/mcs/class/System.Runtime.Remoting/Test/GenericTest.cs 2007-09-08
23:16:34 UTC (rev 85527)
@@ -18,81 +18,183 @@
namespace MonoTests.Remoting
{
- class Server <T> : MarshalByRefObject
+ public interface INested
{
- public T Field;
+ int Test (int i);
+ int Test (int a, int b);
+ V Test <V> (V v);
+ V Test <V, T> (V v, T t);
+ }
- public void Test ()
+ public interface ITest
+ {
+ V TestIface<V> (V v);
+ int TestDirectIfaceImpl (int i);
+ INested GetNested ();
+ INested GetNestedMbr ();
+ }
+
+ public class ServerBase<T> : MarshalByRefObject, ITest
+ {
+ public virtual V TestVirt<V> (V v)
{
+ return default (V);
}
- public V Test2 <V> (V v)
+ public V TestIface<V> (V v)
{
return v;
}
- public T Test3 (T t)
+ int ITest.TestDirectIfaceImpl (int i)
{
- return t;
+ return i;
}
+
+ public INested GetNested ()
+ {
+ return new Nested ();
+ }
+
+ public INested GetNested (string s)
+ {
+ return new Nested ();
+ }
+
+ public INested GetNestedMbr ()
+ {
+ return new NestedMbr ();
+ }
}
- [TestFixture]
- public class GenericTest
+ public class Server<T> : ServerBase<T>
{
- class Helper
+ public override V TestVirt<V> (V v)
{
- public static void Test (string url)
- {
- // create server
- Server <int> server = new Server <int> ();
- RemotingServices.Marshal (server, "test");
- try {
- // create client
- Server <int> client = (Server <int>)
RemotingServices.Connect (
- typeof (Server <int>), url);
-
- // invoke
- client.Test ();
- Assert.AreEqual ("hello", client.Test2
<string> ("hello"), "#01");
- Assert.AreEqual (42, client.Test3 (42),
"#02");
+ return v;
+ }
+ }
- } finally {
- RemotingServices.Disconnect (server);
- }
- }
+ [Serializable]
+ public class Nested : INested
+ {
+ public int Test (int i)
+ {
+ return i;
}
- [Test]
- public void TestTcp ()
+ int INested.Test (int a, int b)
{
- TcpChannel c = new TcpChannel (18181);
- Helper.Test ("tcp://127.0.0.1:18181/test");
- c.StopListening (null);
+ return a + b;
}
+ public V Test <V> (V v)
+ {
+ return v;
+ }
+
+ V INested.Test <V, T> (V v, T t)
+ {
+ return default (V);
+ }
+ }
+
+ public class NestedMbr : MarshalByRefObject, INested
+ {
+ public int Test (int i)
+ {
+ return i;
+ }
+
+ int INested.Test (int a, int b)
+ {
+ return a + b;
+ }
+
+ public V Test <V> (V v)
+ {
+ return v;
+ }
+
+ V INested.Test <V, T> (V v, T t)
+ {
+ return default (V);
+ }
+ }
+
+
+ [TestFixture]
+ public class GenericTest
+ {
[Test]
- public void TestIpc ()
+ public void TestCrossAppDomainChannel ()
{
- string portName = "ipc" + Guid.NewGuid ().ToString
("N");
- IpcChannel c = new IpcChannel (portName);
- // FIXME: the named pipe of the Win32 IpcServerChannel
- // seems to require a sleep because the pipe is not
- // ready immediately after creation.
- Thread.Sleep (1000);
- Helper.Test ("ipc://" + portName + "/test");
- c.StopListening (null);
+ RunTests (GetRemObject <Server<object>> ());
}
[Test]
- [Ignore ("The SOAP formatter doesn't support generics.")]
- // FIXME: change the SOAP formatter to throw on generic types
- public void TestHttp ()
+ public void TestTcpChannel ()
{
- HttpChannel c = new HttpChannel (19191);
- Helper.Test ("http://127.0.0.1:19191/test");
- c.StopListening (null);
+ RunTests (GetRemObjectTcp <Server<object>> ());
}
+
+ static T GetRemObject <T> () where T: MarshalByRefObject
+ {
+ AppDomain d = AppDomain.CreateDomain ("Foo");
+ return (T) d.CreateInstanceAndUnwrap (
+ typeof (T).Assembly.FullName,
+ typeof (T).FullName);
+ }
+
+ static T GetRemObjectTcp <T> () where T: MarshalByRefObject
+ {
+ new TcpChannel (18191);
+ object obj = Activator.CreateInstance (typeof(T));
+ RemotingServices.Marshal ((MarshalByRefObject)obj,
"test.rem");
+ return (T) RemotingServices.Connect (typeof (T),
"tcp://localhost:18191/test.rem");
+ }
+
+ static void RunTests (ServerBase<object> rem)
+ {
+ Assert.AreEqual (42, rem.TestIface<int>(42),
+ "#1 calling TestIface on object
instance");
+
+ Assert.AreEqual (42, rem.TestVirt<int>(42),
+ "#2 calling TestVirt");
+
+ ITest i = rem;
+ Assert.AreEqual (42, i.TestIface<int>(42),
+ "#3 calling TestIface on interface");
+
+ Assert.AreEqual (42, i.TestDirectIfaceImpl (42),
+ "#4 calling TestDirectIfaceImp");
+
+ INested cao = rem.GetNested ();
+ Assert.AreEqual (42, cao.Test (42),
+ "#5 calling INested.Test (int)");
+
+ Assert.AreEqual (42, cao.Test (21, 21),
+ "#6 calling INested.Test (int, int)");
+
+ Assert.AreEqual (42, cao.Test<int> (42),
+ "#7 calling INested.Test<V>");
+
+ Assert.AreEqual (0, cao.Test<int, string> (42, "bar"),
+ "#8 calling INested.Test<V, T>");
+
+ cao = rem.GetNestedMbr ();
+ Assert.AreEqual (42, cao.Test (42),
+ "#9 calling INested.Test (int)");
+
+ Assert.AreEqual (42, cao.Test (21, 21),
+ "#10 calling INested.Test (int, int)");
+
+ Assert.AreEqual (42, cao.Test<int> (42),
+ "#11 calling INested.Test<V>");
+
+ Assert.AreEqual (0, cao.Test<int, string> (42, "bar"),
+ "#12 calling INested.Test<V, T>");
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches