~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to tools/pysflphone/pysflphone_testdbus.py

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2012-02-18 21:47:09 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120218214709-6362d71gqdsdkrj5
Tags: 1.0.2-1
* New upstream release
  - remove logging patch (applied upstream)
  - update s390 patch since it was partially applied upstream
* Include the Evolution plugin as a separate binary package

* Fix compilation issues on SH4 (closes: #658987)
* Merge Ubuntu's binutils-gold linking fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
import signal
 
3
 
 
4
import time
 
5
import sys
 
6
 
 
7
import getopt
 
8
import gtk
 
9
 
 
10
from threading import Thread
 
11
from threading import Event
 
12
 
 
13
print "Import SFLphone"
 
14
from sflphonectrlsimple import SflPhoneCtrlSimple
 
15
 
 
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"
 
20
 
 
21
# Defines phone numbers
 
22
PHONE1="27182"
 
23
PHONE2="31416"
 
24
PHONE3="14142"
 
25
 
 
26
 
 
27
# Define function callback to emulate UA behavior on
 
28
# recieving a call (peer hangup))
 
29
def acceptOnIncomingCall(sflphone):
 
30
 
 
31
    sflphone.Accept(sflphone.currentCallId)
 
32
 
 
33
 
 
34
# Define function callback to emulate UA behavior on
 
35
# receiving a call and hanging up
 
36
def acceptOnIncomingCallHangup(sflphone):
 
37
 
 
38
    sflphone.Accept(sflphone.currentCallId)
 
39
    sflphone.HangUp(sflphone.currentCallId)
 
40
 
 
41
 
 
42
# Define function callback to emulate UA behavior on
 
43
# refusing a call
 
44
def refuseOnIncomingCall(sflphone):
 
45
    # time.sleep(0.5)
 
46
    sflphone.Refuse(sflphone.currentCallId)
 
47
 
 
48
 
 
49
class SflPhoneTests():
 
50
 
 
51
    def __init__(self, sfl):
 
52
        print "Create test instance"
 
53
        self.sflphone = sfl
 
54
 
 
55
    def test_get_allaccounts_methods(self):
 
56
 
 
57
        for account in self.getAllAccounts():
 
58
            print "  " + account
 
59
 
 
60
        for account in self.getAllRegisteredAccounts():
 
61
            print "  " + account
 
62
 
 
63
        for account in self.getAllSipAccounts():
 
64
            print "  " + account
 
65
 
 
66
        for account in self.getAllIaxAccounts():
 
67
            print "  " + account
 
68
 
 
69
    def test_create_account(self):
 
70
        """Create a new sip account"""
 
71
 
 
72
        CONFIG_ACCOUNT_TYPE = "Account.type"
 
73
        CONFIG_ACCOUNT_ALIAS = "Account.alias"
 
74
        HOSTNAME = "hostname"
 
75
        USERNAME = "username"
 
76
        PASSWORD = "password"
 
77
        
 
78
        accDetails = {CONFIG_ACCOUNT_TYPE:"SIP", CONFIG_ACCOUNT_ALIAS:"testsuiteaccount",
 
79
                      HOSTNAME:"192.168.50.79", USERNAME:"31416",
 
80
                      PASSWORD:"1234"}
 
81
 
 
82
 
 
83
        accountID = self.sflphone.addAccount(accDetails)
 
84
        print "New Account ID " + accountID
 
85
 
 
86
        return accountID
 
87
 
 
88
 
 
89
    def test_remove_account(self, accountID):
 
90
        """Remove test account"""
 
91
 
 
92
        self.sflphone.removeAccount(accountID)
 
93
        print "Account with ID " + accountID + " removed"
 
94
 
 
95
 
 
96
    # SCENARIO 1 Test 1
 
97
    def test_ip2ip_send_hangup(self):
 
98
        """Make a call to a server (sipp) on port 5062"""
 
99
        i = 0
 
100
        while(i < 500):
 
101
 
 
102
            callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
 
103
            time.sleep(0.5)
 
104
 
 
105
            self.sflphone.HangUp(callid)
 
106
            time.sleep(0.5)
 
107
 
 
108
            i = i+1
 
109
 
 
110
        self.sflphone.unregister()
 
111
        del self.sflphone
 
112
 
 
113
 
 
114
    # SCENARIO 1 Test 2
 
115
    def test_ip2ip_send_peer_hungup(self):
 
116
        """Make a call to a server (sipp) on port 5062"""
 
117
        i = 0
 
118
        while(i < 10):
 
119
 
 
120
            callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
 
121
            time.sleep(1.0)
 
122
 
 
123
            i = i+1
 
124
 
 
125
        del self.sflphone
 
126
 
 
127
 
 
128
    # SCENARIO 1 Test 3
 
129
    def test_ip2ip_recv_hangup(self):
 
130
        """Wait for calls, answer then hangup"""
 
131
 
 
132
        # Add callback for this test
 
133
        self.sflphone.onIncomingCall_cb = acceptOnIncomingCallHangup
 
134
 
 
135
        # Start Glib mainloop
 
136
        self.sflphone.start()
 
137
 
 
138
 
 
139
 
 
140
 
 
141
    # SCENARIO 1 Test 4
 
142
    def test_ip2ip_recv_peer_hungup(self):
 
143
        """Wait for calls, answer, peer hangup"""
 
144
 
 
145
        # Add callback for this test
 
146
        self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
 
147
 
 
148
        # Start Glib mainloop
 
149
        self.sflphone.start()
 
150
 
 
151
 
 
152
    # SCENARIO 2 Test 1
 
153
    def test_account_send_hangup(self):
 
154
        """Send new account call, hangup once peer answered"""
 
155
 
 
156
        i = 0
 
157
        while(i < 10):
 
158
 
 
159
            callid = self.sflphone.Call(PHONE1)
 
160
            time.sleep(0.2)
 
161
 
 
162
            self.sflphone.HangUp(callid)
 
163
            time.sleep(0.2)
 
164
 
 
165
            i = i+1
 
166
 
 
167
        # del self.sflphone
 
168
 
 
169
 
 
170
    # SCENARIO 2 Test 2
 
171
    def test_account_send_peer_hungup(self):
 
172
        """Send new account call, hangup once peer answered"""
 
173
 
 
174
        i = 0
 
175
        while(i < 10):
 
176
 
 
177
            callid = self.sflphone.Call(PHONE1)
 
178
            time.sleep(1.0)
 
179
 
 
180
            i = i+1
 
181
 
 
182
        del self.sflphone
 
183
 
 
184
 
 
185
    # SCENARIO 2 Test 3
 
186
    def test_account_recv_hangup(self):
 
187
        """Register an account and wait for incoming calls"""
 
188
 
 
189
        # Add callback for this test
 
190
        self.sflphone.onIncomingCall_cb = acceptOnIncomingCallHangup
 
191
 
 
192
        # Start Glib mainloop
 
193
        self.sflphone.start()
 
194
 
 
195
 
 
196
    # SCENARIO 2 Test 4
 
197
    def test_account_recv_peer_hungup(self):
 
198
        """Register an account and wait for incoming calls"""
 
199
 
 
200
        # Add callback for this test
 
201
        self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
 
202
 
 
203
        # Start Glib mainloop
 
204
        self.sflphone.start()
 
205
 
 
206
 
 
207
    # SCENARIO 3 Test 1
 
208
    def test_ip2ip_send_hold_offhold(self):
 
209
        """Send new call, hold this call, offhold, hangup"""
 
210
        i = 0
 
211
        while(i < 10):
 
212
 
 
213
            callid = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
 
214
            time.sleep(0.5)
 
215
 
 
216
            self.sflphone.Hold(callid)
 
217
            time.sleep(0.5)
 
218
 
 
219
            self.sflphone.UnHold(callid)
 
220
            time.sleep(0.5)
 
221
 
 
222
            self.sflphone.HangUp(callid)
 
223
            time.sleep(0.5)
 
224
 
 
225
            i = i+1
 
226
 
 
227
        del self.sflphone
 
228
 
 
229
 
 
230
    # SCENARIO 4 Test 1
 
231
    def test_account_send_transfer(self):
 
232
        """Send new calls, transfer it to a new instance"""
 
233
 
 
234
        i = 0
 
235
        while(i < 1):
 
236
 
 
237
            callid = self.sflphone.Call(PHONE1)
 
238
            time.sleep(1.0)
 
239
 
 
240
            self.sflphone.Transfer(callid,PHONE3)
 
241
            # self.sflphone.HangUp(callid)
 
242
            # time.sleep(1.0)
 
243
 
 
244
            i = i+1
 
245
 
 
246
 
 
247
    # SCENARIO 5 Test 1
 
248
    def test_ip2ip_recv_refuse(self):
 
249
        """Receive an incoming IP2IP call, refuse it"""
 
250
 
 
251
        # Add callback for this test
 
252
        self.sflphone.onIncomingCall_cb = refuseOnIncomingCall
 
253
 
 
254
        # Start Glib mainloop
 
255
        self.sflphone.start()
 
256
 
 
257
 
 
258
    # SCENARIO 6 Test 1
 
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)"""
 
261
        i = 0
 
262
        while(i < 500):
 
263
 
 
264
            callid1 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo)
 
265
            time.sleep(0.1)
 
266
 
 
267
            callid2 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo2)
 
268
            time.sleep(0.1)
 
269
 
 
270
            callid3 = self.sflphone.Call("sip:test@" + REMOTEADDR_lo3)
 
271
            time.sleep(0.1)
 
272
 
 
273
            self.sflphone.HangUp(callid1)
 
274
            time.sleep(0.1)
 
275
 
 
276
            self.sflphone.HangUp(callid2)
 
277
            time.sleep(0.1)
 
278
 
 
279
            self.sflphone.HangUp(callid3)
 
280
            time.sleep(0.1)
 
281
 
 
282
            i = i+1
 
283
 
 
284
        del self.sflphone
 
285
 
 
286
 
 
287
    # SCENARIO 6 Test 2
 
288
    def test_mult_ip2ip_send_hangup(self):
 
289
        """Receive multiple calls peer hangup"""
 
290
 
 
291
        # Add callback for this test
 
292
        self.sflphone.onIncomingCall_cb = acceptOnIncomingCall
 
293
 
 
294
        # Start Glib mainloop
 
295
        self.sflphone.start()
 
296
 
 
297
        del self.sflphone
 
298
 
 
299
 
 
300
 
 
301
# Open sflphone and connect to sflphoned through dbus
 
302
sflphone = SflPhoneCtrlSimple(True)
 
303
 
 
304
# Init test suite
 
305
testsuite = SflPhoneTests(sflphone)
 
306
 
 
307
# Register the first account available, should be the test account
 
308
sflphone.setFirstRegisteredAccount();
 
309
 
 
310
 
 
311
# ============================ Test Suite ============================
 
312
 
 
313
 
 
314
 
 
315
# SCENARIO 1: IP2IP Normal flow calls
 
316
 
 
317
# Test 1: - Send an IP2IP call
 
318
#         - Hangup
 
319
# testsuite.test_ip2ip_send_hangup()
 
320
 
 
321
# Test 2: - Send an IP2IP call
 
322
#         - Peer Hangup
 
323
# testsuite.test_ip2ip_send_peer_hungup()
 
324
 
 
325
# Test 3: - Receive an IP2IP call
 
326
#         - Hangup
 
327
testsuite.test_ip2ip_recv_hangup()
 
328
 
 
329
# Test 4: - Receive an IP2IP call
 
330
#         - Peer Hangup
 
331
# testsuite.test_ip2ip_recv_peer_hungup()
 
332
 
 
333
 
 
334
 
 
335
# SCENARIO 2: ACCOUNT Normal flow calls
 
336
 
 
337
# Test 1: - Send an ACCOUNT call
 
338
#         - Hangup
 
339
# testsuite.test_account_send_hangup()
 
340
 
 
341
# Test 2: - Send an ACCOUNT call
 
342
#         - Peer Hangup
 
343
# testsuite.test_account_send_peer_hungup()
 
344
 
 
345
# Test 3: - Receive an ACCOUNT call
 
346
#         - Hangup
 
347
# testsuite.test_account_recv_hangup()
 
348
 
 
349
# Test 4: - Receive an ACCOUNT call
 
350
#         - Peer Hangup
 
351
# testsuite.test_account_recv_peer_hungup()
 
352
 
 
353
 
 
354
 
 
355
# SCENARIO 3: IP2IP Call, HOLD/OFFHOLD
 
356
 
 
357
# Test 1: - Send an IP2IP call
 
358
#         - Put this call on HOLD
 
359
#         - Off HOLD this call
 
360
#         - Hangup
 
361
# testsuite.test_ip2ip_send_hold_offhold()
 
362
 
 
363
 
 
364
 
 
365
# SCENARIO 4: IP2IP Call, HOLD/OFFHOLD
 
366
 
 
367
# Test 1: - Send an IP2IP call
 
368
#         - Transfer this call to another sipp instance
 
369
#         - Hangup
 
370
# testsuite.test_account_send_transfer()
 
371
 
 
372
 
 
373
 
 
374
# SCENARIO 5: IP2IP Call, Refuse
 
375
 
 
376
# Test 1: - Receive an incoming call
 
377
#         - Hangup without answer
 
378
# testsuite.test_ip2ip_recv_refuse()
 
379
 
 
380
 
 
381
 
 
382
# SCENARIO 6: Multiple simultaneous calls
 
383
 
 
384
# Test 1: - Send multiple simultaneous IP2IP call
 
385
#         - Hangup
 
386
# testsuite.test_mult_ip2ip_send_hangup()
 
387
 
 
388
# Test 2: - Receive simultaneous IP2IP call
 
389
#         - Hangup
 
390
# testsuite.test_mult_ip2ip_send_hangup()