45f76791b7cf6841752a917937f876b03e70b52e
[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                 [Ignore ("https://bugzilla.xamarin.com/show_bug.cgi?id=36634")]
32                 public void Bug609381 ()
33                 {
34                         string portName = "ipc" + Guid.NewGuid ().ToString ("N");
35                         string objUri = "ipcserver609381.rem";
36                         string url = String.Format ("ipc://{0}/{1}", portName, objUri);
37
38                         IpcChannel serverChannel = new IpcChannel (portName);
39                         ChannelServices.RegisterChannel (serverChannel);
40
41                         RemotingServices.Marshal (new Server (), objUri);
42
43                         Server client = (Server) RemotingServices.Connect (typeof (Server), url);
44                         
45                         int count = 10 * 1024 * 1024;
46                         byte[] sendBuf = new byte[count];
47                         sendBuf [sendBuf.Length - 1] = 41;
48                         
49                         byte[] recvBuf = client.Send (sendBuf);
50
51                         Assert.IsNotNull (recvBuf);
52                         Assert.AreNotSame (sendBuf, recvBuf);
53                         Assert.AreEqual (count, recvBuf.Length);
54                         Assert.AreEqual (42, recvBuf [recvBuf.Length - 1]);
55
56                         sendBuf = null;
57                         recvBuf = null;
58
59                         ChannelServices.UnregisterChannel (serverChannel);
60                 }
61
62                 class Server : MarshalByRefObject
63                 {
64                         public byte[] Send (byte[] payload)
65                         {
66                                 payload [payload.Length - 1]++;
67                                 return payload;
68                         }
69                 }
70
71                 [Test]
72                 public void TestCtor2 ()
73                 {
74                         string channelName = Guid.NewGuid ().ToString ("N");
75                         string portName = "ipc" + Guid.NewGuid ().ToString ("N");
76                         string url = String.Format ("ipc://{0}/server.rem", portName);
77
78                         IpcServerChannel chan = new IpcServerChannel (channelName, portName);
79                         string[] uris = chan.GetUrlsForUri ("server.rem");
80                         Assert.IsNotNull (uris);
81                         AssertHelper.Greater (uris.Length, 0);
82
83                         bool found = false;
84                         foreach (string s in uris) {
85                                 if (s == url) {
86                                         found = true;
87                                         break;
88                                 }
89                         }
90                         Assert.IsTrue (found);
91                 }
92
93                 [Test]
94                 public void TestCtor3 ()
95                 {
96                         string portName = "ipc" + Guid.NewGuid ().ToString ("N");
97                         string url = String.Format ("ipc://{0}/server.rem", portName);
98
99                         Hashtable props = new Hashtable ();
100                         props ["portName"] = portName;
101                         IpcChannel chan = new IpcChannel (props, null, null);
102                         string[] uris = chan.GetUrlsForUri ("server.rem");
103                         Assert.IsNotNull (uris);
104                         AssertHelper.Greater (uris.Length, 0);
105
106                         bool found = false;
107                         foreach (string s in uris) {
108                                 if (s == url) {
109                                         found = true;
110                                         break;
111                                 }
112                         }
113                         Assert.IsTrue (found);
114                 }
115         }
116 }
117