Merge pull request #200 from ch5oh/master
[mono.git] / mcs / class / corlib / Test / System / MarshalByRefObjectTest.cs
old mode 100755 (executable)
new mode 100644 (file)
index 8b1c22f..45dcf5d
-// MarshalByRefObjectTest.cs Test class for\r
-// System.MarshalByRefObject class\r
-// \r
-// Jean-Marc Andre (jean-marc.andre@polymtl.ca)\r
-//\r
-\r
-using System;\r
-using System.Runtime.Remoting;\r
-using System.Runtime.Remoting.Lifetime;\r
-using System.Runtime.Serialization;\r
-using System.Runtime.Remoting.Channels;\r
-using System.Runtime.Remoting.Channels.Tcp;\r
-\r
-// Just an internal test namespace for\r
-// the MarshalByRefObjectTest class\r
-namespace MonoTests.System.MarshalByRefObjectTestInternal\r
-  {\r
-\r
-  // Object from this class can be marshaled\r
-  public class MarshalObject: MarshalByRefObject\r
-    {\r
-    public MarshalObject(){}\r
-\r
-    public MarshalObject(int id)\r
-      {\r
-      this.id = id;\r
-      }\r
-\r
-    // This method override the default one\r
-    // so we can set some properties of the lifetime\r
-    // of the remot object\r
-    public override object InitializeLifetimeService()\r
-      {\r
-      ILease lease = (ILease) base.InitializeLifetimeService();\r
-\r
-      // By default InitialLeaseTime is set to 5 minutes\r
-      // we set it at 10 seconds\r
-      if(lease.CurrentState == LeaseState.Initial)\r
-       {\r
-       lease.InitialLeaseTime = TimeSpan.FromSeconds(10);\r
-       }\r
-      return lease;\r
-      }\r
-\r
-    public int Id\r
-      {\r
-      get { return id;}\r
-      }\r
-\r
-    private int id = 0;\r
-    } // MarshalObject\r
-\r
-  } // MonoTests.System.MarshalByRefObjectTestInternal\r
-\r
-\r
-namespace MonoTests.System\r
-  {\r
-  using MonoTests.System.MarshalByRefObjectTestInternal;\r
-  using NUnit.Framework;\r
-\r
-  // The main test class\r
-  [TestFixture]\r
-  public class MarshalByRefObjectTest\r
-    {\r
-    public MarshalByRefObjectTest()\r
-      {\r
-\r
-      }\r
-\r
-    // This method test the CreateObjRef\r
-    [Test]\r
-      public void CreateObjRef()\r
-      {\r
-      MarshalObject objMarshal = new MarshalObject();\r
-\r
-      RemotingServices.SetObjectUriForMarshal(objMarshal, "MarshalByRefObjectTest.objMarshal1");\r
-      RemotingServices.Marshal(objMarshal);\r
-\r
-      ObjRef objRef = objMarshal.CreateObjRef(typeof(MarshalObject));\r
-      Assertion.AssertEquals("#A01", objRef.URI, RemotingServices.GetObjectUri(objMarshal));\r
-\r
-      // TODO: When implemented in the mono RemotingServices class\r
-      //RemotingServices.Disconnect(objMarshal);\r
-      }\r
-\r
-    [Test]\r
-      [ExpectedException(typeof(RemotingException))]\r
-      public void CreateObjRefThrowException()\r
-      {\r
-      MarshalObject objMarshal = new MarshalObject();\r
-\r
-      ObjRef objRef = objMarshal.CreateObjRef(typeof(MarshalObject));\r
-      }\r
-\r
-    // This method both tests InitializeLifetimeService()\r
-    // and GetLifetimeService()\r
-    [Test]\r
-      public void LifetimeService()\r
-      {\r
-      MarshalObject objMarshal = new MarshalObject();\r
-\r
-      RemotingServices.SetObjectUriForMarshal(objMarshal, "MarshalByRefObjectTest.objMarshal2");\r
-      RemotingServices.Marshal(objMarshal);\r
-      \r
-      objMarshal.InitializeLifetimeService();\r
-      ILease lease = (ILease) objMarshal.GetLifetimeService();\r
-      Assertion.AssertEquals("#A02", lease.InitialLeaseTime, TimeSpan.FromSeconds(10));\r
-      \r
-      // TODO: When implemented in the mono RemotingServices class\r
-      //RemotingServices.Disconnect(objMarshal);\r
-      }\r
-\r
-    // Here we test if we a published object can be get \r
-    // through a TcpChannel\r
-    [Test]\r
-      public void GetObject()\r
-      {\r
-      MarshalObject objMarshal = new MarshalObject(1);\r
-\r
-      RemotingServices.SetObjectUriForMarshal(objMarshal, "MarshalByRefObjectTest.objMarshal3");\r
-      RemotingServices.Marshal(objMarshal);\r
-\r
-      TcpChannel chn = new TcpChannel(1294);\r
-      ChannelServices.RegisterChannel(chn);\r
-      \r
-      object objRem = Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1294/MarshalByRefObjectTest.objMarshal3");\r
-\r
-      MarshalObject objMarshalRem = (MarshalObject) objRem;\r
-\r
-      Assertion.AssertEquals("#A03", 1, objMarshalRem.Id);\r
-\r
-      // TODO: When implemented in the mono RemotingServices class\r
-      //RemotingServices.Disconnect(objMarshal);\r
-//      chn.StopListening(null);\r
-      ChannelServices.UnregisterChannel(chn);\r
-\r
-      }\r
-    }\r
-  }\r
+// MarshalByRefObjectTest.cs Test class for
+// System.MarshalByRefObject class
+// 
+// Jean-Marc Andre (jean-marc.andre@polymtl.ca)
+//
+
+using System;
+using System.Runtime.Remoting;
+using System.Runtime.Remoting.Lifetime;
+using System.Runtime.Serialization;
+using System.Runtime.Remoting.Channels;
+using System.Runtime.Remoting.Channels.Tcp;
+
+// Just an internal test namespace for
+// the MarshalByRefObjectTest class
+namespace MonoTests.System.MarshalByRefObjectTestInternal
+  {
+
+  // Object from this class can be marshaled
+  public class MarshalObject: MarshalByRefObject
+    {
+    public MarshalObject(){}
+
+    public MarshalObject(int id)
+      {
+      this.id = id;
+      }
+
+    // This method override the default one
+    // so we can set some properties of the lifetime
+    // of the remot object
+    public override object InitializeLifetimeService()
+      {
+      ILease lease = (ILease) base.InitializeLifetimeService();
+
+      // By default InitialLeaseTime is set to 5 minutes
+      // we set it at 10 seconds
+      if(lease.CurrentState == LeaseState.Initial)
+       {
+       lease.InitialLeaseTime = TimeSpan.FromSeconds(10);
+       }
+      return lease;
+      }
+
+    public int Id
+      {
+      get { return id;}
+      }
+
+    private int id = 0;
+    } // MarshalObject
+
+  } // MonoTests.System.MarshalByRefObjectTestInternal
+
+
+namespace MonoTests.System
+  {
+  using MonoTests.System.MarshalByRefObjectTestInternal;
+  using NUnit.Framework;
+
+  // The main test class
+  [TestFixture]
+  public class MarshalByRefObjectTest
+    {
+    public MarshalByRefObjectTest()
+      {
+
+      }
+
+    // This method test the CreateObjRef
+    [Test]
+      public void CreateObjRef()
+      {
+      MarshalObject objMarshal = new MarshalObject();
+
+      RemotingServices.SetObjectUriForMarshal(objMarshal, "MarshalByRefObjectTest.objMarshal1");
+      RemotingServices.Marshal(objMarshal);
+
+      ObjRef objRef = objMarshal.CreateObjRef(typeof(MarshalObject));
+      Assert.AreEqual(objRef.URI, RemotingServices.GetObjectUri(objMarshal), "#A01");
+
+      // TODO: When implemented in the mono RemotingServices class
+      //RemotingServices.Disconnect(objMarshal);
+      }
+
+    [Test]
+      [ExpectedException(typeof(RemotingException))]
+      public void CreateObjRefThrowException()
+      {
+      MarshalObject objMarshal = new MarshalObject();
+
+      ObjRef objRef = objMarshal.CreateObjRef(typeof(MarshalObject));
+      }
+
+    // This method both tests InitializeLifetimeService()
+    // and GetLifetimeService()
+    [Test]
+      public void LifetimeService()
+      {
+      MarshalObject objMarshal = new MarshalObject();
+
+      RemotingServices.SetObjectUriForMarshal(objMarshal, "MarshalByRefObjectTest.objMarshal2");
+      RemotingServices.Marshal(objMarshal);
+      
+      objMarshal.InitializeLifetimeService();
+      ILease lease = (ILease) objMarshal.GetLifetimeService();
+      Assert.AreEqual(lease.InitialLeaseTime, TimeSpan.FromSeconds(10), "#A02");
+      
+      // TODO: When implemented in the mono RemotingServices class
+      //RemotingServices.Disconnect(objMarshal);
+      }
+
+    // Here we test if we a published object can be get 
+    // through a TcpChannel
+    [Test]
+      public void GetObject()
+      {
+      MarshalObject objMarshal = new MarshalObject(1);
+
+      RemotingServices.SetObjectUriForMarshal(objMarshal, "MarshalByRefObjectTest.objMarshal3");
+      RemotingServices.Marshal(objMarshal);
+
+      TcpChannel chn = new TcpChannel(1294);
+      ChannelServices.RegisterChannel(chn);
+      
+      object objRem = Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1294/MarshalByRefObjectTest.objMarshal3");
+
+      MarshalObject objMarshalRem = (MarshalObject) objRem;
+
+      Assert.AreEqual(1, objMarshalRem.Id, "#A03");
+
+      // TODO: When implemented in the mono RemotingServices class
+      //RemotingServices.Disconnect(objMarshal);
+//      chn.StopListening(null);
+      ChannelServices.UnregisterChannel(chn);
+
+      }
+    }
+  }