[utils] Fix inet_pton fallback.
[mono.git] / mcs / class / System.Runtime.Remoting / Test / HttpBugTests.cs
1
2 using System;
3 using System.Xml;
4 using System.Collections;
5 using System.Runtime.Remoting;
6 using System.Runtime.Remoting.Channels;
7 using System.Runtime.Remoting.Channels.Http;
8 using NUnit.Framework;
9
10 namespace MonoTests.Remoting.Http
11 {
12         //Test for Bug 324362 - SoapFormatter cannot deserialize the same MBR twice
13         [TestFixture]
14         public class Bug324362
15         {
16                 [Test]
17 //              [Category ("NotWorking")] // the assertion fails, and if it's removed, there's an exception
18                 [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.")]
19                 public void Test ()
20                 {
21                         new HttpChannel (8086);
22                         RemotingServices.Marshal (new Service (), "test");
23
24                         Service remObj = (Service) RemotingServices.Connect (
25                                 typeof (Service), "http://localhost:8086/test");
26
27                         ArrayList list;
28                         remObj.Test (out list);
29                         // it's of type 'ObjRef' instead of 'Service':
30                         Assert.IsTrue (list [0] is Service);
31
32                         Service [] array;
33                         remObj.Test (out array);
34                 }
35         
36                 public class Service : MarshalByRefObject
37                 {
38                         public Service Test (out Service[] a)
39                         {
40                                 Service obj = new Service ();
41                                 a = new Service [] { obj };
42                                 return obj;
43                                 // return null or return otherObj works
44                         }
45                 
46                         public Service Test (out ArrayList a)
47                         {
48                                 a = new ArrayList ();
49                                 Service obj = new Service ();
50                                 a.Add (obj);
51                                 return obj; 
52                                 // return null or return otherObj works
53                         }
54                 }
55         }
56         
57         //Bug 321420 - SoapReader fails to deserialize some method calls
58         [TestFixture]
59         public class Bug321420 : MarshalByRefObject
60         {
61                 HttpChannel channel;
62                 
63                 public void Method (string p1, string p2)
64                 {
65                 }
66                 
67                 [Test]
68                 public void Main ()
69                 {
70                         channel = new HttpChannel (3344);
71                         ChannelServices.RegisterChannel (channel);
72                         RemotingConfiguration.RegisterWellKnownServiceType
73                                 (typeof (Bug321420),"Server.soap", WellKnownObjectMode.Singleton);
74                         
75                         Bug321420 s = (Bug321420) Activator.GetObject (typeof
76                                 (Bug321420), "http://localhost:3344/Server.soap");
77                         
78                         // this works: s.Method ("a", "b");
79                         s.Method ("a", "a");
80                 }
81                 
82                 [TestFixtureTearDown]
83                 public void Stop ()
84                 {
85                         if (channel != null)
86                                 ChannelServices.UnregisterChannel (channel);
87                 }
88         }
89         
90         //Bug 315570 - Remoting over HTTP fails when returning a null reference.
91         [TestFixture]   
92         public class Bug315570
93         {
94                 Server server;
95                 
96                 [Test]
97                 [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.")]
98                 public void Main ()
99                 {
100                         Foo foo = (Foo) Activator.GetObject (typeof (Foo),
101                                 "http://localhost:4321/Test");
102
103                         Bar bar = foo.Login ();
104                         if (bar != null)
105                                 bar.Foobar ();
106                 }
107                 
108                 [TestFixtureSetUp]
109                 public void Start ()
110                 {
111                         AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
112                         server = (Server) domain.CreateInstanceAndUnwrap
113                                 (typeof (Server).Assembly.FullName, typeof (Server).FullName);
114                         server.Start ();
115                 }
116
117                 [TestFixtureTearDown]
118                 public void Stop ()
119                 {
120                         server.Stop ();
121                 }
122                 
123                 public class Foo: MarshalByRefObject
124                 {
125                         public Bar Login ()
126                         {
127                                 return null;
128                         }
129                 }
130                 
131                 public class Bar: MarshalByRefObject
132                 {
133                         public void Foobar ()
134                         {
135                         //      Console.WriteLine("Bar::foo()");
136                         }
137                 }
138                 
139                 public class Server : MarshalByRefObject
140                 {
141                         HttpChannel c;
142                         
143                         public void Start ()
144                         {
145                                 c = new HttpChannel (4321);
146                                 ChannelServices.RegisterChannel (c);
147                                 
148                                 Type t = typeof(Foo);
149                                 RemotingConfiguration.RegisterWellKnownServiceType (t, "Test",
150                                         WellKnownObjectMode.SingleCall);
151                         }
152                         
153                         public void Stop ()
154                         {
155                                 c.StopListening (null);
156                                 ChannelServices.UnregisterChannel (c);
157                         }
158                 }
159         }
160         
161         //Bug 315170 - exception thrown in remoting if interface parameter names differ from the impelmentation method parameter names
162         [TestFixture]
163         public class Bug315170
164         {
165                 Server server;
166                 HttpChannel channel;
167                 
168                 [Test]
169                 public void Main ()
170                 {
171                         channel = new HttpChannel (0);
172                         ChannelServices.RegisterChannel (channel);
173                         MarshalByRefObject obj = (MarshalByRefObject) RemotingServices.Connect (
174                                 typeof (IFactorial),
175                                 "http://localhost:60000/MyEndPoint");
176                         IFactorial cal = (IFactorial) obj;
177                         Assert.AreEqual (cal.CalculateFactorial (4), 24);
178                 }
179                 
180                 [TestFixtureSetUp]
181                 public void Start ()
182                 {
183                         AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
184                         server = (Server) domain.CreateInstanceAndUnwrap
185                                 (typeof (Server).Assembly.FullName, typeof (Server).FullName);
186                         server.Start ();
187                 }
188
189                 [TestFixtureTearDown]
190                 public void Stop ()
191                 {
192                         server.Stop ();
193                         if (channel != null)
194                                 ChannelServices.UnregisterChannel (channel);
195                 }
196                 
197                 public interface IFactorial
198                 {
199                         // With this line everything works
200                         //ulong CalculateFactorial(uint a);
201                         // With this line it doesn't
202                         ulong CalculateFactorial(uint b);
203                 }
204
205                 
206                 public class Server : MarshalByRefObject
207                 {
208                         HttpChannel c;
209                         
210                         public void Start ()
211                         {
212                                 c = new HttpChannel (60000);
213                                 ChannelServices.RegisterChannel (c);
214                                 
215                                 Type t = typeof(Calculator);
216                                 RemotingConfiguration.RegisterWellKnownServiceType (t, "MyEndPoint",
217                                         WellKnownObjectMode.Singleton);
218                         }
219                         
220                         public void Stop ()
221                         {
222                                 c.StopListening (null);
223                                 ChannelServices.UnregisterChannel (c);
224                         }
225                 }
226                 
227                 public class Calculator : MarshalByRefObject, IFactorial
228                 {
229                         public ulong CalculateFactorial (uint a)
230                         {
231                                 ulong res = 1;
232                                 for (uint i=1 ; i<=a; i++)
233                                         res = res * i;
234                                 return res;
235                         }
236                 }
237         }
238 }
239
240