In corlib/System.Runtime.InteropServices:
[mono.git] / mcs / class / System.Runtime.Remoting / Test / GenericTest.cs
1 //
2 // MonoTests.Remoting.GenericTest.cs
3 //
4 // Authors:
5 //     Robert Jordan  <robertj@gmx.net>
6 //
7
8 #if NET_2_0
9
10 using System;
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 System.Runtime.Remoting.Channels.Ipc;
16 using System.Threading;
17 using NUnit.Framework;
18
19 namespace MonoTests.Remoting
20 {
21         class Server <T> : MarshalByRefObject
22         {
23                 public T Field;
24
25                 public void Test ()
26                 {
27                 }
28
29                 public V Test2 <V> (V v)
30                 {
31                         return v;
32                 }
33
34                 public T Test3 (T t)
35                 {
36                         return t;
37                 }
38         }
39
40         [TestFixture]
41         public class GenericTest
42         {
43                 class Helper
44                 {
45                         public static void Test (string url)
46                         {
47                                 // create server
48                                 Server <int> server = new Server <int> ();
49                                 RemotingServices.Marshal (server, "test");
50                                 try {
51                                         // create client
52                                         Server <int> client = (Server <int>) RemotingServices.Connect (
53                                                 typeof (Server <int>), url);
54                         
55                                         // invoke
56                                         client.Test ();
57                                         Assert.AreEqual ("hello", client.Test2 <string> ("hello"), "#01");
58                                         Assert.AreEqual (42, client.Test3 (42), "#02");
59
60                                 } finally {
61                                         RemotingServices.Disconnect (server);
62                                 }
63                         }
64                 }
65
66                 [Test]
67                 public void TestTcp ()
68                 {
69                         TcpChannel c = new TcpChannel (18181);
70                         Helper.Test ("tcp://127.0.0.1:18181/test");
71                         c.StopListening (null);
72                 }
73
74                 [Test]
75                 public void TestIpc ()
76                 {
77                         string portName = "ipc" + Guid.NewGuid ().ToString ("N");
78                         IpcChannel c = new IpcChannel (portName);
79                         // FIXME: the named pipe of the Win32 IpcServerChannel
80                         // seems to require a sleep because the pipe is not
81                         // ready immediately after creation.
82                         Thread.Sleep (1000);
83                         Helper.Test ("ipc://" + portName + "/test");
84                         c.StopListening (null);
85                 }
86
87                 [Test]
88                 [Ignore ("The SOAP formatter doesn't support generics.")]
89                 // FIXME: change the SOAP formatter to throw on generic types
90                 public void TestHttp ()
91                 {
92                         HttpChannel c = new HttpChannel (19191);
93                         Helper.Test ("http://127.0.0.1:19191/test");
94                         c.StopListening (null);
95                 }
96         }
97 }
98
99 #endif