diff options
author | Benny Prijono <bennylp@teluu.com> | 2008-12-22 18:54:58 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2008-12-22 18:54:58 +0000 |
commit | 0723dbc601c74330f792db67ad75f6d580c30d8b (patch) | |
tree | a10e1cc45bdeb80210168f2e26421ae0d7e7295d /tests/pjsua/mod_recvfrom.py | |
parent | 341dea971f9d548cc922f5f3446d80130a1d57d9 (diff) |
Created top-level directory tests and moved test-pjsua there. This will be the placeholder for future developed tests
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2392 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'tests/pjsua/mod_recvfrom.py')
-rw-r--r-- | tests/pjsua/mod_recvfrom.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/pjsua/mod_recvfrom.py b/tests/pjsua/mod_recvfrom.py new file mode 100644 index 00000000..1510aed1 --- /dev/null +++ b/tests/pjsua/mod_recvfrom.py @@ -0,0 +1,94 @@ +# $Id$ +import imp +import sys +import inc_sip as sip +import inc_const as const +import re +from inc_cfg import * + +# Read configuration +cfg_file = imp.load_source("cfg_file", ARGS[1]) + +# Default server port (should we randomize?) +srv_port = 50070 + +def test_func(test): + pjsua = test.process[0] + dlg = sip.Dialog("127.0.0.1", pjsua.inst_param.sip_port, + local_port=srv_port, + tcp=cfg_file.recvfrom_cfg.tcp) + + last_cseq = 0 + last_method = "" + for t in cfg_file.recvfrom_cfg.transaction: + # Print transaction title + if t.title != "": + dlg.trace(t.title) + # Run command and expect patterns + for c in t.cmds: + if c[0] and c[0] != "": + pjsua.send(c[0]) + if len(c)>1 and c[1] and c[1] != "": + pjsua.expect(c[1]) + # Wait for request + if t.check_cseq: + # Absorbs retransmissions + cseq = 0 + method = last_method + while cseq <= last_cseq and method == last_method: + request, src_addr = dlg.wait_msg_from(10) + if request==None or request=="": + raise TestError("Timeout waiting for request") + method = request.split(" ", 1)[0] + cseq_hval = sip.get_header(request, "CSeq") + cseq_hval = cseq_hval.split(" ")[0] + cseq = int(cseq_hval) + last_cseq = cseq + last_method = method + else: + request, src_addr = dlg.wait_msg_from(10) + if request==None or request=="": + raise TestError("Timeout waiting for request") + + # Check for include patterns + for pat in t.include: + if re.search(pat, request, re.M | re.I)==None: + if t.title: + tname = " in " + t.title + " transaction" + else: + tname = "" + raise TestError("Pattern " + pat + " not found" + tname) + # Check for exclude patterns + for pat in t.exclude: + if re.search(pat, request, re.M | re.I)!=None: + if t.title: + tname = " in " + t.title + " transaction" + else: + tname = "" + raise TestError("Excluded pattern " + pat + " found" + tname) + # Create response + if t.resp_code!=0: + response = dlg.create_response(request, t.resp_code, "Status reason") + # Add headers to response + for h in t.resp_hdr: + response = response + h + "\r\n" + # Add message body if required + if t.body: + response = response + t.body + # Send response + dlg.send_msg(response, src_addr) + + # Expect something to happen in pjsua + if t.expect != "": + pjsua.expect(t.expect) + # Sync + pjsua.sync_stdout() + +# Replace "$PORT" with server port in pjsua args +cfg_file.recvfrom_cfg.inst_param.arg = cfg_file.recvfrom_cfg.inst_param.arg.replace("$PORT", str(srv_port)) + +# Here where it all comes together +test = TestParam(cfg_file.recvfrom_cfg.name, + [cfg_file.recvfrom_cfg.inst_param], + test_func) + |