Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
Test Struct Reference

#include <Tests.h>

Collaboration diagram for Test:
Collaboration graph
[legend]

List of all members.

Classes

class  TestCallback

Public Member Functions

static IntPtr GetTestImpl ()
static IntPtr GetTestImpl ()

Static Public Member Functions

static void Main (string[] args)
static void Main ()
static int xptinfo_test (string[] args)
static int xptinvoke_test_cb ()
static int xptinvoke_test_add (string[] args)
static int Main (string[] args)

Public Attributes

TCHAR szName [256]
TCHAR szDesc [256]
TestProc pfn
TestResult nLastResult
const char * s1
const char * s2
PRIntn n
const char * name
TestFunc func

Private Member Functions

static int StartXPCOM (out IntPtr srvmgr)
static int StartXPCOM (out IntPtr srvmgr)

Static Private Member Functions

static void GenerateInterfaceMethod (TypeBuilder tb, MethodDescriptor desc)
static void EmitPtrAndFlagsStore (ILGenerator ilg, LocalBuilder bufLocal, int argnum, IntPtr ptr, sbyte flags)
static void EmitTypeStore (ILGenerator ilg, LocalBuilder bufLocal, TypeInfo.TypeDescriptor t, int argnum)
static void EmitComputeBufferLoc (ILGenerator ilg, LocalBuilder bufLocal, int argnum)
static void EmitPrepareArgStore (ILGenerator ilg, LocalBuilder bufLocal, int argnum)
static void EmitLoadArg (ILGenerator ilg, int argnum)
static void EmitLoadReturnSlot_1 (ILGenerator ilg, LocalBuilder bufLocal, int slotnum)
static void EmitOutParamPrep (ILGenerator ilg, LocalBuilder bufLocal, TypeInfo.TypeDescriptor type, int argnum)
static void EmitProxyConstructor (TypeBuilder tb, FieldInfo thisField)
static unsafe void GenerateProxyMethod (TypeBuilder tb, MethodDescriptor desc, FieldInfo thisField)

Private Attributes

const int VARIANT_SIZE = 16

Static Private Attributes

static IntPtr srvmgr

Detailed Description

Definition at line 65 of file Tests.h.


Member Function Documentation

static void Test.EmitComputeBufferLoc ( ILGenerator  ilg,
LocalBuilder  bufLocal,
int  argnum 
) [inline, static, private]

Definition at line 60 of file generate-assembly.cs.

    {
        ilg.Emit(OpCodes.Ldloc, bufLocal);
        ilg.Emit(OpCodes.Ldc_I4, argnum * VARIANT_SIZE);
        ilg.Emit(OpCodes.Add);
    }

Here is the caller graph for this function:

static void Test.EmitLoadArg ( ILGenerator  ilg,
int  argnum 
) [inline, static, private]

Definition at line 75 of file generate-assembly.cs.

    {
        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;
        }
    }

Here is the caller graph for this function:

static void Test.EmitLoadReturnSlot_1 ( ILGenerator  ilg,
LocalBuilder  bufLocal,
int  slotnum 
) [inline, static, private]

Definition at line 96 of file generate-assembly.cs.

    {
        ilg.Emit(OpCodes.Ldloc, bufLocal);
        ilg.Emit(OpCodes.Ldc_I4, (slotnum - 1) * VARIANT_SIZE);
        ilg.Emit(OpCodes.Add);
        ilg.Emit(OpCodes.Ldind_I4);
    }

Here is the caller graph for this function:

static void Test.EmitOutParamPrep ( ILGenerator  ilg,
LocalBuilder  bufLocal,
TypeInfo.TypeDescriptor  type,
int  argnum 
) [inline, static, private]

Definition at line 105 of file generate-assembly.cs.

    {
        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! */
    }

Here is the caller graph for this function:

static void Test.EmitPrepareArgStore ( ILGenerator  ilg,
LocalBuilder  bufLocal,
int  argnum 
) [inline, static, private]

Definition at line 68 of file generate-assembly.cs.

    {
        EmitComputeBufferLoc(ilg, bufLocal, argnum);
        EmitLoadArg(ilg, argnum);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static void Test.EmitProxyConstructor ( TypeBuilder  tb,
FieldInfo  thisField 
) [inline, static, private]

Definition at line 124 of file generate-assembly.cs.

    {
        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);
    }

Here is the caller graph for this function:

static void Test.EmitPtrAndFlagsStore ( ILGenerator  ilg,
LocalBuilder  bufLocal,
int  argnum,
IntPtr  ptr,
sbyte  flags 
) [inline, static, private]

Definition at line 32 of file generate-assembly.cs.

    {
        //= 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);
    }

Here is the caller graph for this function:

static void Test.EmitTypeStore ( ILGenerator  ilg,
LocalBuilder  bufLocal,
TypeInfo.TypeDescriptor  t,
int  argnum 
) [inline, static, private]

Definition at line 50 of file generate-assembly.cs.

    {
        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);
    }

Here is the caller graph for this function:

static void Test.GenerateInterfaceMethod ( TypeBuilder  tb,
MethodDescriptor  desc 
) [inline, static, private]

Definition at line 20 of file generate-assembly.cs.

    {
        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);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static unsafe void Test.GenerateProxyMethod ( TypeBuilder  tb,
MethodDescriptor  desc,
FieldInfo  thisField 
) [inline, static, private]

Definition at line 141 of file generate-assembly.cs.

    {
        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);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static IntPtr Test.GetTestImpl ( )
static IntPtr Test.GetTestImpl ( )

Here is the caller graph for this function:

static void Test.Main ( ) [inline, static]

Definition at line 15 of file sample-app.cs.

    {
        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!");
    }

Here is the call graph for this function:

static int Test.Main ( string[]  args) [inline, static]

Definition at line 43 of file test-invoke.cs.

    {
        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;
    }

Here is the call graph for this function:

static void Test.Main ( string[]  args) [inline, static]

Definition at line 250 of file generate-assembly.cs.

    {
        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));
    }

Here is the call graph for this function:

static int Test.StartXPCOM ( out IntPtr  srvmgr) [private]
static int Test.StartXPCOM ( out IntPtr  srvmgr) [private]

Here is the caller graph for this function:

static int Test.xptinfo_test ( string[]  args) [inline, static]

Definition at line 16 of file test-invoke.cs.

    {
        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;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static int Test.xptinvoke_test_add ( string[]  args) [inline, static]

Definition at line 33 of file test-invoke.cs.

    {
        int a = Int32.Parse(args[1]);
        int b = Int32.Parse(args[2]);

        IntPtr impl = GetTestImpl();
        Invoker.Invoke(impl, "test", "add", a, b);
        return 0;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static int Test.xptinvoke_test_cb ( ) [inline, static]

Definition at line 24 of file test-invoke.cs.

    {
        object o = new object();

        IntPtr impl = GetTestImpl();
        Invoker.Invoke(impl, "test", "callback", o);
        return 0;
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 474 of file TestMinStringAPI.cpp.

PRIntn Test::n

Definition at line 83 of file TestCRT.cpp.

const char * Test::name

Definition at line 473 of file TestMinStringAPI.cpp.

Definition at line 70 of file Tests.h.

Definition at line 69 of file Tests.h.

const char* Test::s1

Definition at line 81 of file TestCRT.cpp.

const char* Test::s2

Definition at line 82 of file TestCRT.cpp.

static IntPtr Test.srvmgr [static, private]

Definition at line 15 of file generate-assembly.cs.

Definition at line 68 of file Tests.h.

Definition at line 67 of file Tests.h.

const int Test.VARIANT_SIZE = 16 [private]

Definition at line 139 of file generate-assembly.cs.


The documentation for this struct was generated from the following files: