123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- #!/usr/bin/env python
- import signal
- import time
- import sys
- import getopt
- import gtk
- from threading import Thread
- from threading import Event
- print "Import SFLphone"
- from sflphonectrlsimple import SflPhoneCtrlSimple
- # Define remote IP address constant
- REMOTEADDR_lo="127.0.0.1:5062"
- REMOTEADDR_lo2="127.0.0.1:5064"
- REMOTEADDR_lo3="127.0.0.1:5066"
- # Defines phone numbers
- PHONE1="27182"
- PHONE2="31416"
- PHONE3="14142"
- # Define function callback to emulate UA behavior on
- # recieving a call (peer hangup))
- def acceptOnIncomingCall(sflphone):
- sflphone.Accept(sflphone.currentCallId)
- # Define function callback to emulate UA behavior on
- # receiving a call and hanging up
- def acceptOnIncomingCallHangup(sflphone):
- sflphone.Accept(sflphone.currentCallId)
- sflphone.HangUp(sflphone.currentCallId)
- # Define function callback to emulate UA behavior on
- # refusing a call
- def refuseOnIncomingCall(sflphone):
- # time.sleep(0.5)
- sflphone.Refuse(sflphone.currentCallId)
- class SflPhoneTests():
- def __init__(self, sfl):
- print "Create test instance"
- self.sflphone = sfl
- def test_get_allaccounts_methods(self):
- for account in self.getAllAccounts():
- print " " + account
- for account in self.getAllRegisteredAccounts():
- print " " + account
- for account in self.getAllSipAccounts():
- print " " + account
- def test_create_account(self):
- """Create a new sip account"""
- CONFIG_ACCOUNT_TYPE = "Account.type"
- CONFIG_ACCOUNT_ALIAS = "Account.alias"
- HOSTNAME = "hostname"
- USERNAME = "username"
- PASSWORD = "password"
- accDetails = {CONFIG_ACCOUNT_TYPE:"SIP", CONFIG_ACCOUNT_ALIAS:"testsuiteaccount",
- HOSTNAME:"192.168.50.79", USERNAME:"31416",
- PASSWORD:"1234"}
- accountID = self.sflphone.addAccount(accDetails)
- print "New Account ID " + accountID
- return accountID
- def test_remove_account(self, accountID):
- """Remove test account"""
- self.sflphone.removeAccount(accountID)
- print "Account with ID " + accountID + " removed"
- # SCENARIO 1 Test 1
- def test_ip2ip_send_hangup(self):
- """Make a call to a server (sipp) on port 5062"""
- i = 0
- while(i < 500):
- callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
- time.sleep(0.5)
- self.sflphone.HangUp(callid)
- time.sleep(0.5)
- i = i+1
- self.sflphone.unregister()
- del self.sflphone
- # SCENARIO 1 Test 2
- def test_ip2ip_send_peer_hungup(self):
- """Make a call to a server (sipp) on port 5062"""
- i = 0
- while(i < 10):
- callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
- time.sleep(1.0)
- i = i+1
- del self.sflphone
- # SCENARIO 1 Test 3
- def test_ip2ip_recv_hangup(self):
- """Wait for calls, answer then hangup"""
- # Add callback for this test
- self.sflphone.onIncomingCall_cb = acceptOnIncomingCallHangup
- # Start Glib mainloop
- self.sflphone.start()
- # SCENARIO 1 Test 4
- def test_ip2ip_recv_peer_hungup(self):
- """Wait for calls, answer, peer hangup"""
- # Add callback for this test
- self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
- # Start Glib mainloop
- self.sflphone.start()
- # SCENARIO 2 Test 1
- def test_account_send_hangup(self):
- """Send new account call, hangup once peer answered"""
- i = 0
- while(i < 10):
- callid = self.sflphone.Call(PHONE1)
- time.sleep(0.2)
- self.sflphone.HangUp(callid)
- time.sleep(0.2)
- i = i+1
- # del self.sflphone
- # SCENARIO 2 Test 2
- def test_account_send_peer_hungup(self):
- """Send new account call, hangup once peer answered"""
- i = 0
- while(i < 10):
- callid = self.sflphone.Call(PHONE1)
- time.sleep(1.0)
- i = i+1
- del self.sflphone
- # SCENARIO 2 Test 3
- def test_account_recv_hangup(self):
- """Register an account and wait for incoming calls"""
- # Add callback for this test
- self.sflphone.onIncomingCall_cb = acceptOnIncomingCallHangup
- # Start Glib mainloop
- self.sflphone.start()
- # SCENARIO 2 Test 4
- def test_account_recv_peer_hungup(self):
- """Register an account and wait for incoming calls"""
- # Add callback for this test
- self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
- # Start Glib mainloop
- self.sflphone.start()
- # SCENARIO 3 Test 1
- def test_ip2ip_send_hold_offhold(self):
- """Send new call, hold this call, offhold, hangup"""
- i = 0
- while(i < 10):
- callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
- time.sleep(0.5)
- self.sflphone.Hold(callid)
- time.sleep(0.5)
- self.sflphone.UnHold(callid)
- time.sleep(0.5)
- self.sflphone.HangUp(callid)
- time.sleep(0.5)
- i = i+1
- del self.sflphone
- # SCENARIO 4 Test 1
- def test_account_send_transfer(self):
- """Send new calls, transfer it to a new instance"""
- i = 0
- while(i < 1):
- callid = self.sflphone.Call(PHONE1)
- time.sleep(1.0)
- self.sflphone.Transfer(callid,PHONE3)
- # self.sflphone.HangUp(callid)
- # time.sleep(1.0)
- i = i+1
- # SCENARIO 5 Test 1
- def test_ip2ip_recv_refuse(self):
- """Receive an incoming IP2IP call, refuse it"""
- # Add callback for this test
- self.sflphone.onIncomingCall_cb = refuseOnIncomingCall
- # Start Glib mainloop
- self.sflphone.start()
- # SCENARIO 6 Test 1
- def test_mult_ip2ip_send_hangup(self):
- """Make a first call to a sipp server (5062) and a second to sipp server (5064)"""
- i = 0
- while(i < 500):
- callid1 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
- time.sleep(0.1)
- callid2 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo2)
- time.sleep(0.1)
- callid3 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo3)
- time.sleep(0.1)
- self.sflphone.HangUp(callid1)
- time.sleep(0.1)
- self.sflphone.HangUp(callid2)
- time.sleep(0.1)
- self.sflphone.HangUp(callid3)
- time.sleep(0.1)
- i = i+1
- del self.sflphone
- # SCENARIO 6 Test 2
- def test_mult_ip2ip_send_hangup(self):
- """Receive multiple calls peer hangup"""
- # Add callback for this test
- self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
- # Start Glib mainloop
- self.sflphone.start()
- del self.sflphone
- # Open sflphone and connect to sflphoned through dbus
- sflphone = SflPhoneCtrlSimple(True)
- # Init test suite
- testsuite = SflPhoneTests(sflphone)
- # Register the first account available, should be the test account
- sflphone.setFirstRegisteredAccount();
- # ============================ Test Suite ============================
- # SCENARIO 1: IP2IP Normal flow calls
- # Test 1: - Send an IP2IP call
- # - Hangup
- # testsuite.test_ip2ip_send_hangup()
- # Test 2: - Send an IP2IP call
- # - Peer Hangup
- # testsuite.test_ip2ip_send_peer_hungup()
- # Test 3: - Receive an IP2IP call
- # - Hangup
- testsuite.test_ip2ip_recv_hangup()
- # Test 4: - Receive an IP2IP call
- # - Peer Hangup
- # testsuite.test_ip2ip_recv_peer_hungup()
- # SCENARIO 2: ACCOUNT Normal flow calls
- # Test 1: - Send an ACCOUNT call
- # - Hangup
- # testsuite.test_account_send_hangup()
- # Test 2: - Send an ACCOUNT call
- # - Peer Hangup
- # testsuite.test_account_send_peer_hungup()
- # Test 3: - Receive an ACCOUNT call
- # - Hangup
- # testsuite.test_account_recv_hangup()
- # Test 4: - Receive an ACCOUNT call
- # - Peer Hangup
- # testsuite.test_account_recv_peer_hungup()
- # SCENARIO 3: IP2IP Call, HOLD/OFFHOLD
- # Test 1: - Send an IP2IP call
- # - Put this call on HOLD
- # - Off HOLD this call
- # - Hangup
- # testsuite.test_ip2ip_send_hold_offhold()
- # SCENARIO 4: IP2IP Call, HOLD/OFFHOLD
- # Test 1: - Send an IP2IP call
- # - Transfer this call to another sipp instance
- # - Hangup
- # testsuite.test_account_send_transfer()
- # SCENARIO 5: IP2IP Call, Refuse
- # Test 1: - Receive an incoming call
- # - Hangup without answer
- # testsuite.test_ip2ip_recv_refuse()
- # SCENARIO 6: Multiple simultaneous calls
- # Test 1: - Send multiple simultaneous IP2IP call
- # - Hangup
- # testsuite.test_mult_ip2ip_send_hangup()
- # Test 2: - Receive simultaneous IP2IP call
- # - Hangup
- # testsuite.test_mult_ip2ip_send_hangup()
|