add test programs and drivers

This commit is contained in:
shaver%mozilla.org 2005-02-17 03:38:17 +00:00
parent 879cf24bf6
commit 3c96d45066
7 changed files with 944 additions and 0 deletions

View File

@ -0,0 +1,23 @@
MCS ?= mcs
MCSFLAGS ?= /debug
all: tests
test.h: test.idl
/usr/lib/mozilla-1.6/xpidl -m header -I /usr/share/idl/mozilla-1.6 test.idl
test.xpt: test.idl
/usr/lib/mozilla-1.6/xpidl -m typelib -I /usr/share/idl/mozilla-1.6 test.idl
test.so: test.h test.cpp
c++ -g -shared -o test.so `pkg-config --cflags mozilla-xpcom` test.cpp `pkg-config --libs mozilla-xpcom`
%.exe: %.cs
$(MCS) $(MCSFLAGS) -unsafe /out:$@ /r:../Mozilla.XPCOM.Interfaces.dll /r:../xpcom-dotnet.dll $<
TESTOBJS=test-invoke.exe test.so test.xpt generate-assembly.exe sample-app.exe loader.exe
tests: $(TESTOBJS)
clean:
rm -f test.h $(TESTOBJS)

View File

@ -0,0 +1,334 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Reflection.Emit;
using Mozilla.XPCOM;
using MethodDescriptor = Mozilla.XPCOM.TypeInfo.MethodDescriptor;
using TypeTag = Mozilla.XPCOM.TypeInfo.TypeTag;
using ParamFlags = Mozilla.XPCOM.TypeInfo.ParamFlags;
public class Test
{
[DllImport("xpcom-dotnet.so")]
static extern int StartXPCOM(out IntPtr srvmgr);
static IntPtr srvmgr;
[DllImport("test.so", EntryPoint="GetImpl")]
public static extern IntPtr GetTestImpl();
static void GenerateInterfaceMethod(TypeBuilder tb, MethodDescriptor desc)
{
if (!desc.IsVisible()) {
Console.WriteLine("HIDDEN: {0}", desc);
return;
}
const MethodAttributes attrs = MethodAttributes.Public |
MethodAttributes.Abstract | MethodAttributes.Virtual;
tb.DefineMethod(desc.name, attrs, desc.resultType, desc.argTypes);
Console.WriteLine("\t{0}", desc);
}
static void EmitPtrAndFlagsStore(ILGenerator ilg, LocalBuilder bufLocal,
int argnum, IntPtr ptr, sbyte flags)
{
//= bufLocal[argnum].ptr = ptr;
ilg.Emit(OpCodes.Ldloc, bufLocal);
ilg.Emit(OpCodes.Ldc_I4, argnum * VARIANT_SIZE + 8);
ilg.Emit(OpCodes.Add);
ilg.Emit(OpCodes.Ldc_I4, ptr.ToInt32());
ilg.Emit(OpCodes.Stind_I4);
//= bufLocal[argnum].flags = flags;
ilg.Emit(OpCodes.Ldloc, bufLocal);
ilg.Emit(OpCodes.Ldc_I4, argnum * VARIANT_SIZE + 13);
ilg.Emit(OpCodes.Add);
ilg.Emit(OpCodes.Ldc_I4, (Int32)flags);
ilg.Emit(OpCodes.Stind_I1);
}
static void EmitTypeStore(ILGenerator ilg, LocalBuilder bufLocal,
TypeInfo.TypeDescriptor t, int argnum)
{
ilg.Emit(OpCodes.Ldloc, bufLocal);
ilg.Emit(OpCodes.Ldc_I4, argnum * VARIANT_SIZE + 12);
ilg.Emit(OpCodes.Add);
ilg.Emit(OpCodes.Ldc_I4, (Int32)t.tag);
ilg.Emit(OpCodes.Stind_I4);
}
static void EmitComputeBufferLoc(ILGenerator ilg, LocalBuilder bufLocal,
int argnum)
{
ilg.Emit(OpCodes.Ldloc, bufLocal);
ilg.Emit(OpCodes.Ldc_I4, argnum * VARIANT_SIZE);
ilg.Emit(OpCodes.Add);
}
static void EmitPrepareArgStore(ILGenerator ilg, LocalBuilder bufLocal,
int argnum)
{
EmitComputeBufferLoc(ilg, bufLocal, argnum);
EmitLoadArg(ilg, argnum);
}
static void EmitLoadArg(ILGenerator ilg, int argnum)
{
switch (argnum) {
case 0:
ilg.Emit(OpCodes.Ldarg_1);
break;
case 1:
ilg.Emit(OpCodes.Ldarg_2);
break;
case 2:
ilg.Emit(OpCodes.Ldarg_3);
break;
default:
if (argnum < 254)
ilg.Emit(OpCodes.Ldarg_S, argnum + 1);
else
ilg.Emit(OpCodes.Ldarg, argnum + 1);
break;
}
}
static void EmitLoadReturnSlot_1(ILGenerator ilg, LocalBuilder bufLocal,
int slotnum)
{
ilg.Emit(OpCodes.Ldloc, bufLocal);
ilg.Emit(OpCodes.Ldc_I4, (slotnum - 1) * VARIANT_SIZE);
ilg.Emit(OpCodes.Add);
ilg.Emit(OpCodes.Ldind_I4);
}
static void EmitOutParamPrep(ILGenerator ilg, LocalBuilder bufLocal,
TypeInfo.TypeDescriptor type, int argnum)
{
ilg.Emit(OpCodes.Nop);
ilg.Emit(OpCodes.Ldloc, bufLocal);
ilg.Emit(OpCodes.Ldc_I4, argnum * VARIANT_SIZE + 13);
ilg.Emit(OpCodes.Add);
ilg.Emit(OpCodes.Ldc_I4, 1); // PTR_IS_DATA
ilg.Emit(OpCodes.Stind_I1);
ilg.Emit(OpCodes.Ldloc, bufLocal);
ilg.Emit(OpCodes.Ldc_I4, argnum * VARIANT_SIZE + 8); // offsetof(ptr)
ilg.Emit(OpCodes.Add);
ilg.Emit(OpCodes.Ldloc, bufLocal);
ilg.Emit(OpCodes.Ldc_I4, argnum * VARIANT_SIZE + 0); // offsetof(val)
ilg.Emit(OpCodes.Add);
ilg.Emit(OpCodes.Stind_I4); /* XXX 64-bitness! */
}
static void EmitProxyConstructor(TypeBuilder tb, FieldInfo thisField)
{
ConstructorBuilder ctor =
tb.DefineConstructor(MethodAttributes.Public,
CallingConventions.Standard,
new Type[1] { typeof(IntPtr) });
ILGenerator ilg = ctor.GetILGenerator();
ilg.Emit(OpCodes.Ldarg_0);
ilg.Emit(OpCodes.Call, typeof(object).GetConstructor(new Type[0]));
ilg.Emit(OpCodes.Ldarg_0);
ilg.Emit(OpCodes.Ldarg_1);
ilg.Emit(OpCodes.Stfld, thisField);
ilg.Emit(OpCodes.Ret);
}
const int VARIANT_SIZE = 16; /* sizeof(XPTCVariant) */
unsafe static void GenerateProxyMethod(TypeBuilder tb,
MethodDescriptor desc,
FieldInfo thisField)
{
if (!desc.IsVisible()) {
Console.WriteLine("HIDDEN: {0}", desc);
return;
}
const MethodAttributes attrs =
MethodAttributes.Public | MethodAttributes.Virtual;
Type ret = desc.resultType;
MethodBuilder meth =
tb.DefineMethod(desc.name, attrs, ret, desc.argTypes);
ILGenerator ilg = meth.GetILGenerator();
TypeInfo.ParamDescriptor[] args = desc.args;
LocalBuilder bufLocal =
ilg.DeclareLocal(System.Type.GetType("System.Int32*"));
Type marshalType = typeof(System.Runtime.InteropServices.Marshal);
// Marshal.AllocCoTaskMem(constify(argBufSize))
int argCount = args.Length;
int argBufSize = VARIANT_SIZE * args.Length;
ilg.Emit(OpCodes.Ldc_I4, argBufSize);
ilg.Emit(OpCodes.Call, marshalType.GetMethod("AllocCoTaskMem"));
ilg.Emit(OpCodes.Stloc, bufLocal);
for (int i = 0; i < argCount; i++) {
TypeInfo.ParamDescriptor param = args[i];
TypeInfo.TypeDescriptor type = param.type;
IntPtr ptr = IntPtr.Zero;
sbyte flags = 0;
EmitTypeStore(ilg, bufLocal, type, i);
if ((param.flags & ParamFlags.Out) != 0) {
EmitOutParamPrep(ilg, bufLocal, type, i);
continue;
}
switch (type.tag) {
case TypeTag.Int8:
case TypeTag.Int16:
case TypeTag.UInt8:
case TypeTag.UInt16:
case TypeTag.Char:
case TypeTag.WChar:
case TypeTag.UInt32:
EmitPrepareArgStore(ilg, bufLocal, i);
// XXX do I need to cast this?
ilg.Emit(OpCodes.Castclass, typeof(Int32));
ilg.Emit(OpCodes.Stind_I4);
break;
case TypeTag.Int32:
EmitPrepareArgStore(ilg, bufLocal, i);
ilg.Emit(OpCodes.Stind_I4);
break;
case TypeTag.String:
EmitPrepareArgStore(ilg, bufLocal, i);
// the string arg is now on the stack
ilg.Emit(OpCodes.Call,
marshalType.GetMethod("StringToCoTaskMemAnsi"));
ilg.Emit(OpCodes.Stind_I4);
break;
default:
/*
String msg = String.Format("{0}: type {1} not supported",
param.Name(), type.tag.ToString());
throw new Exception(msg);
*/
break;
}
EmitPtrAndFlagsStore(ilg, bufLocal, i, ptr, flags);
}
//= (void)XPTC_InvokeByIndex(thisptr, desc.index, length, bufLocal);
ilg.Emit(OpCodes.Ldarg_0);
ilg.Emit(OpCodes.Ldfld, thisField);
ilg.Emit(OpCodes.Ldc_I4, desc.index);
ilg.Emit(OpCodes.Ldc_I4, args.Length);
ilg.Emit(OpCodes.Ldloc_0);
ilg.Emit(OpCodes.Call, typeof(Mozilla.XPCOM.Invoker).
GetMethod("XPTC_InvokeByIndex",
BindingFlags.Static | BindingFlags.NonPublic));
ilg.Emit(OpCodes.Pop);
if (ret == typeof(string)) {
ilg.Emit(OpCodes.Ldstr, "FAKE RETURN STRING");
} else if (ret == typeof(object)) {
ilg.Emit(OpCodes.Newobj,
typeof(object).GetConstructor(new Type[0]));
} else if (ret == typeof(int)) {
EmitLoadReturnSlot_1(ilg, bufLocal, args.Length);
} else if (ret == typeof(void)) {
// Nothing
} else {
throw new Exception(String.Format("return type {0} not " +
"supported yet",
desc.result.type.tag));
}
//= Marshal.FreeCoTaskMem(bufLocal);
ilg.Emit(OpCodes.Ldloc, bufLocal);
ilg.Emit(OpCodes.Call, marshalType.GetMethod("FreeCoTaskMem"));
ilg.Emit(OpCodes.Ret);
Console.WriteLine("$\t{0}", desc);
}
public static void Main(string[] args)
{
int res = StartXPCOM(out srvmgr);
if (res != 0) {
Console.WriteLine("StartXPCOM failed: {0:X2}", res);
return;
}
string ifaceName = args[0];
MethodDescriptor[] descs = TypeInfo.GetMethodData(ifaceName);
Console.WriteLine("Interface {0}:", ifaceName);
AssemblyName an = new AssemblyName();
an.Version = new Version(1, 0, 0, 0);
an.Name = "Mozilla.XPCOM.Interfaces." + ifaceName;
AppDomain currentDomain = AppDomain.CurrentDomain;
AssemblyBuilderAccess access;
if (args.Length > 1)
access = AssemblyBuilderAccess.RunAndSave;
else
access = AssemblyBuilderAccess.Run;
AssemblyBuilder ab = currentDomain.DefineDynamicAssembly(an, access);
ModuleBuilder mb;
if (args.Length > 1)
mb = ab.DefineDynamicModule(an.Name, args[1]);
else
mb = ab.DefineDynamicModule(an.Name);
TypeBuilder ifaceTb = mb.DefineType(ifaceName, (TypeAttributes.Public |
TypeAttributes.Interface));
for (int i = 3; i < descs.Length; i++) {
GenerateInterfaceMethod(ifaceTb, descs[i]);
}
ifaceTb.CreateType();
TypeBuilder proxyTb = mb.DefineType(ifaceName + "$Proxy",
(TypeAttributes.Class),
typeof(object),
new Type[1] { ifaceTb } );
FieldBuilder thisField = proxyTb.DefineField("this", typeof(IntPtr),
FieldAttributes.Private);
EmitProxyConstructor(proxyTb, thisField);
for (int i = 3; i < descs.Length; i++) {
GenerateProxyMethod(proxyTb, descs[i], thisField);
}
if (args.Length > 1)
ab.Save(args[1]);
Type proxyType = proxyTb.CreateType();
Console.WriteLine("proxyType: {0}", proxyType);
ConstructorInfo proxyCtor =
proxyType.GetConstructor(new Type[1] { typeof(IntPtr) });
Console.WriteLine("proxyCtor: {0}", proxyCtor);
IntPtr impl = GetTestImpl();
Console.WriteLine("proxyThis: {0:X2}", impl.ToInt32());
object proxy = proxyCtor.Invoke(new object[] { impl });
MethodInfo proxyAdd = proxyType.GetMethod("add");
Console.WriteLine("proxyAdd: {0}", proxyAdd);
object proxyRet = proxyAdd.Invoke(proxy, new object[] { 3, 5 });
Console.WriteLine("proxyRet: {0}", (int)proxyRet);
MethodInfo proxySay = proxyType.GetMethod("say");
Console.WriteLine("proxySay: {0}", proxySay);
proxySay.Invoke(proxy, new object[] { "holy cow!" });
PropertyInfo proxyIntProp = proxyType.GetProperty("intProp");
Console.WriteLine("proxyIntProp: {0}", proxyIntProp);
Console.WriteLine("proxyIntProp(get): {0}",
proxyIntProp.GetValue(proxy, null));
proxyIntProp.SetValue(proxy, 31337, null);
Console.WriteLine("proxyIntProp(get): {0}",
proxyIntProp.GetValue(proxy, null));
}
}

View File

@ -0,0 +1,30 @@
using System;
using Mozilla.XPCOM;
using Interfaces = Mozilla.XPCOM.Interfaces;
public class Test
{
class TestCallback : Mozilla.XPCOM.Interfaces.testCallback
{
public void Call() {
Console.WriteLine("Callback invoked!");
}
}
public static void Main()
{
Interfaces.test myTest = (Interfaces.test)
Components.CreateInstance("@off.net/test-component;1",
typeof(Interfaces.test));
Console.WriteLine("3 + 5 = {0}", myTest.Add(3, 5));
int before = myTest.IntProp;
myTest.IntProp = 99;
Console.WriteLine("intProp: {0}, (= 99), {1}", before, myTest.IntProp);
Console.WriteLine("roIntProp: {0}", myTest.RoIntProp);
Console.WriteLine("Invoking callback:");
TestCallback tcb = new TestCallback();
myTest.Callback(tcb);
Console.WriteLine("Done!");
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Runtime.InteropServices;
using Mozilla.XPCOM;
using MethodDescriptor = Mozilla.XPCOM.TypeInfo.MethodDescriptor;
public class Test
{
[DllImport("xpcom-dotnet.so")]
static extern int StartXPCOM(out IntPtr srvmgr);
static IntPtr srvmgr;
[DllImport("test.so", EntryPoint="GetImpl")]
public static extern IntPtr GetTestImpl();
public static int xptinfo_test(string[] args)
{
int index = Int32.Parse(args[2]);
MethodDescriptor meth = TypeInfo.GetMethodData(args[1], index);
Console.WriteLine("{0}#{1}: {2}", args[1], index, meth.ToString());
return 0;
}
public static int xptinvoke_test_cb()
{
object o = new object();
IntPtr impl = GetTestImpl();
Invoker.Invoke(impl, "test", "callback", o);
return 0;
}
public static int xptinvoke_test_add(string[] args)
{
int a = Int32.Parse(args[1]);
int b = Int32.Parse(args[2]);
IntPtr impl = GetTestImpl();
Invoker.Invoke(impl, "test", "add", a, b);
return 0;
}
public static int Main(string[] args)
{
int res = StartXPCOM(out srvmgr);
if (res != 0) {
Console.WriteLine("StartXPCOM failed: {0:X2}", res);
return 1;
}
if (args[0] == "add")
return xptinvoke_test_add(args);
if (args[0] == "xptinfo")
return xptinfo_test(args);
if (args[0] == "cb")
return xptinvoke_test_cb();
Console.WriteLine("Unknown test mode: {0}", args[0]);
return 1;
}
}

View File

@ -0,0 +1,86 @@
#include "test.h"
#include <stdio.h>
class testimpl : public test
{
public:
testimpl() : mIntProp(-5) { }
NS_DECL_ISUPPORTS
NS_DECL_TEST
private:
PRInt32 mIntProp;
};
NS_IMPL_ISUPPORTS1(testimpl, test);
NS_IMETHODIMP
testimpl::Poke(const char *with)
{
fprintf(stderr, "poke: %s!\n", with);
return NS_OK;
}
NS_IMETHODIMP
testimpl::Say(const char *sayIt)
{
fprintf(stderr, "testimpl says: %s!\n", sayIt);
return NS_OK;
}
NS_IMETHODIMP
testimpl::Shout(const char *shoutIt)
{
fprintf(stderr, "testimpl shouts: %s!\n", shoutIt);
return NS_OK;
}
NS_IMETHODIMP
testimpl::Add(PRInt32 a, PRInt32 b, PRInt32 *result)
{
*result = a + b;
fprintf(stderr, "%d(%08x) + %d(%08x) = %d(%08x)\n", a, a, b, b,
*result, *result);
return NS_OK;
}
NS_IMETHODIMP
testimpl::Peek(char **retval)
{
*retval = strdup("AHOY!");
fprintf(stderr, "ahoy is %p @ %p\n", *retval, retval);
return NS_OK;
}
NS_IMETHODIMP
testimpl::Callback(testCallback *cb)
{
fprintf(stderr, "testCallback is %p\n", cb);
return cb->Call();
}
NS_IMETHODIMP
testimpl::GetIntProp(PRInt32 *aIntProp)
{
*aIntProp = mIntProp;
return NS_OK;
}
NS_IMETHODIMP
testimpl::SetIntProp(PRInt32 aIntProp)
{
mIntProp = aIntProp;
return NS_OK;
}
NS_IMETHODIMP
testimpl::GetRoIntProp(PRInt32 *aRoIntProp)
{
*aRoIntProp = 42;
return NS_OK;
}
extern "C" testimpl*
GetImpl(void)
{
return new testimpl;
}

378
extensions/mono/test/test.h Normal file
View File

@ -0,0 +1,378 @@
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM test.idl
*/
#ifndef __gen_test_h__
#define __gen_test_h__
#ifndef __gen_nsISupports_h__
#include "nsISupports.h"
#endif
/* For IDL files that don't want to include root IDL files. */
#ifndef NS_NO_VTABLE
#define NS_NO_VTABLE
#endif
/* starting interface: testCallback */
#define TESTCALLBACK_IID_STR "75d2225d-0a67-4dbc-91de-78319594cce8"
#define TESTCALLBACK_IID \
{0x75d2225d, 0x0a67, 0x4dbc, \
{ 0x91, 0xde, 0x78, 0x31, 0x95, 0x94, 0xcc, 0xe8 }}
class NS_NO_VTABLE testCallback : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(TESTCALLBACK_IID)
/* void call (); */
NS_IMETHOD Call(void) = 0;
};
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_TESTCALLBACK \
NS_IMETHOD Call(void);
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_TESTCALLBACK(_to) \
NS_IMETHOD Call(void) { return _to Call(); }
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
#define NS_FORWARD_SAFE_TESTCALLBACK(_to) \
NS_IMETHOD Call(void) { return !_to ? NS_ERROR_NULL_POINTER : _to->Call(); }
#if 0
/* Use the code below as a template for the implementation class for this interface. */
/* Header file */
class _MYCLASS_ : public testCallback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_TESTCALLBACK
_MYCLASS_();
virtual ~_MYCLASS_();
/* additional members */
};
/* Implementation file */
NS_IMPL_ISUPPORTS1(_MYCLASS_, testCallback)
_MYCLASS_::_MYCLASS_()
{
/* member initializers and constructor code */
}
_MYCLASS_::~_MYCLASS_()
{
/* destructor code */
}
/* void call (); */
NS_IMETHODIMP _MYCLASS_::Call()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* End of implementation class template. */
#endif
/* starting interface: test */
#define TEST_IID_STR "1afbcf6a-e23f-4e12-b191-4c0a76cd9cec"
#define TEST_IID \
{0x1afbcf6a, 0xe23f, 0x4e12, \
{ 0xb1, 0x91, 0x4c, 0x0a, 0x76, 0xcd, 0x9c, 0xec }}
class NS_NO_VTABLE test : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(TEST_IID)
/* void say (in string sayIt); */
NS_IMETHOD Say(const char *sayIt) = 0;
/* void shout (in string shoutIt); */
NS_IMETHOD Shout(const char *shoutIt) = 0;
/* void poke (in string with); */
NS_IMETHOD Poke(const char *with) = 0;
/* PRInt32 add (in PRInt32 a, in PRInt32 b); */
NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval) = 0;
/* string peek (); */
NS_IMETHOD Peek(char **_retval) = 0;
/* void callback (in testCallback cb); */
NS_IMETHOD Callback(testCallback *cb) = 0;
/* attribute PRInt32 intProp; */
NS_IMETHOD GetIntProp(PRInt32 *aIntProp) = 0;
NS_IMETHOD SetIntProp(PRInt32 aIntProp) = 0;
/* readonly attribute PRInt32 roIntProp; */
NS_IMETHOD GetRoIntProp(PRInt32 *aRoIntProp) = 0;
};
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_TEST \
NS_IMETHOD Say(const char *sayIt); \
NS_IMETHOD Shout(const char *shoutIt); \
NS_IMETHOD Poke(const char *with); \
NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval); \
NS_IMETHOD Peek(char **_retval); \
NS_IMETHOD Callback(testCallback *cb); \
NS_IMETHOD GetIntProp(PRInt32 *aIntProp); \
NS_IMETHOD SetIntProp(PRInt32 aIntProp); \
NS_IMETHOD GetRoIntProp(PRInt32 *aRoIntProp);
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_TEST(_to) \
NS_IMETHOD Say(const char *sayIt) { return _to Say(sayIt); } \
NS_IMETHOD Shout(const char *shoutIt) { return _to Shout(shoutIt); } \
NS_IMETHOD Poke(const char *with) { return _to Poke(with); } \
NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval) { return _to Add(a, b, _retval); } \
NS_IMETHOD Peek(char **_retval) { return _to Peek(_retval); } \
NS_IMETHOD Callback(testCallback *cb) { return _to Callback(cb); } \
NS_IMETHOD GetIntProp(PRInt32 *aIntProp) { return _to GetIntProp(aIntProp); } \
NS_IMETHOD SetIntProp(PRInt32 aIntProp) { return _to SetIntProp(aIntProp); } \
NS_IMETHOD GetRoIntProp(PRInt32 *aRoIntProp) { return _to GetRoIntProp(aRoIntProp); }
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
#define NS_FORWARD_SAFE_TEST(_to) \
NS_IMETHOD Say(const char *sayIt) { return !_to ? NS_ERROR_NULL_POINTER : _to->Say(sayIt); } \
NS_IMETHOD Shout(const char *shoutIt) { return !_to ? NS_ERROR_NULL_POINTER : _to->Shout(shoutIt); } \
NS_IMETHOD Poke(const char *with) { return !_to ? NS_ERROR_NULL_POINTER : _to->Poke(with); } \
NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->Add(a, b, _retval); } \
NS_IMETHOD Peek(char **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->Peek(_retval); } \
NS_IMETHOD Callback(testCallback *cb) { return !_to ? NS_ERROR_NULL_POINTER : _to->Callback(cb); } \
NS_IMETHOD GetIntProp(PRInt32 *aIntProp) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetIntProp(aIntProp); } \
NS_IMETHOD SetIntProp(PRInt32 aIntProp) { return !_to ? NS_ERROR_NULL_POINTER : _to->SetIntProp(aIntProp); } \
NS_IMETHOD GetRoIntProp(PRInt32 *aRoIntProp) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetRoIntProp(aRoIntProp); }
#if 0
/* Use the code below as a template for the implementation class for this interface. */
/* Header file */
class _MYCLASS_ : public test
{
public:
NS_DECL_ISUPPORTS
NS_DECL_TEST
_MYCLASS_();
virtual ~_MYCLASS_();
/* additional members */
};
/* Implementation file */
NS_IMPL_ISUPPORTS1(_MYCLASS_, test)
_MYCLASS_::_MYCLASS_()
{
/* member initializers and constructor code */
}
_MYCLASS_::~_MYCLASS_()
{
/* destructor code */
}
/* void say (in string sayIt); */
NS_IMETHODIMP _MYCLASS_::Say(const char *sayIt)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void shout (in string shoutIt); */
NS_IMETHODIMP _MYCLASS_::Shout(const char *shoutIt)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void poke (in string with); */
NS_IMETHODIMP _MYCLASS_::Poke(const char *with)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* PRInt32 add (in PRInt32 a, in PRInt32 b); */
NS_IMETHODIMP _MYCLASS_::Add(PRInt32 a, PRInt32 b, PRInt32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* string peek (); */
NS_IMETHODIMP _MYCLASS_::Peek(char **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void callback (in testCallback cb); */
NS_IMETHODIMP _MYCLASS_::Callback(testCallback *cb)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute PRInt32 intProp; */
NS_IMETHODIMP _MYCLASS_::GetIntProp(PRInt32 *aIntProp)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP _MYCLASS_::SetIntProp(PRInt32 aIntProp)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute PRInt32 roIntProp; */
NS_IMETHODIMP _MYCLASS_::GetRoIntProp(PRInt32 *aRoIntProp)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* End of implementation class template. */
#endif
/* starting interface: testString */
#define TESTSTRING_IID_STR "5a1f21a2-8aa3-4147-a808-1e1a422dcb76"
#define TESTSTRING_IID \
{0x5a1f21a2, 0x8aa3, 0x4147, \
{ 0xa8, 0x08, 0x1e, 0x1a, 0x42, 0x2d, 0xcb, 0x76 }}
class NS_NO_VTABLE testString : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(TESTSTRING_IID)
/* void say (in string sayIt); */
NS_IMETHOD Say(const char *sayIt) = 0;
};
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_TESTSTRING \
NS_IMETHOD Say(const char *sayIt);
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_TESTSTRING(_to) \
NS_IMETHOD Say(const char *sayIt) { return _to Say(sayIt); }
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
#define NS_FORWARD_SAFE_TESTSTRING(_to) \
NS_IMETHOD Say(const char *sayIt) { return !_to ? NS_ERROR_NULL_POINTER : _to->Say(sayIt); }
#if 0
/* Use the code below as a template for the implementation class for this interface. */
/* Header file */
class _MYCLASS_ : public testString
{
public:
NS_DECL_ISUPPORTS
NS_DECL_TESTSTRING
_MYCLASS_();
virtual ~_MYCLASS_();
/* additional members */
};
/* Implementation file */
NS_IMPL_ISUPPORTS1(_MYCLASS_, testString)
_MYCLASS_::_MYCLASS_()
{
/* member initializers and constructor code */
}
_MYCLASS_::~_MYCLASS_()
{
/* destructor code */
}
/* void say (in string sayIt); */
NS_IMETHODIMP _MYCLASS_::Say(const char *sayIt)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* End of implementation class template. */
#endif
/* starting interface: testInt */
#define TESTINT_IID_STR "5a1f21a2-8aa3-4147-a808-1e1a422dcb77"
#define TESTINT_IID \
{0x5a1f21a2, 0x8aa3, 0x4147, \
{ 0xa8, 0x08, 0x1e, 0x1a, 0x42, 0x2d, 0xcb, 0x77 }}
class NS_NO_VTABLE testInt : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(TESTINT_IID)
/* void add (in PRInt32 a, in PRInt32 b); */
NS_IMETHOD Add(PRInt32 a, PRInt32 b) = 0;
};
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_TESTINT \
NS_IMETHOD Add(PRInt32 a, PRInt32 b);
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_TESTINT(_to) \
NS_IMETHOD Add(PRInt32 a, PRInt32 b) { return _to Add(a, b); }
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
#define NS_FORWARD_SAFE_TESTINT(_to) \
NS_IMETHOD Add(PRInt32 a, PRInt32 b) { return !_to ? NS_ERROR_NULL_POINTER : _to->Add(a, b); }
#if 0
/* Use the code below as a template for the implementation class for this interface. */
/* Header file */
class _MYCLASS_ : public testInt
{
public:
NS_DECL_ISUPPORTS
NS_DECL_TESTINT
_MYCLASS_();
virtual ~_MYCLASS_();
/* additional members */
};
/* Implementation file */
NS_IMPL_ISUPPORTS1(_MYCLASS_, testInt)
_MYCLASS_::_MYCLASS_()
{
/* member initializers and constructor code */
}
_MYCLASS_::~_MYCLASS_()
{
/* destructor code */
}
/* void add (in PRInt32 a, in PRInt32 b); */
NS_IMETHODIMP _MYCLASS_::Add(PRInt32 a, PRInt32 b)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* End of implementation class template. */
#endif
#endif /* __gen_test_h__ */

View File

@ -0,0 +1,32 @@
#include "nsISupports.idl"
[scriptable,uuid(75d2225d-0a67-4dbc-91de-78319594cce8)]
interface testCallback : nsISupports
{
void call();
};
[scriptable,uuid(1afbcf6a-e23f-4e12-b191-4c0a76cd9cec)]
interface test : nsISupports
{
void say(in string sayIt);
void shout(in string shoutIt);
void poke(in string with);
PRInt32 add(in PRInt32 a, in PRInt32 b);
string peek();
void callback(in testCallback cb);
attribute PRInt32 intProp;
readonly attribute PRInt32 roIntProp;
};
[scriptable,uuid(5a1f21a2-8aa3-4147-a808-1e1a422dcb76)]
interface testString : nsISupports
{
void say(in string sayIt);
};
[scriptable,uuid(5a1f21a2-8aa3-4147-a808-1e1a422dcb77)]
interface testInt : nsISupports
{
void add(in PRInt32 a, in PRInt32 b);
};