Exemple #1
0
 def method_test(self):
     """Test XML with methods."""
     xml = '''
     <node>
         <interface name="Interface">
             <method name="Method1"/>
             <method name="Method2">
                 <arg direction="in" name="x" type="i"/>
             </method>
             <method name="Method3">
                 <arg direction="out" name="return" type="i"/>
             </method>
             <method name="Method4">
                 <arg direction="in" name="x" type="ad"/>
                 <arg direction="in" name="y" type="h"/>
                 <arg direction="out" name="return" type="(ib)"/>
             </method>
         </interface>
     </node>
     '''
     self._compare(xml, [
         DBusSpecification.Method(
             name='Method1',
             interface_name='Interface',
             in_type=None,
             out_type=None
         ),
         DBusSpecification.Method(
             name='Method2',
             interface_name='Interface',
             in_type='(i)',
             out_type=None
         ),
         DBusSpecification.Method(
             name='Method3',
             interface_name='Interface',
             in_type=None,
             out_type='(i)'
         ),
         DBusSpecification.Method(
             name='Method4',
             interface_name='Interface',
             in_type='(adh)',
             out_type='((ib))'
         )
     ])
Exemple #2
0
    def introspect_test(self):
        """Test the introspection."""
        self._set_reply(
            get_variant("(s)", (dedent("""
        <node>
            <interface name="Interface">
                <method name="Method1"/>
            </interface>
        </node>
        """), )))

        self.handler = ClientObjectHandler(self.message_bus, self.service_name,
                                           self.object_path)
        self.assertIsNotNone(self.handler.specification)
        self._check_call("org.freedesktop.DBus.Introspectable",
                         "Introspect",
                         reply_type=get_variant_type("(s)"))

        self.assertIn(
            DBusSpecification.Method("Method1", "Interface", None, None),
            self.handler.specification.members)
Exemple #3
0
    def ignore_test(self):
        """Ignore invalid XML elements.."""
        xml = '''
        <node>
           <interface name="InterfaceA">
                <method name="MethodA">
                    <arg direction="out" name="return" type="i"/>
                    <ignored />
                </method>
                <property access="read" name="PropertyA" type="d"/>
                <signal name="SignalA">
                   <ignored />
                </signal>
                <ignored />
            </interface>
            <ignored />
        </node>
        '''
        self._compare(xml, [
            DBusSpecification.Method(
                name='MethodA',
                interface_name='InterfaceA',
                in_type=None,
                out_type='(i)'
            ),
            DBusSpecification.Property(
                name='PropertyA',
                interface_name='InterfaceA',
                readable=True,
                writable=False,
                type='d'
            ),
            DBusSpecification.Signal(
                name='SignalA',
                interface_name='InterfaceA',
                type=None
            )
        ])

        self._compare("<ignored />", [])
Exemple #4
0
    def from_members_test(self):
        """Test a specification created from members."""
        method = DBusSpecification.Method(
            name="Method",
            interface_name="A",
            in_type="()",
            out_type="(s)"
        )

        signal = DBusSpecification.Signal(
            name="Signal",
            interface_name="B",
            type="(ii)"
        )

        prop = DBusSpecification.Property(
            name="Property",
            interface_name="B",
            readable=True,
            writable=False,
            type="i"
        )

        specification = DBusSpecification()
        specification.add_member(method)
        specification.add_member(signal)
        specification.add_member(prop)

        with self.assertRaises(DBusSpecificationError):
            specification.get_member("A", "Invalid")

        with self.assertRaises(DBusSpecificationError):
            specification.get_member("Invalid", "Method")

        self.assertEqual(specification.interfaces, ["A", "B"])
        self.assertEqual(specification.members, [method, signal, prop])
        self.assertEqual(specification.get_member("A", "Method"), method)
        self.assertEqual(specification.get_member("B", "Signal"), signal)
        self.assertEqual(specification.get_member("B", "Property"), prop)
Exemple #5
0
 def standard_interfaces_test(self):
     """Test with the standard interfaces."""
     specification = DBusSpecificationParser.parse_specification('<node />')
     self.assertEqual(specification.members, [
         DBusSpecification.Method(
             name='Introspect',
             interface_name='org.freedesktop.DBus.Introspectable',
             in_type=None,
             out_type='(s)'
         ),
         DBusSpecification.Method(
             name='Ping',
             interface_name='org.freedesktop.DBus.Peer',
             in_type=None,
             out_type=None
         ),
         DBusSpecification.Method(
             name='GetMachineId',
             interface_name='org.freedesktop.DBus.Peer',
             in_type=None,
             out_type='(s)'
         ),
         DBusSpecification.Method(
             name='Get',
             interface_name='org.freedesktop.DBus.Properties',
             in_type='(ss)',
             out_type='(v)'
         ),
         DBusSpecification.Method(
             name='GetAll',
             interface_name='org.freedesktop.DBus.Properties',
             in_type='(s)',
             out_type='(a{sv})'
         ),
         DBusSpecification.Method(
             name='Set',
             interface_name='org.freedesktop.DBus.Properties',
             in_type='(ssv)',
             out_type=None
         ),
         DBusSpecification.Signal(
             name='PropertiesChanged',
             interface_name='org.freedesktop.DBus.Properties',
             type='(sa{sv}as)'
         )
     ])
Exemple #6
0
    def from_xml_test(self):
        """Test a specification created from XML."""
        xml = '''
        <node>
           <interface name="ComplexA">
                <method name="MethodA">
                    <arg direction="out" name="return" type="i"/>
                </method>
                <property access="read" name="PropertyA" type="d"/>
                <signal name="SignalA">
                   <arg direction="out" name="x" type="i"/>
                </signal>
            </interface>
            <interface name="ComplexB">
                <method name="MethodB">
                    <arg direction="in" name="a" type="s"/>
                    <arg direction="in" name="b" type="ad"/>
                    <arg direction="in" name="c" type="i"/>
                    <arg direction="out" name="return" type="i"/>
                </method>
                <property access="read" name="PropertyB" type="d"/>
                <signal name="SignalB">
                    <arg direction="out" name="x" type="b"/>
                    <arg direction="out" name="y" type="d"/>
                    <arg direction="out" name="z" type="(ii)"/>
                </signal>
            </interface>
        </node>
        '''
        specification = DBusSpecification.from_xml(xml)
        self.assertEqual(specification.interfaces, [
            'org.freedesktop.DBus.Introspectable',
            'org.freedesktop.DBus.Peer',
            'org.freedesktop.DBus.Properties',
            'ComplexA',
            'ComplexB',
        ])

        self.assertEqual(specification.members, [
            DBusSpecification.Method(
                name='Introspect',
                interface_name='org.freedesktop.DBus.Introspectable',
                in_type=None,
                out_type='(s)'
            ),
            DBusSpecification.Method(
                name='Ping',
                interface_name='org.freedesktop.DBus.Peer',
                in_type=None,
                out_type=None
            ),
            DBusSpecification.Method(
                name='GetMachineId',
                interface_name='org.freedesktop.DBus.Peer',
                in_type=None,
                out_type='(s)'
            ),
            DBusSpecification.Method(
                name='Get',
                interface_name='org.freedesktop.DBus.Properties',
                in_type='(ss)',
                out_type='(v)'
            ),
            DBusSpecification.Method(
                name='GetAll',
                interface_name='org.freedesktop.DBus.Properties',
                in_type='(s)',
                out_type='(a{sv})'
            ),
            DBusSpecification.Method(
                name='Set',
                interface_name='org.freedesktop.DBus.Properties',
                in_type='(ssv)',
                out_type=None
            ),
            DBusSpecification.Signal(
                name='PropertiesChanged',
                interface_name='org.freedesktop.DBus.Properties',
                type='(sa{sv}as)'
            ),
            DBusSpecification.Method(
                name='MethodA',
                interface_name='ComplexA',
                in_type=None,
                out_type='(i)'
            ),
            DBusSpecification.Property(
                name='PropertyA',
                interface_name='ComplexA',
                readable=True,
                writable=False,
                type='d'
            ),
            DBusSpecification.Signal(
                name='SignalA',
                interface_name='ComplexA',
                type='(i)'
            ),
            DBusSpecification.Method(
                name='MethodB',
                interface_name='ComplexB',
                in_type='(sadi)',
                out_type='(i)'
            ),
            DBusSpecification.Property(
                name='PropertyB',
                interface_name='ComplexB',
                readable=True,
                writable=False,
                type='d'
            ),
            DBusSpecification.Signal(
                name='SignalB',
                interface_name='ComplexB',
                type='(bd(ii))'
            )
        ])