* qt/Makfile.am:
[platform/upstream/dbus.git] / mono / Test.cs
1 using System;
2 using System.Threading;
3 using DBus;
4 using Gtk;
5
6 namespace DBus.Test
7 {
8   public class Test
9   {
10     public static Service service = null;
11     public static Connection connection = null;
12     
13     public static int Main(string [] args)
14     {
15       TestServer testServer = new TestServer();
16       Thread serverThread = new Thread(new ThreadStart(testServer.StartServer));
17       serverThread.Start();
18
19       connection = Bus.GetSessionBus();
20       service = Service.Get(connection, "org.freedesktop.Test");
21       Thread.Sleep (1000);
22
23       TestObject testObject = (TestObject) service.GetObject(typeof(TestObject), "/org/freedesktop/Test/TestObject");
24
25       Console.WriteLine ("Got object [{0}]", testObject);
26       
27       System.Console.WriteLine(testObject.Test1("Hello"));
28
29       Console.WriteLine ("Got object [{0}]", testObject);
30
31       //RunTests(testObject);
32
33       return 0;
34     }
35
36     public static void RunTests(TestObject testObject) 
37     {
38       System.Console.WriteLine(testObject.Test1("Hello"));
39     }
40   }
41
42   public class TestServer
43   {
44     public Connection connection;
45     public Service service;
46
47     public TestServer()
48     {
49       Application.Init();
50       
51       System.Console.WriteLine("Starting server...");
52
53       connection = Bus.GetSessionBus();
54       service = new Service(connection, "org.freedesktop.Test");
55       TestObject testObject = new TestObject();
56       service.RegisterObject(testObject, "/org/freedesktop/Test/TestObject");
57       
58       System.Console.WriteLine("Foo!");
59     }
60     
61     public void StartServer()
62     {
63       Application.Run();
64     }
65   }
66
67   [Interface("org.freedesktop.Test.TestObject")]
68   public class TestObject
69   {
70     [Method]
71     public virtual int Test1(string x)
72     {
73       System.Console.WriteLine("Called: " + x);
74       return 5;
75     }
76   }    
77 }