Reenable MonoTests.Remoting.IpcChannelTest.Bug609381 (#5245)
[mono.git] / mcs / class / System.Runtime.Remoting / Test / IpcChannelTest.cs
1 //
2 // MonoTests.Remoting.IpcChannelTests.cs
3 //
4 // Authors:
5 //      Robert Jordan (robertj@gmx.net)
6 //
7
8
9 using System;
10 using System.Collections;
11 using System.Runtime.Remoting;
12 using System.Runtime.Remoting.Channels;
13 using System.Runtime.Remoting.Channels.Ipc;
14 using NUnit.Framework;
15
16 namespace MonoTests.Remoting
17 {
18         [TestFixture]
19         public class IpcChannelTest
20         {
21                 [Test]
22                 public void Bug81653 ()
23                 {
24                         IpcClientChannel c = new IpcClientChannel ();
25                         ChannelDataStore cd = new ChannelDataStore (new string[] { "foo" });
26                         string objectUri;
27                         c.CreateMessageSink (null, cd, out objectUri);
28                 }
29
30                 [Test]
31                 public void Bug609381 ()
32                 {
33                         string portName = "ipc" + Guid.NewGuid ().ToString ("N");
34                         string objUri = "ipcserver609381.rem";
35                         string url = String.Format ("ipc://{0}/{1}", portName, objUri);
36
37                         IpcChannel serverChannel = new IpcChannel (portName);
38                         ChannelServices.RegisterChannel (serverChannel);
39
40                         RemotingServices.Marshal (new Server (), objUri);
41
42                         Server client = (Server) RemotingServices.Connect (typeof (Server), url);
43                         
44                         int count = 10 * 1024 * 1024;
45                         byte[] sendBuf = new byte[count];
46                         sendBuf [sendBuf.Length - 1] = 41;
47                         
48                         byte[] recvBuf = client.Send (sendBuf);
49
50                         Assert.IsNotNull (recvBuf);
51                         Assert.AreNotSame (sendBuf, recvBuf);
52                         Assert.AreEqual (count, recvBuf.Length);
53                         Assert.AreEqual (42, recvBuf [recvBuf.Length - 1]);
54
55                         sendBuf = null;
56                         recvBuf = null;
57
58                         ChannelServices.UnregisterChannel (serverChannel);
59                 }
60
61                 class Server : MarshalByRefObject
62                 {
63                         public byte[] Send (byte[] payload)
64                         {
65                                 payload [payload.Length - 1]++;
66                                 return payload;
67                         }
68                 }
69
70                 [Test]
71                 public void TestCtor2 ()
72                 {
73                         string channelName = Guid.NewGuid ().ToString ("N");
74                         string portName = "ipc" + Guid.NewGuid ().ToString ("N");
75                         string url = String.Format ("ipc://{0}/server.rem", portName);
76
77                         IpcServerChannel chan = new IpcServerChannel (channelName, portName);
78                         string[] uris = chan.GetUrlsForUri ("server.rem");
79                         Assert.IsNotNull (uris);
80                         AssertHelper.Greater (uris.Length, 0);
81
82                         bool found = false;
83                         foreach (string s in uris) {
84                                 if (s == url) {
85                                         found = true;
86                                         break;
87                                 }
88                         }
89                         Assert.IsTrue (found);
90                 }
91
92                 [Test]
93                 public void TestCtor3 ()
94                 {
95                         string portName = "ipc" + Guid.NewGuid ().ToString ("N");
96                         string url = String.Format ("ipc://{0}/server.rem", portName);
97
98                         Hashtable props = new Hashtable ();
99                         props ["portName"] = portName;
100                         IpcChannel chan = new IpcChannel (props, null, null);
101                         string[] uris = chan.GetUrlsForUri ("server.rem");
102                         Assert.IsNotNull (uris);
103                         AssertHelper.Greater (uris.Length, 0);
104
105                         bool found = false;
106                         foreach (string s in uris) {
107                                 if (s == url) {
108                                         found = true;
109                                         break;
110                                 }
111                         }
112                         Assert.IsTrue (found);
113                 }
114         }
115 }
116