Benny Prijono | 4b4adb3 | 2008-06-12 15:37:22 +0000 | [diff] [blame] | 1 | # $Id$
|
| 2 | import time
|
| 3 | import imp
|
| 4 | import sys
|
| 5 | import inc_param as param
|
| 6 | import inc_const as const
|
| 7 |
|
| 8 | # Load configuration
|
| 9 | cfg_file = imp.load_source("cfg_file", sys.argv[2])
|
| 10 |
|
| 11 | # Test title
|
| 12 | title = cfg_file.config.title
|
| 13 | port1 = "9060"
|
| 14 |
|
| 15 | # First pjsua
|
| 16 | p1 = 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
|
| 24 | p2 = 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
|
| 32 | def test_func(t):
|
| 33 | callee = t.process[0]
|
| 34 | caller = t.process[1]
|
| 35 |
|
| 36 | # Caller making call
|
| 37 | caller.send("m")
|
Benny Prijono | a8a144c | 2008-06-12 19:13:51 +0000 | [diff] [blame] | 38 | caller.send("sip:localhost:" + port1 + cfg_file.config.uri_param)
|
Benny Prijono | 4b4adb3 | 2008-06-12 15:37:22 +0000 | [diff] [blame] | 39 | 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 Prijono | 62ae5c6 | 2008-06-12 18:10:22 +0000 | [diff] [blame] | 53 | # 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 Prijono | 4b4adb3 | 2008-06-12 15:37:22 +0000 | [diff] [blame] | 60 | time.sleep(2)
|
Benny Prijono | 62ae5c6 | 2008-06-12 18:10:22 +0000 | [diff] [blame] | 61 | 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 Prijono | 4b4adb3 | 2008-06-12 15:37:22 +0000 | [diff] [blame] | 69 | 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 Prijono | 62ae5c6 | 2008-06-12 18:10:22 +0000 | [diff] [blame] | 79 | # 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 Prijono | 4b4adb3 | 2008-06-12 15:37:22 +0000 | [diff] [blame] | 111 | time.sleep(2)
|
Benny Prijono | 62ae5c6 | 2008-06-12 18:10:22 +0000 | [diff] [blame] | 112 | 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 Prijono | 4b4adb3 | 2008-06-12 15:37:22 +0000 | [diff] [blame] | 120 | callee.send("U")
|
| 121 | callee.expect(const.MEDIA_ACTIVE)
|
| 122 | caller.expect(const.MEDIA_ACTIVE)
|
| 123 |
|
Benny Prijono | 62ae5c6 | 2008-06-12 18:10:22 +0000 | [diff] [blame] | 124 | # 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 Prijono | 4b4adb3 | 2008-06-12 15:37:22 +0000 | [diff] [blame] | 131 | 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
|
| 149 | test = param.Test(title, run=[p1, p2], func=test_func)
|
| 150 |
|
| 151 |
|