summaryrefslogtreecommitdiff
path: root/tests/twisted/test-debug.py
blob: 6c079a32cdce3ab1f19c2085177fbc1fb9647efe (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

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

from servicetest import assertEquals, sync_dbus, call_async, ProxyWrapper
from servicetest import EventPattern
from gabbletest import exec_test
import constants as cs

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, cs.DEBUG_PATH),
            cs.DEBUG_IFACE)
    debug.connect_to_signal('NewDebugMessage', new_message)

    assert len(debug.GetMessages()) > 0

    # Turn signalling on and generate some messages.

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

    channel_path, props = conn.Requests.CreateChannel({
        cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
        cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
        cs.TARGET_HANDLE: conn.Properties.Get(cs.CONN, "SelfHandle")
        })
    q.expect('dbus-signal', signal = 'NewDebugMessage')

    assert len(messages) > 0

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

    debug.Properties.Set(cs.DEBUG_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')

    channel_path, props = conn.Requests.CreateChannel({
        cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
        cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
        cs.TARGET_HANDLE: conn.Properties.Get(cs.CONN, "SelfHandle")
        })
    q.expect('dbus-signal', signal='NewChannels')

    assertEquals (snapshot, messages)

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