Example #1
0
    def test_mergeDifferent(self):
        """
        Test that merging two typelibs with completely different interfaces
        produces the correctly merged typelib.
        
        """
        t1 = xpt.Typelib()
        # add an unresolved interface
        t1.interfaces.append(xpt.Interface("IFoo"))
        t2 = xpt.Typelib()
        # add an unresolved interface
        t2.interfaces.append(xpt.Interface("IBar"))
        t3 = xpt.xpt_link([t1, t2])

        self.assertEqual(2, len(t3.interfaces))
        # Interfaces should wind up sorted
        self.assertEqual("IBar", t3.interfaces[0].name)
        self.assertEqual("IFoo", t3.interfaces[1].name)

        # Add some IID values
        t1 = xpt.Typelib()
        # add an unresolved interface
        t1.interfaces.append(xpt.Interface("IFoo", iid="11223344-5566-7788-9900-aabbccddeeff"))
        t2 = xpt.Typelib()
        # add an unresolved interface
        t2.interfaces.append(xpt.Interface("IBar", iid="44332211-6655-8877-0099-aabbccddeeff"))
        t3 = xpt.xpt_link([t1, t2])

        self.assertEqual(2, len(t3.interfaces))
        # Interfaces should wind up sorted
        self.assertEqual("IFoo", t3.interfaces[0].name)
        self.assertEqual("IBar", t3.interfaces[1].name)
Example #2
0
    def test_mergeUnresolvedIID(self):
        """
        Test that merging a typelib with an unresolved definition of
        an interface that's also unresolved in this typelib, but one
        has a valid IID copies the IID value to the resulting typelib.

        """
        # Unresolved in both, but t1 has an IID value
        t1 = xpt.Typelib()
        # add an unresolved interface with a valid IID
        t1.interfaces.append(xpt.Interface("IFoo", iid="11223344-5566-7788-9900-aabbccddeeff"))
        t2 = xpt.Typelib()
        # add an unresolved interface, no IID
        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)
        # Unresolved in both, but t2 has an IID value
        t1 = xpt.Typelib()
        # add an unresolved interface, no IID
        t1.interfaces.append(xpt.Interface("IFoo"))
        t2 = xpt.Typelib()
        # add an unresolved interface with a valid IID
        t2.interfaces.append(xpt.Interface("IFoo", iid="11223344-5566-7788-9900-aabbccddeeff"))
        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)
Example #3
0
    def copy(self, dest):
        '''
        Link the registered XPTs and place the resulting linked XPT at the
        destination given as a string or a Dest instance. Avoids an expensive
        XPT linking if the interfaces in an existing destination match those of
        the individual XPTs to link.
        '''
        if isinstance(dest, basestring):
            dest = Dest(dest)
        assert isinstance(dest, Dest)

        from xpt import xpt_link, Typelib, Interface
        all_typelibs = [Typelib.read(f.open()) for f in self._files]
        if dest.exists():
            # Typelib.read() needs to seek(), so use a BytesIO for dest
            # content.
            dest_interfaces = \
                dict((i.name, i)
                     for i in Typelib.read(BytesIO(dest.read())).interfaces
                     if i.iid != Interface.UNRESOLVED_IID)
            identical = True
            for f in self._files:
                typelib = Typelib.read(f.open())
                for i in typelib.interfaces:
                    if i.iid != Interface.UNRESOLVED_IID and \
                            not (i.name in dest_interfaces and
                                 i == dest_interfaces[i.name]):
                        identical = False
                        break
            if identical:
                return False
        s = BytesIO()
        xpt_link(all_typelibs).write(s)
        dest.write(s.getvalue())
        return True
Example #4
0
    def generateXpcomXpt(self, config, targetPath, files, cache_dir):
        if not self.targetNeedBuild(targetPath):
            return
        xpts = []
        includePaths = [mozpath.join(config.topobjdir, 'dist/idl'),
            mozpath.join(self.libxul_sdk, 'idl')]

        import xpidl
        import xpt
        import typelib
        deps = set()
        p = xpidl.IDLParser(outputdir=cache_dir)
        for f in files:
            idl_data = open(f).read()
            filename =  mozpath.join('../../../dist/idl', os.path.basename(f))

            idl = p.parse(idl_data, filename = filename)
            idl.resolve(includePaths, p)
            xptIo = io.BytesIO()
            typelib.write_typelib(idl, xptIo, filename = filename)
            xptIo.seek(0)
            xpts.append(xptIo)

            self.updateIdlDeps(config, idl.deps, deps)

        print("Generating %s" % targetPath)
        xpt.xpt_link(xpts).write(targetPath)
        self.addDependencies(targetPath, deps)
        self.addDependencies(targetPath, [targetPath])
Example #5
0
def process(input_dir, inc_paths, cache_dir, header_dir, xpcrs_dir,
            xpt_dir, deps_dir, module, stems):
    p = IDLParser(outputdir=cache_dir)

    xpts = {}
    mk = Makefile()
    rule = mk.create_rule()

    # Write out dependencies for Python modules we import. If this list isn't
    # up to date, we will not re-process XPIDL files if the processor changes.
    rule.add_dependencies(iter_modules_in_path(topsrcdir))

    for stem in stems:
        path = os.path.join(input_dir, '%s.idl' % stem)
        idl_data = open(path).read()

        idl = p.parse(idl_data, filename=path)
        idl.resolve([input_dir] + inc_paths, p)

        header_path = os.path.join(header_dir, '%s.h' % stem)
        rs_rt_path = os.path.join(xpcrs_dir, 'rt', '%s.rs' % stem)
        rs_bt_path = os.path.join(xpcrs_dir, 'bt', '%s.rs' % stem)

        xpt = BytesIO()
        write_typelib(idl, xpt, path)
        xpt.seek(0)
        xpts[stem] = xpt

        rule.add_dependencies(idl.deps)

        with FileAvoidWrite(header_path) as fh:
            print_header(idl, fh, path)

        with FileAvoidWrite(rs_rt_path) as fh:
            print_rust_bindings(idl, fh, path)

        with FileAvoidWrite(rs_bt_path) as fh:
            print_rust_macros_bindings(idl, fh, path)

    # TODO use FileAvoidWrite once it supports binary mode.
    xpt_path = os.path.join(xpt_dir, '%s.xpt' % module)
    xpt_link(xpts.values()).write(xpt_path)

    rule.add_targets([xpt_path])
    if deps_dir:
        deps_path = os.path.join(deps_dir, '%s.pp' % module)
        with FileAvoidWrite(deps_path) as fh:
            mk.dump(fh)
Example #6
0
    def test_xpt_link(self):
        """
        Test the xpt_link method.
        
        """
        t1 = xpt.Typelib()
        # add an unresolved interface
        t1.interfaces.append(xpt.Interface("IFoo"))
        f1 = self.gettempfile()
        t1.write(f1)

        t2 = xpt.Typelib()
        # add an unresolved interface
        t2.interfaces.append(xpt.Interface("IBar"))
        f2 = self.gettempfile()
        t2.write(f2)

        f3 = self.gettempfile()
        xpt.xpt_link(f3, [f1, f2])
        t3 = xpt.Typelib.read(f3)
        
        self.assertEqual(2, len(t3.interfaces))
        # Interfaces should wind up sorted
        self.assertEqual("IBar", t3.interfaces[0].name)
        self.assertEqual("IFoo", t3.interfaces[1].name)

        # Add some IID values
        t1 = xpt.Typelib()
        # add an unresolved interface
        t1.interfaces.append(xpt.Interface("IFoo", iid="11223344-5566-7788-9900-aabbccddeeff"))
        f1 = self.gettempfile()
        t1.write(f1)

        t2 = xpt.Typelib()
        # add an unresolved interface
        t2.interfaces.append(xpt.Interface("IBar", iid="44332211-6655-8877-0099-aabbccddeeff"))
        f2 = self.gettempfile()
        t2.write(f2)

        f3 = self.gettempfile()
        xpt.xpt_link(f3, [f1, f2])
        t3 = xpt.Typelib.read(f3)
        
        self.assertEqual(2, len(t3.interfaces))
        # Interfaces should wind up sorted
        self.assertEqual("IFoo", t3.interfaces[0].name)
        self.assertEqual("IBar", t3.interfaces[1].name)
Example #7
0
def process(input_dir, cache_dir, header_dir, xpt_dir, deps_dir, module, stems):
    p = IDLParser(outputdir=cache_dir)

    xpts = {}
    deps = set()

    # Write out dependencies for Python modules we import. If this list isn't
    # up to date, we will not re-process XPIDL files if the processor changes.
    for imported in ('header', 'typelib', 'xpidl', 'xpt'):
        path = sys.modules[imported].__file__

        if path.endswith('.pyc'):
            path = path[0:-1]

        deps.add(path)

    for stem in stems:
        path = os.path.join(input_dir, '%s.idl' % stem)
        idl_data = open(path).read()

        idl = p.parse(idl_data, filename=path)
        idl.resolve([input_dir], p)

        header_path = os.path.join(header_dir, '%s.h' % stem)
        deps_path = os.path.join(deps_dir, '%s.pp' % stem)

        xpt = BytesIO()
        write_typelib(idl, xpt, path)
        xpt.seek(0)
        xpts[stem] = xpt

        deps |= set(dep.replace('\\', '/') for dep in idl.deps)

        with FileAvoidWrite(header_path) as fh:
            print_header(idl, fh, path)

    # TODO use FileAvoidWrite once it supports binary mode.
    xpt_path = os.path.join(xpt_dir, '%s.xpt' % module)
    xpt_link(xpts.values()).write(xpt_path)

    deps_path = os.path.join(deps_dir, '%s.pp' % module)
    with FileAvoidWrite(deps_path) as fh:
        # Need output to be consistent to avoid rewrites.
        s_deps = sorted(deps)
        fh.write('%s: %s\n' % (xpt_path, ' '.join(s_deps)))
        for dep in s_deps:
            fh.write('%s:\n' % dep)
Example #8
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)
Example #9
0
    def copy(self, dest, skip_if_older=True):
        '''
        Link the registered XPTs and place the resulting linked XPT at the
        destination given as a string or a Dest instance. Avoids an expensive
        XPT linking if the interfaces in an existing destination match those of
        the individual XPTs to link.
        skip_if_older is ignored.
        '''
        if isinstance(dest, basestring):
            dest = Dest(dest)
        assert isinstance(dest, Dest)

        from xpt import xpt_link, Typelib, Interface
        all_typelibs = [Typelib.read(f.open()) for f in self._files]
        if dest.exists():
            # Typelib.read() needs to seek(), so use a BytesIO for dest
            # content.
            dest_interfaces = \
                dict((i.name, i)
                     for i in Typelib.read(BytesIO(dest.read())).interfaces
                     if i.iid != Interface.UNRESOLVED_IID)
            identical = True
            for f in self._files:
                typelib = Typelib.read(f.open())
                for i in typelib.interfaces:
                    if i.iid != Interface.UNRESOLVED_IID and \
                            not (i.name in dest_interfaces and
                                 i == dest_interfaces[i.name]):
                        identical = False
                        break
            if identical:
                return False
        s = BytesIO()
        xpt_link(all_typelibs).write(s)
        dest.write(s.getvalue())
        return True
Example #10
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]))
        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]))
        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)
Example #11
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)
Example #12
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]))
        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]))
        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]))
        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]))
        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)
Example #13
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)
        )
        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]))
        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]))
        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)
        )
        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)
Example #14
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)
Example #15
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)