extra: import at 3.0.1 beta 1
[mozilla-extra.git] / extensions / mono / test / test-invoke.cs
blob86bcb5639b9f1b38d41ef5713fa25abb030a9f44
1 using System;
2 using System.Runtime.InteropServices;
3 using Mozilla.XPCOM;
4 using MethodDescriptor = Mozilla.XPCOM.TypeInfo.MethodDescriptor;
6 public class Test
8 [DllImport("xpcom-dotnet.so")]
9 static extern int StartXPCOM(out IntPtr srvmgr);
11 static IntPtr srvmgr;
13 [DllImport("test.so", EntryPoint="GetImpl")]
14 public static extern IntPtr GetTestImpl();
16 public static int xptinfo_test(string[] args)
18 int index = Int32.Parse(args[2]);
19 MethodDescriptor meth = TypeInfo.GetMethodData(args[1], index);
20 Console.WriteLine("{0}#{1}: {2}", args[1], index, meth.ToString());
21 return 0;
24 public static int xptinvoke_test_cb()
26 object o = new object();
28 IntPtr impl = GetTestImpl();
29 Invoker.Invoke(impl, "test", "callback", o);
30 return 0;
33 public static int xptinvoke_test_add(string[] args)
35 int a = Int32.Parse(args[1]);
36 int b = Int32.Parse(args[2]);
38 IntPtr impl = GetTestImpl();
39 Invoker.Invoke(impl, "test", "add", a, b);
40 return 0;
43 public static int Main(string[] args)
45 int res = StartXPCOM(out srvmgr);
47 if (res != 0) {
48 Console.WriteLine("StartXPCOM failed: {0:X2}", res);
49 return 1;
52 if (args[0] == "add")
53 return xptinvoke_test_add(args);
54 if (args[0] == "xptinfo")
55 return xptinfo_test(args);
56 if (args[0] == "cb")
57 return xptinvoke_test_cb();
58 Console.WriteLine("Unknown test mode: {0}", args[0]);
59 return 1;