to avoid reuse of client proxies.
* CallSeq.cs: Now, "domain ID" is set manually.
* ContextsTest.cs: Added initialization of common domain id. Other small fixes.
* ReflectionCalls.cs: Get the method for the invoke for the correct type.
GetType() for a proxy to interface always return MarshalByRefObject.
* TcpCalls.cs, HttpCalls.cs: Added delegate tests.
* DelegateCalls.cs: New test suite for calls using delegates.
svn path=/trunk/mcs/; revision=17507
public abstract class BaseCallTest : Assertion
{
IChannelSender chs;
- string remoteUri;
+ string[] remoteUris;
CallsDomainServer server;
int remoteDomId;
AppDomain domain = AppDomain.CreateDomain ("testdomain");
server = (CallsDomainServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.System.Runtime.Remoting.CallsDomainServer");
- remoteUri = server.Start (cm);
+ remoteUris = server.Start (cm);
return server.GetDomId ();
}
protected virtual void ShutdownServer ()
{
server.Stop ();
- ChannelServices.UnregisterChannel (chs);
+ if (chs != null)
+ ChannelServices.UnregisterChannel (chs);
}
protected virtual RemoteObject CreateRemoteInstance ()
{
- return (RemoteObject) Activator.GetObject (typeof(RemoteObject), remoteUri);
+ return (RemoteObject) Activator.GetObject (typeof(RemoteObject), remoteUris[0]);
}
protected virtual AbstractRemoteObject CreateRemoteAbstract ()
{
- return (AbstractRemoteObject) Activator.GetObject (typeof(AbstractRemoteObject), remoteUri);
+ return (AbstractRemoteObject) Activator.GetObject (typeof(AbstractRemoteObject), remoteUris[1]);
}
protected virtual IRemoteObject CreateRemoteInterface ()
{
- return (IRemoteObject) Activator.GetObject (typeof(IRemoteObject), remoteUri);
+ return (IRemoteObject) Activator.GetObject (typeof(IRemoteObject), remoteUris[2]);
}
public InstanceSurrogate InternalGetInstanceSurrogate ()
{
IChannelReceiver ch;
- public string Start(ChannelManager cm)
+ public string[] Start(ChannelManager cm)
{
try
{
ch = cm.CreateServerChannel ();
ChannelServices.RegisterChannel ((IChannel)ch);
- RemotingConfiguration.RegisterWellKnownServiceType (typeof (RemoteObject), "test", WellKnownObjectMode.SingleCall);
- return ch.GetUrlsForUri ("test")[0];
+ RemotingConfiguration.RegisterWellKnownServiceType (typeof (RemoteObject), "test1", WellKnownObjectMode.SingleCall);
+ RemotingConfiguration.RegisterWellKnownServiceType (typeof (RemoteObject), "test2", WellKnownObjectMode.SingleCall);
+ RemotingConfiguration.RegisterWellKnownServiceType (typeof (RemoteObject), "test3", WellKnownObjectMode.SingleCall);
+ string[] uris = new string[3];
+ uris[0] = ch.GetUrlsForUri ("test1")[0];
+ uris[1] = ch.GetUrlsForUri ("test2")[0];
+ uris[2] = ch.GetUrlsForUri ("test3")[0];
+ return uris;
}
catch (Exception ex)
{
public void Stop ()
{
- ChannelServices.UnregisterChannel (ch);
+ if (ch != null)
+ ChannelServices.UnregisterChannel (ch);
}
public int GetDomId ()
static int writePos = 0;\r
static string name = "";\r
static ArrayList contexts = new ArrayList ();\r
+ static int domId = 1;\r
\r
public static void Add (string msg)\r
{\r
\r
public static int CommonDomainId\r
{\r
- get\r
- {\r
- if (Thread.GetDomainID() != 1) return 2;\r
- else return 1;\r
- }\r
+ get { return domId; }\r
+ set { domId = value; }\r
}\r
\r
public static void Init (string str)\r
-2003-07-23 Lluis Sanchez Gual <lluis@ximian.com>
+2003-08-22 Lluis Sanchez Gual <lluis@ximian.com>
+
+ * BaseCalls.cs: Create 3 test remote objects, one for each kind of access,
+ to avoid reuse of client proxies.
+ * CallSeq.cs: Now, "domain ID" is set manually.
+ * ContextsTest.cs: Added initialization of common domain id. Other small fixes.
+ * ReflectionCalls.cs: Get the method for the invoke for the correct type.
+ GetType() for a proxy to interface always return MarshalByRefObject.
+ * TcpCalls.cs, HttpCalls.cs: Added delegate tests.
+ * DelegateCalls.cs: New test suite for calls using delegates.
+
+2003-08-20 Lluis Sanchez Gual <lluis@ximian.com>
* AsyncCalls.cs, BaseCalls.cs, HttpCalls.cs, ReflectionCalls.cs, SyncCalls.cs,
TcpCalls.cs: new test suite for remoting. It tests sync calls, async calls
\r
public override object TypeId\r
{\r
+\r
get { return "ContextHook"; }\r
}\r
\r
[TestFixtureSetUp]\r
public void Run()\r
{\r
+ CallSeq.CommonDomainId = 1;\r
Context.RegisterDynamicProperty (new DynProperty("global"), null, null);\r
\r
ch = new TcpChannel(0);\r
public void End ()\r
{\r
Context.UnregisterDynamicProperty ("global", null, null);\r
- ChannelServices.UnregisterChannel (ch);\r
+ if (ch != null)\r
+ ChannelServices.UnregisterChannel (ch);\r
}\r
\r
[Test]\r
[Test]\r
public void TestNewContext ()\r
{\r
+ try\r
+ {\r
CallSeq.Init("TestNewContext");\r
CallSeq.Add (">> TestNewContext");\r
object[] at = new object[] { new ContextHookAttribute ("1",true)};\r
RunTestObject (list);\r
CallSeq.Add ("<< TestNewContext");\r
CallSeq.Check (Checks.seqNewContext,1);\r
+ }\r
+ catch (Exception eX)\r
+ {\r
+ Console.WriteLine (eX);\r
+ }\r
}\r
\r
[Test]\r
public void TestRemoteContext ()\r
{\r
- try\r
- {\r
AppDomain domain = AppDomain.CreateDomain ("test");\r
DomainServer server = (DomainServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.System.Runtime.Remoting.DomainServer");\r
+ try\r
+ {\r
+ CallSeq.Init("TestRemoteContext");\r
+ CallSeq.Add (">> TestRemoteContext");\r
+ object[] at = new object[] { new ContextHookAttribute ("1",true), new UrlAttribute ("tcp://localhost:1122")};\r
+ CallSeq.Add (">> Creating instance");\r
+ ServerList list = (ServerList) Activator.CreateInstance (typeof (ServerList),null,at);\r
+ CallSeq.Add ("<< Creating instance");\r
+ RunTestObject (list);\r
+ CallSeq.Add ("<< TestRemoteContext");\r
+ CallSeq.Check (Checks.seqRemoteContext,1);\r
\r
- CallSeq.Init("TestRemoteContext");\r
- CallSeq.Add (">> TestRemoteContext");\r
- object[] at = new object[] { new ContextHookAttribute ("1",true), new UrlAttribute ("tcp://localhost:1122")};\r
- CallSeq.Add (">> Creating instance");\r
- ServerList list = (ServerList) Activator.CreateInstance (typeof (ServerList),null,at);\r
- CallSeq.Add ("<< Creating instance");\r
- RunTestObject (list);\r
- CallSeq.Add ("<< TestRemoteContext");\r
- CallSeq.Check (Checks.seqRemoteContext,1);\r
-\r
- CallSeq.Init ("TestRemoteContext Server");\r
- CallSeq.Seq = server.GetRemoteSeq ();\r
- CallSeq.Check (Checks.seqRemoteContext,2);\r
- server.Stop ();\r
+ CallSeq.Init ("TestRemoteContext Server");\r
+ CallSeq.Seq = server.GetRemoteSeq ();\r
+ CallSeq.Check (Checks.seqRemoteContext,2);\r
}\r
catch (Exception ex)\r
{\r
Console.WriteLine (ex);\r
throw ex;\r
}\r
+ finally\r
+ {\r
+ server.Stop ();\r
+ }\r
// AppDomain.Unload (domain);\r
}\r
\r
}\r
catch (Exception ex)\r
{\r
- Console.WriteLine (ex.ToString());\r
+ // Console.WriteLine (ex.ToString());\r
throw;\r
}\r
}\r
TcpChannel ch;\r
\r
public DomainServer()\r
- { \r
+ {\r
+ CallSeq.CommonDomainId = 2;\r
try\r
{\r
ch = new TcpChannel(1122);\r
\r
public void Stop ()\r
{\r
- ChannelServices.UnregisterChannel (ch);\r
+ if (ch != null)\r
+ ChannelServices.UnregisterChannel (ch);\r
}\r
}\r
\r
"339 (d1,c1) <-> global DynamicSink Finish ProcessItems client:False",\r
"340 (d1,c0) <-> global DynamicSink Finish ProcessItems client:True",\r
"341 (d1,c0) <-> defcontext DynamicSink Finish ProcessItems client:True",\r
+\r
"342 (d1,c0) <-- EnvoySink(1.d1) SyncProcessMessage ProcessItems",\r
"343 (d1,c0) <-- EnvoySink(x.d1) SyncProcessMessage ProcessItems",\r
"344 (d1,c0) <-> proxy DynamicSink Finish ProcessItems client:True",\r
"034 (d1,c0) <-> defcontext DynamicSink Finish FieldSetter client:True",\r
"035 (d1,c0) <-- EnvoySink(1.d1) SyncProcessMessage FieldSetter",\r
"036 (d1,c0) <-- EnvoySink(x.d1) SyncProcessMessage FieldSetter",\r
+\r
"037 (d1,c0) <-- EnvoySink(x.d2) SyncProcessMessage FieldSetter",\r
\r
"038 (d1,c0) <-> proxy DynamicSink Finish FieldSetter client:True",\r
--- /dev/null
+//
+// MonoTests.System.Runtime.Remoting.DelegateCalls.cs
+//
+// Author: Lluis Sanchez Gual (lluis@ximian.com)
+//
+// 2003 (C) Copyright, Ximian, Inc.
+//
+
+using System;
+using System.Collections;
+using NUnit.Framework;
+
+namespace MonoTests.System.Runtime.Remoting
+{
+ public abstract class DelegateCallTest : BaseCallTest
+ {
+ public override InstanceSurrogate GetInstanceSurrogate () { return new DelegateInstanceSurrogate (); }
+ public override AbstractSurrogate GetAbstractSurrogate () { return new DelegateAbstractSurrogate (); }
+ public override InterfaceSurrogate GetInterfaceSurrogate () { return new DelegateInterfaceSurrogate (); }
+ }
+
+ public class DelegateInstanceSurrogate : InstanceSurrogate
+ {
+ public override int Simple ()
+ {
+ DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
+ return de ();
+ }
+
+ public override string PrimitiveParams (int a, uint b, char c, string d)
+ {
+ DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
+ return de (a,b,c,d);
+ }
+
+ public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
+ {
+ DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
+ return de (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
+ }
+
+ public override Complex ComplexParams (ArrayList a, Complex b, string c)
+ {
+ DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
+ return de (a,b,c);
+ }
+
+ public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, string c)
+ {
+ DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
+ return de (ref a, out b, c);
+ }
+ }
+
+ public class DelegateAbstractSurrogate : AbstractSurrogate
+ {
+ public override int Simple ()
+ {
+ DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
+ return de ();
+ }
+
+ public override string PrimitiveParams (int a, uint b, char c, string d)
+ {
+ DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
+ return de (a,b,c,d);
+ }
+
+ public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
+ {
+ DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
+ return de (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
+ }
+
+ public override Complex ComplexParams (ArrayList a, Complex b, string c)
+ {
+ DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
+ return de (a,b,c);
+ }
+
+ public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, string c)
+ {
+ DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
+ return de (ref a, out b, c);
+ }
+ }
+
+ public class DelegateInterfaceSurrogate : InterfaceSurrogate
+ {
+ public override int Simple ()
+ {
+ DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
+ return de ();
+ }
+
+ public override string PrimitiveParams (int a, uint b, char c, string d)
+ {
+ DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
+ return de (a,b,c,d);
+ }
+
+ public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
+ {
+ DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
+ return de (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
+ }
+
+ public override Complex ComplexParams (ArrayList a, Complex b, string c)
+ {
+ DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
+ return de (a,b,c);
+ }
+
+ public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, string c)
+ {
+ DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
+ return de (ref a, out b, c);
+ }
+ }
+}
}
}
+ [TestFixture]
+ public class HttpDelegateCallTest : DelegateCallTest
+ {
+ public override ChannelManager CreateChannelManager ()
+ {
+ return new HttpChannelManager ();
+ }
+ }
+
[Serializable]
public class HttpChannelManager : ChannelManager
{
public override AbstractSurrogate GetAbstractSurrogate () { return new ReflectionAbstractSurrogate (); }
public override InterfaceSurrogate GetInterfaceSurrogate () { return new ReflectionInterfaceSurrogate (); }
- public static int Simple (object target)
+ public static int Simple (Type type, object target)
{
object[] parms = new object[0];
- MethodBase m = target.GetType ().GetMethod ("Simple");
+ MethodBase m = type.GetMethod ("Simple");
return (int) m.Invoke (target, parms);
}
- public static string PrimitiveParams (object target, int a, uint b, char c, string d)
+ public static string PrimitiveParams (Type type, object target, int a, uint b, char c, string d)
{
object[] parms = new object[] {a,b,c,d};
- MethodBase m = target.GetType ().GetMethod ("PrimitiveParams");
+ MethodBase m = type.GetMethod ("PrimitiveParams");
return (string) m.Invoke (target, parms);
}
- public static string PrimitiveParamsInOut (object target, ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
+ public static string PrimitiveParamsInOut (Type type, object target, ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
{
object[] parms = new object[] {a1,0,b1,0f,c1,'\0',d1,null};
- MethodBase m = target.GetType ().GetMethod ("PrimitiveParamsInOut");
+ MethodBase m = type.GetMethod ("PrimitiveParamsInOut");
string res = (string) m.Invoke (target, parms);
a1 = (int)parms[0];
b1 = (float)parms[2];
return res;
}
- public static Complex ComplexParams (object target, ArrayList a, Complex b, string c)
+ public static Complex ComplexParams (Type type, object target, ArrayList a, Complex b, string c)
{
object[] parms = new object[] {a,b,c};
- MethodBase m = target.GetType ().GetMethod ("ComplexParams");
+ MethodBase m = type.GetMethod ("ComplexParams");
return (Complex) m.Invoke (target, parms);
}
- public static Complex ComplexParamsInOut (object target, ref ArrayList a, out Complex b, string c)
+ public static Complex ComplexParamsInOut (Type type, object target, ref ArrayList a, out Complex b, string c)
{
object[] parms = new object[] {a,null,c};
- MethodBase m = target.GetType ().GetMethod ("ComplexParamsInOut");
+ MethodBase m = type.GetMethod ("ComplexParamsInOut");
Complex res = (Complex) m.Invoke (target, parms);
a = (ArrayList) parms[0];
b = (Complex) parms[1];
{
public override int Simple ()
{
- return ReflectionCallTest.Simple (RemoteObject);
+ return ReflectionCallTest.Simple (typeof (RemoteObject), RemoteObject);
}
public override string PrimitiveParams (int a, uint b, char c, string d)
{
- return ReflectionCallTest.PrimitiveParams (RemoteObject, a, b, c, d);
+ return ReflectionCallTest.PrimitiveParams (typeof (RemoteObject), RemoteObject, a, b, c, d);
}
public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
{
- return ReflectionCallTest.PrimitiveParamsInOut (RemoteObject, ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
+ return ReflectionCallTest.PrimitiveParamsInOut (typeof (RemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
- return ReflectionCallTest.ComplexParams (RemoteObject, a, b, c);
+ return ReflectionCallTest.ComplexParams (typeof (RemoteObject), RemoteObject, a, b, c);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, string c)
{
- return ReflectionCallTest.ComplexParamsInOut (RemoteObject, ref a, out b, c);
+ return ReflectionCallTest.ComplexParamsInOut (typeof (RemoteObject), RemoteObject, ref a, out b, c);
}
}
{
public override int Simple ()
{
- return ReflectionCallTest.Simple (RemoteObject);
+ return ReflectionCallTest.Simple (typeof (AbstractRemoteObject), RemoteObject);
}
public override string PrimitiveParams (int a, uint b, char c, string d)
{
- return ReflectionCallTest.PrimitiveParams (RemoteObject, a, b, c, d);
+ return ReflectionCallTest.PrimitiveParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c, d);
}
public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
{
- return ReflectionCallTest.PrimitiveParamsInOut (RemoteObject, ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
+ return ReflectionCallTest.PrimitiveParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
- return ReflectionCallTest.ComplexParams (RemoteObject, a, b, c);
+ return ReflectionCallTest.ComplexParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, string c)
{
- return ReflectionCallTest.ComplexParamsInOut (RemoteObject, ref a, out b, c);
+ return ReflectionCallTest.ComplexParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a, out b, c);
}
}
{
public override int Simple ()
{
- return ReflectionCallTest.Simple (RemoteObject);
+ return ReflectionCallTest.Simple (typeof (IRemoteObject), RemoteObject);
}
public override string PrimitiveParams (int a, uint b, char c, string d)
{
- return ReflectionCallTest.PrimitiveParams (RemoteObject, a, b, c, d);
+ return ReflectionCallTest.PrimitiveParams (typeof (IRemoteObject), RemoteObject, a, b, c, d);
}
public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
{
- return ReflectionCallTest.PrimitiveParamsInOut (RemoteObject, ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
+ return ReflectionCallTest.PrimitiveParamsInOut (typeof (IRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
- return ReflectionCallTest.ComplexParams (RemoteObject, a, b, c);
+ return ReflectionCallTest.ComplexParams (typeof (IRemoteObject), RemoteObject, a, b, c);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, string c)
{
- return ReflectionCallTest.ComplexParamsInOut (RemoteObject, ref a, out b, c);
+ return ReflectionCallTest.ComplexParamsInOut (typeof (IRemoteObject), RemoteObject, ref a, out b, c);
}
}
}
}
}
+ [TestFixture]
+ public class TcpDelegateCallTest : DelegateCallTest
+ {
+ public override ChannelManager CreateChannelManager ()
+ {
+ return new TcpChannelManager ();
+ }
+ }
+
[Serializable]
public class TcpChannelManager : ChannelManager
{