blob: 07f5a0e7884d6d6f3613e75c42817c9a6a9b5369 [file] [log] [blame]
Benny Prijono4b4adb32008-06-12 15:37:22 +00001# $Id$
2import time
3import imp
4import sys
5import inc_param as param
6import inc_const as const
7
8# Load configuration
9cfg_file = imp.load_source("cfg_file", sys.argv[2])
10
11# Test title
12title = cfg_file.config.title
13port1 = "9060"
14
15# First pjsua
16p1 = param.Pjsua(
17 "callee",
18 args = cfg_file.config.callee_cfg.arg + " --local-port="+port1,
19 echo = cfg_file.config.callee_cfg.echo_enabled,
20 trace = cfg_file.config.callee_cfg.trace_enabled
21 )
22
23# Second pjsua, make call to the first one
24p2 = param.Pjsua(
25 "caller",
26 args = cfg_file.config.caller_cfg.arg + " --local-port=0",
27 echo = cfg_file.config.caller_cfg.echo_enabled,
28 trace = cfg_file.config.caller_cfg.trace_enabled
29 )
30
31# Test body function
32def test_func(t):
33 callee = t.process[0]
34 caller = t.process[1]
35
36 # Caller making call
37 caller.send("m")
Benny Prijonoa8a144c2008-06-12 19:13:51 +000038 caller.send("sip:localhost:" + port1 + cfg_file.config.uri_param)
Benny Prijono4b4adb32008-06-12 15:37:22 +000039 caller.expect(const.STATE_CALLING)
40
41 # Callee answers with 200/OK
42 time.sleep(1)
43 callee.expect(const.EVENT_INCOMING_CALL)
44 callee.send("a")
45 callee.send("200")
46
47 # Wait until call is connected in both endpoints
48 time.sleep(1)
49 if callee.expect(const.STATE_CONFIRMED, False)==None:
50 raise TestError("Call failed")
51 caller.expect(const.STATE_CONFIRMED)
52
Benny Prijono62ae5c62008-06-12 18:10:22 +000053 # Synchronize stdout
54 caller.send("echo 1")
55 caller.expect("echo 1")
56 callee.send("echo 1")
57 callee.expect("echo 1")
58
59 # Test that media is okay (with RFC 2833 DTMF)
Benny Prijono4b4adb32008-06-12 15:37:22 +000060 time.sleep(2)
Benny Prijono62ae5c62008-06-12 18:10:22 +000061 caller.send("#")
62 caller.send("1122")
63 callee.expect(const.RX_DTMF + "1")
64 callee.expect(const.RX_DTMF + "1")
65 callee.expect(const.RX_DTMF + "2")
66 callee.expect(const.RX_DTMF + "2")
67
68 # Hold call
Benny Prijono4b4adb32008-06-12 15:37:22 +000069 caller.send("H")
70 caller.expect(const.MEDIA_HOLD)
71 callee.expect(const.MEDIA_HOLD)
72
73 # Release hold
74 time.sleep(2)
75 caller.send("v")
76 caller.expect(const.MEDIA_ACTIVE)
77 callee.expect(const.MEDIA_ACTIVE)
78
Benny Prijono62ae5c62008-06-12 18:10:22 +000079 # Synchronize stdout
80 caller.send("echo 1")
81 caller.expect("echo 1")
82 callee.send("echo 1")
83 callee.expect("echo 1")
84
85 # Test that media is okay (with RFC 2833 DTMF)
86 caller.send("#")
87 caller.send("1122")
88 callee.expect(const.RX_DTMF + "1")
89 callee.expect(const.RX_DTMF + "1")
90 callee.expect(const.RX_DTMF + "2")
91 callee.expect(const.RX_DTMF + "2")
92
93 # Synchronize stdout
94 caller.send("echo 1")
95 caller.expect("echo 1")
96 callee.send("echo 1")
97 callee.expect("echo 1")
98
99 # UPDATE (by caller)
100 caller.send("U")
101 caller.expect(const.MEDIA_ACTIVE)
102 callee.expect(const.MEDIA_ACTIVE)
103
104 # Synchronize stdout
105 caller.send("echo 1")
106 caller.expect("echo 1")
107 callee.send("echo 1")
108 callee.expect("echo 1")
109
110 # Test that media is okay (with RFC 2833 DTMF)
Benny Prijono4b4adb32008-06-12 15:37:22 +0000111 time.sleep(2)
Benny Prijono62ae5c62008-06-12 18:10:22 +0000112 caller.send("#")
113 caller.send("1122")
114 callee.expect(const.RX_DTMF + "1")
115 callee.expect(const.RX_DTMF + "1")
116 callee.expect(const.RX_DTMF + "2")
117 callee.expect(const.RX_DTMF + "2")
118
119 # UPDATE (by callee)
Benny Prijono4b4adb32008-06-12 15:37:22 +0000120 callee.send("U")
121 callee.expect(const.MEDIA_ACTIVE)
122 caller.expect(const.MEDIA_ACTIVE)
123
Benny Prijono62ae5c62008-06-12 18:10:22 +0000124 # Synchronize stdout
125 caller.send("echo 1")
126 caller.expect("echo 1")
127 callee.send("echo 1")
128 callee.expect("echo 1")
129
130 # Test that media is okay (with RFC 2833 DTMF)
Benny Prijono4b4adb32008-06-12 15:37:22 +0000131 time.sleep(2)
132 caller.send("#")
133 caller.send("1122")
134 callee.expect(const.RX_DTMF + "1")
135 callee.expect(const.RX_DTMF + "1")
136 callee.expect(const.RX_DTMF + "2")
137 callee.expect(const.RX_DTMF + "2")
138
139 # Hangup call
140 time.sleep(1)
141 caller.send("h")
142
143 # Wait until calls are cleared in both endpoints
144 caller.expect(const.STATE_DISCONNECTED)
145 callee.expect(const.STATE_DISCONNECTED)
146
147
148# Here where it all comes together
149test = param.Test(title, run=[p1, p2], func=test_func)
150
151