def get_type(type, calltype, iid_is=None, size_is=None): """ Return the appropriate xpt.Type object for this param """ while isinstance(type, xpidl.Typedef): type = type.realtype if isinstance(type, xpidl.Builtin): if type.name == 'string' and size_is is not None: return xpt.StringWithSizeType(size_is, size_is) elif type.name == 'wstring' and size_is is not None: return xpt.WideStringWithSizeType(size_is, size_is) else: tag = TypeMap[type.name] isPtr = (tag == xpt.Type.Tags.char_ptr or tag == xpt.Type.Tags.wchar_t_ptr) return xpt.SimpleType(tag, pointer=isPtr, reference=False) if isinstance(type, xpidl.Array): # NB: For an Array<T> we pass down the iid_is to get the type of T. # This allows Arrays of InterfaceIs types to work. return xpt.ArrayType( get_type(type.type, calltype, iid_is), size_is, #XXXkhuey length_is duplicates size_is (bug 677788), size_is) if isinstance(type, xpidl.Interface) or isinstance( type, xpidl.Forward): xptiface = None for i in ifaces: if i.name == type.name: xptiface = i if not xptiface: xptiface = xpt.Interface(name=type.name) ifaces.append(xptiface) return xpt.InterfaceType(xptiface) if isinstance(type, xpidl.Native): if type.specialtype: # XXXkhuey jsval is marked differently in the typelib and in the headers :-( isPtr = (type.isPtr(calltype) or type.isRef(calltype) ) and not type.specialtype == 'jsval' isRef = type.isRef( calltype) and not type.specialtype == 'jsval' return xpt.SimpleType(TypeMap[type.specialtype], pointer=isPtr, reference=isRef) elif iid_is is not None: return xpt.InterfaceIsType(iid_is) else: # void ptr return xpt.SimpleType(TypeMap['void'], pointer=True, reference=False) raise Exception("Unknown type!")
def test_methods(self): p = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void)) m = xpt.Method("Bar", p) i = xpt.Interface("IFoo", iid="11223344-5566-7788-9900-aabbccddeeff", methods=[m]) t = xpt.Typelib(interfaces=[i]) self.checkRoundtrip(t) # add some more methods i.methods.append( xpt.Method("One", xpt.Param(xpt.SimpleType(xpt.Type.Tags.int32)), params=[ xpt.Param(xpt.SimpleType(xpt.Type.Tags.int64)), xpt.Param( xpt.SimpleType(xpt.Type.Tags.float, pointer=True)) ])) self.checkRoundtrip(t) # test some other types (should really be more thorough) i.methods.append( xpt.Method("Two", xpt.Param(xpt.SimpleType(xpt.Type.Tags.int32)), params=[ xpt.Param( xpt.SimpleType(xpt.Type.Tags.UTF8String, pointer=True)), xpt.Param( xpt.SimpleType(xpt.Type.Tags.wchar_t_ptr, pointer=True)) ])) self.checkRoundtrip(t) # add a method with an InterfaceType argument bar = xpt.Interface("IBar") t.interfaces.append(bar) i.methods.append( xpt.Method("IFaceMethod", xpt.Param(xpt.SimpleType(xpt.Type.Tags.int32)), params=[xpt.Param(xpt.InterfaceType(bar))])) self.checkRoundtrip(t) # add a method with an InterfaceIsType argument i.methods.append( xpt.Method("IFaceIsMethod", xpt.Param(xpt.SimpleType(xpt.Type.Tags.void)), params=[ xpt.Param(xpt.InterfaceIsType(1)), xpt.Param(xpt.SimpleType(xpt.Type.Tags.nsIID)) ])) self.checkRoundtrip(t) # add a method with an ArrayType argument i.methods.append( xpt.Method("ArrayMethod", xpt.Param(xpt.SimpleType(xpt.Type.Tags.void)), params=[ xpt.Param( xpt.ArrayType( xpt.SimpleType(xpt.Type.Tags.int32), 1, 2)), xpt.Param(xpt.SimpleType(xpt.Type.Tags.int32)), xpt.Param(xpt.SimpleType(xpt.Type.Tags.int32)), ])) self.checkRoundtrip(t) # add a method with a StringWithSize and WideStringWithSize arguments i.methods.append( xpt.Method("StringWithSizeMethod", xpt.Param(xpt.SimpleType(xpt.Type.Tags.void)), params=[ xpt.Param(xpt.StringWithSizeType(1, 2)), xpt.Param(xpt.SimpleType(xpt.Type.Tags.int32)), xpt.Param(xpt.SimpleType(xpt.Type.Tags.int32)), xpt.Param(xpt.WideStringWithSizeType(4, 5)), xpt.Param(xpt.SimpleType(xpt.Type.Tags.int32)), xpt.Param(xpt.SimpleType(xpt.Type.Tags.int32)), ])) self.checkRoundtrip(t)