summaryrefslogtreecommitdiff
path: root/tests/twisted/jingle/call-dtmf.py
blob: 5b19fc7fb98e67d84f5e0bb78b0129e7a55568dc (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"""
Test DMTF events in a Call channel
"""

import dbus
from dbus.exceptions import DBusException
from functools import partial
from servicetest import call_async, EventPattern, assertEquals
from jingletest2 import test_all_dialects
from call_helper import CallTest, run_call_test
import constants as cs

from config import VOIP_ENABLED

if not VOIP_ENABLED:
    print "NOTE: built with --disable-voip"
    raise SystemExit(77)

class CallDtmfTest(CallTest):

    def test_dtmf(self):
        content = self.audio_content
        q = self.q

        # The Stream_ID is specified to be ignored; we use 666 here.
        assertEquals(False, content.Get(cs.CALL_CONTENT_IFACE_DTMF,
                    'CurrentlySendingTones',
                    dbus_interface=dbus.PROPERTIES_IFACE));
    
        call_async(q, content.DTMF, 'StartTone', 3)
        q.expect_many(
                EventPattern('dbus-signal', signal='DTMFChangeRequested',
                    args = [3, cs.CALL_SENDING_STATE_PENDING_SEND]),
                EventPattern('dbus-return', method='StartTone'),
                )
    
        assertEquals(True, content.Get(cs.CALL_CONTENT_IFACE_DTMF,
                    'CurrentlySendingTones',
                    dbus_interface=dbus.PROPERTIES_IFACE));
    
        content.Media.AcknowledgeDTMFChange(3, cs.CALL_SENDING_STATE_SENDING)

        q.expect('dbus-signal', signal='SendingTones', args=['3'])
    
        call_async(q, content.DTMF, 'StopTone')
        q.expect_many(
                EventPattern('dbus-signal', signal='DTMFChangeRequested',
                    args = [3, cs.CALL_SENDING_STATE_PENDING_STOP_SENDING]),
                EventPattern('dbus-return', method='StopTone'),
                )
    
        call_async(q, content.Media, 'AcknowledgeDTMFChange', 3,
                cs.CALL_SENDING_STATE_NONE)
        q.expect_many(
            EventPattern('dbus-signal', signal='StoppedTones', args=[False]),
            EventPattern('dbus-return', method='AcknowledgeDTMFChange'),
            )
    
        assertEquals(False, content.Get(cs.CALL_CONTENT_IFACE_DTMF,
                    'CurrentlySendingTones',
                    dbus_interface=dbus.PROPERTIES_IFACE));
    
        call_async(q, content.DTMF, 'MultipleTones', '123')
        q.expect_many(
            EventPattern('dbus-return', method='MultipleTones'),
            EventPattern('dbus-signal', signal='DTMFChangeRequested',
                args = [1, cs.CALL_SENDING_STATE_PENDING_SEND]),
            )
        content.Media.AcknowledgeDTMFChange(1, cs.CALL_SENDING_STATE_SENDING)

        q.expect('dbus-signal', signal='SendingTones', args=['123'])
    
        q.expect('dbus-signal', signal='DTMFChangeRequested',
                args = [1, cs.CALL_SENDING_STATE_PENDING_STOP_SENDING])
        content.Media.AcknowledgeDTMFChange(1, cs.CALL_SENDING_STATE_NONE)
    
        q.expect_many(
            EventPattern('dbus-signal', signal='DTMFChangeRequested',
                args = [2, cs.CALL_SENDING_STATE_PENDING_SEND]),
            )
        content.Media.AcknowledgeDTMFChange(2, cs.CALL_SENDING_STATE_SENDING)
        q.expect('dbus-signal', signal='SendingTones', args=['23']),

        q.expect('dbus-signal', signal='DTMFChangeRequested',
                args = [2, cs.CALL_SENDING_STATE_PENDING_STOP_SENDING])
        content.Media.AcknowledgeDTMFChange(2, cs.CALL_SENDING_STATE_NONE)
    
        q.expect_many(
            EventPattern('dbus-signal', signal='DTMFChangeRequested',
                args = [3, cs.CALL_SENDING_STATE_PENDING_SEND]),
            )
        content.Media.AcknowledgeDTMFChange(3, cs.CALL_SENDING_STATE_SENDING)
        q.expect('dbus-signal', signal='SendingTones', args=['3']),
        q.expect('dbus-signal', signal='DTMFChangeRequested',
                args = [3, cs.CALL_SENDING_STATE_PENDING_STOP_SENDING])
        content.Media.AcknowledgeDTMFChange(3, cs.CALL_SENDING_STATE_NONE)
    
        q.expect_many(
            EventPattern('dbus-signal', signal='StoppedTones', args=[False])
            )
    
        call_async(q, content.DTMF, 'MultipleTones',
                '1,1' * 100)
        q.expect_many(
            EventPattern('dbus-signal', signal='DTMFChangeRequested',
                args = [1, cs.CALL_SENDING_STATE_PENDING_SEND]),
            EventPattern('dbus-return', method='MultipleTones'),
            )
        call_async(q, content.DTMF, 'MultipleTones', '9')
        q.expect('dbus-error', method='MultipleTones',
                name=cs.SERVICE_BUSY)
        call_async(q, content.DTMF, 'StartTone', 9)
        q.expect('dbus-error', method='StartTone', name=cs.SERVICE_BUSY)
    
        call_async(q, content.DTMF, 'StopTone')
        q.expect_many(
            EventPattern('dbus-signal', signal='DTMFChangeRequested',
                args = [1, cs.CALL_SENDING_STATE_PENDING_STOP_SENDING]),
            EventPattern('dbus-return', method='StopTone'),
            )
        call_async(q, content.Media, 'AcknowledgeDTMFChange',
                1, cs.CALL_SENDING_STATE_NONE)
        q.expect_many(
            EventPattern('dbus-signal', signal='StoppedTones', args=[True]),
            EventPattern('dbus-return', method='AcknowledgeDTMFChange'),
            )
    
        call_async(q, content.DTMF, 'MultipleTones', '1w2')
        q.expect_many(
            EventPattern('dbus-signal', signal='DTMFChangeRequested',
                args = [1, cs.CALL_SENDING_STATE_PENDING_SEND]),
            EventPattern('dbus-return', method='MultipleTones'),
            )
    
        content.Media.AcknowledgeDTMFChange(1, cs.CALL_SENDING_STATE_SENDING)

        q.expect('dbus-signal', signal='SendingTones', args=['1w2']),
    
        q.expect('dbus-signal', signal='DTMFChangeRequested',
                args = [1, cs.CALL_SENDING_STATE_PENDING_STOP_SENDING])
    
        call_async(q, content.Media, 'AcknowledgeDTMFChange', 1,
                cs.CALL_SENDING_STATE_NONE)
        q.expect_many(
            EventPattern('dbus-signal', signal='TonesDeferred', args=['2']),
            EventPattern('dbus-signal', signal='StoppedTones', args=[False]),
            EventPattern('dbus-return', method='AcknowledgeDTMFChange'),
            )
        assertEquals('2', content.Get(cs.CALL_CONTENT_IFACE_DTMF,
                    'DeferredTones', dbus_interface=dbus.PROPERTIES_IFACE));
    
        call_async(q, content.DTMF, 'StartTone', 7)
        q.expect_many(
            EventPattern('dbus-signal', signal='DTMFChangeRequested',
                args = [7, cs.CALL_SENDING_STATE_PENDING_SEND]),
            EventPattern('dbus-return', method='StartTone'),
            )
    
        # Checked that DeferredTones is properly reset
        assertEquals('', content.Get(cs.CALL_CONTENT_IFACE_DTMF,
                    'DeferredTones', dbus_interface=dbus.PROPERTIES_IFACE));

        content.Media.AcknowledgeDTMFChange(7, cs.CALL_SENDING_STATE_SENDING)

        q.expect('dbus-signal', signal='SendingTones', args=['7']),

        call_async(q, content.DTMF, 'StopTone')
        q.expect_many(
                EventPattern('dbus-signal', signal='DTMFChangeRequested',
                    args = [7, cs.CALL_SENDING_STATE_PENDING_STOP_SENDING]),
                EventPattern('dbus-return', method='StopTone'),
                )
        
        content.Media.AcknowledgeDTMFChange(7, cs.CALL_SENDING_STATE_NONE)
        q.expect('dbus-signal', signal='StoppedTones', args=[False])


    def pickup(self):
        CallTest.pickup(self)
        self.test_dtmf()

if __name__ == '__main__':
    test_all_dialects(
            partial(run_call_test, klass=CallDtmfTest, incoming=False))