summaryrefslogtreecommitdiff
path: root/tests/twisted/test-debug.py
blob: d9c18183ed56d3b6eb78be5dc7e593d6e9607bcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

"""
Test the debug message interface.
"""

import dbus

from servicetest import assertEquals, sync_dbus, call_async, ProxyWrapper
from servicetest import EventPattern
from gabbletest import exec_test
import constants as cs
from config import DEBUGGING
path = '/org/freedesktop/Telepathy/debug'
iface = 'org.freedesktop.Telepathy.Debug'

def test(q, bus, conn, stream):
    messages = []

    def new_message(timestamp, domain, level, string):
        messages.append((timestamp, domain, level, string))

    debug = ProxyWrapper(bus.get_object(conn.bus_name, path), iface)
    debug.connect_to_signal('NewDebugMessage', new_message)

    if not DEBUGGING:
        # If we're built with --disable-debug, check that the Debug object
        # isn't present.
        call_async(q, debug, 'GetMessages')
        q.expect('dbus-error', method='GetMessages')
        return

    assert len(debug.GetMessages()) > 0

    # Turn signalling on and generate some messages.

    assert len(messages) == 0
    assert debug.Properties.Get(iface, 'Enabled') == False
    debug.Properties.Set(iface, 'Enabled', True)

    channel_path = conn.RequestChannel(
        cs.CHANNEL_TYPE_TEXT, cs.HT_CONTACT, conn.GetSelfHandle(), True)
    q.expect_many(
        EventPattern ('dbus-signal', signal='NewChannel'),
        EventPattern ('dbus-signal', signal = 'NewDebugMessage'))

    assert len(messages) > 0

    # Turn signalling off and check we don't get any more messages.

    debug.Properties.Set(iface, 'Enabled', False)
    sync_dbus(bus, q, conn)
    snapshot = list(messages)

    channel = bus.get_object(conn.bus_name, channel_path)
    channel.Close(dbus_interface=cs.CHANNEL)
    q.expect('dbus-signal', signal='Closed')

    conn.RequestChannel(
        cs.CHANNEL_TYPE_TEXT, cs.HT_CONTACT, conn.GetSelfHandle(), True)
    q.expect('dbus-signal', signal='NewChannel')

    assertEquals (snapshot, messages)

if __name__ == '__main__':
    exec_test(test)