This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[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.Runtime.Remoting;
11 using System.Runtime.Remoting.Channels;
12 using System.Runtime.Remoting.Channels.Tcp;
13 using System.Runtime.Remoting.Channels.Http;
14 using NUnit.Framework;
15
16 namespace MonoTests.Remoting
17 {
18         [TestFixture]
19         public class ActivationTests
20         {
21                 ActivationServer server;
22                         
23                 [TestFixtureSetUp]
24                 public void Run()
25                 {
26                         try
27                         {
28                                 AppDomain domain = AppDomain.CreateDomain ("testdomain_activation");
29                                 server = (ActivationServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.ActivationServer");
30                                 
31                                 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject1), "tcp://localhost:32433");
32                                 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject2), "http://localhost:32434");
33                                 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall1), "tcp://localhost:32433/wkoSingleCall1");
34                                 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton1), "tcp://localhost:32433/wkoSingleton1");
35                                 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall2), "http://localhost:32434/wkoSingleCall2");
36                                 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton2), "http://localhost:32434/wkoSingleton2");
37                         }
38                         catch (Exception ex)
39                         {
40                                 Console.WriteLine (ex);
41                         }
42                 }
43                 
44                 [Test]
45                 public void TestCreateTcpCao ()
46                 {
47                         CaObject1 ca = new CaObject1 ();
48                         CaObject1 ca2 = new CaObject1 ();
49                         RunTestCreateCao (ca, ca2);
50                 }
51                 
52                 [Test]
53                 public void TestCreateHttpCao ()
54                 {
55                         CaObject2 ca = new CaObject2 ();
56                         CaObject2 ca2 = new CaObject2 ();
57                         RunTestCreateCao (ca, ca2);
58                 }
59                 
60                 public void RunTestCreateCao (BaseObject ca, BaseObject ca2)
61                 {
62                         Assert.AreEqual (0, ca.counter, "#1");
63                         
64                         ca.counter++;
65                         Assert.AreEqual (1, ca.counter, "#2");
66                         
67                         Assert.AreEqual (0, ca2.counter, "#3");
68                         
69                         ca2.counter++;
70                         Assert.AreEqual (1, ca2.counter, "#4");
71                         
72                         Assert.AreEqual (1, ca.counter, "#5");
73                 }
74
75                 [Test]
76                 public void TestCreateTcpWkoSingleCall ()
77                 {
78                         WkObjectSinglecall1 ca = new WkObjectSinglecall1 ();
79                         WkObjectSinglecall1 ca2 = new WkObjectSinglecall1 ();
80                         RunTestCreateWkoSingleCall (ca, ca2);
81                 }
82                 
83                 [Test]
84                 public void TestCreateTcpWkoSingleton ()
85                 {
86                         WkObjectSingleton1 ca = new WkObjectSingleton1 ();
87                         WkObjectSingleton1 ca2 = new WkObjectSingleton1 ();
88                         RunTestCreateWkoSingleton (ca, ca2);
89                 }
90
91                 [Test]
92                 public void TestCreateHttpWkoSingleCall ()
93                 {
94                         WkObjectSinglecall2 ca = new WkObjectSinglecall2 ();
95                         WkObjectSinglecall2 ca2 = new WkObjectSinglecall2 ();
96                         RunTestCreateWkoSingleCall (ca, ca2);
97                 }
98                 
99                 [Test]
100                 public void TestCreateHttpWkoSingleton ()
101                 {
102                         WkObjectSingleton2 ca = new WkObjectSingleton2 ();
103                         WkObjectSingleton2 ca2 = new WkObjectSingleton2 ();
104                         RunTestCreateWkoSingleton (ca, ca2);
105                 }
106                 
107                 public void RunTestCreateWkoSingleCall (BaseObject ca, BaseObject ca2)
108                 {
109                         Assert.AreEqual (0, ca.counter, "#1");
110                         ca.counter++;
111                         Assert.AreEqual (0, ca.counter, "#2");
112
113                         Assert.AreEqual (0, ca2.counter, "#3");
114                         ca2.counter++;
115                         Assert.AreEqual (0, ca2.counter, "#4");
116                 }
117
118                 public void RunTestCreateWkoSingleton (BaseObject ca, BaseObject ca2)
119                 {
120                         Assert.AreEqual (0, ca.counter, "#1");
121                         ca.counter++;
122                         Assert.AreEqual (1, ca.counter, "#2");
123                         ca.counter++;
124                         Assert.AreEqual (2, ca2.counter, "#3");
125                         ca2.counter++;
126                         Assert.AreEqual (3, ca2.counter, "#4");
127                 }
128
129                 [TestFixtureTearDown]
130                 public void End ()
131                 {
132                         server.Stop ();
133                 }
134         }
135         
136         public class ActivationServer: MarshalByRefObject
137         {
138                 TcpChannel tcp;
139                 HttpChannel http;
140                 
141                 public ActivationServer ()
142                 {
143                         TcpChannel tcp =  new TcpChannel (32433);
144                         HttpChannel http =  new HttpChannel (32434);
145                         
146                         ChannelServices.RegisterChannel (tcp);
147                         ChannelServices.RegisterChannel (http);
148                         
149                         RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject1));
150                         RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject2));
151                         RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall1), "wkoSingleCall1", WellKnownObjectMode.SingleCall);
152                         RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton1), "wkoSingleton1", WellKnownObjectMode.Singleton);
153                         RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall2), "wkoSingleCall2", WellKnownObjectMode.SingleCall);
154                         RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton2), "wkoSingleton2", WellKnownObjectMode.Singleton);
155                 }
156                 
157                 public void Stop ()
158                 {
159                         tcp.StopListening (null);
160                         http.StopListening (null);
161                 }
162         }
163         
164         public class BaseObject: MarshalByRefObject
165         {
166                 public int counter;
167         }
168         
169         public class CaObject1: BaseObject
170         {
171         }
172         
173         public class CaObject2: BaseObject
174         {
175         }
176         
177         public class WkObjectSinglecall1: BaseObject
178         {
179         }
180         
181         public class WkObjectSingleton1: BaseObject
182         {
183         }
184         
185         public class WkObjectSinglecall2: BaseObject
186         {
187         }
188         
189         public class WkObjectSingleton2: BaseObject
190         {
191         }
192 }