dringctrl_testdbus.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. #!/usr/bin/env python
  2. import signal
  3. import time
  4. import sys
  5. import getopt
  6. import gtk
  7. from threading import Thread
  8. from threading import Event
  9. print "Import SFLphone"
  10. from sflphonectrlsimple import SflPhoneCtrlSimple
  11. # Define remote IP address constant
  12. REMOTEADDR_lo="127.0.0.1:5062"
  13. REMOTEADDR_lo2="127.0.0.1:5064"
  14. REMOTEADDR_lo3="127.0.0.1:5066"
  15. # Defines phone numbers
  16. PHONE1="27182"
  17. PHONE2="31416"
  18. PHONE3="14142"
  19. # Define function callback to emulate UA behavior on
  20. # recieving a call (peer hangup))
  21. def acceptOnIncomingCall(sflphone):
  22. sflphone.Accept(sflphone.currentCallId)
  23. # Define function callback to emulate UA behavior on
  24. # receiving a call and hanging up
  25. def acceptOnIncomingCallHangup(sflphone):
  26. sflphone.Accept(sflphone.currentCallId)
  27. sflphone.HangUp(sflphone.currentCallId)
  28. # Define function callback to emulate UA behavior on
  29. # refusing a call
  30. def refuseOnIncomingCall(sflphone):
  31. # time.sleep(0.5)
  32. sflphone.Refuse(sflphone.currentCallId)
  33. class SflPhoneTests():
  34. def __init__(self, sfl):
  35. print "Create test instance"
  36. self.sflphone = sfl
  37. def test_get_allaccounts_methods(self):
  38. for account in self.getAllAccounts():
  39. print " " + account
  40. for account in self.getAllRegisteredAccounts():
  41. print " " + account
  42. for account in self.getAllSipAccounts():
  43. print " " + account
  44. def test_create_account(self):
  45. """Create a new sip account"""
  46. CONFIG_ACCOUNT_TYPE = "Account.type"
  47. CONFIG_ACCOUNT_ALIAS = "Account.alias"
  48. HOSTNAME = "hostname"
  49. USERNAME = "username"
  50. PASSWORD = "password"
  51. accDetails = {CONFIG_ACCOUNT_TYPE:"SIP", CONFIG_ACCOUNT_ALIAS:"testsuiteaccount",
  52. HOSTNAME:"192.168.50.79", USERNAME:"31416",
  53. PASSWORD:"1234"}
  54. accountID = self.sflphone.addAccount(accDetails)
  55. print "New Account ID " + accountID
  56. return accountID
  57. def test_remove_account(self, accountID):
  58. """Remove test account"""
  59. self.sflphone.removeAccount(accountID)
  60. print "Account with ID " + accountID + " removed"
  61. # SCENARIO 1 Test 1
  62. def test_ip2ip_send_hangup(self):
  63. """Make a call to a server (sipp) on port 5062"""
  64. i = 0
  65. while(i < 500):
  66. callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
  67. time.sleep(0.5)
  68. self.sflphone.HangUp(callid)
  69. time.sleep(0.5)
  70. i = i+1
  71. self.sflphone.unregister()
  72. del self.sflphone
  73. # SCENARIO 1 Test 2
  74. def test_ip2ip_send_peer_hungup(self):
  75. """Make a call to a server (sipp) on port 5062"""
  76. i = 0
  77. while(i < 10):
  78. callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
  79. time.sleep(1.0)
  80. i = i+1
  81. del self.sflphone
  82. # SCENARIO 1 Test 3
  83. def test_ip2ip_recv_hangup(self):
  84. """Wait for calls, answer then hangup"""
  85. # Add callback for this test
  86. self.sflphone.onIncomingCall_cb = acceptOnIncomingCallHangup
  87. # Start Glib mainloop
  88. self.sflphone.start()
  89. # SCENARIO 1 Test 4
  90. def test_ip2ip_recv_peer_hungup(self):
  91. """Wait for calls, answer, peer hangup"""
  92. # Add callback for this test
  93. self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
  94. # Start Glib mainloop
  95. self.sflphone.start()
  96. # SCENARIO 2 Test 1
  97. def test_account_send_hangup(self):
  98. """Send new account call, hangup once peer answered"""
  99. i = 0
  100. while(i < 10):
  101. callid = self.sflphone.Call(PHONE1)
  102. time.sleep(0.2)
  103. self.sflphone.HangUp(callid)
  104. time.sleep(0.2)
  105. i = i+1
  106. # del self.sflphone
  107. # SCENARIO 2 Test 2
  108. def test_account_send_peer_hungup(self):
  109. """Send new account call, hangup once peer answered"""
  110. i = 0
  111. while(i < 10):
  112. callid = self.sflphone.Call(PHONE1)
  113. time.sleep(1.0)
  114. i = i+1
  115. del self.sflphone
  116. # SCENARIO 2 Test 3
  117. def test_account_recv_hangup(self):
  118. """Register an account and wait for incoming calls"""
  119. # Add callback for this test
  120. self.sflphone.onIncomingCall_cb = acceptOnIncomingCallHangup
  121. # Start Glib mainloop
  122. self.sflphone.start()
  123. # SCENARIO 2 Test 4
  124. def test_account_recv_peer_hungup(self):
  125. """Register an account and wait for incoming calls"""
  126. # Add callback for this test
  127. self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
  128. # Start Glib mainloop
  129. self.sflphone.start()
  130. # SCENARIO 3 Test 1
  131. def test_ip2ip_send_hold_offhold(self):
  132. """Send new call, hold this call, offhold, hangup"""
  133. i = 0
  134. while(i < 10):
  135. callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
  136. time.sleep(0.5)
  137. self.sflphone.Hold(callid)
  138. time.sleep(0.5)
  139. self.sflphone.UnHold(callid)
  140. time.sleep(0.5)
  141. self.sflphone.HangUp(callid)
  142. time.sleep(0.5)
  143. i = i+1
  144. del self.sflphone
  145. # SCENARIO 4 Test 1
  146. def test_account_send_transfer(self):
  147. """Send new calls, transfer it to a new instance"""
  148. i = 0
  149. while(i < 1):
  150. callid = self.sflphone.Call(PHONE1)
  151. time.sleep(1.0)
  152. self.sflphone.Transfer(callid,PHONE3)
  153. # self.sflphone.HangUp(callid)
  154. # time.sleep(1.0)
  155. i = i+1
  156. # SCENARIO 5 Test 1
  157. def test_ip2ip_recv_refuse(self):
  158. """Receive an incoming IP2IP call, refuse it"""
  159. # Add callback for this test
  160. self.sflphone.onIncomingCall_cb = refuseOnIncomingCall
  161. # Start Glib mainloop
  162. self.sflphone.start()
  163. # SCENARIO 6 Test 1
  164. def test_mult_ip2ip_send_hangup(self):
  165. """Make a first call to a sipp server (5062) and a second to sipp server (5064)"""
  166. i = 0
  167. while(i < 500):
  168. callid1 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
  169. time.sleep(0.1)
  170. callid2 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo2)
  171. time.sleep(0.1)
  172. callid3 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo3)
  173. time.sleep(0.1)
  174. self.sflphone.HangUp(callid1)
  175. time.sleep(0.1)
  176. self.sflphone.HangUp(callid2)
  177. time.sleep(0.1)
  178. self.sflphone.HangUp(callid3)
  179. time.sleep(0.1)
  180. i = i+1
  181. del self.sflphone
  182. # SCENARIO 6 Test 2
  183. def test_mult_ip2ip_send_hangup(self):
  184. """Receive multiple calls peer hangup"""
  185. # Add callback for this test
  186. self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
  187. # Start Glib mainloop
  188. self.sflphone.start()
  189. del self.sflphone
  190. # Open sflphone and connect to sflphoned through dbus
  191. sflphone = SflPhoneCtrlSimple(True)
  192. # Init test suite
  193. testsuite = SflPhoneTests(sflphone)
  194. # Register the first account available, should be the test account
  195. sflphone.setFirstRegisteredAccount();
  196. # ============================ Test Suite ============================
  197. # SCENARIO 1: IP2IP Normal flow calls
  198. # Test 1: - Send an IP2IP call
  199. # - Hangup
  200. # testsuite.test_ip2ip_send_hangup()
  201. # Test 2: - Send an IP2IP call
  202. # - Peer Hangup
  203. # testsuite.test_ip2ip_send_peer_hungup()
  204. # Test 3: - Receive an IP2IP call
  205. # - Hangup
  206. testsuite.test_ip2ip_recv_hangup()
  207. # Test 4: - Receive an IP2IP call
  208. # - Peer Hangup
  209. # testsuite.test_ip2ip_recv_peer_hungup()
  210. # SCENARIO 2: ACCOUNT Normal flow calls
  211. # Test 1: - Send an ACCOUNT call
  212. # - Hangup
  213. # testsuite.test_account_send_hangup()
  214. # Test 2: - Send an ACCOUNT call
  215. # - Peer Hangup
  216. # testsuite.test_account_send_peer_hungup()
  217. # Test 3: - Receive an ACCOUNT call
  218. # - Hangup
  219. # testsuite.test_account_recv_hangup()
  220. # Test 4: - Receive an ACCOUNT call
  221. # - Peer Hangup
  222. # testsuite.test_account_recv_peer_hungup()
  223. # SCENARIO 3: IP2IP Call, HOLD/OFFHOLD
  224. # Test 1: - Send an IP2IP call
  225. # - Put this call on HOLD
  226. # - Off HOLD this call
  227. # - Hangup
  228. # testsuite.test_ip2ip_send_hold_offhold()
  229. # SCENARIO 4: IP2IP Call, HOLD/OFFHOLD
  230. # Test 1: - Send an IP2IP call
  231. # - Transfer this call to another sipp instance
  232. # - Hangup
  233. # testsuite.test_account_send_transfer()
  234. # SCENARIO 5: IP2IP Call, Refuse
  235. # Test 1: - Receive an incoming call
  236. # - Hangup without answer
  237. # testsuite.test_ip2ip_recv_refuse()
  238. # SCENARIO 6: Multiple simultaneous calls
  239. # Test 1: - Send multiple simultaneous IP2IP call
  240. # - Hangup
  241. # testsuite.test_mult_ip2ip_send_hangup()
  242. # Test 2: - Receive simultaneous IP2IP call
  243. # - Hangup
  244. # testsuite.test_mult_ip2ip_send_hangup()