Browse Source

* System.Runtime.Remoting_test.dll.sources: add TcpChannelTest.cs.
* RemotingServicesTest.cs: Do not hide exception that occur when
unregistering a channel. Code formatting and removed extra tabs.
* TcpChannelTest.cs: Added simple ctor test that covers bug #355905.
* System.Runtime.Remoting_test.dll.sources: add TcpChannelTest.cs.

svn path=/trunk/mcs/; revision=93956

Gert Driesen 18 năm trước cách đây
mục cha
commit
5b45f4fecc

+ 4 - 0
mcs/class/System.Runtime.Remoting/ChangeLog

@@ -1,3 +1,7 @@
+2008-01-25  Gert Driesen  <[email protected]>
+
+	* System.Runtime.Remoting_test.dll.sources: add TcpChannelTest.cs.
+
 2007-05-19  Robert Jordan  <[email protected]>
 
 	* System.Runtime.Remoting_test.dll.sources: add IpcChannelTest.cs

+ 1 - 0
mcs/class/System.Runtime.Remoting/System.Runtime.Remoting_test.dll.sources

@@ -1,3 +1,4 @@
+System.Runtime.Remoting.Channels.Tcp/TcpChannelTest.cs
 ServerObject.cs
 ContextsTest.cs
 CallSeq.cs

+ 5 - 0
mcs/class/System.Runtime.Remoting/Test/ChangeLog

@@ -1,3 +1,8 @@
+2008-01-25  Gert Driesen  <[email protected]>
+
+	* RemotingServicesTest.cs: Do not hide exception that occur when
+	unregistering a channel. Code formatting and removed extra tabs.
+
 2007-10-30  Robert Jordan  <[email protected]>
 
 	* GenericTest.cs: Add tests for bug #324232.

+ 47 - 75
mcs/class/System.Runtime.Remoting/Test/RemotingServicesTest.cs

@@ -139,25 +139,23 @@ namespace MonoTests.System.Runtime.Remoting.RemotingServicesInternal
 		public void Method1()
 		{
 			_called++;
-			methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());			
+			methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());
 		}
 		
 		public void Method2()
 		{
-			methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());			
+			methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());
 		}
 		
 		public void Method2(int i)
 		{
-			methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());			
-			
+			methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());
 		}
 		
 		[OneWay()]
 		public void Method3()
 		{
-			methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());			
-			
+			methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());
 		}
 		
 		public static int Called
@@ -183,7 +181,7 @@ namespace MonoTests.System.Runtime.Remoting.RemotingServicesInternal
 		public DerivedMarshalObject(){}
 		
 		public DerivedMarshalObject(int id, string uri): base(id, uri) {}
-	}	
+	}
 	
 	interface A
 	{
@@ -267,7 +265,7 @@ namespace MonoTests.Remoting
 			
 			Assert("#A04", objRef.URI.EndsWith(objMarshal.Uri));
 			// TODO: uncomment when RemotingServices.Disconnect is implemented
-			//RemotingServices.Disconnect(objMarshal);		
+			//RemotingServices.Disconnect(objMarshal);
 		}
 		
 		[Test]
@@ -324,7 +322,6 @@ namespace MonoTests.Remoting
 		
 		// Tests RemotingServices.Marshal()
 		[Test]
-		[ExpectedException(typeof(RemotingException))]	
 		public void MarshalThrowException()
 		{
 			MarshalObject objMarshal = NewMarshalObject();
@@ -338,22 +335,19 @@ namespace MonoTests.Remoting
 			RemotingServices.Marshal(objMarshal,objMarshal.Uri);
 			
 			MarshalObject objRem = (MarshalObject) RemotingServices.Connect(typeof(MarshalObject), "tcp://localhost:1237/" + objMarshal.Uri);
-			// This line sould throw a RemotingException
+			// This line should throw a RemotingException
 			// It is forbidden to export an object which is not
 			// a real object
-			try
-			{
+			try {
 				RemotingServices.Marshal(objRem, objMarshal.Uri);
-			}
-			catch(Exception e)
-			{
+				Fail ("#1");
+			} catch (RemotingException e) {
+			} finally {
 				ChannelServices.UnregisterChannel(chn);
 			
-			// TODO: uncomment when RemotingServices.Disconnect is implemented
-			//RemotingServices.Disconnect(objMarshal);
-			
-				throw e;
-			}		
+				// TODO: uncomment when RemotingServices.Disconnect is implemented
+				//RemotingServices.Disconnect(objMarshal);
+			}
 		}
 		
 		// Tests RemotingServices.ExecuteMessage()
@@ -363,8 +357,7 @@ namespace MonoTests.Remoting
 		public void ExecuteMessage()
 		{
 			TcpChannel chn = null;
-			try
-			{
+			try {
 				chn = new TcpChannel(1235);
 				ChannelServices.RegisterChannel(chn);
 				
@@ -388,10 +381,9 @@ namespace MonoTests.Remoting
 				// Tests RemotingServices.ExecuteMessage();
 				// If ExecuteMessage does it job well, Method1 should be called 2 times
 				AssertEquals("#A10", 2, MarshalObject.Called);
-			}
-			finally
-			{
-				if(chn != null) ChannelServices.UnregisterChannel(chn);
+			} finally {
+				if (chn != null)
+					ChannelServices.UnregisterChannel (chn);
 			}
 		}
 		
@@ -400,8 +392,7 @@ namespace MonoTests.Remoting
 		public void IsOneWay()
 		{
 			TcpChannel chn = null;
-			try
-			{
+			try {
 				chn = new TcpChannel(1238);
 				ChannelServices.RegisterChannel(chn);
 				RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MarshalObject.rem", WellKnownObjectMode.Singleton);
@@ -416,10 +407,9 @@ namespace MonoTests.Remoting
 				objRem.Method3();
 				Thread.Sleep(20);
 				Assert("#A10.3", MarshalObject.IsMethodOneWay);
-			}
-			finally
-			{
-				if(chn != null) ChannelServices.UnregisterChannel(chn);
+			} finally {
+				if (chn != null)
+					ChannelServices.UnregisterChannel (chn);
 			}
 		}
 		
@@ -427,8 +417,7 @@ namespace MonoTests.Remoting
 		public void GetObjRefForProxy()
 		{
 			TcpChannel chn = null;
-			try
-			{
+			try {
 				chn = new TcpChannel(1239);
 				ChannelServices.RegisterChannel(chn);
 				
@@ -443,10 +432,9 @@ namespace MonoTests.Remoting
 				ObjRef objRefRem = RemotingServices.GetObjRefForProxy((MarshalByRefObject)objRem);
 				
 				Assert("#A11", objRefRem != null);
-			}
-			finally
-			{
-				if(chn != null) ChannelServices.UnregisterChannel(chn);				
+			} finally {
+				if (chn != null)
+					ChannelServices.UnregisterChannel (chn);
 			}
 		}
 		
@@ -455,8 +443,7 @@ namespace MonoTests.Remoting
 		public void GetRealProxy()
 		{
 			TcpChannel chn = null;
-			try
-			{
+			try {
 				chn = new TcpChannel(1241);
 				ChannelServices.RegisterChannel(chn);
 				
@@ -469,10 +456,9 @@ namespace MonoTests.Remoting
 				
 				Assert("#A12", rp != null);
 				AssertEquals("#A13", "MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType().ToString());
-			}
-			finally
-			{
-				if(chn != null) ChannelServices.UnregisterChannel(chn);
+			} finally {
+				if (chn != null)
+					ChannelServices.UnregisterChannel(chn);
 			}
 		}
 		
@@ -481,8 +467,7 @@ namespace MonoTests.Remoting
 		public void SetObjectUriForMarshal()
 		{
 			TcpChannel chn = null;
-			try
-			{
+			try {
 				chn = new TcpChannel(1242);
 				ChannelServices.RegisterChannel(chn);
 				
@@ -492,11 +477,10 @@ namespace MonoTests.Remoting
 				
 				objRem = (MarshalObject) Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1242/"+objRem.Uri);
 				Assert("#A14", objRem != null);
+			} finally {
+				if (chn != null)
+					ChannelServices.UnregisterChannel (chn);
 			}
-			finally
-			{
-				if(chn != null) ChannelServices.UnregisterChannel(chn);
-			}			
 			
 		}
 		
@@ -506,8 +490,7 @@ namespace MonoTests.Remoting
 		{
 			TcpChannel chn = null;
 			Type type = typeof(MarshalObject);
-			try
-			{
+			try {
 				chn = new TcpChannel(1243);
 				ChannelServices.RegisterChannel(chn);
 				
@@ -517,11 +500,10 @@ namespace MonoTests.Remoting
 				
 				Type typeRem = RemotingServices.GetServerTypeForUri(RemotingServices.GetObjectUri(objRem));
 				AssertEquals("#A15", type, typeRem);
+			} finally {
+				if (chn != null)
+					ChannelServices.UnregisterChannel (chn);
 			}
-			finally
-			{
-				if(chn != null) ChannelServices.UnregisterChannel(chn);
-			}			
 		}
 		
 		// Tests IsObjectOutOfDomain
@@ -530,8 +512,7 @@ namespace MonoTests.Remoting
 		public void IsObjectOutOf()
 		{
 			TcpChannel chn = null;
-			try
-			{
+			try {
 				chn = new TcpChannel(1245);
 				ChannelServices.RegisterChannel(chn);
 				
@@ -545,10 +526,9 @@ namespace MonoTests.Remoting
 				MarshalObject objMarshal = new MarshalObject();
 				Assert("#A18", !RemotingServices.IsObjectOutOfAppDomain(objMarshal));
 				Assert("#A19", !RemotingServices.IsObjectOutOfContext(objMarshal));
-			}
-			finally
-			{
-				ChannelServices.UnregisterChannel(chn);
+			} finally {
+				if (chn != null)
+					ChannelServices.UnregisterChannel (chn);
 			}
 		}
 
@@ -557,8 +537,7 @@ namespace MonoTests.Remoting
 		{
 			RemotingConfiguration.ApplicationName = "app";
 			TcpChannel chn = null;
-			try
-			{
+			try {
 				chn = new TcpChannel(1246);
 				ChannelServices.RegisterChannel(chn);
 				
@@ -577,13 +556,9 @@ namespace MonoTests.Remoting
 				AssertNull ("#AN7", RemotingServices.GetServerTypeForUri ("/whatever/obj3.rem"));
 				AssertNotNull ("#AN8", RemotingServices.GetServerTypeForUri ("/obj3.rem"));
 				AssertNull ("#AN9", RemotingServices.GetServerTypeForUri ("//obj3.rem"));
-			}
-			finally
-			{
-				try {
+			} finally {
+				if (chn != null)
 					ChannelServices.UnregisterChannel(chn);
-				} catch {
-				}
 			}
 		}
 
@@ -599,12 +574,9 @@ namespace MonoTests.Remoting
 
 				string channelData = "test";
 				AssertNotNull ("#01", Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1247/getobjectwithchanneldata.rem", channelData));
-
 			} finally {
-				try {
-					ChannelServices.UnregisterChannel(chn);
-				} catch {
-				}
+				if (chn != null)
+					ChannelServices.UnregisterChannel (chn);
 			}
 		}
 		

+ 4 - 0
mcs/class/System.Runtime.Remoting/Test/System.Runtime.Remoting.Channels.Tcp/ChangeLog

@@ -0,0 +1,4 @@
+2008-01-25  Gert Driesen  <[email protected]>
+
+	* TcpChannelTest.cs: Added simple ctor test that covers bug #355905.
+

+ 93 - 0
mcs/class/System.Runtime.Remoting/Test/System.Runtime.Remoting.Channels.Tcp/TcpChannelTest.cs

@@ -0,0 +1,93 @@
+//
+// TcpChanneltest.cs
+//
+// Author:
+//	Gert Driesen <[email protected]>
+//
+// Copyright (C) 2008 Gert Driesen
+//
+// 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.Net;
+using System.Runtime.Remoting;
+using System.Runtime.Remoting.Channels;
+using System.Runtime.Remoting.Channels.Tcp;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Runtime.Remoting.Channels.Tcp
+{
+	[TestFixture]
+	public class TcpChannelTest
+	{
+		[Test] // TcpChannel (IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)
+		public void Constructor3 ()
+		{
+			const string SERVICE_URI = "MarshalSvc";
+			string [] urls;
+			ChannelDataStore ds;
+			TcpChannel chn;
+
+			MarshalObject marshal = new MarshalObject ();
+
+			IDictionary props = new Hashtable ();
+			props ["name"] = "marshal channel";
+			props ["port"] = 1236;
+			props ["bindTo"] = IPAddress.Loopback.ToString ();
+			chn = new TcpChannel (props, null, null);
+
+			ChannelServices.RegisterChannel (chn);
+
+			Assert.AreEqual ("marshal channel", chn.ChannelName, "#A1");
+			urls = chn.GetUrlsForUri (SERVICE_URI);
+			Assert.IsNotNull (urls, "#A2");
+			Assert.AreEqual (1, urls.Length, "#A3");
+			Assert.AreEqual ("tcp://" + IPAddress.Loopback.ToString () + ":1236/" + SERVICE_URI, urls [0], "#A6");
+			ds = chn.ChannelData as ChannelDataStore;
+			Assert.IsNotNull (ds, "#A4");
+			Assert.AreEqual (1, ds.ChannelUris.Length, "#A5");
+			Assert.AreEqual ("tcp://" + IPAddress.Loopback.ToString () + ":1236", ds.ChannelUris [0], "#A6");
+
+			ChannelServices.UnregisterChannel (chn);
+
+			chn = new TcpChannel ((IDictionary) null, null, null);
+
+			ChannelServices.RegisterChannel (chn);
+
+			Assert.AreEqual ("tcp", chn.ChannelName, "#B1");
+			urls = chn.GetUrlsForUri (SERVICE_URI);
+			Assert.IsNull (urls, "#B1");
+			ds = chn.ChannelData as ChannelDataStore;
+			Assert.IsNull (ds, "#B2");
+
+			ChannelServices.UnregisterChannel (chn);
+		}
+
+		public class MarshalObject : ContextBoundObject
+		{
+			public MarshalObject ()
+			{
+			}
+		}
+	}
+}