Beispiel #1
0
 def build_retval_param(m):
     type = get_type(m.realtype, 'out')
     if isDipperType(type.tag):
         # NB: The retval bit needs to be set here, contrary to what the
         # xpt spec says.
         return xpt.Param(type, in_=True, retval=True, dipper=True)
     return xpt.Param(type, in_=False, out=True, retval=True)
Beispiel #2
0
    def test_mergeResolvedUnresolved(self):
        """
        Test that merging two typelibs, one of which contains an unresolved
        reference to an interface, and the other of which contains a
        resolved reference to the same interface results in keeping the
        resolved reference.

        """
        # t1 has an unresolved interface, t2 has a resolved version
        t1 = xpt.Typelib()
        # add an unresolved interface
        t1.interfaces.append(xpt.Interface("IFoo"))
        t2 = xpt.Typelib()
        # add a resolved interface
        p = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void))
        m = xpt.Method("Bar", p)
        t2.interfaces.append(
            xpt.Interface("IFoo",
                          iid="11223344-5566-7788-9900-aabbccddeeff",
                          methods=[m],
                          scriptable=True))
        t3 = xpt.xpt_link([t1, t2])

        self.assertEqual(1, len(t3.interfaces))
        self.assertEqual("IFoo", t3.interfaces[0].name)
        self.assertEqual("11223344-5566-7788-9900-aabbccddeeff",
                         t3.interfaces[0].iid)
        self.assert_(t3.interfaces[0].resolved)
        self.assertEqual(1, len(t3.interfaces[0].methods))
        self.assertEqual("Bar", t3.interfaces[0].methods[0].name)

        # t1 has a resolved interface, t2 has an unresolved version
        t1 = xpt.Typelib()
        # add a resolved interface
        p = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void))
        m = xpt.Method("Bar", p)
        t1.interfaces.append(
            xpt.Interface("IFoo",
                          iid="11223344-5566-7788-9900-aabbccddeeff",
                          methods=[m],
                          scriptable=True))
        t2 = xpt.Typelib()
        # add an unresolved interface
        t2.interfaces.append(xpt.Interface("IFoo"))
        t3 = xpt.xpt_link([t1, t2])

        self.assertEqual(1, len(t3.interfaces))
        self.assertEqual("IFoo", t3.interfaces[0].name)
        self.assertEqual("11223344-5566-7788-9900-aabbccddeeff",
                         t3.interfaces[0].iid)
        self.assert_(t3.interfaces[0].resolved)
        self.assertEqual(1, len(t3.interfaces[0].methods))
        self.assertEqual("Bar", t3.interfaces[0].methods[0].name)
    def build_attr_param(a, getter=False, setter=False):
        if not (getter or setter):
            raise Exception("Attribute param must be for a getter or a setter!")

        type = get_type(a.realtype, getter and 'out' or 'in')
        if setter:
            return xpt.Param(type)
        else:
            if isDipperType(type.tag):
                # NB: The retval bit needs to be set here, contrary to what the
                # xpt spec says.
                return xpt.Param(type, in_=True, retval=True, dipper=True)
            return xpt.Param(type, in_=False, out=True, retval=True)
Beispiel #4
0
    def test_mergeReplaceArrayTypeParams(self):
        """
        Test that merging an interface correctly updates ArrayType
        params whose element_type is an InterfaceType on methods
        of other interfaces.

        """
        # t1 has an unresolved interface and an interface that uses the
        # unresolved interface as a type in an ArrayType in a parameter
        # of a method. t2 has a resolved version of the unresolved interface.
        t1 = xpt.Typelib()
        # add an unresolved interface
        i = xpt.Interface("IFoo")
        t1.interfaces.append(i)
        # add an interface that uses the unresolved interface
        # as a type in an ArrayType in a param value in a method.
        vp = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void))
        intp = xpt.Param(xpt.SimpleType(xpt.Type.Tags.int32))
        p = xpt.Param(xpt.ArrayType(xpt.InterfaceType(i), 1, 2))
        m = xpt.Method("ArrayIfaceParam", vp, params=[p, intp, intp])
        t1.interfaces.append(
            xpt.Interface("IParam",
                          iid="11111111-1111-1111-1111-111111111111",
                          methods=[m],
                          scriptable=True))
        t2 = xpt.Typelib()
        # add a resolved interface
        m = xpt.Method("Bar", vp)
        t2.interfaces.append(
            xpt.Interface("IFoo",
                          iid="11223344-5566-7788-9900-aabbccddeeff",
                          methods=[m],
                          scriptable=True))
        t3 = xpt.xpt_link([t1, t2])

        self.assertEqual(2, len(t3.interfaces))
        self.assertEqual("IParam", t3.interfaces[0].name)
        self.assertEqual("11111111-1111-1111-1111-111111111111",
                         t3.interfaces[0].iid)
        self.assertEqual("IFoo", t3.interfaces[1].name)
        self.assertEqual("11223344-5566-7788-9900-aabbccddeeff",
                         t3.interfaces[1].iid)
        self.assert_(t3.interfaces[1].resolved)
        # Ensure that IRetval's method's param type has been updated.
        self.assertEqual(1, len(t3.interfaces[0].methods))
        self.assert_(t3.interfaces[0].methods[0].params[0].type.element_type.
                     iface.resolved)
        self.assertEqual(
            t3.interfaces[1],
            t3.interfaces[0].methods[0].params[0].type.element_type.iface)
Beispiel #5
0
 def test_resolvedIdentical(self):
     """
     Test comparison function on xpt.Interface with interfaces with
     identical names and IIDs, both of which are resolved.
     
     """
     p = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void))
     m = xpt.Method("Bar", p)
     i1 = xpt.Interface("ABC", iid="11223344-5566-7788-9900-aabbccddeeff",
                        methods=[m])
     i2 = xpt.Interface("ABC", iid="11223344-5566-7788-9900-aabbccddeeff",
                        methods=[m])
     self.assert_(i2 == i1)
Beispiel #6
0
 def test_unresolvedResolved(self):
     """
     Test comparison function on xpt.Interface with interfaces with
     identical names and IIDs but different resolved status.
     
     """
     i1 = xpt.Interface("ABC", iid="11223344-5566-7788-9900-aabbccddeeff")
     p = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void))
     m = xpt.Method("Bar", p)
     i2 = xpt.Interface("ABC", iid="11223344-5566-7788-9900-aabbccddeeff",
                        methods=[m])
     self.assert_(i2 < i1)
     self.assert_(i2 != i1)
        def build_param(p):
            def findattr(p, attr):
                if hasattr(p, attr) and getattr(p, attr):
                    for i, param in enumerate(m.params):
                        if param.name == getattr(p, attr):
                            return i
                    return None

            iid_is = findattr(p, 'iid_is')
            size_is = findattr(p, 'size_is')

            in_ = p.paramtype.count("in")
            out = p.paramtype.count("out")
            dipper = False
            type = get_type(p.realtype, p.paramtype, iid_is=iid_is, size_is=size_is)
            if out and isDipperType(type.tag):
                out = False
                dipper = True

            return xpt.Param(type, in_, out, p.retval, p.shared, dipper, p.optional)
Beispiel #8
0
    def test_mergeReplaceRetval(self):
        """
        Test that merging an interface correctly updates InterfaceType
        return values on methods of other interfaces.

        """
        # t1 has an unresolved interface and an interface that uses the
        # unresolved interface as a return value from a method. t2
        # has a resolved version of the unresolved interface.
        t1 = xpt.Typelib()
        # add an unresolved interface
        i = xpt.Interface("IFoo")
        t1.interfaces.append(i)
        # add an interface that uses the unresolved interface
        # as a return value in a method.
        p = xpt.Param(xpt.InterfaceType(i))
        m = xpt.Method("ReturnIface", p)
        t1.interfaces.append(
            xpt.Interface("IRetval",
                          iid="11111111-1111-1111-1111-111111111111",
                          methods=[m],
                          scriptable=True))
        t2 = xpt.Typelib()
        # add a resolved interface
        p = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void))
        m = xpt.Method("Bar", p)
        t2.interfaces.append(
            xpt.Interface("IFoo",
                          iid="11223344-5566-7788-9900-aabbccddeeff",
                          methods=[m],
                          scriptable=True))
        t3 = xpt.xpt_link([t1, t2])

        self.assertEqual(2, len(t3.interfaces))
        self.assertEqual("IRetval", t3.interfaces[0].name)
        self.assertEqual("11111111-1111-1111-1111-111111111111",
                         t3.interfaces[0].iid)
        self.assertEqual("IFoo", t3.interfaces[1].name)
        self.assertEqual("11223344-5566-7788-9900-aabbccddeeff",
                         t3.interfaces[1].iid)
        self.assert_(t3.interfaces[1].resolved)
        # Ensure that IRetval's method's return value type has been updated.
        self.assertEqual(1, len(t3.interfaces[0].methods))
        self.assert_(t3.interfaces[0].methods[0].result.type.iface.resolved)
        self.assertEqual(t3.interfaces[1],
                         t3.interfaces[0].methods[0].result.type.iface)

        # t1 has a resolved interface. t2 has an unresolved version and
        # an interface that uses the unresolved interface as a return value
        # from a method.
        t1 = xpt.Typelib()
        # add a resolved interface
        p = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void))
        m = xpt.Method("Bar", p)
        t1.interfaces.append(
            xpt.Interface("IFoo",
                          iid="11223344-5566-7788-9900-aabbccddeeff",
                          methods=[m],
                          scriptable=True))
        t2 = xpt.Typelib()
        # add an unresolved interface
        i = xpt.Interface("IFoo")
        t2.interfaces.append(i)
        # add an interface that uses the unresolved interface
        # as a return value in a method.
        p = xpt.Param(xpt.InterfaceType(i))
        m = xpt.Method("ReturnIface", p)
        t2.interfaces.append(
            xpt.Interface("IRetval",
                          iid="11111111-1111-1111-1111-111111111111",
                          methods=[m],
                          scriptable=True))
        t3 = xpt.xpt_link([t1, t2])

        self.assertEqual(2, len(t3.interfaces))
        self.assertEqual("IRetval", t3.interfaces[0].name)
        self.assertEqual("11111111-1111-1111-1111-111111111111",
                         t3.interfaces[0].iid)
        self.assertEqual("IFoo", t3.interfaces[1].name)
        self.assertEqual("11223344-5566-7788-9900-aabbccddeeff",
                         t3.interfaces[1].iid)
        self.assert_(t3.interfaces[1].resolved)
        # Ensure that IRetval's method's return value type has been updated.
        self.assertEqual(1, len(t3.interfaces[0].methods))
        self.assert_(t3.interfaces[0].methods[0].result.type.iface.resolved)
        self.assertEqual(t3.interfaces[1],
                         t3.interfaces[0].methods[0].result.type.iface)
Beispiel #9
0
    def test_mergeReplaceParents(self):
        """
        Test that merging an interface results in other interfaces' parent
        member being updated properly.

        """
        # t1 has an unresolved interface, t2 has a resolved version,
        # but t1 also has another interface whose parent is the unresolved
        # interface.
        t1 = xpt.Typelib()
        # add an unresolved interface
        pi = xpt.Interface("IFoo")
        t1.interfaces.append(pi)
        # add a child of the unresolved interface
        t1.interfaces.append(
            xpt.Interface("IChild",
                          iid="11111111-1111-1111-1111-111111111111",
                          resolved=True,
                          parent=pi,
                          scriptable=True))
        t2 = xpt.Typelib()
        # add a resolved interface
        p = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void))
        m = xpt.Method("Bar", p)
        t2.interfaces.append(
            xpt.Interface("IFoo",
                          iid="11223344-5566-7788-9900-aabbccddeeff",
                          methods=[m],
                          scriptable=True))
        t3 = xpt.xpt_link([t1, t2])

        self.assertEqual(2, len(t3.interfaces))
        self.assertEqual("IChild", t3.interfaces[0].name)
        self.assertEqual("11111111-1111-1111-1111-111111111111",
                         t3.interfaces[0].iid)
        self.assertEqual("IFoo", t3.interfaces[1].name)
        self.assertEqual("11223344-5566-7788-9900-aabbccddeeff",
                         t3.interfaces[1].iid)
        self.assert_(t3.interfaces[0].resolved)
        # Ensure that IChild's parent has been updated
        self.assertEqual(t3.interfaces[1], t3.interfaces[0].parent)
        self.assert_(t3.interfaces[0].parent.resolved)

        # t1 has a resolved interface, t2 has an unresolved version,
        # but t2 also has another interface whose parent is the unresolved
        # interface.
        t1 = xpt.Typelib()
        # add a resolved interface
        p = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void))
        m = xpt.Method("Bar", p)
        t1.interfaces.append(
            xpt.Interface("IFoo",
                          iid="11223344-5566-7788-9900-aabbccddeeff",
                          methods=[m],
                          scriptable=True))
        t2 = xpt.Typelib()
        # add an unresolved interface
        pi = xpt.Interface("IFoo")
        t2.interfaces.append(pi)
        # add a child of the unresolved interface
        t2.interfaces.append(
            xpt.Interface("IChild",
                          iid="11111111-1111-1111-1111-111111111111",
                          resolved=True,
                          parent=pi,
                          scriptable=True))
        t3 = xpt.xpt_link([t1, t2])

        self.assertEqual(2, len(t3.interfaces))
        self.assertEqual("IChild", t3.interfaces[0].name)
        self.assertEqual("11111111-1111-1111-1111-111111111111",
                         t3.interfaces[0].iid)
        self.assertEqual("IFoo", t3.interfaces[1].name)
        self.assertEqual("11223344-5566-7788-9900-aabbccddeeff",
                         t3.interfaces[1].iid)
        self.assert_(t3.interfaces[0].resolved)
        # Ensure that IChild's parent has been updated
        self.assertEqual(t3.interfaces[1], t3.interfaces[0].parent)
        self.assert_(t3.interfaces[0].parent.resolved)
Beispiel #10
0
    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)
Beispiel #11
0
    def test_mergeReplaceParams(self):
        """
        Test that merging an interface correctly updates InterfaceType
        params on methods of other interfaces.

        """
        # t1 has an unresolved interface and an interface that uses the
        # unresolved interface as a param value in a method. t2
        # has a resolved version of the unresolved interface.
        t1 = xpt.Typelib()
        # add an unresolved interface
        i = xpt.Interface("IFoo")
        t1.interfaces.append(i)
        # add an interface that uses the unresolved interface
        # as a param value in a method.
        vp = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void))
        p = xpt.Param(xpt.InterfaceType(i))
        m = xpt.Method("IfaceParam", vp, params=[p])
        t1.interfaces.append(
            xpt.Interface("IParam",
                          iid="11111111-1111-1111-1111-111111111111",
                          methods=[m]))
        t2 = xpt.Typelib()
        # add a resolved interface
        m = xpt.Method("Bar", vp)
        t2.interfaces.append(
            xpt.Interface("IFoo",
                          iid="11223344-5566-7788-9900-aabbccddeeff",
                          methods=[m]))
        t1.merge(t2)

        self.assertEqual(2, len(t1.interfaces))
        self.assertEqual("IParam", t1.interfaces[0].name)
        self.assertEqual("11111111-1111-1111-1111-111111111111",
                         t1.interfaces[0].iid)
        self.assertEqual("IFoo", t1.interfaces[1].name)
        self.assertEqual("11223344-5566-7788-9900-aabbccddeeff",
                         t1.interfaces[1].iid)
        self.assert_(t1.interfaces[1].resolved)
        # Ensure that IRetval's method's param type has been updated.
        self.assertEqual(1, len(t1.interfaces[0].methods))
        self.assert_(t1.interfaces[0].methods[0].params[0].type.iface.resolved)
        self.assertEqual(t1.interfaces[1],
                         t1.interfaces[0].methods[0].params[0].type.iface)

        # t1 has a resolved interface. t2 has an unresolved version
        # and an interface that uses the unresolved interface as a
        # param value in a method.
        t1 = xpt.Typelib()
        # add a resolved interface
        m = xpt.Method("Bar", vp)
        t1.interfaces.append(
            xpt.Interface("IFoo",
                          iid="11223344-5566-7788-9900-aabbccddeeff",
                          methods=[m]))
        t2 = xpt.Typelib()
        # add an unresolved interface
        i = xpt.Interface("IFoo")
        t2.interfaces.append(i)
        # add an interface that uses the unresolved interface
        # as a param value in a method.
        vp = xpt.Param(xpt.SimpleType(xpt.Type.Tags.void))
        p = xpt.Param(xpt.InterfaceType(i))
        m = xpt.Method("IfaceParam", vp, params=[p])
        t2.interfaces.append(
            xpt.Interface("IParam",
                          iid="11111111-1111-1111-1111-111111111111",
                          methods=[m]))
        t1.merge(t2)

        self.assertEqual(2, len(t1.interfaces))
        self.assertEqual("IParam", t1.interfaces[0].name)
        self.assertEqual("11111111-1111-1111-1111-111111111111",
                         t1.interfaces[0].iid)
        self.assertEqual("IFoo", t1.interfaces[1].name)
        self.assertEqual("11223344-5566-7788-9900-aabbccddeeff",
                         t1.interfaces[1].iid)
        self.assert_(t1.interfaces[1].resolved)
        # Ensure that IRetval's method's param type has been updated.
        self.assertEqual(1, len(t1.interfaces[0].methods))
        self.assert_(t1.interfaces[0].methods[0].params[0].type.iface.resolved)
        self.assertEqual(t1.interfaces[1],
                         t1.interfaces[0].methods[0].params[0].type.iface)
Beispiel #12
0
 def build_result_param(m):
     return xpt.Param(get_result_type(m))
Beispiel #13
0
 def build_nsresult_param():
     return xpt.Param(get_nsresult())