[utils] Fix inet_pton fallback.
[mono.git] / mcs / class / System.Runtime.Remoting / Test / ActivationTests.cs
1 //
2 // MonoTests.Remoting.TcpCalls.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
5 //
6 // 2003 (C) Copyright, Ximian, Inc.
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.Tcp;
14 using System.Runtime.Remoting.Channels.Http;
15 using NUnit.Framework;
16
17 namespace MonoTests.Remoting
18 {
19         [TestFixture]
20         public class ActivationTests
21         {
22                 ActivationServer server;
23                 TcpChannel tcp;
24                 HttpClientChannel http;
25                         
26                 [TestFixtureSetUp]
27                 public void Run()
28                 {
29                         try
30                         {
31                                 tcp =  new TcpChannel (0);
32                                 
33                                 Hashtable options = new Hashtable ();
34                                 options ["timeout"] = 10000; // 10s
35                                 http = new HttpClientChannel (options, null);
36                         
37                                 ChannelServices.RegisterChannel (tcp);
38                                 ChannelServices.RegisterChannel (http);
39                         
40                                 AppDomain domain = BaseCallTest.CreateDomain ("testdomain_activation");
41                                 server = (ActivationServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.ActivationServer");
42                                 
43                                 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject1), "tcp://localhost:9433");
44                                 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject2), "http://localhost:9434");
45                                 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall1), "tcp://localhost:9433/wkoSingleCall1");
46                                 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton1), "tcp://localhost:9433/wkoSingleton1");
47                                 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall2), "http://localhost:9434/wkoSingleCall2");
48                                 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton2), "http://localhost:9434/wkoSingleton2");
49                         }
50                         catch (Exception ex)
51                         {
52                                 Console.WriteLine (ex);
53                         }
54                 }
55                 
56                 [Test]
57                 public void TestCreateTcpCao ()
58                 {
59                         CaObject1 ca = new CaObject1 ();
60                         CaObject1 ca2 = new CaObject1 ();
61                         Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
62                         RunTestCreateCao (ca, ca2);
63                 }
64                 
65                 [Test]
66                 public void TestCreateHttpCao ()
67                 {
68                         CaObject2 ca = new CaObject2 ();
69                         CaObject2 ca2 = new CaObject2 ();
70                         Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
71                         RunTestCreateCao (ca, ca2);
72                 }
73                 
74                 public void RunTestCreateCao (BaseObject ca, BaseObject ca2)
75                 {
76                         Assert.AreEqual (0, ca.counter, "#1");
77                         
78                         ca.counter++;
79                         Assert.AreEqual (1, ca.counter, "#2");
80                         
81                         Assert.AreEqual (0, ca2.counter, "#3");
82                         
83                         ca2.counter++;
84                         Assert.AreEqual (1, ca2.counter, "#4");
85                         
86                         Assert.AreEqual (1, ca.counter, "#5");
87                 }
88
89                 [Test]
90                 public void TestCreateTcpWkoSingleCall ()
91                 {
92                         WkObjectSinglecall1 ca = new WkObjectSinglecall1 ();
93                         WkObjectSinglecall1 ca2 = new WkObjectSinglecall1 ();
94                         Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
95                         RunTestCreateWkoSingleCall (ca, ca2);
96                 }
97                 
98                 [Test]
99                 public void TestCreateTcpWkoSingleton ()
100                 {
101                         WkObjectSingleton1 ca = new WkObjectSingleton1 ();
102                         WkObjectSingleton1 ca2 = new WkObjectSingleton1 ();
103                         Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
104                         RunTestCreateWkoSingleton (ca, ca2);
105                 }
106
107                 [Test]
108                 [Category ("NotWorking")]
109                 public void TestCreateHttpWkoSingleCall ()
110                 {
111                         WkObjectSinglecall2 ca = new WkObjectSinglecall2 ();
112                         WkObjectSinglecall2 ca2 = new WkObjectSinglecall2 ();
113                         Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
114                         RunTestCreateWkoSingleCall (ca, ca2);
115                 }
116                 
117                 [Test]
118                 [Category ("NotWorking")]
119                 public void TestCreateHttpWkoSingleton ()
120                 {
121                         WkObjectSingleton2 ca = new WkObjectSingleton2 ();
122                         WkObjectSingleton2 ca2 = new WkObjectSingleton2 ();
123                         Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
124                         RunTestCreateWkoSingleton (ca, ca2);
125                 }
126                 
127                 public void RunTestCreateWkoSingleCall (BaseObject ca, BaseObject ca2)
128                 {
129                         Assert.AreEqual (0, ca.counter, "#1");
130                         ca.counter++;
131                         Assert.AreEqual (0, ca.counter, "#2");
132
133                         Assert.AreEqual (0, ca2.counter, "#3");
134                         ca2.counter++;
135                         Assert.AreEqual (0, ca2.counter, "#4");
136                 }
137
138                 public void RunTestCreateWkoSingleton (BaseObject ca, BaseObject ca2)
139                 {
140                         Assert.AreEqual (0, ca.counter, "#1");
141                         ca.counter++;
142                         Assert.AreEqual (1, ca.counter, "#2");
143                         ca.counter++;
144                         Assert.AreEqual (2, ca2.counter, "#3");
145                         ca2.counter++;
146                         Assert.AreEqual (3, ca2.counter, "#4");
147                 }
148
149                 [TestFixtureTearDown]
150                 public void End ()
151                 {
152                         ChannelServices.UnregisterChannel (tcp);
153                         ChannelServices.UnregisterChannel (http);
154                         if (server != null)
155                                 server.Stop ();
156                 }
157         }
158         
159         public class ActivationServer: MarshalByRefObject
160         {
161                 TcpChannel tcp;
162                 HttpChannel http;
163                 
164                 public ActivationServer ()
165                 {
166                         tcp =  new TcpChannel (9433);
167                         http =  new HttpChannel (9434);
168                         
169                         ChannelServices.RegisterChannel (tcp);
170                         ChannelServices.RegisterChannel (http);
171                         
172                         RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject1));
173                         RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject2));
174                         RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall1), "wkoSingleCall1", WellKnownObjectMode.SingleCall);
175                         RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton1), "wkoSingleton1", WellKnownObjectMode.Singleton);
176                         RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall2), "wkoSingleCall2", WellKnownObjectMode.SingleCall);
177                         RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton2), "wkoSingleton2", WellKnownObjectMode.Singleton);
178                 }
179                 
180                 public void Stop ()
181                 {
182                         ChannelServices.UnregisterChannel (tcp);
183                         ChannelServices.UnregisterChannel (http);
184                 }
185         }
186         
187         public class BaseObject: MarshalByRefObject
188         {
189                 public int counter;
190                 public static int CreationCount;
191                 
192                 public BaseObject ()
193                 {
194                         CreationCount++;
195                 }
196         }
197         
198         public class CaObject1: BaseObject
199         {
200         }
201         
202         public class CaObject2: BaseObject
203         {
204         }
205         
206         public class WkObjectSinglecall1: BaseObject
207         {
208         }
209         
210         public class WkObjectSingleton1: BaseObject
211         {
212         }
213         
214         public class WkObjectSinglecall2: BaseObject
215         {
216         }
217         
218         public class WkObjectSingleton2: BaseObject
219         {
220         }
221 }