Debian Codegraph @

Xpjproject/tests/pjsua/mod_pres.py

raw symbols SCIP
1 import time
2 import sys
3 import inc_const as const
4 import inc_util as util
5 from inc_cfg import *
6
7 # Load configuration
8 cfg_file = util.load_module_from_file("cfg_file", ARGS[1])
9
10
11 # Test body function
12 def test_func(t):
13 u1 = t.process[0]
14 uri1 = cfg_file.test_param.inst_params[0].uri
15 acc1 = "-1"
16 u2 = t.process[1]
17 uri2 = cfg_file.test_param.inst_params[1].uri
18 acc2 = "-1"
19
20 # if have_reg then wait for couple of seconds for PUBLISH
21 # to complete (just in case pUBLISH is used)
22 if u1.inst_param.have_reg:
23 time.sleep(1)
24 if u2.inst_param.have_reg:
25 time.sleep(1)
26
27 # U1 adds U2 as buddy
28 if u1.use_telnet:
29 u1.send("im add_b " + uri2)
30 else:
31 u1.send("+b")
32 u1.send(uri2)
33 u1.expect("Subscription state changed NULL --> SENT")
34 u1.expect("Presence subscription.*is ACCEPTED")
35 if not u2.inst_param.have_publish:
36 # Process incoming SUBSCRIBE in U2
37 # Finds out which account gets the subscription in U2
38 line = u2.expect("pjsua_pres.*subscription.*using account")
39 acc2 = line.split("using account ")[1]
40 # wait until we've got Online notification
41 u1.expect(uri2 + ".*Online")
42
43 # Synchronize stdout
44 u1.sync_stdout()
45 u2.sync_stdout()
46
47 # U2 adds U1 as buddy
48 if u2.use_telnet:
49 u2.send("im add_b " + uri1)
50 else:
51 u2.send("+b")
52 u2.send(uri1)
53 u2.expect("Subscription state changed NULL --> SENT")
54 # sometime it is NULL->SENT->ACCEPTED->ACTIVE
55 # some othertime NULL->SENT->ACTIVE
56 #u2.expect("Presence subscription.*is ACCEPTED")
57 u2.expect("Presence subscription.*is ACTIVE")
58 if not u1.inst_param.have_publish:
59 # Process incoming SUBSCRIBE in U1
60 # Finds out which account gets the subscription in U1
61 line = u1.expect("pjsua_pres.*subscription.*using account")
62 acc1 = line.split("using account ")[1]
63 # wait until we've got Online notification
64 u2.expect(uri1 + ".*Online")
65
66 # Synchronize stdout
67 u1.sync_stdout()
68 u2.sync_stdout()
69
70 # Set current account in both U1 and U2
71 if acc1!="-1":
72 if u1.use_telnet:
73 u1.send("acc prev " + acc1)
74 else:
75 u1.send(">")
76 u1.send(acc1)
77 u1.expect("Current account changed")
78 if acc2!="-1":
79 if u2.use_telnet:
80 u2.send("acc prev " + acc2)
81 else:
82 u2.send(">")
83 u2.send(acc2)
84 u2.expect("Current account changed")
85
86 # Synchronize stdout
87 u1.sync_stdout()
88 u2.sync_stdout()
89
90 # u2 toggles online status
91 if u2.use_telnet:
92 u2.send("im tog_state")
93 else:
94 u2.send("t")
95 u1.expect(uri2 + ".*status.*Offline")
96 u2.expect("offline")
97
98 # Synchronize stdout
99 u1.sync_stdout()
100 u2.sync_stdout()
101
102 # u1 toggles online status
103 if u1.use_telnet:
104 u1.send("im tog_state")
105 else:
106 u1.send("t")
107 u2.expect(uri1 + ".*status.*Offline")
108 u1.expect("offline")
109
110 # Synchronize stdout
111 u1.sync_stdout()
112 u2.sync_stdout()
113
114 # u2 set online status to On the phone
115 if u2.use_telnet:
116 u2.send("im pre_text 3")
117 else:
118 u2.send("T")
119 u2.send("3")
120 u1.expect(uri2 + ".*status.*On the phone")
121 u2.expect("On the phone")
122
123 # Synchronize stdout
124 u1.sync_stdout()
125 u2.sync_stdout()
126
127 # Synchronize stdout
128 u1.sync_stdout()
129 u2.sync_stdout()
130
131 # U1 send IM
132 if u1.use_telnet:
133 im_text = "Hello-World-from-U1"
134 u1.send("im send_im %s %s" % (uri2, im_text))
135 else:
136 im_text = "Hello World from U1"
137 u1.send("i")
138 u1.send(uri2)
139 u2.expect(" is typing")
140 u1.send(im_text)
141 u1.expect(im_text+".*delivered successfully")
142 u2.expect("MESSAGE from.*"+im_text)
143
144 # Synchronize stdout
145 u1.sync_stdout()
146 u2.sync_stdout()
147
148
149 # Here where it all comes together
150 test = cfg_file.test_param
151 test.test_func = test_func
152