10
from threading import Thread
11
from threading import Event
13
print "Import SFLphone"
14
from sflphonectrlsimple import SflPhoneCtrlSimple
16
# Define remote IP address constant
17
REMOTEADDR_lo="127.0.0.1:5062"
18
REMOTEADDR_lo2="127.0.0.1:5064"
19
REMOTEADDR_lo3="127.0.0.1:5066"
21
# Defines phone numbers
27
# Define function callback to emulate UA behavior on
28
# recieving a call (peer hangup))
29
def acceptOnIncomingCall(sflphone):
31
sflphone.Accept(sflphone.currentCallId)
34
# Define function callback to emulate UA behavior on
35
# receiving a call and hanging up
36
def acceptOnIncomingCallHangup(sflphone):
38
sflphone.Accept(sflphone.currentCallId)
39
sflphone.HangUp(sflphone.currentCallId)
42
# Define function callback to emulate UA behavior on
44
def refuseOnIncomingCall(sflphone):
46
sflphone.Refuse(sflphone.currentCallId)
49
class SflPhoneTests():
51
def __init__(self, sfl):
52
print "Create test instance"
55
def test_get_allaccounts_methods(self):
57
for account in self.getAllAccounts():
60
for account in self.getAllRegisteredAccounts():
63
for account in self.getAllSipAccounts():
66
for account in self.getAllIaxAccounts():
69
def test_create_account(self):
70
"""Create a new sip account"""
72
CONFIG_ACCOUNT_TYPE = "Account.type"
73
CONFIG_ACCOUNT_ALIAS = "Account.alias"
78
accDetails = {CONFIG_ACCOUNT_TYPE:"SIP", CONFIG_ACCOUNT_ALIAS:"testsuiteaccount",
79
HOSTNAME:"192.168.50.79", USERNAME:"31416",
83
accountID = self.sflphone.addAccount(accDetails)
84
print "New Account ID " + accountID
89
def test_remove_account(self, accountID):
90
"""Remove test account"""
92
self.sflphone.removeAccount(accountID)
93
print "Account with ID " + accountID + " removed"
97
def test_ip2ip_send_hangup(self):
98
"""Make a call to a server (sipp) on port 5062"""
102
callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
105
self.sflphone.HangUp(callid)
110
self.sflphone.unregister()
115
def test_ip2ip_send_peer_hungup(self):
116
"""Make a call to a server (sipp) on port 5062"""
120
callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
129
def test_ip2ip_recv_hangup(self):
130
"""Wait for calls, answer then hangup"""
132
# Add callback for this test
133
self.sflphone.onIncomingCall_cb = acceptOnIncomingCallHangup
135
# Start Glib mainloop
136
self.sflphone.start()
142
def test_ip2ip_recv_peer_hungup(self):
143
"""Wait for calls, answer, peer hangup"""
145
# Add callback for this test
146
self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
148
# Start Glib mainloop
149
self.sflphone.start()
153
def test_account_send_hangup(self):
154
"""Send new account call, hangup once peer answered"""
159
callid = self.sflphone.Call(PHONE1)
162
self.sflphone.HangUp(callid)
171
def test_account_send_peer_hungup(self):
172
"""Send new account call, hangup once peer answered"""
177
callid = self.sflphone.Call(PHONE1)
186
def test_account_recv_hangup(self):
187
"""Register an account and wait for incoming calls"""
189
# Add callback for this test
190
self.sflphone.onIncomingCall_cb = acceptOnIncomingCallHangup
192
# Start Glib mainloop
193
self.sflphone.start()
197
def test_account_recv_peer_hungup(self):
198
"""Register an account and wait for incoming calls"""
200
# Add callback for this test
201
self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
203
# Start Glib mainloop
204
self.sflphone.start()
208
def test_ip2ip_send_hold_offhold(self):
209
"""Send new call, hold this call, offhold, hangup"""
213
callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
216
self.sflphone.Hold(callid)
219
self.sflphone.UnHold(callid)
222
self.sflphone.HangUp(callid)
231
def test_account_send_transfer(self):
232
"""Send new calls, transfer it to a new instance"""
237
callid = self.sflphone.Call(PHONE1)
240
self.sflphone.Transfer(callid,PHONE3)
241
# self.sflphone.HangUp(callid)
248
def test_ip2ip_recv_refuse(self):
249
"""Receive an incoming IP2IP call, refuse it"""
251
# Add callback for this test
252
self.sflphone.onIncomingCall_cb = refuseOnIncomingCall
254
# Start Glib mainloop
255
self.sflphone.start()
259
def test_mult_ip2ip_send_hangup(self):
260
"""Make a first call to a sipp server (5062) and a second to sipp server (5064)"""
264
callid1 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
267
callid2 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo2)
270
callid3 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo3)
273
self.sflphone.HangUp(callid1)
276
self.sflphone.HangUp(callid2)
279
self.sflphone.HangUp(callid3)
288
def test_mult_ip2ip_send_hangup(self):
289
"""Receive multiple calls peer hangup"""
291
# Add callback for this test
292
self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
294
# Start Glib mainloop
295
self.sflphone.start()
301
# Open sflphone and connect to sflphoned through dbus
302
sflphone = SflPhoneCtrlSimple(True)
305
testsuite = SflPhoneTests(sflphone)
307
# Register the first account available, should be the test account
308
sflphone.setFirstRegisteredAccount();
311
# ============================ Test Suite ============================
315
# SCENARIO 1: IP2IP Normal flow calls
317
# Test 1: - Send an IP2IP call
319
# testsuite.test_ip2ip_send_hangup()
321
# Test 2: - Send an IP2IP call
323
# testsuite.test_ip2ip_send_peer_hungup()
325
# Test 3: - Receive an IP2IP call
327
testsuite.test_ip2ip_recv_hangup()
329
# Test 4: - Receive an IP2IP call
331
# testsuite.test_ip2ip_recv_peer_hungup()
335
# SCENARIO 2: ACCOUNT Normal flow calls
337
# Test 1: - Send an ACCOUNT call
339
# testsuite.test_account_send_hangup()
341
# Test 2: - Send an ACCOUNT call
343
# testsuite.test_account_send_peer_hungup()
345
# Test 3: - Receive an ACCOUNT call
347
# testsuite.test_account_recv_hangup()
349
# Test 4: - Receive an ACCOUNT call
351
# testsuite.test_account_recv_peer_hungup()
355
# SCENARIO 3: IP2IP Call, HOLD/OFFHOLD
357
# Test 1: - Send an IP2IP call
358
# - Put this call on HOLD
359
# - Off HOLD this call
361
# testsuite.test_ip2ip_send_hold_offhold()
365
# SCENARIO 4: IP2IP Call, HOLD/OFFHOLD
367
# Test 1: - Send an IP2IP call
368
# - Transfer this call to another sipp instance
370
# testsuite.test_account_send_transfer()
374
# SCENARIO 5: IP2IP Call, Refuse
376
# Test 1: - Receive an incoming call
377
# - Hangup without answer
378
# testsuite.test_ip2ip_recv_refuse()
382
# SCENARIO 6: Multiple simultaneous calls
384
# Test 1: - Send multiple simultaneous IP2IP call
386
# testsuite.test_mult_ip2ip_send_hangup()
388
# Test 2: - Receive simultaneous IP2IP call
390
# testsuite.test_mult_ip2ip_send_hangup()