diff options
author | Mikhail Zabaluev <mikhail.zabaluev@nokia.com> | 2011-09-05 11:01:37 +0300 |
---|---|---|
committer | Mikhail Zabaluev <mikhail.zabaluev@nokia.com> | 2011-09-05 11:01:37 +0300 |
commit | 6acdc05cf49cd03a1ec8058eae5a4f2d043323e9 (patch) | |
tree | c50d90b0d852fd3686fe0944d20bef9dd338fbab /tests | |
parent | cf94024c49bc64ca31961cb5895249ce0dc57048 (diff) | |
parent | cb9453be492f28cf7b12c53f10b639ee9c56ed0f (diff) |
Merge branch 'master' into debug-lite
Diffstat (limited to 'tests')
-rw-r--r-- | tests/twisted/Makefile.am | 1 | ||||
-rw-r--r-- | tests/twisted/constants.py | 3 | ||||
-rw-r--r-- | tests/twisted/voip/dtmf.py | 160 | ||||
-rw-r--r-- | tests/twisted/voip/outgoing-basics.py | 34 | ||||
-rw-r--r-- | tests/twisted/voip/voip_test.py | 30 |
5 files changed, 204 insertions, 24 deletions
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index 816c77d..74645c2 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -12,6 +12,7 @@ TWISTED_TESTS = \ text/initiate-requestotron.py \ voip/incoming-basics.py \ voip/outgoing-basics.py \ + voip/dtmf.py \ $(NULL) TESTS = diff --git a/tests/twisted/constants.py b/tests/twisted/constants.py index 1ffa4d8..c590b3d 100644 --- a/tests/twisted/constants.py +++ b/tests/twisted/constants.py @@ -17,6 +17,7 @@ CHANNEL = "org.freedesktop.Telepathy.Channel" CHANNEL_IFACE_CALL_STATE = CHANNEL + ".Interface.CallState" CHANNEL_IFACE_CHAT_STATE = CHANNEL + '.Interface.ChatState' CHANNEL_IFACE_DESTROYABLE = CHANNEL + ".Interface.Destroyable" +CHANNEL_IFACE_DTMF = CHANNEL + ".Interface.DTMF" CHANNEL_IFACE_GROUP = CHANNEL + ".Interface.Group" CHANNEL_IFACE_HOLD = CHANNEL + ".Interface.Hold" CHANNEL_IFACE_MEDIA_SIGNALLING = CHANNEL + ".Interface.MediaSignalling" @@ -63,6 +64,8 @@ CALL_INITIAL_AUDIO = CHANNEL_TYPE_CALL + '.InitialAudio' CALL_INITIAL_VIDEO = CHANNEL_TYPE_CALL + '.InitialVideo' CALL_MUTABLE_CONTENTS = CHANNEL_TYPE_CALL + '.MutableContents' +DTMF_INITIAL_TONES = CHANNEL_IFACE_DTMF + '.InitialTones' + CALL_CONTENT = 'org.freedesktop.Telepathy.Call.Content.DRAFT' CALL_CONTENT_IFACE_MEDIA = \ 'org.freedesktop.Telepathy.Call.Content.Interface.Media.DRAFT' diff --git a/tests/twisted/voip/dtmf.py b/tests/twisted/voip/dtmf.py new file mode 100644 index 0000000..4369bc3 --- /dev/null +++ b/tests/twisted/voip/dtmf.py @@ -0,0 +1,160 @@ +""" +Test DTMF dialstring playback and signalling. +""" + +from sofiatest import exec_test +from servicetest import ( + call_async, wrap_channel, EventPattern, + assertEquals, assertContains, assertLength, assertSameSets + ) +from voip_test import VoipTestContext +import constants as cs + +def setup_dtmf_channel(context, initial_tones=None): + q = context.q + bus = context.bus + conn = context.conn + + conn.Connect() + q.expect('dbus-signal', signal='StatusChanged', args=[0, 1]) + + request_params = { + cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_STREAMED_MEDIA, + cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, + cs.TARGET_ID: context.peer, + cs.INITIAL_AUDIO: True, + } + if initial_tones: + request_params[cs.DTMF_INITIAL_TONES] = initial_tones + + path = conn.Requests.CreateChannel(request_params)[0] + + chan = wrap_channel(bus.get_object(conn.bus_name, path), 'StreamedMedia', + ['MediaSignalling', 'DTMF']) + + channel_props = chan.Properties.GetAll(cs.CHANNEL) + + assertContains(cs.CHANNEL_IFACE_DTMF, channel_props['Interfaces']) + + dtmf_props = chan.Properties.GetAll(cs.CHANNEL_IFACE_DTMF) + + if initial_tones: + assertEquals(initial_tones, dtmf_props['InitialTones']) + else: + assertEquals('', dtmf_props['InitialTones']) + assertEquals(False, dtmf_props['CurrentlySendingTones']) + + stream_handler = context.handle_audio_session(chan) + + invite_event = q.expect('sip-invite') + + context.accept(invite_event.sip_message) + + q.expect('dbus-signal', signal='SetRemoteCodecs') + + stream_handler.SupportedCodecs(context.get_audio_codecs_dbus()) + stream_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED) + + return chan + +def request_initial_tones(q, bus, conn, sip_proxy, peer='foo@bar.com'): + context = VoipTestContext(q, conn, bus, sip_proxy, 'sip:testacc@127.0.0.1', peer) + + tones = '123' + + chan = setup_dtmf_channel(context, tones) + + q.expect_many( + EventPattern('dbus-signal', signal='SendingTones', args=[tones]), + EventPattern('dbus-signal', signal='StartTelephonyEvent', args=[int(tones[0])])) + + assertEquals(True, chan.Properties.Get(cs.CHANNEL_IFACE_DTMF, 'CurrentlySendingTones')) + + q.expect('dbus-signal', signal='StopTelephonyEvent') + + for i in range(1, len(tones) - 1): + q.expect('dbus-signal', signal='StartTelephonyEvent', args=[int(tones[i])]) + q.expect('dbus-signal', signal='StopTelephonyEvent') + + q.expect('dbus-signal', signal='StoppedTones', args=[False]) + + assertEquals(False, chan.Properties.Get(cs.CHANNEL_IFACE_DTMF, 'CurrentlySendingTones')) + +def multiple_tones(q, bus, conn, sip_proxy, peer='foo@bar.com'): + + context = VoipTestContext(q, conn, bus, sip_proxy, 'sip:testacc@127.0.0.1', peer) + + chan = setup_dtmf_channel(context) + + tones_deferred = '78' + tones = '56w' + tones_deferred + + chan.DTMF.MultipleTones(tones) + + q.expect_many( + EventPattern('dbus-signal', signal='SendingTones', args=[tones]), + EventPattern('dbus-signal', signal='StartTelephonyEvent', args=[int(tones[0])])) + + dtmf_props = chan.Properties.GetAll(cs.CHANNEL_IFACE_DTMF) + assertEquals(True, dtmf_props['CurrentlySendingTones']) + assertEquals('', dtmf_props['DeferredTones']) + + q.expect('dbus-signal', signal='StopTelephonyEvent') + + q.expect('dbus-signal', signal='StartTelephonyEvent', args=[int(tones[1])]) + q.expect('dbus-signal', signal='StopTelephonyEvent') + + q.expect('dbus-signal', signal='TonesDeferred', args=[tones_deferred]) + + dtmf_props = chan.Properties.GetAll(cs.CHANNEL_IFACE_DTMF) + + assertEquals(False, dtmf_props['CurrentlySendingTones']) + assertEquals(tones_deferred, dtmf_props['DeferredTones']) + + chan.DTMF.MultipleTones(tones_deferred) + + q.expect_many( + EventPattern('dbus-signal', signal='SendingTones', args=[tones_deferred]), + EventPattern('dbus-signal', signal='StartTelephonyEvent', args=[int(tones_deferred[0])])) + + dtmf_props = chan.Properties.GetAll(cs.CHANNEL_IFACE_DTMF) + + assertEquals(True, dtmf_props['CurrentlySendingTones']) + assertEquals('', dtmf_props['DeferredTones']) + + q.expect('dbus-signal', signal='StopTelephonyEvent') + + for i in range(1, len(tones_deferred) - 1): + q.expect('dbus-signal', signal='StartTelephonyEvent', args=[int(tones_deferred[i])]) + q.expect('dbus-signal', signal='StopTelephonyEvent') + + q.expect('dbus-signal', signal='StoppedTones', args=[False]) + +def bleep_bloop(q, bus, conn, sip_proxy, peer='foo@bar.com'): + + context = VoipTestContext(q, conn, bus, sip_proxy, 'sip:testacc@127.0.0.1', peer) + + chan = setup_dtmf_channel(context) + + call_async(q, chan.DTMF, 'StartTone', 666, 3) + q.expect_many( + EventPattern('dbus-signal', signal='StartTelephonyEvent'), + EventPattern('dbus-signal', signal='SendingTones', args=['3']), + EventPattern('dbus-return', method='StartTone'), + ) + + assertEquals(True, chan.Properties.Get(cs.CHANNEL_IFACE_DTMF, 'CurrentlySendingTones')) + + call_async(q, chan.DTMF, 'StopTone', 666) + q.expect_many( + EventPattern('dbus-signal', signal='StopTelephonyEvent'), + EventPattern('dbus-signal', signal='StoppedTones', args=[True]), + EventPattern('dbus-return', method='StopTone'), + ) + + assertEquals(False, chan.Properties.Get(cs.CHANNEL_IFACE_DTMF, 'CurrentlySendingTones')) + +if __name__ == '__main__': + exec_test(request_initial_tones) + exec_test(multiple_tones) + exec_test(bleep_bloop) diff --git a/tests/twisted/voip/outgoing-basics.py b/tests/twisted/voip/outgoing-basics.py index f09a59b..d840c18 100644 --- a/tests/twisted/voip/outgoing-basics.py +++ b/tests/twisted/voip/outgoing-basics.py @@ -7,9 +7,8 @@ import dbus from sofiatest import exec_test from servicetest import ( - make_channel_proxy, wrap_channel, - EventPattern, call_async, - assertEquals, assertContains, assertLength, + wrap_channel, EventPattern, call_async, + assertEquals, assertContains, assertLength, assertSameSets ) import constants as cs from voip_test import VoipTestContext @@ -175,23 +174,7 @@ def worker(q, bus, conn, sip_proxy, variant, peer): cs.MEDIA_STREAM_PENDING_REMOTE_SEND), streams[0][1:]) - # S-E does state recovery to get the session handler, and calls Ready on it - session_handlers = chan.MediaSignalling.GetSessionHandlers() - sh_path, sh_type = session_handlers[0] - - assert sh_type == 'rtp' - - session_handler = make_channel_proxy(conn, sh_path, 'Media.SessionHandler') - session_handler.Ready() - - e = q.expect('dbus-signal', signal='NewStreamHandler') - - stream_handler = make_channel_proxy(conn, e.args[0], 'Media.StreamHandler') - - stream_handler.NewNativeCandidate("fake", context.get_remote_transports_dbus()) - stream_handler.NativeCandidatesPrepared() - stream_handler.Ready(context.get_audio_codecs_dbus()) - stream_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED) + stream_handler = context.handle_audio_session(chan) sh_props = stream_handler.GetAll( cs.STREAM_HANDLER, dbus_interface=dbus.PROPERTIES_IFACE) @@ -228,7 +211,11 @@ def worker(q, bus, conn, sip_proxy, variant, peer): EventPattern('dbus-signal', signal='MembersChanged', args=['', [remote_handle], [], [], [], remote_handle, cs.GC_REASON_NONE]), - ) + EventPattern('dbus-signal', signal='SetRemoteCodecs'), + ), + + stream_handler.SupportedCodecs(context.get_audio_codecs_dbus()) + stream_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED) # Time passes ... afterwards we close the chan @@ -272,12 +259,13 @@ def rccs(q, bus, conn, stream): expected_allowed = [ cs.TARGET_ID, cs.TARGET_HANDLE, - cs.INITIAL_VIDEO, cs.INITIAL_AUDIO + cs.INITIAL_VIDEO, cs.INITIAL_AUDIO, + cs.DTMF_INITIAL_TONES ] allowed.sort() expected_allowed.sort() - assertEquals(expected_allowed, allowed) + assertSameSets(expected_allowed, allowed) if __name__ == '__main__': diff --git a/tests/twisted/voip/voip_test.py b/tests/twisted/voip/voip_test.py index b31928f..c8724af 100644 --- a/tests/twisted/voip/voip_test.py +++ b/tests/twisted/voip/voip_test.py @@ -4,7 +4,10 @@ import uuid import twisted.protocols.sip -from servicetest import assertContains +from servicetest import ( + make_channel_proxy, + assertContains, + ) class VoipTestContext(object): # Default audio codecs for the remote end @@ -178,3 +181,28 @@ class VoipTestContext(object): def terminate(self): return self.send_message('BYE', call_id=self.call_id) + + def handle_audio_session(self, chan): + """ + Serves a SessionHandler and a StreamHandler for the MediaSignalling + channel. Returns the interface proxy for StreamHandler. + """ + session_handlers = chan.MediaSignalling.GetSessionHandlers() + sh_path, sh_type = session_handlers[0] + + assert sh_type == 'rtp' + + session_handler = make_channel_proxy(self.conn, sh_path, + 'Media.SessionHandler') + session_handler.Ready() + + e = self.q.expect('dbus-signal', signal='NewStreamHandler') + + stream_handler = make_channel_proxy(self.conn, e.args[0], + 'Media.StreamHandler') + + stream_handler.NewNativeCandidate("fake", self.get_remote_transports_dbus()) + stream_handler.NativeCandidatesPrepared() + stream_handler.Ready(self.get_audio_codecs_dbus()) + + return stream_handler |