summaryrefslogtreecommitdiff
path: root/tests/pjsua/mod_pres.py
blob: 7dafd52f78c79a2c659919c8c45e666318a84a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# $Id$
import time
import imp
import sys
import inc_const as const
from inc_cfg import *

# Load configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])


# Test body function
def test_func(t):
	u1 = t.process[0]
	uri1 = cfg_file.test_param.inst_params[0].uri
	acc1 = "-1"
	u2 = t.process[1]
	uri2 = cfg_file.test_param.inst_params[1].uri
	acc2 = "-1"

	# if have_reg then wait for couple of seconds for PUBLISH
	# to complete (just in case pUBLISH is used)
	if u1.inst_param.have_reg:
		time.sleep(1)
	if u2.inst_param.have_reg:
		time.sleep(1)

	# U1 adds U2 as buddy
	u1.send("+b")
	u1.send(uri2)
	u1.expect("Subscription state changed NULL --> SENT")
	u1.expect("Presence subscription.*is ACCEPTED")
	if not u2.inst_param.have_publish:
		# Process incoming SUBSCRIBE in U2
		# Finds out which account gets the subscription in U2
		line = u2.expect("pjsua_pres.*subscription.*using account")
		acc2 = line.split("using account ")[1]
	# wait until we've got Online notification
	u1.expect(uri2 + ".*Online")

	# Synchronize stdout
	u1.sync_stdout()
	u2.sync_stdout()

	# U2 adds U1 as buddy
	u2.send("+b")
	u2.send(uri1)
	u2.expect("Subscription state changed NULL --> SENT")
	u2.expect("Presence subscription.*is ACCEPTED")
	if not u1.inst_param.have_publish:
		# Process incoming SUBSCRIBE in U1
		# Finds out which account gets the subscription in U1
		line = u1.expect("pjsua_pres.*subscription.*using account")
		acc1 = line.split("using account ")[1]
	# wait until we've got Online notification
	u2.expect(uri1 + ".*Online")

	# Synchronize stdout
	u1.sync_stdout()
	u2.sync_stdout()

	# Set current account in both U1 and U2
	if acc1!="-1":
		u1.send(">")
		u1.send(acc1)
		u1.expect("Current account changed")
	if acc2!="-1":
		u2.send(">")
		u2.send(acc2)
		u2.expect("Current account changed")

	# Synchronize stdout
	u1.sync_stdout()
	u2.sync_stdout()

	# u2 toggles online status
	u2.send("t")
	u1.expect(uri2 + ".*status.*Offline")
	u2.expect("offline")
	
	# Synchronize stdout
	u1.sync_stdout()
	u2.sync_stdout()

	# u1 toggles online status
	u1.send("t")
	u2.expect(uri1 + ".*status.*Offline")
	u1.expect("offline")

	# Synchronize stdout
	u1.sync_stdout()
	u2.sync_stdout()

	# u2 set online status to On the phone
	u2.send("T")
	u2.send("3")
	u1.expect(uri2 + ".*status.*On the phone")
	u2.expect("On the phone")
	
	# Synchronize stdout
	u1.sync_stdout()
	u2.sync_stdout()

	# Synchronize stdout
	u1.sync_stdout()
	u2.sync_stdout()

	# U1 send IM
	im_text = "Hello World from U1"
	u1.send("i")
	u1.send(uri2)
	u2.expect(" is typing")
	u1.send(im_text)
	u1.expect(im_text+".*delivered successfully")
	u2.expect("MESSAGE from.*"+im_text)
	
	# Synchronize stdout
	u1.sync_stdout()
	u2.sync_stdout()


# Here where it all comes together
test = cfg_file.test_param
test.test_func = test_func