Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,221 @@
//
// MonoTests.Remoting.TcpCalls.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using NUnit.Framework;
namespace MonoTests.Remoting
{
[TestFixture]
public class ActivationTests
{
ActivationServer server;
TcpChannel tcp;
HttpClientChannel http;
[TestFixtureSetUp]
public void Run()
{
try
{
tcp = new TcpChannel (0);
Hashtable options = new Hashtable ();
options ["timeout"] = 10000; // 10s
http = new HttpClientChannel (options, null);
ChannelServices.RegisterChannel (tcp);
ChannelServices.RegisterChannel (http);
AppDomain domain = BaseCallTest.CreateDomain ("testdomain_activation");
server = (ActivationServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.ActivationServer");
RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject1), "tcp://localhost:9433");
RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject2), "http://localhost:9434");
RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall1), "tcp://localhost:9433/wkoSingleCall1");
RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton1), "tcp://localhost:9433/wkoSingleton1");
RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall2), "http://localhost:9434/wkoSingleCall2");
RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton2), "http://localhost:9434/wkoSingleton2");
}
catch (Exception ex)
{
Console.WriteLine (ex);
}
}
[Test]
public void TestCreateTcpCao ()
{
CaObject1 ca = new CaObject1 ();
CaObject1 ca2 = new CaObject1 ();
Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
RunTestCreateCao (ca, ca2);
}
[Test]
public void TestCreateHttpCao ()
{
CaObject2 ca = new CaObject2 ();
CaObject2 ca2 = new CaObject2 ();
Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
RunTestCreateCao (ca, ca2);
}
public void RunTestCreateCao (BaseObject ca, BaseObject ca2)
{
Assert.AreEqual (0, ca.counter, "#1");
ca.counter++;
Assert.AreEqual (1, ca.counter, "#2");
Assert.AreEqual (0, ca2.counter, "#3");
ca2.counter++;
Assert.AreEqual (1, ca2.counter, "#4");
Assert.AreEqual (1, ca.counter, "#5");
}
[Test]
public void TestCreateTcpWkoSingleCall ()
{
WkObjectSinglecall1 ca = new WkObjectSinglecall1 ();
WkObjectSinglecall1 ca2 = new WkObjectSinglecall1 ();
Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
RunTestCreateWkoSingleCall (ca, ca2);
}
[Test]
public void TestCreateTcpWkoSingleton ()
{
WkObjectSingleton1 ca = new WkObjectSingleton1 ();
WkObjectSingleton1 ca2 = new WkObjectSingleton1 ();
Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
RunTestCreateWkoSingleton (ca, ca2);
}
[Test]
[Category ("NotWorking")]
public void TestCreateHttpWkoSingleCall ()
{
WkObjectSinglecall2 ca = new WkObjectSinglecall2 ();
WkObjectSinglecall2 ca2 = new WkObjectSinglecall2 ();
Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
RunTestCreateWkoSingleCall (ca, ca2);
}
[Test]
[Category ("NotWorking")]
public void TestCreateHttpWkoSingleton ()
{
WkObjectSingleton2 ca = new WkObjectSingleton2 ();
WkObjectSingleton2 ca2 = new WkObjectSingleton2 ();
Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
RunTestCreateWkoSingleton (ca, ca2);
}
public void RunTestCreateWkoSingleCall (BaseObject ca, BaseObject ca2)
{
Assert.AreEqual (0, ca.counter, "#1");
ca.counter++;
Assert.AreEqual (0, ca.counter, "#2");
Assert.AreEqual (0, ca2.counter, "#3");
ca2.counter++;
Assert.AreEqual (0, ca2.counter, "#4");
}
public void RunTestCreateWkoSingleton (BaseObject ca, BaseObject ca2)
{
Assert.AreEqual (0, ca.counter, "#1");
ca.counter++;
Assert.AreEqual (1, ca.counter, "#2");
ca.counter++;
Assert.AreEqual (2, ca2.counter, "#3");
ca2.counter++;
Assert.AreEqual (3, ca2.counter, "#4");
}
[TestFixtureTearDown]
public void End ()
{
ChannelServices.UnregisterChannel (tcp);
ChannelServices.UnregisterChannel (http);
if (server != null)
server.Stop ();
}
}
public class ActivationServer: MarshalByRefObject
{
TcpChannel tcp;
HttpChannel http;
public ActivationServer ()
{
tcp = new TcpChannel (9433);
http = new HttpChannel (9434);
ChannelServices.RegisterChannel (tcp);
ChannelServices.RegisterChannel (http);
RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject1));
RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject2));
RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall1), "wkoSingleCall1", WellKnownObjectMode.SingleCall);
RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton1), "wkoSingleton1", WellKnownObjectMode.Singleton);
RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall2), "wkoSingleCall2", WellKnownObjectMode.SingleCall);
RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton2), "wkoSingleton2", WellKnownObjectMode.Singleton);
}
public void Stop ()
{
ChannelServices.UnregisterChannel (tcp);
ChannelServices.UnregisterChannel (http);
}
}
public class BaseObject: MarshalByRefObject
{
public int counter;
public static int CreationCount;
public BaseObject ()
{
CreationCount++;
}
}
public class CaObject1: BaseObject
{
}
public class CaObject2: BaseObject
{
}
public class WkObjectSinglecall1: BaseObject
{
}
public class WkObjectSingleton1: BaseObject
{
}
public class WkObjectSinglecall2: BaseObject
{
}
public class WkObjectSingleton2: BaseObject
{
}
}

View File

@@ -0,0 +1,190 @@
//
// MonoTests.Remoting.AsyncCalls.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//
using System;
using System.Collections;
using System.Threading;
using NUnit.Framework;
using System.Text;
using System.Runtime.InteropServices;
namespace MonoTests.Remoting
{
public abstract class AsyncCallTest : BaseCallTest
{
public override InstanceSurrogate GetInstanceSurrogate () { return new AsyncInstanceSurrogate (); }
public override AbstractSurrogate GetAbstractSurrogate () { return new AsyncAbstractSurrogate (); }
public override InterfaceSurrogate GetInterfaceSurrogate () { return new AsyncInterfaceSurrogate (); }
public static void DoWork ()
{
for (int n=0; n<10; n++)
Thread.Sleep (1);
}
}
public delegate int DelegateSimple ();
public delegate string DelegatePrimitiveParams (int a, uint b, char c, string d);
public delegate string DelegatePrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2);
public delegate Complex DelegateComplexParams (ArrayList a, Complex b, string c);
public delegate Complex DelegateComplexParamsInOut (ref ArrayList a, out Complex b, byte[] bytes, StringBuilder sb, string c);
public delegate void DelegateProcessContextData ();
public class AsyncInstanceSurrogate : InstanceSurrogate
{
public override int Simple ()
{
DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
IAsyncResult ar = de.BeginInvoke (null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ar);
}
public override string PrimitiveParams (int a, uint b, char c, string d)
{
DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
IAsyncResult ar = de.BeginInvoke (a,b,c,d,null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ar);
}
public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
{
DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
IAsyncResult ar = de.BeginInvoke (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2, null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2, ar);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
IAsyncResult ar = de.BeginInvoke (a,b,c,null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ar);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, StringBuilder sb, string c)
{
DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
IAsyncResult ar = de.BeginInvoke (ref a, out b, bytes, sb, c, null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ref a, out b, ar);
}
public override void ProcessContextData ()
{
DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
IAsyncResult ar = de.BeginInvoke (null,null);
AsyncCallTest.DoWork ();
de.EndInvoke (ar);
}
}
public class AsyncAbstractSurrogate : AbstractSurrogate
{
public override int Simple ()
{
DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
IAsyncResult ar = de.BeginInvoke (null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ar);
}
public override string PrimitiveParams (int a, uint b, char c, string d)
{
DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
IAsyncResult ar = de.BeginInvoke (a,b,c,d,null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ar);
}
public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
{
DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
IAsyncResult ar = de.BeginInvoke (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2, null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2, ar);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
IAsyncResult ar = de.BeginInvoke (a,b,c,null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ar);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, StringBuilder sb, string c)
{
DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
IAsyncResult ar = de.BeginInvoke (ref a, out b, bytes, sb, c, null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ref a, out b, ar);
}
public override void ProcessContextData ()
{
DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
IAsyncResult ar = de.BeginInvoke (null,null);
AsyncCallTest.DoWork ();
de.EndInvoke (ar);
}
}
public class AsyncInterfaceSurrogate : InterfaceSurrogate
{
public override int Simple ()
{
DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
IAsyncResult ar = de.BeginInvoke (null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ar);
}
public override string PrimitiveParams (int a, uint b, char c, string d)
{
DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
IAsyncResult ar = de.BeginInvoke (a,b,c,d,null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ar);
}
public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
{
DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
IAsyncResult ar = de.BeginInvoke (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2, null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2, ar);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
IAsyncResult ar = de.BeginInvoke (a,b,c,null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ar);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, StringBuilder sb, string c)
{
DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
IAsyncResult ar = de.BeginInvoke (ref a, out b, bytes, sb, c, null,null);
AsyncCallTest.DoWork ();
return de.EndInvoke (ref a, out b, ar);
}
public override void ProcessContextData ()
{
DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
IAsyncResult ar = de.BeginInvoke (null,null);
AsyncCallTest.DoWork ();
de.EndInvoke (ar);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,101 @@
//
// MonoTests.Remoting.CallSeq.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//
using System;
using System.Threading;
using System.Collections;
using NUnit.Framework;
namespace MonoTests.Remoting
{
public class CallSeq
{
static ArrayList calls = new ArrayList();
static int checkPos = 0;
static int writePos = 0;
static string name = "";
static ArrayList contexts = new ArrayList ();
static int domId = 1;
public static void Add (string msg)
{
writePos++;
msg = writePos.ToString ("000") + " (d" + CommonDomainId + ",c" + CommonContextId + ") " + msg;
calls.Add (msg);
}
public static int CommonContextId
{
get
{
int id = Thread.CurrentContext.ContextID;
int idc = contexts.IndexOf (id);
if (idc == -1)
{
idc = contexts.Count;
contexts.Add (id);
}
return idc;
}
}
public static int CommonDomainId
{
get { return domId; }
set { domId = value; }
}
public static void Init (string str)
{
calls = new ArrayList();
contexts = new ArrayList ();
name = str;
checkPos = 0;
writePos = 0;
}
public static void Check (string msg, int domain)
{
bool optional = false;
if (msg.StartsWith ("#"))
{
optional = true;
msg = msg.Substring (1);
}
if (msg[6].ToString() != domain.ToString()) return;
if (checkPos >= calls.Count)
{
if (!optional) Assert.Fail ("[" + name + "] Call check failed. Expected call not made: \"" + msg + "\"");
else return;
}
string call = (string) calls[checkPos++];
if (msg.Substring (3) != call.Substring (3))
{
if (optional) checkPos--;
else Assert.Fail ("[" + name + "] Call check failed in step " + (checkPos+1) + ". Expected \"" + msg + "\" found \"" + call + "\"");
}
}
public static void Check (string[] msgs, int domain)
{
foreach (string msg in msgs)
Check (msg, domain);
}
public static ArrayList Seq
{
get { return calls; }
set { calls = value; }
}
}
}

View File

@@ -0,0 +1,239 @@
2010-05-29 Robert Jordan <robertj@gmx.net>
* IpcChannelTest.cs: Add test for bug #609381.
2010-02-28 Robert Jordan <robertj@gmx.net>
* BaseCalls.cs: Enable tests again. See bug #576618.
2010-02-11 Jonathan Pobst <monkey@jpobst.com>
* ActivationTests.cs: Disable TestCreateHttpWkoSingleCall and
TestCreateHttpWkoSingleton due to sporadic failures.
Filed as bug #579277.
2010-02-03 Jonathan Pobst <monkey@jpobst.com>
* HttpCalls.cs: Disable all tests here due to excessive
sporadic failures. Filed as bug #576724.
2010-02-03 Jonathan Pobst <monkey@jpobst.com>
* BaseCalls.cs: Mark tests as NotWorking. Reported as bug #576618.
2009-09-12 Gonzalo Paniagua Javier <gonzalo@novell.com>
* HttpServerChannelTests.cs:
* BaseCalls.cs:
* System.Runtime.Remoting.Channels.Tcp/TcpChannelTest.cs: ignore tests
that fail on MS.NET.
2009-05-24 Robert Jordan <robertj@gmx.net>
* GenericTest.cs: differentiate between "Test(int)" and
"Test<int>(int)" to prove that the correct method is invoked.
2009-05-24 Robert Jordan <robertj@gmx.net>
* GenericTest.cs (TestCrossAppDomainChannel): disable on MS.NET as
some generic calls do not seem to be supported anymore. It looks
like a bug, though, since the same tests are passing when performed
over the TCP channel.
2009-05-24 Robert Jordan <robertj@gmx.net>
* GenericTest.cs (TestTcpChannel): create a unique channel and
unregister it upon termination. Fixes issues that were uncovered
by the NUnit upgrade (see Atsushi's changelogs below).
2009-01-07 Atsushi Enomoto <atsushi@ximian.com>
* RemotingServicesTest.cs : mark failing test as NotWorking, and
Ignore the blocker for other tests.
Remoting tests are finally back!
2009-01-07 Atsushi Enomoto <atsushi@ximian.com>
* BaseCalls.cs : fully name is sometimes rejected ... ?
2009-01-07 Atsushi Enomoto <atsushi@ximian.com>
* GenericTest.cs : change from NotWorking to Ignore which also fails
and blocks further tests under .NET.
2009-01-07 Atsushi Enomoto <atsushi@ximian.com>
* HttpBugTests.cs : mark some tests as [Ignore] as they are blocker
to other http tests. Make sure to unregister HTTP channel.
2009-01-07 Atsushi Enomoto <atsushi@ximian.com>
* GenericTest.cs, HttpServerChannelTests.cs, ActivationTests.cs,
BaseCalls.cs, CrossDomainCalls.cs, HttpBugTests.cs,
ContextsTest.cs : explicitly set applicationBasePath to load
the test assembly itself. It reduces hundreds of test failures
under .NET and upgraded NUnit.
Marked some tests as NotWorking (due to nunit upgrade).
2008-09-24 Michael Hutchinson <mhutchinson@novell.com>
* HttpServerChannelTests.cs: Don't check for a chunked response from
the Mono HTTP server; it no longer chunks since that was breaking
other tests.
2008-09-19 Michael Hutchinson <mhutchinson@novell.com>
* ActivationTests.cs:
* HttpCalls.cs: Add a timeout on the client.
* HttpBugTests.cs: Add tests for some bugzilla bugs. One's not fixed,
so is marked as not working.
2008-09-19 Jeffrey Stedfast <fejj@novell.com>
* HttpServerChannelTests.cs: More unit tests for
HttpServerChannel.
2008-09-17 Jeffrey Stedfast <fejj@novell.com>
* BaseCalls.cs (RemoteObject): Added more methods for invoking.
2008-01-25 Gert Driesen <drieseng@users.sourceforge.net>
* ActivationTests.cs: Only stop server if it was actually created.
* RemotingServicesTest.cs: Always/only unregister channels if they were
actually created. More code formatting.
2008-01-25 Gert Driesen <drieseng@users.sourceforge.net>
* RemotingServicesTest.cs: Do not hide exception that occur when
unregistering a channel. Code formatting and removed extra tabs.
2007-10-30 Robert Jordan <robertj@gmx.net>
* GenericTest.cs: Add tests for bug #324232.
2007-09-09 Robert Jordan <robertj@gmx.net>
* GenericTest.cs: Add tests for bug #78882, #81554.
2007-06-05 Robert Jordan <robertj@gmx.net>
* RemotingServicesTest.cs: Add test for bug #81811.
2007-05-19 Robert Jordan <robertj@gmx.net>
* IpcChannelTest.cs: Add test for bug #81653.
2007-02-05 Robert Jordan <robertj@gmx.net>
* BaseCalls.cs (PrimitiveParams): Add dummy overload method for
bug #77191.
* ReflectionCalls.cs (PrimitiveParams): Due to the change above
we need to specify the exact signature because PrimitiveParams ()
is overloaded now.
2007-01-09 Robert Jordan <robertj@gmx.net>
* GenericTest.cs: Added test for generics in remoting interfaces.
See bug #80383.
2006-12-18 Lluis Sanchez Gual <lluis@ximian.com>
* BaseCalls.cs: Added some tests for exceptions.
2005-12-02 Robert Jordan <robertj@gmx.net>
* RemotingServicesTest.cs: Added test for bug #76809.
2005-12-01 Robert Jordan <robertj@gmx.net>
* IpcCalls.cs: Made the IPC channel names unique to match the
Tcp/HttpChannel(0) semantics, because the test suite
relies on that.
2005-10-16 Robert Jordan <robertj@gmx.net>
* IpcCalls.cs: Added.
2005-04-27 Lluis Sanchez Gual <lluis@ximian.com>
* RemotingServicesTest.cs: Fix warning.
* ContextsTest.cs: Removed unneeded exception catch.
Changed the order in which GetEnvoySink is called. I think
this is a safe chenge, since it is not defined where the
call to GetEnvoySink should be made.
2005-02-16 Lluis Sanchez Gual <lluis@ximian.com>
* HttpCalls.cs, TcpCalls.cs: Don't use a hardcoded port number for the
test channels, take any free port.
2004-12-17 Lluis Sanchez Gual <lluis@ximian.com>
* HttpCalls.cs: Use a different port.
2004-12-17 Lluis Sanchez Gual <lluis@ximian.com>
* BaseCalls.cs: Removed useless try/catch.
2004-09-27 Lluis Sanchez Gual <lluis@ximian.com>
* ContextsTest.cs: Fixed test sequence.
* RemotingServicesTest.cs: Minor fix.
* ServerObject.cs: Added check for transparent proxy in all CBO methods.
2004-07-02 Lluis Sanchez Gual <lluis@ximian.com>
* ActivationTests.cs: Fixed and enhanced tests.
* RemotingServicesTest.cs: Added.
2004-06-23 Lluis Sanchez Gual <lluis@ximian.com>
* ActivationTests.cs: New tests.
* BaseCalls.cs, CallSeq.cs: Use Assert instead of the deprecated Assertion.
2004-05-03 Lluis Sanchez Gual <lluis@ximian.com>
* AsyncCalls.cs, BaseCalls.cs, DelegateCalls.cs, ReflectionCalls.cs,
ServerObject.cs, SyncCalls.cs: Improved PrimitiveParamsInOut test case.
2004-02-23 Lluis Sanchez Gual <lluis@ximian.com>
* AsyncCalls.cs, BaseCalls.cs, CallSeq.cs, ContextHookAttribute.cs,
ContextsTest.cs, CrossDomainCalls.cs, DelegateCalls.cs, HttpCalls.cs,
ReflectionCalls.cs, ServerObject.cs, SyncCalls.cs, TcpCalls.cs:
Shortened namespace name.
2003-11-11 Lluis Sanchez Gual <lluis@ximian.com>
* BaseCalls.cs: Little fix.
* ContextsTest.cs: Unregister dynamic properties even if there is an exception.
* CrossDomainCalls.cs: New test for the cross-app domain channel.
2003-09-01 Nick Drochak <ndrochak@gol.com>
* AsyncCalls.cs: Fix Build breaker on .NET 1.1.
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
and reflection calls using tcp and http channels.
* CallSeq.cs, ContextHookAttribute.cs: Add methods for getting a context and
domain ids that are the same between tests runs.
* ContextsTest.cs: unregister channel on test shutdown.
2003-07-23 Lluis Sanchez Gual <lluis@ximian.com>
* ContextsTest.cs, CallSeq.cs, ContextHookAttribute.cs, ServerObject.cs: Added.

View File

@@ -0,0 +1,171 @@
//
// MonoTests.Remoting.ContextHookAttribute.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//
using System;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting;
using System.Threading;
namespace MonoTests.Remoting
{
[Serializable,AttributeUsage(AttributeTargets.Class)]
public class ContextHookAttribute: Attribute, IContextAttribute, IContextProperty, IContributeObjectSink, IContributeServerContextSink, IContributeEnvoySink, IContributeClientContextSink
{
bool newContext = false;
string id = "";
public ContextHookAttribute()
{
}
public ContextHookAttribute(string idp, bool newContext)
{
id = idp;
if (id != "") id += ".";
id += "d" + CallSeq.CommonDomainId;
this.newContext = newContext;
}
public override object TypeId
{
get { return "ContextHook"; }
}
bool IContextAttribute.IsContextOK(Context ctx, IConstructionCallMessage ctor)
{
CallSeq.Add("ContextHookAttribute(" + id + ").IsContextOK");
return !newContext;
}
public bool IsNewContextOK(Context ctx)
{
CallSeq.Add("ContextHookAttribute(" + id + ").IsNewContextOK");
return true;
}
public void Freeze(Context ctx)
{
CallSeq.Add("ContextHookAttribute(" + id + ").Freeze");
}
public String Name
{
get { return "ContextHook(" + id + ")"; }
}
void IContextAttribute.GetPropertiesForNewContext(IConstructionCallMessage ctor)
{
CallSeq.Add("IContextAttribute(" + id + ").GetPropertiesForNewContext");
ctor.ContextProperties.Add(this);
}
IMessageSink IContributeObjectSink.GetObjectSink(MarshalByRefObject o, IMessageSink next)
{
CallSeq.Add("IContributeObjectSink(" + id + ").GetObjectSink");
return new GenericMessageSink(o,next,"ObjectSink(" + id + ")");
}
IMessageSink IContributeServerContextSink.GetServerContextSink(IMessageSink next)
{
CallSeq.Add("IContributeServerContextSink(" + id + ").GetServerContextSink");
return new GenericMessageSink(null,next,"ServerContextSink(" + id + ")");
}
IMessageSink IContributeEnvoySink.GetEnvoySink(MarshalByRefObject obj, IMessageSink nextSink)
{
CallSeq.Add("IContributeEnvoySink(" + id + ").GetEnvoySink");
return new GenericMessageSink(obj,nextSink,"EnvoySink(" + id + ")");
}
IMessageSink IContributeClientContextSink.GetClientContextSink (IMessageSink nextSink )
{
CallSeq.Add("IContributeClientContextSink(" + id + ").GetClientContextSink");
return new GenericMessageSink(null,nextSink,"ClientContextSink(" + id + ")");
}
}
[Serializable]
class GenericMessageSink: IMessageSink
{
IMessageSink _next;
string _type;
public GenericMessageSink(MarshalByRefObject obj, IMessageSink nextSink, string type)
{
_type = type;
_next = nextSink;
}
public IMessageSink NextSink
{
get { return _next; }
}
public IMessage SyncProcessMessage(IMessage imCall)
{
CallSeq.Add("--> " + _type + " SyncProcessMessage " + imCall.Properties["__MethodName"]);
IMessage ret = _next.SyncProcessMessage(imCall);
CallSeq.Add("<-- " + _type + " SyncProcessMessage " + imCall.Properties["__MethodName"]);
return ret;
}
public IMessageCtrl AsyncProcessMessage(IMessage im, IMessageSink ims)
{
CallSeq.Add("--> " + _type + " AsyncProcessMessage " + im.Properties["__MethodName"]);
IMessageCtrl ret = _next.AsyncProcessMessage(im, ims);
CallSeq.Add("<-- " + _type + " AsyncProcessMessage " + im.Properties["__MethodName"]);
return ret;
}
}
[Serializable]
class GenericDynamicSink: IDynamicMessageSink
{
string _name;
public GenericDynamicSink (string name)
{
_name = name;
}
void IDynamicMessageSink.ProcessMessageFinish(IMessage replyMsg, bool bCliSide, bool bAsync)
{
CallSeq.Add("<-> " + _name + " DynamicSink Finish " + replyMsg.Properties["__MethodName"] + " client:" + bCliSide);
}
void IDynamicMessageSink.ProcessMessageStart(IMessage replyMsg, bool bCliSide, bool bAsync)
{
CallSeq.Add("<-> " + _name + " DynamicSink Start " + replyMsg.Properties["__MethodName"] + " client:" + bCliSide);
}
}
public class DynProperty: IDynamicProperty, IContributeDynamicSink
{
string _name;
public DynProperty (string name)
{
_name = name;
}
public string Name
{
get { return _name; }
}
public IDynamicMessageSink GetDynamicSink()
{
CallSeq.Add("IContributeDynamicSink(" + _name + ").GetDynamicSink");
return new GenericDynamicSink(_name);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,153 @@
//
// MonoTests.Remoting.CrossDomainCalls.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Novell, Inc.
//
using System;
using System.Threading;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using NUnit.Framework;
namespace MonoTests.Remoting
{
class CrossDomainServer: MarshalByRefObject
{
public RemoteObject CreateRemoteInstance ()
{
return new RemoteObject();
}
public AbstractRemoteObject CreateRemoteAbstract ()
{
return new RemoteObject();
}
public IRemoteObject CreateRemoteInterface ()
{
return new RemoteObject();
}
public int GetDomId ()
{
return Thread.GetDomainID();
}
}
[TestFixture]
public class CrossDomainSyncCallTest : SyncCallTest
{
CrossDomainServer server;
protected override int CreateServer ()
{
AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
server = (CrossDomainServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.CrossDomainServer");
return server.GetDomId ();
}
protected override RemoteObject CreateRemoteInstance ()
{
return server.CreateRemoteInstance ();
}
protected override AbstractRemoteObject CreateRemoteAbstract ()
{
return server.CreateRemoteAbstract ();
}
protected override IRemoteObject CreateRemoteInterface ()
{
return server.CreateRemoteInterface ();
}
}
[TestFixture]
public class CrossDomainAsyncCallTest : AsyncCallTest
{
CrossDomainServer server;
protected override int CreateServer ()
{
AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
server = (CrossDomainServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.CrossDomainServer");
return server.GetDomId ();
}
protected override RemoteObject CreateRemoteInstance ()
{
return server.CreateRemoteInstance ();
}
protected override AbstractRemoteObject CreateRemoteAbstract ()
{
return server.CreateRemoteAbstract ();
}
protected override IRemoteObject CreateRemoteInterface ()
{
return server.CreateRemoteInterface ();
}
}
[TestFixture]
public class CrossDomainReflectionCallTest : ReflectionCallTest
{
CrossDomainServer server;
protected override int CreateServer ()
{
AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
server = (CrossDomainServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.CrossDomainServer");
return server.GetDomId ();
}
protected override RemoteObject CreateRemoteInstance ()
{
return server.CreateRemoteInstance ();
}
protected override AbstractRemoteObject CreateRemoteAbstract ()
{
return server.CreateRemoteAbstract ();
}
protected override IRemoteObject CreateRemoteInterface ()
{
return server.CreateRemoteInterface ();
}
}
[TestFixture]
public class CrossDomainDelegateCallTest : DelegateCallTest
{
CrossDomainServer server;
protected override int CreateServer ()
{
AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
server = (CrossDomainServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.CrossDomainServer");
return server.GetDomId ();
}
protected override RemoteObject CreateRemoteInstance ()
{
return server.CreateRemoteInstance ();
}
protected override AbstractRemoteObject CreateRemoteAbstract ()
{
return server.CreateRemoteAbstract ();
}
protected override IRemoteObject CreateRemoteInterface ()
{
return server.CreateRemoteInterface ();
}
}
}

View File

@@ -0,0 +1,140 @@
//
// MonoTests.Remoting.DelegateCalls.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//
using System;
using System.Collections;
using NUnit.Framework;
using System.Text;
using System.Runtime.InteropServices;
namespace MonoTests.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, int filler, 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, filler, 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, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
{
DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
return de (ref a, out b, bytes, sb, c);
}
public override void ProcessContextData ()
{
DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
de ();
}
}
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, int filler, 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, filler, 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, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
{
DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
return de (ref a, out b, bytes, sb, c);
}
public override void ProcessContextData ()
{
DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
de ();
}
}
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, int filler, 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, filler, 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, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
{
DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
return de (ref a, out b, bytes, sb, c);
}
public override void ProcessContextData ()
{
DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
de ();
}
}
}

View File

@@ -0,0 +1,253 @@
//
// MonoTests.Remoting.GenericTest.cs
//
// Authors:
// Robert Jordan <robertj@gmx.net>
//
#if NET_2_0
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels.Ipc;
using System.Threading;
using NUnit.Framework;
namespace MonoTests.Remoting
{
public interface INested
{
int Test ();
int Test (int i);
int Test (int a, int b);
V Test <V> (V v);
V Test <V, T> (V v, T t);
}
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 TestIface<V> (V v)
{
return v;
}
int ITest.TestDirectIfaceImpl (int i)
{
return i;
}
public int TestDirectIfaceImpl (int i)
{
return -1;
}
public INested GetNested ()
{
return new Nested ();
}
public INested GetNested (string s)
{
return new Nested ();
}
public INested GetNestedMbr ()
{
return new NestedMbr ();
}
}
public class Server<T> : ServerBase<T>
{
public override V TestVirt<V> (V v)
{
return v;
}
}
[Serializable]
public class Nested : INested
{
public int Test ()
{
return 47;
}
int INested.Test ()
{
return 42;
}
public int Test (int i)
{
return i + 500;
}
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);
}
}
public class NestedMbr : MarshalByRefObject, INested
{
public int Test ()
{
return 47;
}
int INested.Test ()
{
return 42;
}
public int Test (int i)
{
return i + 500;
}
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
{
// Under MS.NET, INested.Test<V>(V v) isn't supported over the
// xappdom channel anymore (as of .NET 3.5). The stacktrace
// looks like if INested.Test(int) is invoked in place of
// INested.Test<int>(int).
[Category("NotDotNet")]
[Test]
public void TestCrossAppDomainChannel ()
{
RunTests (RegisterAndConnect <Server<object>> ());
}
[Test]
public void TestTcpChannel ()
{
IDictionary props = new Hashtable ();
props ["name"] = Guid.NewGuid ().ToString("N");
props ["port"] = 18191;
TcpChannel chan = new TcpChannel (props, null, null);
ChannelServices.RegisterChannel (chan);
try {
Register <Server<object>> ("gentcptest.rem");
RunTests (Connect <Server<object>> ("tcp://localhost:18191/gentcptest.rem"));
} finally {
ChannelServices.UnregisterChannel (chan);
}
}
static T RegisterAndConnect <T> () where T: MarshalByRefObject
{
AppDomain d = BaseCallTest.CreateDomain ("GenericTests");
return (T) d.CreateInstanceAndUnwrap (
typeof (T).Assembly.FullName,
typeof (T).FullName);
}
static void Register <T> (string uri) where T: MarshalByRefObject
{
object obj = Activator.CreateInstance (typeof(T));
RemotingServices.Marshal ((MarshalByRefObject)obj, uri);
}
static T Connect <T> (string uri) where T: MarshalByRefObject
{
return (T) RemotingServices.Connect (typeof (T), uri);
}
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 (),
"#5a calling INested.Test ()");
Assert.AreEqual (42 + 500, 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 (),
"#9a calling INested.Test ()");
Assert.AreEqual (42 + 500, 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>");
}
}
}
#endif

View File

@@ -0,0 +1,244 @@
using System;
using System.Xml;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using NUnit.Framework;
namespace MonoTests.Remoting.Http
{
//Test for Bug 324362 - SoapFormatter cannot deserialize the same MBR twice
[TestFixture]
public class Bug324362
{
[Test]
// [Category ("NotWorking")] // the assertion fails, and if it's removed, there's an exception
[Ignore ("This test somehow keeps http channel registered and then blocks any further http tests working. This also happens under .NET, so this test itself is wrong with nunit 2.4.8.")]
public void Test ()
{
new HttpChannel (8086);
RemotingServices.Marshal (new Service (), "test");
Service remObj = (Service) RemotingServices.Connect (
typeof (Service), "http://localhost:8086/test");
ArrayList list;
remObj.Test (out list);
// it's of type 'ObjRef' instead of 'Service':
Assert.IsTrue (list [0] is Service);
Service [] array;
remObj.Test (out array);
}
public class Service : MarshalByRefObject
{
public Service Test (out Service[] a)
{
Service obj = new Service ();
a = new Service [] { obj };
return obj;
// return null or return otherObj works
}
public Service Test (out ArrayList a)
{
a = new ArrayList ();
Service obj = new Service ();
a.Add (obj);
return obj;
// return null or return otherObj works
}
}
}
//Bug 321420 - SoapReader fails to deserialize some method calls
[TestFixture]
public class Bug321420 : MarshalByRefObject
{
HttpChannel channel;
public void Method (string p1, string p2)
{
}
[Test]
public void Main ()
{
channel = new HttpChannel (3344);
ChannelServices.RegisterChannel (channel);
RemotingConfiguration.RegisterWellKnownServiceType
(typeof (Bug321420),"Server.soap", WellKnownObjectMode.Singleton);
Bug321420 s = (Bug321420) Activator.GetObject (typeof
(Bug321420), "http://localhost:3344/Server.soap");
// this works: s.Method ("a", "b");
s.Method ("a", "a");
}
[TestFixtureTearDown]
public void Stop ()
{
if (channel != null)
ChannelServices.UnregisterChannel (channel);
}
}
//Bug 315570 - Remoting over HTTP fails when returning a null reference.
[TestFixture]
public class Bug315570
{
Server server;
[Test]
[Ignore ("This test somehow keeps http channel registered and then blocks any further http tests working. This also happens under .NET, so this test itself is wrong with nunit 2.4.8.")]
public void Main ()
{
Foo foo = (Foo) Activator.GetObject (typeof (Foo),
"http://localhost:4321/Test");
Bar bar = foo.Login ();
if (bar != null)
bar.Foobar ();
}
[TestFixtureSetUp]
public void Start ()
{
AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
server = (Server) domain.CreateInstanceAndUnwrap
(typeof (Server).Assembly.FullName, typeof (Server).FullName);
server.Start ();
}
[TestFixtureTearDown]
public void Stop ()
{
server.Stop ();
}
public class Foo: MarshalByRefObject
{
public Bar Login ()
{
return null;
}
}
public class Bar: MarshalByRefObject
{
public void Foobar ()
{
// Console.WriteLine("Bar::foo()");
}
}
public class Server : MarshalByRefObject
{
HttpChannel c;
public void Start ()
{
c = new HttpChannel (4321);
ChannelServices.RegisterChannel (c);
Type t = typeof(Foo);
RemotingConfiguration.RegisterWellKnownServiceType (t, "Test",
WellKnownObjectMode.SingleCall);
}
public void Stop ()
{
c.StopListening (null);
ChannelServices.UnregisterChannel (c);
}
}
}
//Bug 315170 - exception thrown in remoting if interface parameter names differ from the impelmentation method parameter names
[TestFixture]
public class Bug315170
{
Server server;
HttpChannel channel;
[Test]
public void Main ()
{
channel = new HttpChannel (0);
try {
ChannelServices.RegisterChannel (channel);
MarshalByRefObject obj = (MarshalByRefObject) RemotingServices.Connect (
typeof (IFactorial),
"http://localhost:60000/MyEndPoint");
IFactorial cal = (IFactorial) obj;
Assert.AreEqual (cal.CalculateFactorial (4), 24);
} finally {
ChannelServices.UnregisterChannel (channel);
}
}
[TestFixtureSetUp]
public void Start ()
{
AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
server = (Server) domain.CreateInstanceAndUnwrap
(typeof (Server).Assembly.FullName, typeof (Server).FullName);
server.Start ();
}
[TestFixtureTearDown]
public void Stop ()
{
server.Stop ();
if (channel != null)
ChannelServices.UnregisterChannel (channel);
}
public interface IFactorial
{
// With this line everything works
//ulong CalculateFactorial(uint a);
// With this line it doesn't
ulong CalculateFactorial(uint b);
}
public class Server : MarshalByRefObject
{
HttpChannel c;
public void Start ()
{
c = new HttpChannel (60000);
ChannelServices.RegisterChannel (c);
Type t = typeof(Calculator);
RemotingConfiguration.RegisterWellKnownServiceType (t, "MyEndPoint",
WellKnownObjectMode.Singleton);
}
public void Stop ()
{
c.StopListening (null);
ChannelServices.UnregisterChannel (c);
}
}
public class Calculator : MarshalByRefObject, IFactorial
{
public ulong CalculateFactorial (uint a)
{
ulong res = 1;
for (uint i=1 ; i<=a; i++)
res = res * i;
return res;
}
}
}
}

View File

@@ -0,0 +1,96 @@
//
// MonoTests.Remoting.HttpCalls.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using NUnit.Framework;
namespace MonoTests.Remoting
{
//[TestFixture]
public class HttpSyncCallTest : SyncCallTest
{
public override ChannelManager CreateChannelManager ()
{
return new HttpChannelManager ();
}
}
//[TestFixture]
public class HttpAsyncCallTest : AsyncCallTest
{
public override ChannelManager CreateChannelManager ()
{
return new HttpChannelManager ();
}
}
//[TestFixture]
public class HttpReflectionCallTest : ReflectionCallTest
{
public override ChannelManager CreateChannelManager ()
{
return new HttpChannelManager ();
}
}
//[TestFixture]
public class HttpDelegateCallTest : DelegateCallTest
{
public override ChannelManager CreateChannelManager ()
{
return new HttpChannelManager ();
}
}
//[TestFixture]
public class HttpBinarySyncCallTest : SyncCallTest
{
public override ChannelManager CreateChannelManager ()
{
return new HttpChannelManager ();
}
}
[Serializable]
public class HttpChannelManager : ChannelManager
{
public override IChannelSender CreateClientChannel ()
{
Hashtable options = new Hashtable ();
options ["timeout"] = 10000; // 10s
return new HttpClientChannel (options, null);
}
public override IChannelReceiver CreateServerChannel ()
{
return new HttpChannel (0);
}
}
[Serializable]
public class HttpBinaryChannelManager : ChannelManager
{
public override IChannelSender CreateClientChannel ()
{
Hashtable options = new Hashtable ();
options ["timeout"] = 10000; // 10s
options ["name"] = "binary http channel";
return new HttpClientChannel (options, new BinaryClientFormatterSinkProvider ());
}
public override IChannelReceiver CreateServerChannel ()
{
return new HttpChannel (0);
}
}
}

View File

@@ -0,0 +1,492 @@
//
// HttpServerChannelTest.cs
// - Unit tests for System.Runtime.Remoting.Channels.Http
//
// Author: Jeffrey Stedfast <fejj@novell.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Text;
using System.Reflection;
using System.Net.Sockets;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Threading;
using NUnit.Framework;
namespace MonoTests.Remoting {
[TestFixture]
public class HttpServerChannelTests {
HttpServerChannel serverChannel;
int port = 9090;
[TestFixtureSetUp]
public void StartHttpServer ()
{
if (serverChannel != null)
return;
serverChannel = new HttpServerChannel ("HttpServerChannelTests", port);
ChannelServices.RegisterChannel (serverChannel);
RemotingConfiguration.RegisterWellKnownServiceType (
typeof (RemoteObject), "RemoteObject.rem",
WellKnownObjectMode.Singleton);
}
[TestFixtureTearDown]
public void StopHttpServer ()
{
ChannelServices.UnregisterChannel (serverChannel);
}
struct ParseURLTestCase {
public readonly string input;
public readonly string retval;
public readonly string objectURI;
public ParseURLTestCase (string s0, string s1, string s2)
{
input = s0;
retval = s1;
objectURI = s2;
}
};
ParseURLTestCase[] ParseURLTests = new ParseURLTestCase[] {
//new ParseURLTestCase ("http:", "http:", null), // KnownFailure but works on Microsoft's .NET
new ParseURLTestCase ("http://", "http://", null),
new ParseURLTestCase ("http:localhost", null, null),
new ParseURLTestCase ("ftp://localhost", null, null),
new ParseURLTestCase ("http://localhost", "http://localhost", null),
new ParseURLTestCase ("hTtP://localhost", "hTtP://localhost", null),
new ParseURLTestCase ("https://localhost", "https://localhost", null),
new ParseURLTestCase ("http://localhost:/", "http://localhost:", "/"),
new ParseURLTestCase ("http://localhost:9090", "http://localhost:9090", null),
new ParseURLTestCase ("http://localhost:9090/", "http://localhost:9090", "/"),
new ParseURLTestCase ("http://localhost:9090/RemoteObject.rem", "http://localhost:9090", "/RemoteObject.rem"),
new ParseURLTestCase ("http://localhost:q24691247abc1297/RemoteObject.rem", "http://localhost:q24691247abc1297", "/RemoteObject.rem"),
};
[Test] // HttpChannel.Parse ()
[Ignore ("Fails on MS")]
public void ParseURL ()
{
HttpChannel channel;
int i;
channel = new HttpChannel ();
for (i = 0; i < ParseURLTests.Length; i++) {
string retval, objectURI;
retval = channel.Parse (ParseURLTests[i].input, out objectURI);
Assert.AreEqual (ParseURLTests[i].retval, retval);
Assert.AreEqual (ParseURLTests[i].objectURI, objectURI);
}
}
static void Send (NetworkStream stream, string str)
{
byte [] buf = Encoding.ASCII.GetBytes (str);
Send (stream, buf);
}
static void Send (NetworkStream stream, byte[] buf)
{
//Console.Write ("C: ");
//DumpByteArray (buf, 3);
//Console.Write ("\n");
stream.Write (buf, 0, buf.Length);
}
static int Receive (NetworkStream stream, int chunks, out byte[] buf)
{
byte[] buffer = new byte [4096];
int n, nread = 0;
do {
if ((n = stream.Read (buffer, nread, buffer.Length - nread)) > 0)
nread += n;
chunks--;
} while (n > 0 && chunks > 0);
//Console.Write ("S: ");
if (nread > 0) {
buf = new byte [nread];
for (int i = 0; i < nread; i++)
buf[i] = buffer[i];
//DumpByteArray (buf, 3);
//Console.Write ("\n");
} else {
//Console.Write ("(null)\n");
buf = null;
}
return nread;
}
static string ByteArrayToString (byte[] buf, int indent)
{
StringBuilder sb = new StringBuilder ();
for (int i = 0; i < buf.Length; i++) {
if (!Char.IsControl ((char) buf[i])) {
sb.Append ((char) buf[i]);
} else if (buf[i] == '\r') {
sb.Append ("\\r");
} else if (buf[i] == '\n') {
sb.Append ("\\n\n");
for (int j = 0; j < indent; j++)
sb.Append (' ');
} else {
sb.Append (String.Format ("\\x{0:x2}", buf[i]));
}
}
return sb.ToString ();
}
static void DumpByteArray (byte[] buf, int indent)
{
Console.Write (ByteArrayToString (buf, indent));
}
static int GetResponseContentOffset (byte[] response)
{
for (int i = 0; i < response.Length - 3; i++) {
if (response[i + 0] == '\r' && response[i + 1] == '\n' &&
response[i + 2] == '\r' && response[i + 3] == '\n')
return i + 3;
}
return -1;
}
static bool ResponseMatches (byte[] expected, byte[] actual)
{
int i, j;
// First, we compare the first line of the response - they should match
for (i = 0; i < expected.Length && i < actual.Length; i++) {
if (actual[i] != expected[i]) {
// HTTP/1.1 vs HTTP/1.0
if (i == 7 && expected[0] == 'H' && expected[1] == 'T' && expected[2] == 'T' &&
expected[3] == 'P' && expected[4] == '/' && expected[5] == '1' && expected[6] == '.' &&
expected[7] == '1' && actual[7] == '0')
continue;
//Console.WriteLine ("\nFirst line of actual response did not match");
return false;
}
if (expected[i] == '\n')
break;
}
if (i >= actual.Length) {
//Console.WriteLine ("Actual response too short");
return false;
}
// now compare the content
i = GetResponseContentOffset (expected);
j = GetResponseContentOffset (actual);
for ( ; i < expected.Length && j < actual.Length; i++, j++) {
if (actual[j] != expected[i]) {
//Console.WriteLine ("Content of actual response did not match");
return false;
}
}
if (i < expected.Length) {
//Console.WriteLine ("Expected more content data...");
return false;
}
if (j < actual.Length) {
//Console.WriteLine ("Got too much content data in the server response");
return false;
}
return true;
}
static void CreateBinaryMethodInvoke (string assemblyName, string objectName, string methodName, out byte[] content)
{
string text = String.Format ("{0}, {1}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", objectName, assemblyName);
byte[] lead = new byte [] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x15, 0x11, 0x00, 0x00, 0x00, 0x12 };
byte[] buf;
int index;
content = new byte [lead.Length + 1 + methodName.Length + 1 + 1 + text.Length + 1];
lead.CopyTo (content, 0);
index = lead.Length;
buf = Encoding.ASCII.GetBytes (methodName);
content[index++] = (byte) buf.Length;
buf.CopyTo (content, index);
index += buf.Length;
content[index++] = (byte) 0x12;
buf = Encoding.ASCII.GetBytes (text);
content[index++] = (byte) buf.Length;
buf.CopyTo (content, index);
index += buf.Length;
content[index] = (byte) 0x0b;
}
[Test]
[Category ("NotWorking")] // the faked request content string might be wrong?
public void TestBinaryTransport ()
{
string assemblyName = Assembly.GetExecutingAssembly ().GetName ().Name;
Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Connect (new IPEndPoint (IPAddress.Loopback, port));
NetworkStream stream = new NetworkStream (sock);
byte[] content, buf, outbuf;
CreateBinaryMethodInvoke (assemblyName, typeof (RemoteObject).FullName, "ReturnOne", out content);
// send our POST request
Send (stream, String.Format ("POST /RemoteObject.rem HTTP/1.1\r\n" +
"User-Agent: Mozilla/4.0+(compatible; MSIE 6.0; Windows 6.0.6000.0; MS .NET Remoting; MS .NET CLR 2.0.50727.1433 )\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Host: 127.0.0.1:{0}\r\n" +
"Content-Length: {1}\r\n" +
"Expect: 100-continue\r\n" +
"Connection: Keep-Alive\r\n" +
"\r\n", port, content.Length));
// create our expected response buffer
buf = Encoding.ASCII.GetBytes ("HTTP/1.1 100 Continue\r\n\r\n");
Receive (stream, 1, out outbuf);
Assert.IsNotNull (outbuf, "Server continuation response is null");
Assert.IsTrue (ResponseMatches (buf, outbuf), "Unexpected server continuation response:\n" + ByteArrayToString (outbuf, 0));
// send our content data
Send (stream, content);
// create our expected response buffer
buf = new byte[] { 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31,
0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61,
0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x2f, 0x6f, 0x63, 0x74, 0x65, 0x74,
0x2d, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x0d,
0x0a, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a,
0x20, 0x4d, 0x53, 0x20, 0x2e, 0x4e, 0x45, 0x54,
0x20, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x69, 0x6e,
0x67, 0x2c, 0x20, 0x4d, 0x53, 0x20, 0x2e, 0x4e,
0x45, 0x54, 0x20, 0x43, 0x4c, 0x52, 0x20, 0x32,
0x2e, 0x30, 0x2e, 0x35, 0x30, 0x37, 0x32, 0x37,
0x2e, 0x31, 0x34, 0x33, 0x33, 0x0d, 0x0a, 0x43,
0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c,
0x65, 0x6e, 0x67, 0x74, 0x68, 0x3a, 0x20, 0x32,
0x38, 0x0d, 0x0a, 0x0d, 0x0a, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x11,
0x08, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00,
0x0b };
Receive (stream, 2, out outbuf);
Assert.IsNotNull (outbuf, "Server method-invoke response is null");
Assert.IsTrue (ResponseMatches (buf, outbuf), "Unexpected server method-invoke response:\n" + ByteArrayToString (outbuf, 0));
stream.Close ();
}
[Test]
[Category ("NotWorking")] // The test itself passes, but the runtime goes infinite loop at end of nunit-console udner 2.4.8.
public void TestSoapTransport ()
{
string assemblyName = Assembly.GetExecutingAssembly ().GetName ().Name;
Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Connect (new IPEndPoint (IPAddress.Loopback, port));
NetworkStream stream = new NetworkStream (sock);
string methodName = "ReturnOne";
string headers, content;
byte[] buf, outbuf;
content = String.Format ("<SOAP-ENV:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
"xmlns:clr=\"http://schemas.microsoft.com/soap/encoding/clr/1.0/\" " +
"SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" +
"<SOAP-ENV:Body>\r\n" +
"<i2:{0} id=\"ref-1\" xmlns:i2=\"http://schemas.microsoft.com/clr/nsassem/{1}/{2}\">\r\n" +
"</i2:{0}>\r\n" +
"</SOAP-ENV:Body>\r\n" +
"</SOAP-ENV:Envelope>", methodName, typeof (RemoteObject).FullName, assemblyName);
headers = String.Format ("POST /RemoteObject.rem HTTP/1.1\r\n" +
"User-Agent: Mozilla/4.0+(compatible; MSIE 6.0; Windows 6.0.6000.0; MS .NET Remoting; MS .NET CLR 2.0.50727.1433 )\r\n" +
"Content-Type: text/xml; charset=\"utf-8\"\r\n" +
"SOAPAction: \"http://schemas.microsoft.com/clr/nsassem/{0}/{1}#{2}\"\r\n" +
"Host: 127.0.0.1:{3}\r\n" +
"Content-Length: {4}\r\n" +
"Expect: 100-continue\r\n" +
"Connection: Keep-Alive\r\n" +
"\r\n", typeof (RemoteObject).FullName, assemblyName, methodName, port, content.Length);
Send (stream, headers);
// create our expected response buffer
buf = Encoding.ASCII.GetBytes ("HTTP/1.1 100 Continue\r\n\r\n");
Receive (stream, 1, out outbuf);
Assert.IsNotNull (outbuf, "Server continuation response is null");
Assert.IsTrue (ResponseMatches (buf, outbuf), "Unexpected server continuation response:\n" + ByteArrayToString (outbuf, 0));
// send our content data
Send (stream, content);
// create our expected response buffer
#if MICROSOFT_DOTNET_SERVER
content = String.Format ("<SOAP-ENV:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
"xmlns:clr=\"http://schemas.microsoft.com/soap/encoding/clr/1.0\" " +
"SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" +
"<SOAP-ENV:Body>\r\n" +
"<i2:{0}Response id=\"ref-1\" xmlns:i2=\"http://schemas.microsoft.com/clr/nsassem/{1}/{2}\">\r\n" +
"<return>1</return>\r\n" +
"</i2:{0}Response>\r\n" +
"</SOAP-ENV:Body>\r\n" +
"</SOAP-ENV:Envelope>\r\n", methodName, typeof (RemoteObject).FullName, assemblyName);
#else
//slight differences in formatting
content = String.Format ("<SOAP-ENV:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
"xmlns:clr=\"http://schemas.microsoft.com/clr/\" " +
"SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
" <SOAP-ENV:Body>\n" +
" <i2:{0}Response id=\"ref-1\" xmlns:i2=\"http://schemas.microsoft.com/clr/nsassem/{1}/{2}\">\n" +
" <return xsi:type=\"xsd:int\">1</return>\n" +
" </i2:{0}Response>\n" +
" </SOAP-ENV:Body>\n" +
"</SOAP-ENV:Envelope>", methodName, typeof (RemoteObject).FullName, assemblyName);
#endif
headers = String.Format ("HTTP/1.1 200 OK\r\nContent-Type: text/xml; charset=\"utf-8\"\r\n" +
"Server: MS .NET Remoting, MS .NET CLR 2.0.50727.1433\r\n" +
"Content-Length: {0}\r\n\r\n", content.Length);
buf = Encoding.ASCII.GetBytes (headers + content);
Receive (stream, 2, out outbuf);
Assert.IsNotNull (outbuf, "Server method-invoke response is null");
Assert.IsTrue (ResponseMatches (buf, outbuf), "Unexpected server method-invoke response:\n" + ByteArrayToString (outbuf, 0));
stream.Close ();
}
object mutex = new object ();
bool []retvals;
void MultiClientStart ()
{
int rv = 0;
// the prupose of this is just to block until all clients have been created
lock (mutex) {
rv++;
}
RemoteObject remObj = new RemoteObject ();
rv = remObj.Increment ();
// make sure the value returned hasn't been returned to another thread as well
lock (retvals) {
Assert.IsTrue (!retvals[rv], "RemoteObject.Increment() has already returned " + rv);
retvals[rv] = true;
}
}
[Test]
[Category ("NotWorking")] // disabled as it got not working by NUnit upgrade to 2.4.8
public void MultiClientConnection ()
{
int num_clients = 20;
Hashtable options = new Hashtable ();
options ["timeout"] = 10000; // 10s
options ["name"] = "MultiClientConnection"; // 10s
HttpClientChannel clientChannel = new HttpClientChannel (options, null);
ChannelServices.RegisterChannel (clientChannel);
try {
WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry (
typeof (RemoteObject), "http://127.0.0.1:9090/RemoteObject.rem");
RemotingConfiguration.RegisterWellKnownClientType (remoteType);
// start a bunch of clients...
Thread []clients = new Thread [num_clients];
retvals = new bool [num_clients];
lock (mutex) {
for (int i = 0; i < num_clients; i++) {
clients[i] = new Thread (MultiClientStart);
clients[i].Start ();
retvals[i] = false;
}
}
// wait for all clients to finish...
for (int i = 0; i < num_clients; i++)
clients[i].Join ();
for (int i = 0; i < num_clients; i++)
Assert.IsTrue (retvals[i], "RemoteObject.Incrememnt() didn't return a value of " + i);
} finally {
ChannelServices.UnregisterChannel (clientChannel);
}
}
}
}

View File

@@ -0,0 +1,93 @@
//
// System.Runtime.Remoting.Test.IpcCalls.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
// Robert Jordan (robertj@gmx.net)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
using NUnit.Framework;
namespace MonoTests.Remoting
{
[TestFixture]
public class IpcSyncCallTest : SyncCallTest
{
public override ChannelManager CreateChannelManager ()
{
return new IpcChannelManager ();
}
}
[TestFixture]
public class IpcAsyncCallTest : AsyncCallTest
{
public override ChannelManager CreateChannelManager ()
{
return new IpcChannelManager ();
}
}
[TestFixture]
public class IpcReflectionCallTest : ReflectionCallTest
{
public override ChannelManager CreateChannelManager ()
{
return new IpcChannelManager ();
}
}
[TestFixture]
public class IpcDelegateCallTest : DelegateCallTest
{
public override ChannelManager CreateChannelManager ()
{
return new IpcChannelManager ();
}
}
[Serializable]
public class IpcChannelManager : ChannelManager
{
public override IChannelSender CreateClientChannel ()
{
return new IpcChannel ();
}
public override IChannelReceiver CreateServerChannel ()
{
// simulate the Tcp/HttpChannel(0) semantics with a GUID.
string portName = "ipc" + Guid.NewGuid ().ToString ("N");
return new IpcChannel (portName);
}
}
}
#endif

View File

@@ -0,0 +1,118 @@
//
// MonoTests.Remoting.IpcChannelTests.cs
//
// Authors:
// Robert Jordan (robertj@gmx.net)
//
#if NET_2_0
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
using NUnit.Framework;
namespace MonoTests.Remoting
{
[TestFixture]
public class IpcChannelTest
{
[Test]
public void Bug81653 ()
{
IpcClientChannel c = new IpcClientChannel ();
ChannelDataStore cd = new ChannelDataStore (new string[] { "foo" });
string objectUri;
c.CreateMessageSink (null, cd, out objectUri);
}
[Test]
public void Bug609381 ()
{
string portName = "ipc" + Guid.NewGuid ().ToString ("N");
string objUri = "ipcserver609381.rem";
string url = String.Format ("ipc://{0}/{1}", portName, objUri);
IpcChannel serverChannel = new IpcChannel (portName);
ChannelServices.RegisterChannel (serverChannel);
RemotingServices.Marshal (new Server (), objUri);
Server client = (Server) RemotingServices.Connect (typeof (Server), url);
int count = 10 * 1024 * 1024;
byte[] sendBuf = new byte[count];
sendBuf [sendBuf.Length - 1] = 41;
byte[] recvBuf = client.Send (sendBuf);
Assert.IsNotNull (recvBuf);
Assert.AreNotSame (sendBuf, recvBuf);
Assert.AreEqual (count, recvBuf.Length);
Assert.AreEqual (42, recvBuf [recvBuf.Length - 1]);
sendBuf = null;
recvBuf = null;
ChannelServices.UnregisterChannel (serverChannel);
}
class Server : MarshalByRefObject
{
public byte[] Send (byte[] payload)
{
payload [payload.Length - 1]++;
return payload;
}
}
[Test]
public void TestCtor2 ()
{
string channelName = Guid.NewGuid ().ToString ("N");
string portName = "ipc" + Guid.NewGuid ().ToString ("N");
string url = String.Format ("ipc://{0}/server.rem", portName);
IpcServerChannel chan = new IpcServerChannel (channelName, portName);
string[] uris = chan.GetUrlsForUri ("server.rem");
Assert.IsNotNull (uris);
Assert.Greater (uris.Length, 0);
bool found = false;
foreach (string s in uris) {
if (s == url) {
found = true;
break;
}
}
Assert.IsTrue (found);
}
[Test]
public void TestCtor3 ()
{
string portName = "ipc" + Guid.NewGuid ().ToString ("N");
string url = String.Format ("ipc://{0}/server.rem", portName);
Hashtable props = new Hashtable ();
props ["portName"] = portName;
IpcChannel chan = new IpcChannel (props, null, null);
string[] uris = chan.GetUrlsForUri ("server.rem");
Assert.IsNotNull (uris);
Assert.Greater (uris.Length, 0);
bool found = false;
foreach (string s in uris) {
if (s == url) {
found = true;
break;
}
}
Assert.IsTrue (found);
}
}
}
#endif

View File

@@ -0,0 +1,177 @@
//
// MonoTests.Remoting.ReflectionCalls.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//
using System;
using System.Reflection;
using System.Collections;
using NUnit.Framework;
using System.Text;
using System.Runtime.InteropServices;
namespace MonoTests.Remoting
{
public abstract class ReflectionCallTest : BaseCallTest
{
public override InstanceSurrogate GetInstanceSurrogate () { return new ReflectionInstanceSurrogate (); }
public override AbstractSurrogate GetAbstractSurrogate () { return new ReflectionAbstractSurrogate (); }
public override InterfaceSurrogate GetInterfaceSurrogate () { return new ReflectionInterfaceSurrogate (); }
public static int Simple (Type type, object target)
{
object[] parms = new object[0];
MethodBase m = type.GetMethod ("Simple");
return (int) m.Invoke (target, parms);
}
public static string PrimitiveParams (Type type, object target, int a, uint b, char c, string d)
{
object[] parms = new object[] {a,b,c,d};
Type[] sig = new Type[] {typeof (int), typeof (uint), typeof (char), typeof (string)};
MethodBase m = type.GetMethod ("PrimitiveParams", sig);
return (string) m.Invoke (target, parms);
}
public static string PrimitiveParamsInOut (Type type, object target, ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
{
object[] parms = new object[] {a1,0,b1,0f,filler,c1,'\0',d1,null};
MethodBase m = type.GetMethod ("PrimitiveParamsInOut");
string res = (string) m.Invoke (target, parms);
a1 = (int)parms[0];
b1 = (float)parms[2];
c1 = (char)parms[5];
d1 = (string)parms[7];
a2 = (int)parms[1];
b2 = (float)parms[3];
c2 = (char)parms[6];
d2 = (string)parms[8];
return res;
}
public static Complex ComplexParams (Type type, object target, ArrayList a, Complex b, string c)
{
object[] parms = new object[] {a,b,c};
MethodBase m = type.GetMethod ("ComplexParams");
return (Complex) m.Invoke (target, parms);
}
public static Complex ComplexParamsInOut (Type type, object target, ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
{
object[] parms = new object[] {a,null,bytes,sb,c};
MethodBase m = type.GetMethod ("ComplexParamsInOut");
Complex res = (Complex) m.Invoke (target, parms);
a = (ArrayList) parms[0];
b = (Complex) parms[1];
return res;
}
public static void ProcessContextData (Type type, object target)
{
MethodBase m = type.GetMethod ("ProcessContextData");
m.Invoke (target, null);
}
}
public class ReflectionInstanceSurrogate : InstanceSurrogate
{
public override int Simple ()
{
return ReflectionCallTest.Simple (typeof (RemoteObject), RemoteObject);
}
public override string PrimitiveParams (int a, uint b, char c, string 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, int filler, ref char c1, out char c2, ref string d1, out string d2)
{
return ReflectionCallTest.PrimitiveParamsInOut (typeof (RemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
return ReflectionCallTest.ComplexParams (typeof (RemoteObject), RemoteObject, a, b, c);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
{
return ReflectionCallTest.ComplexParamsInOut (typeof (RemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
}
public override void ProcessContextData ()
{
ReflectionCallTest.ProcessContextData (typeof (RemoteObject), RemoteObject);
}
}
public class ReflectionAbstractSurrogate : AbstractSurrogate
{
public override int Simple ()
{
return ReflectionCallTest.Simple (typeof (AbstractRemoteObject), RemoteObject);
}
public override string PrimitiveParams (int a, uint b, char c, string 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, int filler, ref char c1, out char c2, ref string d1, out string d2)
{
return ReflectionCallTest.PrimitiveParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
return ReflectionCallTest.ComplexParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
{
return ReflectionCallTest.ComplexParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
}
public override void ProcessContextData ()
{
ReflectionCallTest.ProcessContextData (typeof (AbstractRemoteObject), RemoteObject);
}
}
public class ReflectionInterfaceSurrogate : InterfaceSurrogate
{
public override int Simple ()
{
return ReflectionCallTest.Simple (typeof (IRemoteObject), RemoteObject);
}
public override string PrimitiveParams (int a, uint b, char c, string 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, int filler, ref char c1, out char c2, ref string d1, out string d2)
{
return ReflectionCallTest.PrimitiveParamsInOut (typeof (IRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
return ReflectionCallTest.ComplexParams (typeof (IRemoteObject), RemoteObject, a, b, c);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
{
return ReflectionCallTest.ComplexParamsInOut (typeof (IRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
}
public override void ProcessContextData ()
{
ReflectionCallTest.ProcessContextData (typeof (IRemoteObject), RemoteObject);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,174 @@
//
// MonoTests.Remoting.ServerObject.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Lifetime;
using System.Collections;
using NUnit.Framework;
namespace MonoTests.Remoting
{
// A list of ServerObject instances
[ContextHook("x", false)]
public class ServerList:
ContextBoundObject,
IDisposable
{
ArrayList values = new ArrayList();
public int NumVal = 0;
public string StrVal = "val";
public ServerList()
{
Assert.IsTrue (RemotingServices.IsTransparentProxy(this));
CallSeq.Add ("List created");
}
public void Dispose()
{
Assert.IsTrue (RemotingServices.IsTransparentProxy(this));
CallSeq.Add ("List disposed");
}
public void Add (ServerObject v)
{
Assert.IsTrue (RemotingServices.IsTransparentProxy(this));
values.Add (v);
CallSeq.Add ("Added " + v.Name);
}
public void ProcessItems ()
{
Assert.IsTrue (RemotingServices.IsTransparentProxy(this));
CallSeq.Add ("Processing");
int total = 0;
foreach (ServerObject ob in values)
total += ob.GetValue();
CallSeq.Add ("Total: " + total);
}
public void Clear()
{
Assert.IsTrue (RemotingServices.IsTransparentProxy(this));
CallSeq.Add ("Clearing");
values.Clear();
}
public void ParameterTest1 (int a, out string b)
{
Assert.IsTrue (RemotingServices.IsTransparentProxy(this));
b = "adeu " + a;
}
public void ParameterTest2 (int a, out int b)
{
Assert.IsTrue (RemotingServices.IsTransparentProxy(this));
b = a+1;
}
public ServerObject NewItem(string name)
{
Assert.IsTrue (RemotingServices.IsTransparentProxy(this));
ServerObject obj = new ServerObject(name);
Add (obj);
return obj;
}
public ServerObject CreateItem(string name, int val)
{
Assert.IsTrue (RemotingServices.IsTransparentProxy(this));
ServerObject obj = new ServerObject(name);
obj.SetValue (val);
return obj;
}
public ComplexData SetComplexData (ComplexData data)
{
Assert.IsTrue (RemotingServices.IsTransparentProxy(this));
CallSeq.Add ("Showing content of ComplexData");
data.Dump ();
return data;
}
public override ObjRef CreateObjRef (Type type)
{
Assert.IsTrue (RemotingServices.IsTransparentProxy(this));
CallSeq.Add ("### ServerList.CreateObjRef");
return base.CreateObjRef (type);
}
}
// A remotable object
public class ServerObject:
// ContextBoundObject
MarshalByRefObject
{
int _value;
string _name;
public ServerObject (string name)
{
_name = name;
}
public string Name
{
get { return _name; }
}
public void SetValue (int v)
{
CallSeq.Add ("ServerObject " + _name + ": setting " + v);
_value = v;
}
public int GetValue ()
{
CallSeq.Add ("ServerObject " + _name + ": getting " + _value);
return _value;
}
public override ObjRef CreateObjRef (Type type)
{
CallSeq.Add ("### ServerObject.CreateObjRef");
return base.CreateObjRef (type);
}
}
// Some complex data for testing serialization
public enum AnEnum { a,b,c,d,e };
[Serializable]
public class ComplexData
{
public AnEnum Val = AnEnum.a;
public object[] Info;
public ComplexData (AnEnum va, object[] info)
{
Info = info;
Val = va;
}
public void Dump ()
{
CallSeq.Add ("Content:");
CallSeq.Add ("Val: " + Val);
foreach (object ob in Info)
CallSeq.Add ("Array item: " + ob);
}
}
}

View File

@@ -0,0 +1,122 @@
//
// MonoTests.Remoting.SyncCalls.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//
using System;
using System.Collections;
using NUnit.Framework;
using System.Text;
using System.Runtime.InteropServices;
namespace MonoTests.Remoting
{
public abstract class SyncCallTest : BaseCallTest
{
public override InstanceSurrogate GetInstanceSurrogate () { return new SyncInstanceSurrogate (); }
public override AbstractSurrogate GetAbstractSurrogate () { return new SyncAbstractSurrogate (); }
public override InterfaceSurrogate GetInterfaceSurrogate () { return new SyncInterfaceSurrogate (); }
}
public class SyncInstanceSurrogate : InstanceSurrogate
{
public override int Simple ()
{
return RemoteObject.Simple ();
}
public override string PrimitiveParams (int a, uint b, char c, string d)
{
return RemoteObject.PrimitiveParams (a, b, c, d);
}
public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
{
return RemoteObject.PrimitiveParamsInOut (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
return RemoteObject.ComplexParams (a, b, c);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
{
return RemoteObject.ComplexParamsInOut (ref a, out b, bytes, sb, c);
}
public override void ProcessContextData ()
{
RemoteObject.ProcessContextData ();
}
}
public class SyncAbstractSurrogate : AbstractSurrogate
{
public override int Simple ()
{
return RemoteObject.Simple ();
}
public override string PrimitiveParams (int a, uint b, char c, string d)
{
return RemoteObject.PrimitiveParams (a, b, c, d);
}
public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
{
return RemoteObject.PrimitiveParamsInOut (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
return RemoteObject.ComplexParams (a, b, c);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
{
return RemoteObject.ComplexParamsInOut (ref a, out b, bytes, sb, c);
}
public override void ProcessContextData ()
{
RemoteObject.ProcessContextData ();
}
}
public class SyncInterfaceSurrogate : InterfaceSurrogate
{
public override int Simple ()
{
return RemoteObject.Simple ();
}
public override string PrimitiveParams (int a, uint b, char c, string d)
{
return RemoteObject.PrimitiveParams (a, b, c, d);
}
public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
{
return RemoteObject.PrimitiveParamsInOut (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
}
public override Complex ComplexParams (ArrayList a, Complex b, string c)
{
return RemoteObject.ComplexParams (a, b, c);
}
public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
{
return RemoteObject.ComplexParamsInOut (ref a, out b, bytes, sb, c);
}
public override void ProcessContextData ()
{
RemoteObject.ProcessContextData ();
}
}
}

View File

@@ -0,0 +1,15 @@
2008-09-17 Jeffrey Stedfast <fejj@novell.com>
* TcpChannelTest.cs: Changed the namespace to MonoTests.Remoting
like the other Remoting tests and added a client<->server
communication test. Throw in a ftp:// url for the url-parsing test
to make sure the parser returns null on that.
2008-09-11 Jeffrey Stedfast <fejj@novell.com>
* TcpChannelTest.cs: Added TcpChannel.Parse() tests.
2008-01-25 Gert Driesen <drieseng@users.sourceforge.net>
* TcpChannelTest.cs: Added simple ctor test that covers bug #355905.

Some files were not shown because too many files have changed in this diff Show More